Parent: #480 Related: #637, #645, #650
Evidence
The unchanged 4 MiB torn-object recovery witness passes normal Linux and local TSan, but fresh Linux TSan repeatedly reclaims no usable post-recovery allocation window:
- prior run: https://github.com/zig-utils/zig-js/actions/runs/32388315489/job/96488305083
- current run: https://github.com/zig-utils/zig-js/actions/runs/32394940123/job/96509796504
Both failures complete the pressure phase and full collection, publish no torn object, and leak nothing, but all 500 complete-object attempts catch OOM (made == 0).
Diagnosis
GcCellBacking.trimEmptyTailChunks deliberately retains up to eight empty tail chunks behind each live size-class prefix for task-to-task reuse. That is sensible with ordinary allocator headroom, but under Context.heap_limit_bytes those fully empty slabs still consume the same fail-closed quota needed by reclaimed object side storage. A full collection can therefore free the reserve graph yet strand the returned bytes behind the reusable-tail policy. #637 makes a new final slab adapt to available headroom; it does not return already-empty retained slabs when quota pressure remains high.
Required change
- Give full-collection cleanup a Context-level hard-cap headroom policy.
- Preserve bounded reusable tails when quota headroom is healthy.
- Under high quota utilization, release every empty tail slab so reclaimed bytes are available to complete object publication and side stores.
- Apply the same policy to explicit, quiescent, serialized allocation-failure, and parallel allocation-failure full collections.
- Add deterministic backing-policy coverage plus the unchanged 4 MiB end-to-end witness.
No-workaround rules
No cap increase, reserve inflation, fewer pressure/probe iterations, weaker made > 0 oracle, forced arena mode, skipped TSan, or unconditional cache deletion in healthy heaps. Live slabs and exact realm ownership remain untouched.
Acceptance
- Healthy heaps retain the existing bounded reuse tail.
- Hard-cap pressure releases only fully empty tails and restores usable headroom.
- The unchanged torn-object witness passes normal and TSan with at least one validated post-recovery object.
- Full units have zero regressions/leaks.
- Test262 flips 0 (allocator retention policy only).