Repository navigation
Conversation
Run runtime plugin compilation in owned one-shot esbuild processes so no compiler service or synchronous API worker remains resident. Join accepted browser catalog work before registry shutdown, then bound residual handles only after final cleanup and output draining.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces resident plugin compiler resources with one-shot processes and shortens the clean Gateway exit fallback after final cleanup. Example: A clean POSIX Gateway shutdown leaves a referenced 4,800 ms timer.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this useful maintainer-authored repair open; no concrete introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherPlugin source loading and browser import discovery invoke esbuild; registry retirement joins accepted catalog work, and CLI finalization drains logs and output before bounding residual process handles. flowchart TD
A[Plugin source and browser assets] --> B[Existing compilation owners]
B --> C[One-shot esbuild processes]
C --> D[Compiled modules and import metadata]
D --> E[Registry shutdown joins accepted work]
E --> F[CLI finalizers and output draining]
F --> G[Natural exit or settled SIGTERM fallback]
Technical reviewBest possible solution: Retain the focused compiler-lifetime and cleanup-ordering repair, completing the author’s declared Linux acceptance comparison before making the draft ready. Do we have a high-confidence way to reproduce the issue? Current-main source permits a referenced timer to retain a clean Gateway until the timer expires or the 10-second watchdog fires; no target code was executed during this read-only review. Is this the best way to solve the issue? The change uses existing compilation, registry lifecycle, and CLI finalization owners while preserving lazy compilation, synchronous module hooks, preload traversal, and failed-cleanup handling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f55024a909ac. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +54, Tests +148, Docs +5, Other +290. Total +497 across 14 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 9, 2026, 10:50 AM ET / 15:50 UTC. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28f88a9573
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| child = spawn(process.execPath, ["-e", browserCompilerHost, require.resolve("esbuild")], { | ||
| windowsHide: true, | ||
| stdio: ["ignore", "ignore", "inherit", "ipc"], | ||
| }); |
There was a problem hiding this comment.
Launch the compiler host in standalone script mode
When the Gateway runs from a compiled Bun standalone executable, process.execPath is the OpenClaw application, not a generic JavaScript runner. This spawn inherits the application environment without enabling BUN_BE_BUN, so it launches the OpenClaw entrypoint instead of evaluating browserCompilerHost. The existing resolveRuntimeScriptEnv() owner in cli-invocation.mjs explicitly documents that a compiled executable needs this mode to execute scripts. Consequently, a cold plugin browser catalog cannot complete its compiler exchange, and compiler disposal can reject the catalog request and retain a shutdown failure. Use the standalone-aware runtime environment when launching this host.
Useful? React with 👍 / 👎.
|
Landing note (maintainer review). On Team, the Gateway exited 3.4–4.8 s after "[shutdown] completed cleanly" on planned restarts. systemd went inactive 2.5–4.2 ms after the main exit, so the wait was Node itself. A live |
* fix(gateway): exit promptly after clean shutdown Run runtime plugin compilation in owned one-shot esbuild processes so no compiler service or synchronous API worker remains resident. Join accepted browser catalog work before registry shutdown, then bound residual handles only after final cleanup and output draining. * fix(gateway): reap batched browser compilers * test(gateway): align compiler lifecycle test allocation * fix(gateway): preserve natural exit margin and report lingering handles
What Problem This Solves
A clean Gateway shutdown could wait seconds for a referenced handle after its owners had settled. Runtime plugin compilation also left esbuild services resident, and terminating a source-compilation worker could leave a live service and zombie.
User Impact
Runtime plugin compilation now leaves no resident esbuild service or sync-API worker. Clean POSIX Gateway exits bound residual handles to 1,000 ms after finalizers, file logs and output pipes settle. Failed or retained cleanup keeps its existing handling. No configuration, dependency or schema changes.
Why This Change Was Made
Synchronous module hooks invoke the stock one-shot esbuild executable and reap it before returning. Browser catalogs use one lazy, short-lived compiler host per serialized batch. That host uses the async API, captures its native child handles, calls stop(), and awaits their close before exiting; Gateway awaits the host. Warm catalog hits spawn nothing. Registry shutdown joins admitted work and retains compiler cleanup failures separately from request serialization.
The snapshot owns import traversal, with one ordered set replacing duplicate queue/visited bookkeeping. Lazy parsing, cycles, re-exports, revision budgets and optional parse failures remain. Native source diagnostics retain source positions through CLI formatting. Net production growth is 77 lines for explicit ownership, failure receipts and final output draining. The existing POSIX SIGTERM fallback avoids forcing V8 teardown through process.exit().
Watchdog review follow-up
The final bound is one second, retaining margin for healthy natural exits. Before forcing SIGTERM, the existing synchronous one-line diagnostic now includes both active resource counts and
_getActiveHandles()constructor-name counts; it contains no addresses or payload data. A real-process regression proves a 600 ms timer exits naturally after finalization (the old 100 ms bound killed it), while a five-second lingering timer remains bounded after its durable finalizer receipt.The original 34-run Linux/btrfs results classify as 22 natural exits and 12 watchdog-forced exits. All 17 exact-parent runs were natural. At the prior 100 ms candidate bound, all five healthy controls were natural; all ten deliberate lingering-timer runs and both profiled lingering-timer runs were forced. Thus healthy forced exits were 0/5 at 100 ms, or 0/10 including the parent controls. Those original probes did not capture arming, so an exact historical armed-to-exit distribution is unavailable.
Follow-up head:
9241cdbe1235b5eb1eaad4b354b64b283f2d81b4. The 25-run follow-up records arming, JavaScript exit and OS process exit separately on the same synthetic Linux/btrfs shape. Healthy bounds alternate in repeated pairs. Local static checks/review were also active for part of this run; load is recorded. This is a lifecycle-margin measurement, not a new startup/CPU performance claim.At 100 ms, ranges are 0.214–0.444 ms to JavaScript exit and 65.205–133.188 ms to OS exit. At one second, ranges are 0.193–0.328 ms and 70.809–106.052 ms. The process can remain in native teardown past the timer deadline after JavaScript has exited; that is not a watchdog-forced shutdown. The one-second healthy clean-to-process-exit median is 123.764 ms (107.003–148.179 ms).
All five one-second deliberate lingering-handle runs were forced: arm-to-SIGTERM median 1,001.734 ms (1,001.416–1,006.089 ms), clean-to-process-exit median 1,084.242 ms (1,073.370–1,127.458 ms). Every follow-up run has zero startup compiler children and zero tracked survivors at exit. The forced log is one line, for example:
Node omits timers from
_getActiveHandles(), so the resource summary remains useful alongside handle types. The real Node process test separately verifiesSocketx2. The 100 ms replay changes only the test observer's timer delay using--watchdog-ms 100; it is not runtime configuration or an exact historical-binary rerun. The original 34-run classification above comes from the actual retained runs.Linux build inputs differ from the final follow-up only in test-allocation/assertion updates and equivalent comment/computed-property formatting; normalized emitted watchdog JavaScript matches. Exact-head verification for
9241cdbe1235b5eb1eaad4b354b64b283f2d81b4: CI 42668661311 passed, artifact build 42668660967 passed, and final security/gate reconciliation 42670294565 passed for this PR/head. The commit status API reports success foropenclaw/ci-gate,openclaw/security-sensitive-reviewandopenclaw/dependency-review. Both UI-e2e shards also passed. Skipped checks are not counted as proof. The one-second margin is conservative: the healthy samples did not require an increase, but the new 600 ms residual-work regression proves the extra margin preserves natural teardown.Focused follow-up proof: 175 run-loop tests and 12 CLI process tests pass; Codex autoreview is scoped-clean at P0–P2. The full Linux artifact build passed. Scoped check:changed completed; new assertion-comment placement and underscore-API lint findings were corrected and their affected checks rerun green. The known exact-parent main regressions remain below. The seven added regression-test lines have a matching allocation increase.
Original compiler-owner evidence (100 ms candidate)
These measurements describe the earlier 100 ms candidate at 28f88a9; they do not claim the same forced-tail latency at the final one-second bound.
Controlled Linux arm64/Node 24.22.1 comparison on btrfs, four CPU quota, 16 GiB/no swap: a real Gateway with 24 synthetic plugins exercising both compiler paths, roughly 38 workers, about 3.7 GiB main RSS and 24 owned children. Ten fault runs per revision use alternating A/A–B/B pairs; five healthy controls and two separate allocation profiles per revision. The controlled fault is a referenced 4.8-second timer injected after the clean receipt.
The compiler host costs about 32 ms (+19%) per cold catalog batch in fault runs; healthy controls show 174 → 190 ms. Healthy startup is 7,298 → 7,096 ms and CPU 13.059 → 13.082 s. No tracked child survives exit in either arm; candidate has no startup zombie. Spawn-PID tracking catches orphans as well as descendants. A/A repeat tail differences have median 8.0 ms before and 1.0 ms after. This does not measure a precise cgroup-empty timestamp because the harness remains alive.
Separate post-clean allocation samples (n=2 per revision, 32 KiB sampling) have median 3,553,512 → 3,981,672 bytes (+0.41 MiB, +12%). These are sampled tail allocations, not whole-startup allocations or retained heap; profiled timings are excluded from the table.
Idle esbuild alone did not reproduce a multi-second tail; the exact production waiting handle is not claimed as proven. The exact-parent source-owner test independently reproduces the live-service/zombie defect. The controlled timer proves the final exit bound after cleanup.
Rerun after building the selected revision; use a new btrfs output directory:
Omit --leak-ms for healthy controls; use separate --profile runs for post-clean allocation sampling. Ready for review; no merge requested.
Five initial automation runs had startup_failure with no jobs (ClawSweeper Dispatch, Auto response, Security Review, PR context and evidence, Labeler). Their startup cause is unclassified, not claimed as inherited. The later head-specific Security Review reconciliation and all applicable required commit statuses succeeded as linked above. The PR remains unmerged.