Repository navigation
fix(gateway): prevent readiness probes from freezing the main thread - #200370
Conversation
Route asynchronous runtime viability probes through the existing broker host without re-entering command diagnosis. Keep broker state separate from startup and detect removed runtimes even while the transport is unavailable. Preserve the detection introduced by @obviyus in #200038 and the spawn ownership established by #150564.
|
🦞👀 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 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. |
|
Codex review: needs changes before merge. What this changesRoute asynchronous Node runtime probes through the existing spawn broker while preserving runtime-failure detection. Example: A readiness request reaches an approximately 8 GB RSS Linux Gateway.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — suspected predecessor, not a causality claim: source commit Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 2 items remain This PR addresses a concrete Gateway stall still reachable on current main, but introduces a broken extracted-tool runtime and a static import cycle. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway readiness, health, and recovery call the child-runtime owner, which launches Node and returns availability or loader diagnostics. flowchart TD
A[Readiness and health requests] --> B[Child runtime viability]
B --> C[Shared broker context]
C --> D[Existing spawn broker]
B --> E[Native launch without broker]
D --> F[Node version probe]
E --> F
F --> G[Availability and recovery]
Technical reviewBest possible solution: Keep the existing broker and runtime-classification owners, repair their dependency and extraction boundaries, and preserve uncached loader detection. Do we have a high-confidence way to reproduce the issue? Current-main source confirms readiness reaches native execFile, and the report identifies the Linux clone stack and production stall; this review did not execute a reproduction. Is this the best way to solve the issue? Reusing the existing broker is the smallest coherent fix because it removes the large-parent fork while retaining the loader-detection contract and native-only scopes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f57dbb4ff67e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +39, Tests +65, Docs +3. Total +107 across 5 files. Added test files: 0. 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. LabelsLabel changes:
Label justifications:
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 16, 2026, 9:59 PM ET / November 17, 2026, 02:59 UTC. |
Remove the type dependency cycle found by PR CI while retaining the existing host factory and operations. Keep runtime viability below host startup and diagnosis.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0be6550dd4
ℹ️ 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".
| const broker = getSpawnBroker(); | ||
| if (broker) { | ||
| const remote = broker.spawnExeca([execPath, "--version"], { |
There was a problem hiding this comment.
Keep broker restart diagnosis independent of the failed broker
If an already-registered broker dies and its replacement cannot start because Node reports an ambiguous loader failure such as version 'GLIBC_2.38' not found, its own runtime diagnosis now uses the unavailable broker. In host.ts, failure handling sets available = false before observeBrokerChildDiagnostics calls prepareChildRuntimeFailure; this new branch therefore rejects instead of probing Node. prepareBrokerFailureCause converts that rejection into an aggregate error, so the runtime is never marked unavailable and automatic runtime recovery is not triggered. Subsequent readiness observations also report the runtime as available because the executable still passes stat. Keep the broker's own restart diagnosis in an explicit native-only scope while retaining broker routing for ordinary readiness probes.
Useful? React with 👍 / 👎.
Integrate main to repair the CI merge-ref declaration failure: native resource lifecycle consumers now use two host getters added after the original base. Include those existing operations in the leaf contract. The selected SDK package boundary compile, core types, dependency-cycle guard, and 35 viability/broker tests pass.
Keep extracted native wrapper sources closed over the runtime viability imports. The missing state module broke isolated bootstrap, which cascaded into private provisioning fixture failures. Existing runtime probes remain unchanged.
|
Merged via squash.
|
…penclaw#200370) * fix(gateway): keep runtime probes off the main spawn thread Route asynchronous runtime viability probes through the existing broker host without re-entering command diagnosis. Keep broker state separate from startup and detect removed runtimes even while the transport is unavailable. Preserve the detection introduced by @obviyus in openclaw#200038 and the spawn ownership established by openclaw#150564. * refactor(process): separate the spawn broker host contract Remove the type dependency cycle found by PR CI while retaining the existing host factory and operations. Keep runtime viability below host startup and diagnosis. * fix(process): include broker state in the PR wrapper runtime inventory Keep extracted native wrapper sources closed over the runtime viability imports. The missing state module broke isolated bootstrap, which cascaded into private provisioning fixture failures. Existing runtime probes remain unchanged.
…0216) Move private socket directory creation and cleanup to the existing broker process. Keep exclusive admission, private permissions, startup errors, and joined cleanup. Parent crash cleanup follows successful readiness. Accept the recoverable private directory orphan before readiness. (cherry picked from commit 775be7a) Release adaptation: retain the stable inline 103-byte socket path bound instead of importing the newer socket-directory helper. Reuse the saved real cold-resource regression with direct filesystem spies instead of introducing the later all-filesystem observation helper. Required companion: #200453 (22d5c87) will follow to preserve the parent-decided directory in broker bootstrap. #200320 source capture, #200370 host/readiness interface, #200567 retired request cleanup, and 4a9273a export correction are separate owners, not prerequisites for this stable private-directory lifetime. Co-authored-by: RomneyDa <[email protected]>
…200370) * fix(gateway): keep runtime probes off the main spawn thread Route asynchronous runtime viability probes through the existing broker host without re-entering command diagnosis. Keep broker state separate from startup and detect removed runtimes even while the transport is unavailable. Preserve the detection introduced by @obviyus in #200038 and the spawn ownership established by #150564. * refactor(process): separate the spawn broker host contract Remove the type dependency cycle found by PR CI while retaining the existing host factory and operations. Keep runtime viability below host startup and diagnosis. * fix(process): include broker state in the PR wrapper runtime inventory Keep extracted native wrapper sources closed over the runtime viability imports. The missing state module broke isolated bootstrap, which cascaded into private provisioning fixture failures. Existing runtime probes remain unchanged. (cherry picked from commit df78722) Companion audit: context-state and host-contract preserve broker owner; focused runtime probe test retained. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 8899507525a1caaf7947d042270257b3f33c24f4)
Related: #200038, #150564
What Problem This Solves
Readiness requests can freeze every WebSocket client and RPC on a large Linux Gateway. In the reported November 16 production incident at
aeabca2e, an approximately 8 GB RSS Gateway stalled for 3,682 ms duringgateway:http; its main thread spent 3,576 ms in D-state while launching the child-runtime probe. An earlier observation stalled for 877 ms.User Impact
When a spawn broker is available, asynchronous runtime viability checks launch from that small process. Readiness and health keep detecting removed/replaced runtimes and loader failures on every observation, with the same unavailable results and recovery hook. CLI and other scopes without a broker retain native execution. No configuration, protocol, or persisted-state changes.
Why This Change Was Made
The probe added by #200038 called native
execFile(process.execPath, ["--version"])directly. Linuxuv_spawnforks usingclone(SIGCHLD|CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID), so the calling Gateway thread copies its large address space. Under btrfs I/O pressure, the observed stack wasclone → copy_process → dup_mm → dup_mmap → __vma_start_write → __vma_start_exclude_readers; the JavaScript profile reachedprepareChildRuntimeViability → probeChildRuntimeExecutable → execFile → spawnthrough readiness preparation.Use the existing host's
spawnExecalaunch primitive directly. It never enters the command runner's runtime-failure diagnosis, so a failed probe cannot recursively request another probe. Preserve the 1-second timeout, 8 KiB output bound, caller environment/cwd, and loader diagnostics; drain and join the broker child before publishing. There is no result cache or polling skip.Separate the existing broker scope/state from Gateway startup so low-level runtime workers can read the current broker without importing its lazy host factory. Both existing context exports and the probe use the same state owner. The host contract is separate from its implementation so this lookup also avoids a static dependency cycle; the existing factory and operations are unchanged. Include the new runtime state module in the trusted PR wrapper inventory so isolated bootstrap/provisioning retains its complete import closure. A transport failure still checks executable existence asynchronously, so an unavailable broker cannot hide a removed runtime during its own restart.
Thanks to @obviyus (Ayaan Zaidi) for the original runtime/loader detection in #200038; this preserves that behavior while following #150564's spawn ownership.
Evidence
execFilelaunches despite a ready broker. Final candidate: 3 passed, zero parentexecFile/spawn/spawnSynclaunches, three broker requests per case, and unavailable publication for removed and loader-broken runtimes. The removed-runtime case also closes the broker before the failure observation.available: trueinstead offalse; the async existence check fixes it without a native retry. The final affected runtime/recovery run passed 33 tests. The prior 93-test run also covered health/readiness, run-loop recovery, broker startup fallback, and native broker lifecycle paths. The final contract extraction rerun passed all 15 viability tests and 16 host tests, plus three of four startup fallback cases. The timeout fallback case reached its outer 30-secondspawnSyncdeadline; a scoped replay passed (1 passed / 3 filtered skips, 58.12 s wall). After integratingmain, the final rerun passed all 35 viability/broker tests, including all four startup fallback cases, in 74.94 s wall. The earlier timeout cause is not established, and passing replays are not claimed as a fix.OPENCLAW_VITEST_RUNTIME=node pnpm test src/infra/child-runtime-viability.async.test.ts --maxWorkers=1. Final affected run included that file pluschild-runtime-viability.test.tsandprocess-respawn.runtime-unavailable.test.ts: 33 passed, 108.03 s wall including worker preparation (84.17 s); the three tests in the changed file totaled 2.78 s. This proves launch routing and detection, rather than reproducing the Linux kernel stall duration.pnpm tsgo:core, targeted infra/services test typechecks (3.8 s / 3.3 s), changed-file oxlint, formatting, andgit diff --checkpassed. Fullpnpm buildwith integratedmainpassed in 5m 26.4s, including declarations and runtime/lazy-boundary checks. The build caught the initial startup-import expansion; the state split removes it. First-head CI caught a type-import cycle incheck-guards-architecture(run 44005142337); the host contract extraction fixes it, and the local Madge guard now reports 0 cycles. CI then compiled newermainlifecycle callers against the extracted contract and found two missing resource-state getters (run 44007179770). Integratingmainand including those existing getters fixes that failure: the full SDK declaration preparation and selected codex/slack/telegram package boundary compile passed locally (111.494 s). Core types and the cycle guard passed again. A one-line host lint overage was resolved by combining the type exports; final targeted lint/format pass. Subsequent CI exposed the missingcontext-state.tswrapper inventory entry through eager-import closure and native provisioning tests; adding that runtime source completes the cutover without pulling the host startup factory into low-level workers. After the repair, the three failed files rerun locally with 41 passed / 1 failed / 1 skipped (819.47 s wall): both closure files pass all 24 tests, and the CI-failing provisioning cases exercised on macOS pass (the unsupported-filesystem cell is platform-skipped). The remaining failure is the additional macOS-only warm/sparse sibling scenario, which hit its existing 120 s timeout with 246.517 s observed. No assertion failure identified a functional regression; the timeout cause remains unresolved, and no timeout relaxation or suppression was added. Current-head CI passed in run 44011585588. The CI watcher reported GREEN with zero pending checks; 21 superseded checks explain the raw GitHub failure rollup. Native landing verified head718b3368d3986726b1656143b9c35dccbefa5f0cmerged asdf78722789e096c3dfc7154526d67037d6ed4803.$autoreview, Codex engine, complete local snapshot against the integratedb4fc05346afb4d6c88b4ab2e8ae3d1eba380917fbaseline, on the complete final staged snapshot, integrated withmainatb4fc05346afb4and committed as718b3368d3986: scoped-clean through P2, no remaining accepted findings. Author simplification pass retained only the routing, necessary build boundary, and regression repair. Production +66 net lines; tests +65 net lines, two new parameterized cases.src/infra/child-runtime-viability.ts:286, called only by the synchronous SQLite reader atsrc/infra/sqlite-readonly-worker.ts:614. Readiness and health runtime observations use async preparation and do not reach it. No STOP condition or broker protocol gap.