Repository navigation
fix: keep Gateway responsive during cold terminal startup - #200162
Conversation
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.
|
🦞👀 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. |
There was a problem hiding this comment.
💡 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"; |
There was a problem hiding this comment.
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 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherTerminal 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +97, Tests +19, Docs +3, Generated +29, Other +6. Total +154 across 17 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: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed November 16, 2026, 11:30 AM ET / 16:30 UTC (Revision 2). |
|
Addressed both items from the latest ClawSweeper review in aeb5ec9:
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 |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…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
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]>
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:changedcompleted. 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.