Child tracker from #11/#16/#1.
Goal
Define and maintain the public heap-cap and per-thread OOM contract for zig-js contexts, including how allocation pressure is surfaced to hosts and to shared-realm Thread joiners.
Current status
The original PR-249 blocker semantics/oom-one-thread.js is now promoted. GC-backed capped contexts can collect and retry at safe GC cell allocation failures and ArrayBuffer byte allocation failures, and the reference recovery witness passes.
Implemented contract:
Context.Options.heap_limit_bytesapplies a thread-safe outstanding-byte budget to Context-owned allocator traffic.Context.heapBudgetStats()reports limit, used, peak, and remaining bytes for capped contexts.- Top-level host evaluation reports unrecovered cap pressure as Zig
error.OutOfMemory. - A capped context prebuilds an immutable
OutOfMemoryErrorobject so shared-realmThreadcompletion can publish a deterministic JS error value even when ordinary heap allocation is exhausted. join()rethrows that reserved object, and already-createdasyncJoin()reactions reject with it when they can be delivered.- Allocation-site OOM can become catchable by active JS handlers in the covered interpreter/tree-walker paths, including catch-binding pressure that has pre-reserved environment storage.
- Arena-backed caps remain fail-closed and non-reclaimable unless callers opt into GC-backed recovery.
- GC-backed capped contexts can recover after unreachable pressure is collected at safe allocation-recovery points.
Remaining linked work
- #30 tracks the remaining emergency-recovery perfection work: no-GIL root-publication recovery, side-store pressure, and avoiding lock-order deadlocks during collect/retry.
- Keep documenting any new capped allocation classes as either fail-closed, catchable, or recoverable.
- Keep the PR-249 audit/probe evidence current if a future behavior change affects heap-cap cases.
Acceptance criteria
- Heap-cap behavior is documented for arena-backed and GC-backed contexts.
- Allocation failure remains observable as ordinary JS/host errors without corrupting GC state.
- One capped shared-realm
Threadcan hit OOM while siblings and cleanup/finalization remain well-defined. - Promoted reference coverage and focused unit tests prove the intended supported contract.
- Remaining uncovered allocation classes are tracked by narrower follow-up issues rather than hidden behind this parent tracker.