Skip to content

fix(gateway): prevent readiness probes from freezing the main thread - #200370

Merged
steipete merged 4 commits into
mainfrom
codex/runtime-probe-spawn-broker
Nov 17, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/runtime-probe-spawn-broker

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 during gateway: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. Linux uv_spawn forks using clone(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 was clone → copy_process → dup_mm → dup_mmap → __vma_start_write → __vma_start_exclude_readers; the JavaScript profile reached prepareChildRuntimeViability → probeChildRuntimeExecutable → execFile → spawn through readiness preparation.

Use the existing host's spawnExeca launch 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

  • Owning-boundary regression with a real broker (Node on macOS): base 2 failed / 1 passed, each new case recording 3 parent execFile launches despite a ready broker. Final candidate: 3 passed, zero parent execFile/spawn/spawnSync launches, 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.
  • Codex review found that a registered but unavailable broker could hide removal during restart. This reproduced as 1 failed / 2 passed, with available: true instead of false; 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-second spawnSync deadline; a scoped replay passed (1 passed / 3 filtered skips, 58.12 s wall). After integrating main, 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.
  • Regression command: OPENCLAW_VITEST_RUNTIME=node pnpm test src/infra/child-runtime-viability.async.test.ts --maxWorkers=1. Final affected run included that file plus child-runtime-viability.test.ts and process-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, and git diff --check passed. Full pnpm build with integrated main passed 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 in check-guards-architecture (run 44005142337); the host contract extraction fixes it, and the local Madge guard now reports 0 cycles. CI then compiled newer main lifecycle callers against the extracted contract and found two missing resource-state getters (run 44007179770). Integrating main and 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 missing context-state.ts wrapper 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 head 718b3368d3986726b1656143b9c35dccbefa5f0c merged as df78722789e096c3dfc7154526d67037d6ed4803.
  • $autoreview, Codex engine, complete local snapshot against the integrated b4fc05346afb4d6c88b4ab2e8ae3d1eba380917f baseline, on the complete final staged snapshot, integrated with main at b4fc05346afb4 and committed as 718b3368d3986: 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.
  • Synchronous runtime probing remains at src/infra/child-runtime-viability.ts:286, called only by the synchronous SQLite reader at src/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.

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.
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T03:16:07.494604Z 0441f44 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Route 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.

  • Before: The reported native probe launch stalled the Gateway for 3,682 ms.
  • After: With a broker available, the broker launches Node --version instead of the large Gateway process.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The repair has clear value and meaningful real-process regression coverage, but two introduced integration defects block merge and shipped-entry-point proof is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A readiness request can freeze every connected client while a large Linux Gateway forks its Node probe.
Reason: The reported incident and current source establish a concrete availability problem, and the maintainer-authored direction reuses existing infrastructure without adding configuration or persistent state.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit db4b2edd6d08 by Peter Steinberger; no PR verified.

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
Reviewed head: ca903e569cf5f1bf49296e418f2abee747887c54

Before merge

  • Include the new state module in the extracted wrapper inventory (P1) - The new unconditional import is reachable from runtime files already extracted by scripts/pr, but scripts/pr-lib/wrapper-components.txt omits context-state.ts. Extracted wrapper execution therefore fails with Cannot find module before lease/bootstrap work can proceed. Exact-head checks-node-compact-small-1 reports both the missing inventory entry and the failing bootstrap. Add the module to the existing inventory and retain the closure assertions.
  • Break the new static dependency cycle through the broker host (P2) - Importing SpawnBrokerHost here closes child-runtime-viability.ts → context-state.ts → host.ts → child-runtime-viability.ts. The repository's static cycle checker intentionally counts type-only imports, so this split still fails check:madge-import-cycles; exact-head architecture CI reports that failure. Put the required transport contract behind an acyclic leaf boundary rather than importing the concrete host back into the low-level state owner.

Findings

  • [P1] Include the new state module in the extracted wrapper inventory — src/infra/child-runtime-viability.ts:7
  • [P2] Break the new static dependency cycle through the broker host — src/process/spawn-broker/context-state.ts:2

Tests

  • Missing end-to-end proof: Supply redacted after-fix output from a real Linux Gateway showing readiness probes use the broker while concurrent requests remain responsive and removed or loader-broken runtimes remain unavailable.
Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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:

  • [P1] Include the new state module in the extracted wrapper inventory — src/infra/child-runtime-viability.ts:7
    The new unconditional import is reachable from runtime files already extracted by scripts/pr, but scripts/pr-lib/wrapper-components.txt omits context-state.ts. Extracted wrapper execution therefore fails with Cannot find module before lease/bootstrap work can proceed. Exact-head checks-node-compact-small-1 reports both the missing inventory entry and the failing bootstrap. Add the module to the existing inventory and retain the closure assertions.
    Confidence: 1
  • [P2] Break the new static dependency cycle through the broker host — src/process/spawn-broker/context-state.ts:2
    Importing SpawnBrokerHost here closes child-runtime-viability.ts → context-state.ts → host.ts → child-runtime-viability.ts. The repository's static cycle checker intentionally counts type-only imports, so this split still fails check:madge-import-cycles; exact-head architecture CI reports that failure. Put the required transport contract behind an acyclic leaf boundary rather than importing the concrete host back into the low-level state owner.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f57dbb4ff67e.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:madge-import-cycles
  • pnpm check:import-cycles
  • pnpm test test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts test/scripts/pr-worktree-provision.test.ts --maxWorkers=1
  • OPENCLAW_VITEST_RUNTIME=node pnpm test src/infra/child-runtime-viability.async.test.ts src/infra/child-runtime-viability.test.ts src/infra/process-respawn.runtime-unavailable.test.ts src/process/spawn-broker/context.test.ts --maxWorkers=1
  • pnpm tsgo:core

What I checked:

PR surface

Source +39, Tests +65, Docs +3. Total +107 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 62 23 +39
Tests 1 66 1 +65
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 131 24 +107

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: The reported readiness probe freezes unrelated WebSocket and RPC work across a running Linux Gateway.
  • add merge-risk: 🚨 automation: The omitted runtime inventory entry breaks extracted PR-wrapper execution, as exact-head CI demonstrates.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The reported readiness probe freezes unrelated WebSocket and RPC work across a running Linux Gateway.
  • merge-risk: 🚨 automation: The omitted runtime inventory entry breaks extracted PR-wrapper execution, as exact-head CI demonstrates.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +157 to +159
const broker = getSpawnBroker();
if (broker) {
const remote = broker.spawnExeca([execPath, "--version"], {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 17, 2026
@steipete
steipete merged commit df78722 into main Nov 17, 2026
146 of 148 checks passed
@steipete
steipete deleted the codex/runtime-probe-spawn-broker branch November 17, 2026 03:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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.
RomneyDa added a commit that referenced this pull request Nov 18, 2026
…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]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant