If the item stack size is too large (e.g. 400M), then after ~4.2G items, the memory unit counter goes back to 0.
Was able to fix it by making every instance of unit_data.comfortable at most 2147483647 (I didn't check if there's a better upper bound, just copied the number from the function update_combinator).
I think this happens because every container with n items displays mod(n, ~4.2G) items (If you hover over a chest with 10G of an item, it will show it has 1.4G).
Thanks in advance :)