Skip to content

fix(cli): let the dev runner own child shutdown - #138239

Merged
steipete merged 2 commits into
mainfrom
codex/fix-dev-runner-child-lifecycle
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-dev-runner-child-lifecycle

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Stopping a source-checkout Gateway could leave its process alive after the development launcher exited. Release validation encountered a restart refusal because the previous Gateway still owned the state directory. A separate real-process reproduction confirmed a launcher defect consistent with that failure: a child that needs forced shutdown survives its launcher and becomes orphaned.

Why This Change Was Made

The JavaScript shim and runNodeMain each started a five-second escalation timer, but their child processes occupied different process groups. The outer timer could kill the inner owner before the inner timer cleaned up its own child group.

run-node.mjs now explicitly delegates termination to its implementation. The shim forwards signals and joins that implementation without running a competing deadline. runNodeMain retains its existing five-second cleanup and handles SIGHUP through the same signal/build-lock lifecycle as SIGINT and SIGTERM. This keeps the existing Node implementation under Bun and leaves other shim callers' ownership unchanged.

An in-process loader was considered, but it would either move the owner and postbuild work into Bun or introduce a second execution path. Raising the outer deadline would retain competing owners. Explicit delegation is the smaller ownership repair.

User Impact

Source-checkout Gateway shutdown cleans up a slow child before its launcher completes, allowing a subsequent start to acquire the state directory. No configuration, environment variable, protocol, database, dependency, or published CLI option changes.

Release-note context: fix orphaned Gateway processes during development-launcher shutdown and restart.

Evidence

  • Real SIGTERM and SIGHUP regression cases fail on the original code because a separately detached child remains alive. Assertions inspect liveness before independent cleanup; they pass after the fix.
  • Final runner coverage: node scripts/run-vitest.mjs test/scripts/run-node-lifecycle.test.ts src/infra/run-node.test.ts — 94 passing cases, in both release and main contexts. The shared direct-entrypoint suite also passed 48 cases.
  • Complete changed-file checks pass in both contexts, including script and root-test types, lint, erasability and boundary guards. Independent P0–P2 review has zero findings.
  • Linux Testbox proof, Node 24.19.0: both real-process regressions pass. A fresh private-QA build then passes the unchanged node-worker-launch-wire.e2e.test.ts Gateway restart scenario in 86.797 seconds. Production/helper hashes match the final patch; the later test-only change adds an explicit environment type annotation.
  • Production/tooling: +29/−24, net +5. Tests/support: +72/−1, net +71. The added ownership selector removes the competing deadline, while the shared signal table absorbs hangup handling.

The original Gateway failure did not reproduce in an earlier unchanged isolated rerun; the launcher orphan is independently proven, but that historical CI failure is not conclusively attributed. This focused proof does not replace full release qualification.

Named sibling follow-up: inspect run-with-env.mts and watch-node.mts supervision, which have their own outer deadlines, plus managed-child shim users such as run-oxlint.mjs and check-changed.mjs. Those additional wrapper paths were source-audited but are not claimed as repaired by this change.

Canonical CI fixture refresh

The first exact-head CI completed with one failed test shard and its aggregate. Three Code Mode denial cases used an incomplete synthetic session: nested observation needed missing getAppendParentId/appendMessage methods, and the bare Agent fixture omitted AgentSession's structured-failure classification. The actual denied action and preparer remained unentered.

Head 1afa189b693560220dc1816911937a7c3f4ba925 adopts only the two relevant test/support files already repaired in #138238, commit e7fffcf7a0935ac4abdd6a0efa8bb4dc5a585e6b. The fixture now matches those existing contracts and asserts the exact denial reasons. Other changes from that source PR are not included. All five launcher files are byte-unchanged.

The pre-edit file reproduced the same three failures. The complete original test group then passed all 112 files and 1,666 tests, with the original denial-case order retained. The full changed-file gate and managed incremental P0–P2 review pass. This refresh adds 24 and removes 21 test/support lines, zero production lines; the full PR is production +29/−24 (net +5), tests/support +96/−22 (net +74), seven files. The subsequent exact-head CI is green.

Exact-head CI for 1afa189b693560220dc1816911937a7c3f4ba925 completed successfully at 12:54:08 UTC on September 4, 2026, including the required openclaw/ci-gate. All attached checks are complete with no failures or pending checks; Workflow Sanity passed and the three Testbox workflow filters do not apply to these changed paths. The completed ClawSweeper review found no introduced correctness defect. Its before-merge request and sole rank-up move were to let these exact-head checks finish, which is now satisfied.

The JavaScript shim and dev runner both escalated after five seconds. The
shim could kill the runner first, leaving its separately detached child
alive. Delegate termination to the runner and handle SIGHUP through its
existing signal and build-lock lifecycle. Preserve Node execution under Bun
and other shim callers' termination behavior.

Real process regressions fail before the fix and pass for SIGTERM/SIGHUP.
Runner and entrypoint tests, changed-file checks, and independent review
pass. A fresh Linux Node 24.19.0 build passes the original Gateway worker
restart scenario (Actions 33868737194).

Release-note context: source-checkout Gateway shutdown no longer abandons a
slow child when the development launcher's shutdown timers race.
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 11:55

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks correct. One termination owner removes the orphan window; handling SIGHUP through the same lifecycle is consistent.

Adopt the two relevant test-only corrections already landed in #138238
(e7fffcf). Supply the session methods consumed by nested tool
observation and classify structured tool failures as AgentSession does.
Keep policy-denial and never-entered action/preparer assertions intact.

The original file reproduces three failures. All 112 files and 1,666 tests
pass after this correction, with complete changed-file gates and independent
review. Launcher implementation and release candidate are unchanged.
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 8:41 AM ET / 12:41 UTC.

ClawSweeper review

What this changes

The PR lets the development runner, rather than its TypeScript shim, own child-process shutdown, adds SIGHUP handling, and adds real-process lifecycle coverage plus already-merged agent-fixture corrections.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: current main still has the competing shim shutdown deadline, while this PR’s run-node-only delegation preserves a single child-group lifecycle owner. No introduced correctness defect was found; normal exact-head checks remain in progress.

Priority: P1
Reviewed head: 1afa189b693560220dc1816911937a7c3f4ba925

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-bound lifecycle repair with a meaningful real-process regression test and no identified correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Its body nevertheless links a Linux Testbox real-process run for the same shim-to-runner child-cleanup path; that linked run was not independently retrievable in this review environment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Its body nevertheless links a Linux Testbox real-process run for the same shim-to-runner child-cleanup path; that linked run was not independently retrievable in this review environment.
Evidence reviewed 7 items Explicit lifecycle handoff: The introduced shim change still forwards signals but omits its own forced-kill deadline only when the implementation declares itself the termination owner.
Runner owns the child group: The runner forwards the first signal, retains its five-second escalation, and force-cleans the owned process group after its direct child exits; both runtime and build paths use this helper.
Boundary regression coverage: The new test starts a real TERM/HUP-resistant child through the shim, signals the shim, waits for completion, and checks child liveness before its independent cleanup.
Findings None None.
Security None None.

How this fits together

The source-checkout development launcher starts a Node runner through a TypeScript shim. Shutdown signals pass through the shim to the runner, which must terminate its child process group before a later Gateway start can reuse the state directory.

flowchart LR
A[Operator stops development Gateway] --> B[TypeScript launcher shim]
B --> C[Node development runner]
C --> D[Gateway or build child group]
B --> E[Forwarded shutdown signal]
E --> C
C --> F[Graceful and forced cleanup]
F --> G[Restart can acquire state directory]
Loading

Before merge

  • Resolve merge risk (P1) - This intentionally removes the shim’s last-resort watchdog for one launcher; a missed runner lifecycle phase could affect shutdown or restart availability. The real-process regression targets TERM and HUP, but the supplied exact-head check set is still incomplete.
Agent review details

Security

None.

PR surface

Tests +74, Other +5. Total +79 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 96 22 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 29 24 +5
Total 7 125 46 +79

Review metrics

Metric Value Why it matters
Production versus test delta production +5 net (+29/−24); tests/support +74 net (+96/−22) The small production increase is the run-node-only ownership selector and shared SIGHUP table; the larger test change exercises the real process boundary and aligns existing fixtures with merged contracts.

Merge-risk options

Maintainer options:

  1. Verify the owner-bound shutdown path (recommended)
    Merge after the exact-head checks confirm that the runner still joins and cleans its child group for the forwarded shutdown signals.
  2. Pause if lifecycle validation exposes a gap
    Keep the PR open for a focused runner repair if the exact-head lifecycle checks show that any launch phase escapes the delegated owner.

Technical review

Best possible solution:

Retain the explicit run-node handoff so the process-group owner performs all escalation, with the real TERM/HUP lifecycle regression guarding the boundary before merge.

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

Yes—source-reproducible: the added real-process test launches a resistant child, signals the actual launcher PID, then verifies that the child is dead before cleanup. This read-only review did not execute the test.

Is this the best way to solve the issue?

Yes—the runner is already the owner of the child process group and its existing escalation path, so delegating the shim deadline avoids competing lifecycle owners while preserving the watchdog for other shim callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c3f394f3bda6.

Labels

Label changes:

  • add P1: An orphaned development child can retain the Gateway state directory and block a normal restart.
  • add merge-risk: 🚨 availability: The PR changes signal forwarding and forced process-group shutdown, directly affecting launcher exit and restart availability.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Its body nevertheless links a Linux Testbox real-process run for the same shim-to-runner child-cleanup path; that linked run was not independently retrievable in this review environment.

Label justifications:

  • P1: An orphaned development child can retain the Gateway state directory and block a normal restart.
  • merge-risk: 🚨 availability: The PR changes signal forwarding and forced process-group shutdown, directly affecting launcher exit and restart availability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Its body nevertheless links a Linux Testbox real-process run for the same shim-to-runner child-cleanup path; that linked run was not independently retrievable in this review environment.

Evidence

What I checked:

  • Explicit lifecycle handoff: The introduced shim change still forwards signals but omits its own forced-kill deadline only when the implementation declares itself the termination owner. (scripts/lib/tsx-cli-shim.mjs:114, cf86ed2429cb)
  • Runner owns the child group: The runner forwards the first signal, retains its five-second escalation, and force-cleans the owned process group after its direct child exits; both runtime and build paths use this helper. (scripts/run-node.mts:1121, cf86ed2429cb)
  • Boundary regression coverage: The new test starts a real TERM/HUP-resistant child through the shim, signals the shim, waits for completion, and checks child liveness before its independent cleanup. (test/scripts/run-node-lifecycle.test.ts:9, cf86ed2429cb)
  • Current main still lacks the repair: At fetched main, the shim always schedules its own SIGKILL, run-node does not select an implementation owner, and the runner only handles SIGINT and SIGTERM. (scripts/lib/tsx-cli-shim.mjs:114, c3f394f3bda6)
  • Fixture refresh already matches main: The two agent test/support files are byte-identical to the corresponding merged correction, so their introduced branch hunks do not create a separate runtime behavior on current main. (src/agents/embedded-agent-runner/run/attempt.tool-search-catalog-abort.test.ts:121, e7fffcf7a093)
  • Introduced-change provenance: The lifecycle commit has the pinned PR base as its sole recorded parent; the subsequent head commit is the fixture-only refresh. (cf86ed2429cb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason O'Neal: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the already-queued exact-head checks complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 7a8dc4b into main Sep 4, 2026
163 of 165 checks passed
@steipete
steipete deleted the codex/fix-dev-runner-child-lifecycle branch September 4, 2026 13:08
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
* fix(cli): let the dev runner own child shutdown

The JavaScript shim and dev runner both escalated after five seconds. The
shim could kill the runner first, leaving its separately detached child
alive. Delegate termination to the runner and handle SIGHUP through its
existing signal and build-lock lifecycle. Preserve Node execution under Bun
and other shim callers' termination behavior.

Real process regressions fail before the fix and pass for SIGTERM/SIGHUP.
Runner and entrypoint tests, changed-file checks, and independent review
pass. A fresh Linux Node 24.19.0 build passes the original Gateway worker
restart scenario (Actions 33868737194).

Release-note context: source-checkout Gateway shutdown no longer abandons a
slow child when the development launcher's shutdown timers race.

* test(agents): align attempt fixtures with session contracts

Adopt the two relevant test-only corrections already landed in openclaw#138238
(ce8b5ca). Supply the session methods consumed by nested tool
observation and classify structured tool failures as AgentSession does.
Keep policy-denial and never-entered action/preparer assertions intact.

The original file reproduces three failures. All 112 files and 1,666 tests
pass after this correction, with complete changed-file gates and independent
review. Launcher implementation and release candidate are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S 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.

2 participants