Skip to content

fix(compile-cache): bound persistence after termination signals - #36

Merged
steipete merged 2 commits into
mainfrom
codex/compile-cache-exit-budget
Sep 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/compile-cache-exit-budget

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown

Cold NODE_COMPILE_CACHE persistence can delay SIGTERM shutdown while Bun recompiles every loaded module. The reported OpenClaw Gateway measurement was 12.6 seconds cold versus 0.44 seconds warm (0.45 seconds with compile caching disabled).

Record native SIGTERM/SIGINT/SIGHUP before JavaScript dispatch and cap automatic exit persistence to 250 ms after those signals. Normal exits and explicit module.flushCompileCache() still fully persist. Signals received while automatic persistence is already waiting activate the same budget, including time already spent.

Generate and atomically publish cache entries after a quiet, mostly idle main-loop window. Background notifications are coalesced, the worker runs at reduced priority where available, and new module loads pause its batch. Weak VM wakeups keep deferred work moving without keeping the VM alive. Generation and disk I/O run outside the module-fetch lock. Standalone --compile --bytecode behavior is unchanged.

Current integration and native validation

Rebased onto openclaw/main 4c1d6f60d5320f08faf24681036ec9e38f4e5f72, including #37's deferred IPC/stdio ports on top of #28. Final head and tested native binary: 84f039d39c1eec8043e36328b93ede8bcea46be3. Both PR commits are unchanged by range-diff; the rebase had no conflicts. In the overlapping files, #37 adds IPC channel-reference fields and changes message/disconnect listener accounting. The termination-signal hooks, both idle-poll hooks, and budgeted persistence retain their exact placement and implementation. #37's IPC/stdio changes remain intact.

A fresh macOS arm64 release build of this combined result passed. The prior build directory had been removed, so this qualification recreated it using cached toolchain/dependencies. Main already contains the SDK27 signpost fix; no build-only patch or workflow/WebKit build-script change is included.

Native check on the final head Result
Bun module, standalone and bytecode suites 71 passed, 1 Windows-only skip, 1 existing debugger todo
Ported Node compile-cache suites 14/14 passed, including the large TypeScript fixture
test/js/bun/spawn/spawn.ipc.test.ts 19 passed
test/js/node/child_process/child_process.test.ts 91 passed, 12 existing skips, 1 existing todo
Compile-cache watch reload 1 passed
Source lints 176 passed
Rust, C++ and touched JS/docs formatting; JS lint Passed
Independent P0–P2 integration review Scoped-clean

All runtime suites passed on their first run after this rebuild. IPC/child-process suites used #37's qualification settings: BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1 BUN_GARBAGE_COLLECTOR_LEVEL=0, --max-concurrency 2, run sequentially. CI does not build or run these Bun suites; these are local native results.

Compile-cache regressions cover normal/full persistence; handled SIGTERM/SIGINT/SIGHUP; SIGUSR1; unhandled self-SIGTERM; a signal arriving during automatic persistence; accepted warm blobs; atomic entry lengths/hashes; frequent-timer idle; and deferred modules after JS timers are removed. The deferred-idle test detects ten seconds without progress while retaining its thirty-second overall limit. Its former throughput deadline failed under shared-host load on both old and rebased binaries despite continued cache publication; signal-to-exit assertions were not relaxed.

Retained F3 application measurements

The #37 rebase did not change a signal or event-loop hook site, so Gateway measurements were not rerun for this delta. The following measurements are from the immediately preceding F3 qualification, not the new 4c1d build.

Fresh detached OpenClaw origin/main at 20245922ee0d860065d2cb5d513e38950660b619, pnpm install and full pnpm build. Isolated HOME/state/config/cache, loopback ports, and no Node executable on the application PATH. SIGTERM sent immediately after Gateway listening. CLI warm is the second run with the same cache. The source-checkout launcher used its existing OPENCLAW_COMPILE_CACHE_DISABLED_RESPAWNED=1 marker to retain native compile caching.

Unpatched F3 release: 82b5d98968ecfc704192b42baa610518b8959a57 from #35, with the exact same Git tree as merged F3 main e6e11d6837699576857dccc02cdd9d046e5665c5. Candidate native build: 0d8659067e6444cb8df53310a2ca2442e179da41. All own builds/checks finished before measurements. The shared macOS host had substantial timing spread.

Three interleaved rounds per cell; median (min–max), seconds. All samples retained.

Metric Unpatched F3 F3 + compile-cache fix
Gateway cold: listening 17.043 (13.446–25.434) 13.283 (10.094–24.117)
Gateway cold: SIGTERM → exit 11.190 (9.753–12.619) 0.770 (0.397–1.048)
CLI --version cold 0.063 (0.052–0.068) 0.078 (0.067–0.083)
CLI --version warm 0.029 (0.026–0.030) 0.027 (0.026–0.032)
CLI status --json cold 16.145 (14.725–25.286) 13.200 (12.556–17.127)
CLI status --json warm 6.661 (3.288–7.305) 2.688 (2.500–8.919)

The short cold-version result was checked with five additional interleaved pairs: median wall time 91.3 ms unpatched versus 90.3 ms candidate (ranges 58.6–270.8 / 57.1–291.4 ms); warm 36.1 versus 35.2 ms (29.4–59.5 / 28.8–71.2 ms). All samples are retained. The requested warm CLI results showed no measured regression. The 250 ms budget covers compile-cache waiting; the table measures complete Gateway shutdown, including cleanup and scheduling delay. That cohort's integrity audit found 40,312 valid published entries and no partial/corrupt entries.

Earlier five-round pre-F3 qualification verified idle population: 6,219 of 6,221 entries were written before SIGTERM, with a 140 ms median shutdown after idle. Normal-exit TypeScript warm runs were 29.7 ms candidate versus 30.0 ms baseline. These remain historical design checks.

The previous F3 qualification passed all 12 Rust cross-target checks. Current-head Rust/type/lint checks are additionally tracked in this PR's fork CI; they do not replace the native runtime tests above.

Please hold for fork-owner review. This PR remains unmerged; no upstream PR has been submitted.

@steipete
steipete force-pushed the codex/compile-cache-exit-budget branch 2 times, most recently from 5449145 to 80cc4a6 Compare September 30, 2026 07:23
@steipete
steipete marked this pull request as ready for review September 30, 2026 07:23
@steipete
steipete force-pushed the codex/compile-cache-exit-budget branch from 80cc4a6 to 16560b0 Compare September 30, 2026 09:11
Keep full persistence for normal exits and explicit flushes. Record native termination signals before JS dispatch, defer background generation until the main loop is idle, and use weak VM wakeups so pending work is not stranded. Publish completed entries atomically without holding the module-fetch lock across disk I/O.
@steipete
steipete force-pushed the codex/compile-cache-exit-budget branch from 16560b0 to 84f039d Compare September 30, 2026 09:29
@steipete
steipete merged commit e8105cb into main Sep 30, 2026
8 checks passed
@steipete
steipete deleted the codex/compile-cache-exit-budget branch September 30, 2026 09:39
steipete added a commit that referenced this pull request Oct 1, 2026
…53)

On Linux, a tick that consumed pending native wakeups disabled idle accounting but could still park for the full poll timeout, so the idle time deferred compile-cache generation waits for was never counted and persistence starved (#36's 'compile cache wakes an idle loop for deferred modules' hit its watchdog 3/5). Poll without blocking after consuming wakeups so the next tick parks with idle accounting. #36's idle window and signal-exit budget are unchanged; 30/30 isolated runs pass, fault injection still trips the watchdog, cold SIGTERM exit ~264 ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant