Skip to content

fix(infra): handle detached respawn child errors#101489

Merged
vincentkoc merged 4 commits into
mainfrom
feature/issue-101458-detached-spawn-error
Jul 7, 2026
Merged

fix(infra): handle detached respawn child errors#101489
vincentkoc merged 4 commits into
mainfrom
feature/issue-101458-detached-spawn-error

Conversation

@momothemage

@momothemage momothemage commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #101458. Detached gateway update respawns can emit an asynchronous ChildProcess error after spawn() returns; without a listener, Node treats that as unhandled and crashes the current process.

Why This Change Was Made

The detached respawn path now attaches a best-effort error listener before unref(), matching the existing restart-helper pattern. The update handoff still returns the child/pid when spawn succeeds, and synchronous spawn failures still flow through the existing failed result.

User Impact

Users hitting a missing or invalid executable during detached update respawn no longer get an extra uncaught child-process error on the parent process.

Evidence

## without-listener
node=v24.18.0
exit=1 signal=none
stdout=""
stderr-summary=["      throw er; // Unhandled 'error' event","Error: spawn /tmp/openclaw-missing-detached-gateway-1957 ENOENT","  code: 'ENOENT',"]
## with-listener
node=v24.18.0
exit=0 signal=none
stdout="handled child error: ENOENT\nparent still alive"
stderr-summary=[]
  • node scripts/run-vitest.mjs src/infra/process-respawn.test.ts
  • git diff --check
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false pnpm check:changed -- src/infra/process-respawn.ts src/infra/process-respawn.test.ts

@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed. Reviewed July 7, 2026, 6:28 AM ET / 10:28 UTC.

Summary
The branch adds a no-op ChildProcess error listener before unref in the detached gateway update respawn helper and adds focused regression coverage for listener ordering and no-throw behavior.

PR surface: Source +3, Tests +30. Total +33 across 2 files.

Reproducibility: yes. source-level reproduction is high confidence: current main lacks the child error listener, and a direct Node v24.18.0 probe shows the missing-executable child error crashes without a listener and survives with one. I did not run a full OpenClaw package update respawn E2E.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #101458
Summary: This PR is a candidate fix for the open detached gateway respawn ChildProcess error issue; the related closed PRs are parallel attempts at the same listener-before-unref repair.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh or validate the exact merge head because live GitHub reports the branch as BEHIND.
  • [P2] Resolve the failing dispatch check if it remains required by branch protection.

Risk before merge

  • [P1] The live PR is mergeable but BEHIND current base, so landing should use an exact merge-head refresh or validation.
  • [P1] The proof covers the Node child_process failure mode and focused regression tests, not a full live OpenClaw package update respawn.

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused listener-before-unref fix as the canonical fix for Unhandled error on detached spawned gateway process crashes the Node process #101458 after exact-head validation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is needed; the patch is clean and the automerge or maintainer gate should handle exact-head validation before landing.

Security
Cleared: The diff only adds a ChildProcess error listener plus test mocks/assertions, with no new dependencies, permissions, secrets handling, workflow changes, or supply-chain surface.

Review details

Best possible solution:

Land this focused listener-before-unref fix as the canonical fix for #101458 after exact-head validation.

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

Yes, source-level reproduction is high confidence: current main lacks the child error listener, and a direct Node v24.18.0 probe shows the missing-executable child error crashes without a listener and survives with one. I did not run a full OpenClaw package update respawn E2E.

Is this the best way to solve the issue?

Yes. Attaching a best-effort child error listener immediately after spawn and before unref is the narrowest maintainable fix, matches the sibling restart-helper pattern, and preserves the existing unhealthy-child fallback path.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add status: 🚀 automerge armed: This PR is in ClawSweeper's automerge lane. Sufficient (terminal): The PR body includes terminal after-fix proof showing the missing-executable case crashes without a listener and stays alive with the listener installed, plus targeted test and changed-check commands.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 🚀 automerge armed.

Label justifications:

  • P2: This PR fixes a normal-priority gateway update availability bug with a narrow source change and limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 🚀 automerge armed: This PR is in ClawSweeper's automerge lane. Sufficient (terminal): The PR body includes terminal after-fix proof showing the missing-executable case crashes without a listener and stays alive with the listener installed, plus targeted test and changed-check commands.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal after-fix proof showing the missing-executable case crashes without a listener and stays alive with the listener installed, plus targeted test and changed-check commands.
Evidence reviewed

PR surface:

Source +3, Tests +30. Total +33 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 0 +3
Tests 1 34 4 +30
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 37 4 +33

What I checked:

  • Repository policy read: Root AGENTS.md was read fully, no scoped AGENTS.md owns src/infra, and the review applied the root high-confidence process/security PR-review guidance. (AGENTS.md:1, 42e2390b3144)
  • Current main lacks the listener: On current origin/main, spawnDetachedGatewayProcess spawns the detached child, immediately calls child.unref(), and returns it without an error listener. (src/infra/process-respawn.ts:51, cba20f9aec7b)
  • PR head installs the handler before unref: The PR head adds a comment explaining asynchronous detached spawn failures and calls child.on("error", () => {}) before child.unref(). (src/infra/process-respawn.ts:56, 0d8c38ef50a0)
  • Regression coverage: The new test exercises respawnGatewayProcessForUpdate, verifies the child error listener is installed, invokes it without throwing, and asserts listener registration precedes unref. (src/infra/process-respawn.test.ts:398, 0d8c38ef50a0)
  • Caller fallback path: The gateway run loop already treats unhealthy update respawn children as best-effort, kills them if present, marks sentinel failure, and falls back to in-process restart. (src/cli/gateway-cli/run-loop.ts:210, cba20f9aec7b)
  • Sibling detached-spawn precedent: The update restart-script helper already uses the same detached spawn pattern with child.on("error", () => {}) before child.unref(). (src/cli/update-cli/restart-helper.ts:417, cba20f9aec7b)

Likely related people:

  • steipete: git blame on current origin/main attributes the central spawnDetachedGatewayProcess helper and run-loop update respawn path to Peter Steinberger, and shortlog shows the heaviest history across the relevant respawn/run-loop files. (role: current respawn path owner; confidence: high; commits: 82b0f7cdc88d; files: src/infra/process-respawn.ts, src/infra/process-respawn.test.ts, src/cli/gateway-cli/run-loop.ts)
  • ZOOWH: Recent managed update handoff work changed process-respawn, process-respawn tests, the gateway run loop, and update handoff timing around the same update-restart surface. (role: recent adjacent contributor; confidence: medium; commits: b8b946e43db8, 46493bc867dc; files: src/infra/process-respawn.ts, src/infra/process-respawn.test.ts, src/cli/gateway-cli/run-loop.ts)
  • giodl73-repo: The sibling update restart-helper fix added the same best-effort detached child error listener before unref in another restart handoff path. (role: sibling pattern contributor; confidence: medium; commits: 566d8cdf3995; files: src/cli/update-cli/restart-helper.ts, src/cli/update-cli/restart-helper.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-07T08:38:11.347Z sha 2d9b586 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-07T09:07:18.762Z sha 69fc48f :: needs maintainer review before merge. :: none
  • reviewed 2026-07-07T09:16:51.492Z sha 69fc48f :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 7, 2026
@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 7, 2026
@momothemage

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper 🐠 automerge status

ClawSweeper took another look; no safe branch change was available on this pass.

Executor outcome: no planned fix actions.
Worker summary: Canonical this PR is already closed and its fix is present on current main. Current main registers a detached child error listener before unref and includes focused regression coverage, so no merge, close, or repair PR action is needed.

Worker actions:

  • keep_closed on this PR: skipped - Already closed; canonical fix is present on current main.
  • keep_closed on #101458: skipped - Already closed; covered by the canonical fix path.
  • keep_closed on #101482: skipped - Already closed; superseded by the canonical adopted PR path.
  • keep_closed on #101487: skipped - Already closed; no closure or repair action is valid.
  • keep_closed on #101490: skipped - Already closed; no closure or repair action is valid.
  • keep_closed on #101491: skipped - Already closed; no closure or repair action is valid.

This pass stayed observational only. No branch push, replacement, merge, or re-review was started.

fish notes: reasoning high; reviewed against 918c4da.

Automerge progress:

  • 2026-07-07 10:40:01 UTC review queued 918c4daab0fe (after repair)

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label Jul 7, 2026
@clawsweeper
clawsweeper Bot force-pushed the feature/issue-101458-detached-spawn-error branch from 69fc48f to 0d8c38e Compare July 7, 2026 10:11
@clawsweeper clawsweeper Bot added status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 7, 2026
@clawsweeper
clawsweeper Bot force-pushed the feature/issue-101458-detached-spawn-error branch from 0d8c38e to 918c4da Compare July 7, 2026 10:40
@vincentkoc vincentkoc self-assigned this Jul 7, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Land-ready maintainer verification:

Known gap: no destructive end-to-end self-update restart was run. The direct Node contract proof, focused lifecycle test, caller fallback review, remote changed gate, and exact-head CI cover this narrow failure mode.

@vincentkoc
vincentkoc merged commit 695fa4e into main Jul 7, 2026
101 of 102 checks passed
@vincentkoc
vincentkoc deleted the feature/issue-101458-detached-spawn-error branch July 7, 2026 10:51
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 8, 2026
* fix(infra): handle detached respawn child errors

* docs(infra): explain detached respawn error listener

* fix(infra): handle detached respawn child errors

* fix(infra): handle detached respawn child errors

---------

Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
* fix(infra): handle detached respawn child errors

* docs(infra): explain detached respawn error listener

* fix(infra): handle detached respawn child errors

* fix(infra): handle detached respawn child errors

---------

Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled error on detached spawned gateway process crashes the Node process

2 participants