Skip to content

fix: keep Gateway responsive during cold terminal startup - #200162

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-2535-node-probe
Nov 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-2535-node-probe

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #200136

What Problem This Solves

Fixes: starting a terminal under Bun can stall the Gateway event loop while cold Node discovery creates a probe file, waits for Node, and removes the file.

User Impact

Terminal startup and QA subprocess discovery leave the Gateway event loop responsive while the filesystem or Node probe is slow. Supported-version selection, missing-runtime errors, and synchronous CLI/previously shipped callers keep their contracts. Cold asynchronous discovery adds modest CPU/allocation overhead; no new configuration, schema, dependency, or cache is introduced.

Why This Change Was Made

This follows the Team 25c9790 incident (2026-11-16 05:02 PST): a native catalog lock create spent 1.97 s in btrfs transaction wait and stalled the event loop 2,002 ms. #200136 removed that redundant lock. The continuing audit found the same main-thread metadata dependency in Node executable discovery.

The existing probe owner now offers awaited creation, child execution, and joined cleanup. Terminal and QA callers use it; synchronous bootstrap/CLI callers remain supported. Both forms share the same selection policy and existing 16-entry cache. Production growth is 97 handwritten runtime lines plus 29 generated lines and 7 generator lines, needed to preserve synchronous callers while moving serving callers to the async contract. The old probe policy is not duplicated.

Evidence

The existing main-thread filesystem guard fails on the exact parent 6670297 with mkdtempSync/writeFileSync/rmSync and passes through real cold discovery after the fix. Actual terminal helper cancellation/spawn-failure tests and affected QA/materializer consumers pass; all core, UI, extension, script, and test type graphs pass. Codex autoreview is scoped-clean P0–P2. No browser import reaches the changed Node-only modules.

Measurements used the synthetic 35 GiB agent DB / 5,000 sessions / 62,000 workspace files on APFS, with probe files under its temporary directory; this owner does not scan unrelated database/workspace content. Node 26.12.1 simulated Bun's selection branch and spawned real Node children. Five A/A pairs: owner 106.469 / 106.100 ms. Five undelayed A/B pairs: owner 106.631 / 105.923 ms, maximum heartbeat gap 106.821 / 1.469 ms. With a 200 ms injected create delay: owner 317.139 / 308.782 ms, heartbeat 317.333 / 1.605 ms. Separate heartbeat-disabled allocation controls show main CPU 1.404 → 1.731 ms and V8 allocated bytes 0.484 → 2.333 MB; no CPU/allocation speedup claimed. Native/child allocation is excluded. This is fault-injected APFS evidence, not btrfs kernel proof.

pnpm check:changed completed. Affected tests, all type graphs, scoped lint, format and mock-export ratchet pass. Two unchanged dead exports reproduce on the exact parent and were introduced by 24385a2 / #200056. The SDK inventory also exceeds unchanged budgets on the exact parent; exact historical parent/commit reports identify 1595dd2 / #176886 as the first export/callable/wildcard regression. No budget was changed.

Initial CI run 43901737391 found two task-caused generator-consumer fixture failures. Both are repaired, their focused tests pass, and a fresh Codex review is clean. The repair's check:changed passes every selected gate except the same attributed dead exports. The third failure is a separate main regression: #200097 / 5d35af1 deleted agent-harness-completion-delivery.test.ts while leaving it in the CI shard inventory. The same inventory assertion fails on edbc5bc, the exact main parent of CI's checked-out merge 7110478. Final head aeb5ec9 passed CI run 43907296989. ClawSweeper re-reviewed that exact head and reports zero open items. The earlier failed run remains recorded as failed; no inherited-CI exception is needed for this final head.

Await probe-file creation, child execution and joined cleanup from terminal and QA runtime callers. Share selection policy and the existing bounded cache with synchronous CLI and shipped SDK callers. Preserve generated bootstrap ownership and extend the main-thread filesystem regression guard.
@clawsweeper

clawsweeper Bot commented Nov 16, 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 docs Improvements or additions to documentation scripts Repository scripts extensions: qa-lab plugin: file-transfer size: M labels Nov 16, 2026
@steipete
steipete marked this pull request as ready for review November 16, 2026 15:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T15:58:02.230034Z 54588c3 Draft marked ready
ℹ️ 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.

@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: 54588c31ee

ℹ️ 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".

absWorkingDir: rootDir,
stdin: {
contents: `import { materializeRuntimeProcessScriptFile } from "./src/infra/runtime-process-script-file.ts";
contents: `import { materializeRuntimeProcessScriptFile, materializeRuntimeProcessScriptFileAsync } from "./src/infra/runtime-process-script-file.ts";

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 Update the generator test fixture with the async materializer

The existing generates identical executable assets across dependency store locations test in test/scripts/runtime-script-assets.test.ts creates a synthetic checkout whose runtime-process-script-file.ts exports only materializeRuntimeProcessScriptFile (lines 48–50). This new unconditional import makes writeRuntimeScriptAssets({ rootDir: checkout }) fail during its runtime esbuild invocation because the fixture lacks materializeRuntimeProcessScriptFileAsync, so the test cannot reach its dependency-location assertions. Add the async export to that fixture alongside this generator change. Execution could not be confirmed locally because repository dependencies are absent.

Useful? React with 👍 / 👎.

@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes terminal and QA Node discovery asynchronous while preserving synchronous CLI and SDK callers.

Example: Cold Node discovery encounters a 200 ms probe-file creation delay.

  • Before: The reported baseline maximum heartbeat gap is 317.333 ms.
  • After: The reported asynchronous resolver maximum heartbeat gap is 1.605 ms.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation and repaired fixtures look correct, while available behavior evidence stops at the resolver boundary.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Opening a terminal under Bun can freeze unrelated Gateway work while Node discovery blocks the event loop.
Reason: The maintainer-authored direction addresses a concrete shared-runtime stall and explicitly accepts the measured cold-discovery overhead.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current Gateway stall path, and both previously reported fixture defects are fixed; no new actionable code defects were found.

Priority: P2
Reviewed head: aeb5ec9de655d5457ddbcaee74853a8fd01a0349

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted logs or a terminal recording of cold discovery through a real Bun Gateway terminal request, showing successful terminal output and concurrent Gateway responsiveness during the delayed probe.
Agent review details

How this fits together

Terminal startup and QA subprocess launch ask the shared resolver for a supported Node executable; it probes candidates through generated temporary scripts and returns an executable path or undefined.

flowchart TD
  A[Terminal startup] --> C[Shared Node resolver]
  B[QA subprocess launch] --> C
  C --> D[Generated probe script]
  D --> E[Node candidate process]
  E --> F[Executable path or unavailable]
  F --> G[PTY helper or QA child]
Loading

Technical review

Best possible solution:

Keep the asynchronous discovery path in the existing resolver and materializer owners while retaining the shipped synchronous SDK contract.

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

Current main directly performs synchronous temporary-file operations and waits synchronously for Node during terminal discovery; the supplied fault-injection measurements support the stall mechanism, but this review ran no target code.

Is this the best way to solve the issue?

The patch uses the existing owners, preserves supported-runtime selection and compatibility, and updates affected consumers without adding a competing policy or cache.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main retains the blocking path: Fetched main uses synchronous probe materialization and execFileSync, and terminal helper startup calls that resolver. (src/infra/node-runtime-executable.ts:83, 2516bca9fdb8)
  • Shared owner and complete caller cutover: The introduced diff shares selection policy and the existing bounded cache, awaits probe creation, execution and disposal, and migrates terminal and QA callers without removing the synchronous contract. (src/infra/node-runtime-executable.ts:143, aeb5ec9de655)
  • Previous findings resolved: The latest commit adds the async export to the dependency-store fixture and updates both positive and removal assertions for the dead-code consumer projection. (test/scripts/runtime-script-assets.test.ts:50, aeb5ec9de655)
  • Published compatibility contract preserved: The latest stable release exports resolveNodeRuntimeExecutable; retaining it protects existing plugin callers while the additive async export serves runtime requests. (src/plugin-sdk/process-runtime.ts:4, d843d6af39a4)
  • Proof scope and accepted performance tradeoff: The maintainer-authored body reports real Node-child heartbeat measurements under a simulated Bun branch and explicitly accepts additional cold-discovery CPU and allocation cost; the author confirms that a full Bun Gateway terminal roundtrip was not run.
  • Related incident addresses a distinct owner: fix(gateway): avoid filesystem stalls during catalog refresh #200136 removes catalog-refresh filesystem stalls and explicitly describes a bounded audit stage; it does not replace this Node-discovery repair.

Likely related people:

  • Peter Steinberger: Raw commit 21db4e9 adds src/infra/node-runtime-executable.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 21db4e956ed4; files: src/infra/node-runtime-executable.ts)

PR surface

Source +97, Tests +19, Docs +3, Generated +29, Other +6. Total +154 across 17 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 122 25 +97
Tests 6 27 8 +19
Docs 1 4 1 +3
Config 0 0 0 0
Generated 2 30 1 +29
Other 2 8 2 +6
Total 17 191 37 +154

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.

Review metrics

Metric Value Why it matters
Production versus test growth Handwritten runtime +97 lines; tests +19 lines; generated output +29 lines; generator +7 lines Growth preserves the released synchronous interface while sharing selection policy and moving serving callers to asynchronous I/O.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Cold runtime discovery can temporarily stall shared Gateway work, with impact limited to callers requiring discovery.
  • merge-risk: 🚨 compatibility: The PR adds a public process-runtime SDK export; maintainer direction is established and the released synchronous export remains intact.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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-16T16:11:24.186Z sha 54588c3 :: needs changes before merge. :: [P2] [P2] Export the async materializer in the generator test fixture | [P2] [P2] Update the dead-code consumer test for both materializers

Reviewed November 16, 2026, 11:30 AM ET / 16:30 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed both items from the latest ClawSweeper review in aeb5ec9:

  1. Async generator fixture: runtime-script-assets.test.ts:50 now exports both materializers using the same dependency-backed value. The dependency-store invariance assertions remain unchanged.
  2. Dead-code consumer fixture: check-deadcode-exports.test.ts:825 expects both named consumers, and the removal fixture at line 843 removes that same real import. The negative assertion still proves those consumer edges disappear when the generator import is removed.

Both previously failing tests pass under Bun. Fresh Codex review found no actionable P0–P2 finding. check:changed passes all selected gates except the separately attributed, unchanged dead exports described in the PR body. The real resolver delay/heartbeat experiment and actual terminal helper cancellation/failure tests remain the supplied proof; a full Bun Gateway terminal roundtrip has not been run, and the PR body states the simulated-runtime limitation.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@steipete
steipete merged commit 89e05eb into main Nov 16, 2026
149 checks passed
@steipete
steipete deleted the steipete/perf-2535-node-probe branch November 16, 2026 16:56
@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
…00162)

* fix(process): keep cold Node discovery off the event loop

Await probe-file creation, child execution and joined cleanup from terminal and QA runtime callers. Share selection policy and the existing bounded cache with synchronous CLI and shipped SDK callers. Preserve generated bootstrap ownership and extend the main-thread filesystem regression guard.

* test: update runtime script fixtures for async materialization
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport #200162 from 89e05eb. Share stable selection and bounded cache with synchronous public callers; use async probe creation, execution and joined cleanup for terminal and QA runtime paths. Regenerate the standalone bootstrap.

Proof: cold synchronous-fs regression failed on baseline; final resolver suites pass 6 tests (7.13s). Direct real Node and copied standalone bootstrap probes pass; generation, format and diff checks pass. Consumer wrapper runs were compilation-invalidated; lint blocked by linked declaration escape. These gaps remain explicit. Test allocation: 31 net lines for affected runtime boundary regressions.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: qa-lab merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant