Parent: #495 Related: #401, #867
Problem
Pinned Home revision 7ed99c02 passes INT32_MAX to
Zig__GlobalObject__create as the macro-context sentinel. Its pinned
ScriptExecutionContext constructor translates that sentinel through the
process-wide identifier generator; the sentinel itself is never published as a
context ID.
zig-js currently routes every execution_context_id > 1, including
INT32_MAX, through explicit assignment. That exposes 2147483647 as the
stable ID and advances the internal allocator past it. This diverges from the
revision-pinned lifecycle contract and can desynchronize later lazy,
worker-provided, and test-isolation identifiers.
Required design
- Treat
INT32_MAXas a request for a fresh process identifier, never as an externally visible identifier. - Keep generated macro IDs, lazy main/default IDs, explicit Home worker IDs, and test-isolation replacement IDs in one collision-free process namespace.
- Preserve stable nonzero 32-bit identity, exact live lookup, natural/explicit retirement, and owner-thread teardown rules.
- Make sentinel creation failure-atomic: allocation/entropy/exhaustion must not publish a global lifecycle record or partial identifier mapping.
- Match the pinned Home constructor and isolation semantics without expanding the private ABI surface unless an exact consumer requirement proves necessary.
No-workaround rules
- No literal sentinel publication, random externally visible IDs, independent allocators that can collide, ID reuse, predictable fallback, leaked tombstones, scan-for-a-gap loop, arbitrary cap, signature/layout drift, weakened teardown, or fixture-only special case.
Acceptance
- A macro sentinel receives a fresh nonzero ID distinct from
INT32_MAX, and repeated lookup is stable. - Main/default, explicit worker, macro, and isolation sequences remain collision-free in both relevant creation orders.
- Retired IDs remain unresolvable and are never rebound to a newer context.
- Entropy/allocation/exhaustion paths publish no partial registry or lifecycle state.
- Focused lifecycle tests pass in Debug, ReleaseSafe, and TSan; exact Home and Bun fixtures plus public/private ABI audits remain green.