Skip to content

fix(infra): attach error listener to detached spawn in update handoff - #101524

Closed
krissding wants to merge 2 commits into
openclaw:mainfrom
krissding:fix/update-handoff-spawn-error-listener
Closed

krissding wants to merge 2 commits into
openclaw:mainfrom
krissding:fix/update-handoff-spawn-error-listener

Conversation

@krissding

Copy link
Copy Markdown
Contributor

What Problem This Solves

startManagedServiceUpdateHandoff() in src/infra/update-managed-service-handoff.ts spawns a detached child process with child.unref() but no 'error' listener. When spawn fails (e.g. execPath invalid, permissions changed), Node.js emits an async 'error' event on the ChildProcess. Without a listener, this crashes the parent as an unhandled error.

This is the same pattern identified and fixed in #101392 for process-respawn.ts.

Why This Change Was Made

The spawn at line 731 creates a detached handoff process during managed service updates. If the executable path is invalid, the async 'error' event crashes the parent gateway.

Evidence

Before: no error listener → unhandled crash

$ node -e "const{spawn}=require('child_process');spawn('/nonexistent',[],{detached:true,stdio:'ignore'})"
node:events:486
      throw er; // Unhandled 'error' event
      ^
Error: spawn /nonexistent ENOENT

After: error listener attached → graceful handling

$ node -e "
const {spawn} = require('child_process');
const child = spawn('/nonexistent', [], {detached: true, stdio: 'ignore'});
child.on('error', () => {});
console.log('OK: process does not crash');
"
OK: process does not crash

Test mock updated

Updated spawnMock in update-managed-service-handoff.test.ts to include on: vi.fn() in the return value — required because the production code now calls child.on("error", ...).

Merge Risk

Low. The change adds a no-op error listener before child.unref(). Test mock updated accordingly.

🤖 Generated with Claude Code

…openclaw#101392 follow-up)

The spawn() call in startManagedServiceUpdateHandoff() creates a detached child
process with child.unref() but without an 'error' listener. When spawn fails,
Node.js emits an async 'error' event that crashes the parent as an unhandled
error.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clawsweeper

clawsweeper Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 9:15 AM ET / 13:15 UTC.

Summary
The PR adds a ChildProcess error listener to the managed-service update handoff detached spawn and updates the Vitest spawn mock to expose on.

PR surface: Source +1, Tests +1. Total +2 across 2 files.

Reproducibility: yes. Source inspection and local Node probes show failed child-process spawns arrive through an asynchronous error event, and the caller path returns/logs started once this function resolves.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • [P1] Change the implementation so async helper spawn errors reject or otherwise reach managed-service-handoff-failed before callers schedule restart.
  • [P1] Add focused regression coverage for an async spawn error that verifies the caller does not report a started handoff.
  • [P1] Add redacted OpenClaw terminal output, logs, or a reproducible validation transcript for the managed-service handoff failure path.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body has generic Node terminal snippets, but no OpenClaw managed-service update handoff proof showing failed helper-spawn behavior after the patch; redacted terminal output, logs, or a reproducible validation transcript is still needed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] If merged as-is, a missing or invalid handoff helper executable can be swallowed while the update path reports managed-service-handoff-started and schedules restart for a helper that never spawned.
  • [P1] The contributor has not added real OpenClaw managed-service update handoff proof after the prior proof ask.

Maintainer options:

  1. Repair the handoff failure contract (recommended)
    Make failed parent-side helper startup visible to callers so update.run returns or records a failed handoff instead of a false started handoff.
  2. Accept crash prevention only
    Maintainers could intentionally accept this as a crash-only mitigation, but managed updates can still stall after a false started handoff.
  3. Pause for a narrower replacement
    If the branch is not updated, close or replace it with a focused PR that preserves the documented failed-spawn response contract.

Next step before merge

  • [P1] Contributor follow-up is needed because the branch must fix the false-started handoff behavior and add real OpenClaw proof; ClawSweeper should not repair around the contributor proof gate.

Security
Cleared: No security or supply-chain sensitive files are changed; the diff only touches updater spawn handling and its test mock.

Review findings

  • [P1] Surface async helper spawn failure before reporting started — src/infra/update-managed-service-handoff.ts:737
Review details

Best possible solution:

Wait for the helper child to emit spawn or error before returning started, reject async helper-spawn failure through the existing failed-handoff path, and add focused regression coverage plus redacted OpenClaw terminal or log proof.

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

Yes. Source inspection and local Node probes show failed child-process spawns arrive through an asynchronous error event, and the caller path returns/logs started once this function resolves.

Is this the best way to solve the issue?

No. The no-op listener is a crash mitigation, but the best fix preserves the documented failed-handoff contract before reporting a started handoff.

Full review comments:

  • [P1] Surface async helper spawn failure before reporting started — src/infra/update-managed-service-handoff.ts:737
    This remains the same blocker from the previous review: adding a no-op listener stops the unhandled ChildProcess error, but startManagedServiceUpdateHandoff still resolves status: "started" immediately. Callers then schedule the gateway restart even though docs promise managed-service-handoff-failed when the detached helper cannot spawn; wait for spawn or error, or otherwise reject on async spawn failure so the existing catch path is used.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This PR targets a credible managed-service update crash path, but the failure mode is bounded to rare helper spawn failures rather than a current widespread outage.
  • merge-risk: 🚨 availability: The diff can make failed update helper spawns appear started, causing the gateway update/restart flow to proceed without a live handoff helper.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body has generic Node terminal snippets, but no OpenClaw managed-service update handoff proof showing failed helper-spawn behavior after the patch; redacted terminal output, logs, or a reproducible validation transcript is still needed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +1, Tests +1. Total +2 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 1 1 0 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 2 0 +2

What I checked:

  • Live PR diff: The live diff adds only child.on("error", () => {}) before unref() and on: vi.fn() to the spawn mock. (src/infra/update-managed-service-handoff.ts:737, fc36627bb918)
  • Current parent spawn contract: Current main spawns the detached handoff helper, immediately calls child.unref(), and then returns status: "started". (src/infra/update-managed-service-handoff.ts:731, cd86107a10f6)
  • Caller schedules restart after resolved handoff: update.run awaits startManagedServiceUpdateHandoff, records handoff.status: "started", schedules SIGUSR1, and responds ok when the handoff status is started. (src/gateway/server-methods/update.ts:247, cd86107a10f6)
  • Docs promise failed-spawn response: User-facing update docs define managed-service-handoff-failed when the Gateway tried to create the handoff but could not spawn the detached helper. Public docs: docs/cli/update.md. (docs/cli/update.md:207, cd86107a10f6)
  • Node child_process error is asynchronous: A local Node probe for a missing helper showed spawn() returned before the child emitted error with code ENOENT.
  • PR-shaped listener can falsely report started: A local Node probe with a no-op error listener printed a started-shaped result with no child pid for a missing executable.

Likely related people:

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 (2 earlier review cycles)
  • reviewed 2026-07-07T09:42:30.984Z sha 630be7a :: needs real behavior proof before merge. :: [P1] Surface async helper spawn failure before reporting started
  • reviewed 2026-07-07T11:04:10.393Z sha fc36627 :: needs real behavior proof before merge. :: [P1] Surface async helper spawn failure before reporting started

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 7, 2026
@steipete

Copy link
Copy Markdown
Contributor

Superseded and landed via #103278 as a1e75e0c612e64402bc3972890267559ede344cc.

The original change correctly identified the asynchronous detached-spawn crash. The landed repair additionally prevents a false started result, waits for readiness through systemd-run, stops a helper that misses the readiness deadline, preserves both callers' no-restart failure behavior, and removes the complete temporary handoff directory on failure.

I could not safely push the repaired tree back to this fork branch: GitHub's createCommitOnBranch API rejected the far-behind full-tree payload because it exceeded the 45 MB request cap. The replacement therefore used a maintainer branch. Original contributor credit is preserved with Co-authored-by: 丁宇婷0668001435 <[email protected]> in the repaired commit.

Proof: 131 focused tests and the full changed gate passed on Testbox-through-Crabbox; real direct, systemd, and 30-second timeout probes passed; final autoreview was clean; exact-head CI run 29065636575 passed. Full land-ready evidence is recorded in the replacement PR comment.

Thank you, @krissding, for finding and reporting the crash path.

@steipete steipete closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants