Skip to content

fix: keep Gateway runtime checks off the main thread - #197975

Merged
steipete merged 2 commits into
mainfrom
fix/gateway-runtime-readiness-io
Nov 13, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/gateway-runtime-readiness-io

Conversation

@steipete

@steipete steipete commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway-wide stalls when a runtime executable lookup blocks during readiness checks or child-process failure diagnosis.

User Impact

Gateway readiness, health, startup, and recovery can wait for filesystem I/O without blocking unrelated requests. Missing or replaced runtimes still trigger the existing unavailable-runtime and recovery behavior. Public synchronous APIs retain their contracts.

Why This Change Was Made

The existing child-runtime owner now prepares physical facts asynchronously and carries them to publication, where callers also consult current logical state. Native asynchronous diagnosis stays separate from the failing command runner. Child processes retain independent physical-close settlement, so delayed or rejected diagnosis cannot release cleanup custody early. The broker shares one terminal diagnosis while preserving its already-ready failure behavior. No new cache, configuration, schema, or recovery manager is introduced.

This is an availability tradeoff, not a speedup. On a synthetic real-HTTP readiness workload (44 channels, 176 accounts), measured median overhead was approximately 0.013 ms wall, 8.15 µs main-thread CPU, 27.32 µs parent-process CPU, and 2658 sampled allocation bytes per request. All medians increased; loaded-host A/A variability and paired increases are retained below. Production code grows 315 lines to preserve the named synchronous interfaces and separate physical-close from asynchronous diagnosis. One import-time executable stat and explicit synchronous SDK/OOM/SQLite entry points remain.

Evidence

  • Real Gateway HTTP-server/TCP clients: while executable fs.promises.access completion is held, /readyz remains pending and concurrent /healthz returns 200. Changing drain state before release produces /readyz 503 with gateway-draining. This exercises the production HTTP server/router/request lifetime; it is not a full model/plugin startup claim. The existing main-thread fs spy also passes.
  • Integrated candidate: both HTTP tests and the complete agent/environment/artifact RPC flow pass; a source-matching canonical build and three real restart cases pass (original crash/partial-shutdown resume, direct child continuation, and continuation after requester completion). The three previously failed wrapper closure/resolution selectors also pass.
  • Canonical Madge reproduced the owned static type cycle on the previous head. Readiness contracts now live in the existing health type owner; both static and runtime-value cycle guards pass. The new Windows diagnostic module is included in the wrapper inventory.
  • pnpm check:changed --staged --base 2035b073 completed 39/40 stages: all types, lint, format, ratchets and other guards passed. Its dead-export stage reproduces identically on clean exact 2035b073: a test-only trusted-proxy helper export introduced by feat(identity): accept co-author credit from trusted-proxy headers #196867 (f4f290c52) and eight live lazy-UI capability exports introduced by feat(ui): add optional inline command trail #197466 (d90d52cc). These are separate main regressions, not suppressed or treated as noise; no unrelated UI rewrite is included here. pnpm deadcode:unused-files passes with zero production/full-tree entries.
  • Affected Chromium routing (5) and post-deploy E2E (6) pass on the integrated candidate, with a current production UI build and joined Chromium exit. Fresh four-pass Codex P2 review against 2035b073 is scoped-clean; it was static with partitioned supplied context, not four independent complete-context executions. Prior owner 131-case, restart/startup and Windows/Workshop proofs remain explicitly scoped to their recorded predecessor source.
  • Regression guards cover readiness accessSync 2→0 for two requests, cached-health 2 sync→1 async observation, and diagnosed failure accessSync 1 + statSync 1→0 sync with asynchronous observations. These are owner API-call counts, not kernel syscall counts.

The main integration is pinned to 2035b073 for two named CI prerequisites: the createWithRequest producer and merged #197976 protocol inventory repair. Two missed fixture migrations are repaired with exact-parent red/green evidence: #197875 (9ecae401) omitted the artifact API fixture, and #195420 (924a3bc9) intentionally preserved unclaimed yielded work after requester completion while the restart fixture still expected failure. The corrected yield case positively joins requester completion and then proves a later real turn resumes and completes the same child. No timeout or authoritative status was weakened.

Two failures remain investigated uncertainties. An unchanged SPA fallback test timed out on its first HTML request in the initial multi-file run; candidate and exact-parent isolated replays passed at the original timeout. CI also failed the partial-shutdown resume case with unavailable principal facts; its original selector passed once on exact CI main parent 20237d956 and once on the integrated candidate. Neither passing comparison is presented as a fix, flaky diagnosis, or inherited-failure proof.

Measurement scope and integration notes

Thirty separated timing/allocation rows used five rotated A1/B/A2 triplets, each with 5 warm requests and 60 measured requests. macOS Node 26.12.1; load 15.55–18.42. Pooled A→B medians per 60 requests: wall 9.403979→10.165292ms, main CPU 9.246→9.735ms, parent CPU 15.923→17.562ms, sampled allocation 2456500→2615984bytes. Paired increases reached 28.78% wall, 24.75% main CPU, 22.04% parent CPU. A/A ranges were −56.22% to +15.13% wall, −53.13% to +13.36% main CPU, −50.51% to +11.27% parent CPU, and −3.31% to +2.84% allocation. All 30 owned process groups drained naturally; no repeated or discarded rows. Allocation is sampled main-isolate V8 allocation, not total native/worker memory. Parent CPU excludes the source compiler child; setup/import and failure-probe costs are outside the window. The matched frozen source campaign measures this owner delta; exact-main correctness is qualified separately.

Overlapping open work observed during preparation: #157693 readiness cleanup projection/raw readiness fixture, #181390 health observedAt, and #196773 schema child-close waiters. No unrelated peer features were transplanted. Future composition must retain prepared-readiness fixtures and independent physical-child-close settlement.

@clawsweeper

clawsweeper Bot commented Nov 12, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes scripts Repository scripts size: XL labels Nov 12, 2026
@steipete
steipete marked this pull request as ready for review November 12, 2026 23:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-13T02:35:13.500008Z 1b34d7f 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Gateway runtime checks and child-failure diagnosis asynchronous while preserving existing recovery and synchronous caller contracts.

Example: An executable check stalls during GET /readyz.

  • Before: The synchronous check can block the Gateway main thread and delay concurrent GET /healthz requests.
  • After: Readiness waits asynchronously while /healthz returns 200; if draining begins before publication, /readyz returns 503.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source review supports the repair and resolves the prior blocker; changed-path proof is primarily harness-based and exact-head CI remains pending.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; its strongest changed-path evidence is the reported passing production-HTTP-server TCP harness, while the two inspected screenshots show unrelated streaming behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A slow executable lookup or failure probe can make unrelated Gateway requests stop responding.
Reason: The maintainer-authored direction addresses a concrete synchronous blocking path and explicitly accepts measured overhead to preserve availability and existing contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses an existing Gateway availability problem, resolves the previous finding, and has no newly identified correctness or security blockers.

Priority: P2
Reviewed head: 1b34d7fb26c13e4d1ab4f037f0548842ed6b2e0a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The held-executable-I/O scenario has production-server TCP harness coverage, without a supplied full-Gateway runtime trace of that same scenario.
Agent review details

How this fits together

The child-runtime viability owner supplies executable availability and failure diagnoses to Gateway readiness, health, startup, process supervisors, and database workers; the existing lifecycle owner handles recovery.

flowchart TD
  A[HTTP probes and health RPCs] --> B[Runtime viability owner]
  C[Child process failures] --> B
  B --> D[Asynchronous executable observations]
  D --> E[Publish current runtime facts]
  E --> F[Readiness and diagnostic responses]
  E --> G[Existing lifecycle recovery]
  C --> H[Native close and cleanup ownership]
Loading

Technical review

Best possible solution:

Use the existing runtime viability owner for asynchronous observations while preserving synchronous compatibility paths and native-close cleanup ownership.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly connects readiness to synchronous executable access and failure diagnosis to synchronous runtime probes; this read-only review did not execute a reproduction.

Is this the best way to solve the issue?

The change repairs the blocking observations at their existing owner and carries prepared facts through consumers without adding a cache, recovery manager, configuration option, or stored format.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Runtime viability and automatic recovery keeps the original intent (ec23eef: Diagnose missing or replaced Node runtimes and recover through the existing service lifecycle rather than silently failing workers.)
  • Channel-backed readiness keeps the original intent (ab5fcfc: Keep readiness distinct from liveness and report whether managed channels can serve traffic.)
  • Bounded channel reconnect readiness keeps the original intent (c749992: Preserve readiness during bounded normal reconnects while retaining hard failures and degraded-channel details.)
  • Broker and worker cleanup settlement keeps the original intent (98813c2: Retain native workers and child transports through actual cleanup completion before natural shutdown.)
  • Caller-scoped runtime path disclosure keeps the original intent (29c445e: Read-only health and status retain availability diagnostics while executable paths remain admin-scoped.)
  • Windows AppContainer diagnostic loading keeps the original intent (346f195: Token-probe failures log and retain the existing allow-spawn behavior; extracting the logger preserves that decision.)
  • Restarted unclaimed child fixture keeps the original intent (924a3bc: Unclaimed restored waits survive requester turns until a real continuation claim binds them to a task.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still contains the blocking path: Fetched main retains accessSync in runtime viability and spawnSync in failure diagnosis; readiness calls that owner synchronously, so the central repair remains necessary. (src/infra/child-runtime-viability.ts:55, 4fcfbb5cacde)
  • Pinned introduction reviewed: The introduced diff moves physical checks to the existing runtime owner, migrates asynchronous consumers, and retains synchronous viability and SQLite classification paths. (src/infra/child-runtime-viability.ts:74, 1b34d7fb26c1)
  • Previous finding resolved: The wrapper inventory now includes windows-appcontainer-spawn-log.runtime.ts, resolving the earlier missing runtime dependency. (scripts/pr-lib/wrapper-components.txt:1478, 1b34d7fb26c1)
  • Production HTTP boundary coverage: The added case uses TCP clients and the production Gateway HTTP server, holds executable access completion, checks concurrent liveness, and verifies draining produces readiness 503; the author reports it passing. (src/gateway/server-http.runtime-viability.test.ts:65, 1b34d7fb26c1)
  • Physical cleanup remains independently owned: Broker native completion is separate from asynchronous diagnosis, and shutdown joins both; supervisor admissions remain retained while startup diagnosis is pending. (src/process/spawn-broker/host.ts:369, 1b34d7fb26c1)
  • Existing recovery intent preserved: The merged runtime-recovery work explicitly assigns restart decisions to the existing lifecycle owner; this PR changes observation scheduling without replacing that policy. (src/infra/process-respawn.ts:171, ec23eefc9662)

Likely related people:

  • Peter Steinberger: Raw commit ec23eef adds src/infra/child-runtime-viability.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ec23eefc9662; files: src/infra/child-runtime-viability.ts)
  • Olli: Raw commit 92c86fe adds src/infra/child-runtime-viability.ts:29 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 92c86fefcd44; files: src/infra/child-runtime-viability.ts)
  • Vincent Koc: Raw commit 74e7b8d adds src/commands/health.types.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 74e7b8d47b18; files: src/commands/health.types.ts)

PR surface

Source +315, Tests +667, Other +200. Total +1182 across 65 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 31 625 310 +315
Tests 31 743 76 +667
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 315 115 +200
Total 65 1683 501 +1182

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 rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Blocking executable observations can stall unrelated Gateway requests, but no currently affected deployment or urgent regression is established.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-13T00:00:48.503Z sha 683b68c :: needs changes before merge. :: [P2] Include the extracted logger in the wrapper inventory

Reviewed November 12, 2026, 9:40 PM ET / November 13, 2026, 02:40 UTC (Revision 2).

Integrate the known main prerequisite for worker-environment fixture and wrapper inventory repairs. Move readiness contracts to the existing health type owner, retain the Windows diagnostic in native tooling, and prove held runtime I/O through real HTTP clients. Preserve unclaimed yielded-child continuation in the restart fixture.
@steipete

Copy link
Copy Markdown
Contributor Author
  1. Include the extracted logger in the wrapper inventory: fixed at wrapper-components.txt:1478. It now retains windows-appcontainer-spawn-log.runtime.ts. The existing wrapper source-closure and extracted package/alias checks pass on this head (three selected cases). The protocol inventory prerequisite arrived through merged fix(pr): retain OpenClaw ID validator sources in wrapper archives #197976; its entries were not duplicated.

The requested transport evidence is also now present in server-http.runtime-viability.test.ts:65: real TCP clients exercise the production Gateway HTTP server. With executable I/O completion held, /readyz stays pending while /healthz returns 200; drain plus release produces readiness 503. This is the HTTP-server boundary, not a full model/plugin startup claim.

The body records current proof, the exact-main inherited export failures, and the unresolved SPA/resume observations. Four-pass Codex P2 review of the complete candidate is scoped-clean with static/partitioned-context limitations retained.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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 13, 2026
@steipete
steipete merged commit db4b2ed into main Nov 13, 2026
173 checks passed
@steipete
steipete deleted the fix/gateway-runtime-readiness-io branch November 13, 2026 03:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…penclaw#195406)

Backport of c1e55e2.

Release adaptation: retain synchronous release cleanup and its live authority callbacks. Include maintenance database gate and preactivation rollback regression. Exclude documentation and test-allocation metadata. Later async runtime probe repair openclaw#197975 is independent.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit aa2e94a1a07793071600de47831d990a0b0ae590)
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. cli CLI command changes gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant