ReviewOS

home-lang/home

fix(ts): keep cached output on allocation-failed replacement

#906
Closed glennmichael123 opened this 8 days ago ·
8 days ago

The TS emit cache removes an existing key/value before allocating the replacement. A failed allocation therefore destroys the previous cached output, and both replacement and first insertion leak intermediate key/value allocations.

Reproduced on pinned Zig 0.17 with a new public fault-injection test root: before the fix, the unchanged test run had 19/20 passes, one failed replacement assertion, and four allocator-reported leaks. In particular, failing the replacement JS dupe after the old entry is removed makes a subsequent get return null.

Acceptance:

  • Allocate replacement key/value and reserve the map slot before retiring any previous value.
  • Preserve old output and diagnostic metadata on all tested replacement allocation failures; leave failed first insertions empty and leak-free.
  • Compile the shipped static library and run existing plus fault-injection tests on pinned Zig 0.17 and CI Zig 0.18 in Debug and ReleaseFast.
  • Re-run real TS driver/Program cache consumers. Do not claim broader compiler or Bun parity.

Related: #884 (dual-toolchain source coverage), #905 (cache-key correctness), #66.

8 days ago

Fixed and pushed directly to origin/main in 093ff6a as glennmichael123, no coauthors, exactly three files. getOrPut now reserves or finds the slot only after key/value allocations succeed; a failed allocation leaves the previous entry and its diagnostic metadata intact. Failed first insertion leaves no partial entry. The public fault-test root is wired into the shipped-library check/test graph.

Retained red baseline: 19/20 tests passed, one failed replacement assertion and four allocator-reported leaks under the pinned Zig. Same tests after fix: 20/20 plus shipped static-library compilation (9/9 build steps) on Zig 0.17.0-dev.2163 and Zig 0.18.0-dev.146 in Debug and ReleaseFast. Full pinned TS driver 214/214 and Program 321/321 pass; focused Zig 0.18 driver 4/4. Zig fmt --check and staged diff --check pass. Peak guarded tree footprint 2,298 MB under unchanged 3,840 MB ceiling. Remote main tip confirmed at the commit SHA. This closes the replacement/insertion allocation-failure gap, not full TS or Bun parity.

Sign in to comment on this issue.