-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
runRestartScript propagates synchronous spawn() errors as unhandled rejections #83892
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Severity: medium / Confidence: high / Category: bug
Triage: confirmed-bug
Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18)
Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol
Evidence
src/cli/update-cli/restart-helper.ts:248-270(runRestartScript)Reasoning
Node.js child_process.spawn() can throw synchronously (e.g. ENOENT if /bin/sh is absent on an embedded system, or EACCES if the tmp script lacks execute permission). The function has no try/catch and no error listener on the ChildProcess. A synchronous throw escapes the async wrapper as an unhandled rejection, crashing the update process at the exact moment the gateway is already stopped waiting to be restarted. The caller in update-command.ts must also handle the rejection, but defensive handling at the source is safer.
Reproduction
Force /bin/sh to be missing or remove execute permission from the prepared script path; calling runRestartScript will throw rather than silently failing.
Recommendation
Wrap the spawn call in try/catch and attach a no-op error handler on the child process to prevent unhandled rejection:
try { const child = spawn(...); child.on('error', () => {}); child.unref(); } catch { /* best-effort restart; caller continues */ }Why existing tests miss this
No tests exist for this module. The failure mode requires controlling spawn behaviour which unit tests with a mocked spawn would expose.
Suggested regression test
it('does not throw when spawn rejects', async () => { vi.spyOn(childProcess, 'spawn').mockImplementation(() => { throw new Error('ENOENT'); }); await expect(runRestartScript('/tmp/test.sh')).resolves.toBeUndefined(); });
Minimum fix scope
Single try/catch around the spawn call plus a no-op child.on('error') listener inside runRestartScript.
Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID:
fnd_sig-feat-cli-command-0e1f16a0ce-_d0126d3aea.