ReviewOS

home-lang/home

Worker shutdown: cancel admitted ScriptExecutionContext C++ tasks

#565
Closed chris opened this 9 days ago ·
9 days ago

Follow-up to #66, #465, and #468.

Complete the bounded worker-side ownership tranche for C++ EventLoopTask payloads that have already been admitted through ScriptExecutionContext. Worker shutdown must remove its context from the identifier registry while holding the same lock used through lookup and enqueue, then cancel both local-FIFO and concurrent-queue CppTask payloads before JSC teardown. Cleanup-tagged tasks must execute their native cleanup action on the owning context thread. Ordinary tasks must be destroyed without executing their callback or entering stopped JavaScript. Destructors may enqueue more cleanup work, so cancellation must reach a fixed point without reordering unrelated task families.

Own the pinned ScriptExecutionContext.cpp native translation unit from Home without changing its class layout or losing the other implementations in Bun's generated unity unit. Add a build-time source guard for unity include drift and a deterministic native regression with exact branch/action counters plus a natural-drain positive control.

This issue intentionally does not claim raw VM work-pool quiescence (#468), safe cancellation for every non-C++ Zig task tag, or ownership of producers that bypass the ScriptExecutionContext identifier registry. Those remain part of #465/#468 and #66.

9 days ago

Completed and pushed to main in 71c8ff953aab47c918a4f79ebf87592c736c0508 (feat(runtime): cancel queued worker C++ tasks). The commit has Chris Breuer as both author and committer and no coauthor trailers.

Worker shutdown now removes its ScriptExecutionContext from the identifier registry under the same lock held through postTaskTo() lookup and enqueue. It then reaches a fixed point over the local FIFO and concurrent MPSC queue: ordinary C++ tasks are deleted without running their callback, while cleanup-tagged tasks perform their native cleanup action on the owning context thread before JSC teardown. Unrelated task tags retain their order. The early registry removal is recorded outside the class, so the pinned class layout remains unchanged and later GlobalObject destruction does not remove twice.

Home now owns the pinned UnifiedSource-src_jsc_bindings-4.cpp unit through a checked unity wrapper. It replaces only ScriptExecutionContext.cpp, preserves all 31 sibling includes in exact order, and rejects include drift during build configuration. The implementation is copied into the build cache so its quoted headers remain ABI-matched to the selected Bun build.

Verification:

  • native debug build and unchanged cached rebuild: 20/20 steps;
  • home_rt: 1,815 pass / 19 skip / 0 fail, 22/22 build steps;
  • native binding helpers: 5/5;
  • new native shutdown regression: five consecutive processes plus a final hardened replay, all passing; exact natural-drain and termination counters cover the local FIFO and concurrent queue;
  • aggregate runtime suite: 37/38 files pass, including every worker, snapshot, NAPI, FFI, and lifecycle file;
  • focused Pickier, Zig format, and diff whitespace checks pass.

The aggregate failure is native-package-run.test.mjs: a debug tsconfig-extends warning disappears after prior quiet-config invocations. It reproduces on the unchanged pre-checkpoint ReleaseFast binary and is tracked without weakened expectations in #566. It is not counted as a pass.

This issue's admitted identifier-based worker C++ task scope is complete. Raw-VM/work-pool quiescence remains #468. Producers that bypass the identifier registry, late generic queue admission, and non-C++ task families remain under #465/#66.

Sign in to comment on this issue.