pack-objects: fix tree_depth and layer invariants