Repository navigation
fix(server): a failed child spawn no longer crashes the server - #313
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spawnClaudeProcessGroup attached no 'error' listener and read child.stdio[4] on a child that never started, so ENFILE/EMFILE threw a TypeError and then Node emitted an unhandled 'error' that killed the process. Listen first and throw a clear error when the spawn has no pid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tdio Same fault as the Claude CLI spawn: with EMFILE/ENFILE a child has no stdio, so code that reads it before listening throws and then the child's 'error' goes unhandled. Covers the Claude probe, the Namespace CLI runners and the service launcher's runtime spawn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Verifier verdict (round 1): PASS+NOTESIndependent check of head 1. Correctness
2. Tests
3. Missed sitesNone found. I checked every raw 4. CommentsEvery new comment is one line and states a constraint, not the fix. Notes (non-blocking, follow-up at most)
Commands |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenarios4 of 64 scenario measurements changed or failed.
All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
Why
A failed child spawn killed the whole server. On the production home server (runtime-v0.1.141, 2026-11-21 22:16) the machine hit
fs.file-max, every spawn failed with ENFILE, and the process died:spawnClaudeProcessGroupnever attached an'error'listener. After a failed spawnchild.stdiois undefined, sochild.stdio[4]threw a TypeError (the turn failed), then Node emitted'error'on the ChildProcess on the next tick with no listener, which is fatal.What changed
spawnClaudeProcessGrouplistens for'error'right afterspawn, and throws a clear error when the spawn has no pid instead of readingchild.stdio. The errno (ENFILE,EMFILE,EAGAIN, ...) only arrives with the event, so the listener copiescodeandcauseonto the thrown error.spawnClaudeProbeThroughEnv), the Namespace CLI runners (spawnNsc,executeCli), and the service launcher's runtime spawn. Each touchedchild.stdio,child.stdoutorchild.stdinbefore attaching an error listener. With EMFILE/ENFILE those areundefined, notnull.A failed spawn now fails only the turn or operation that asked for it.
Scope
Every raw
node:child_processspawn inapps/server/srcwas checked. Already safe:SpawnHost,spawnHostProcess,SpawnWorker,windowsVerbatimSpawn,speech/native.ts, the systemddaemon-reloadspawn,cli/triage.ts. All attach an error listener synchronously afterspawn.execFile/execFileSync/spawnSynccall sites report errors through their callback or return value. EffectChildProcessSpawnerusers are untouched. Script strings written to disk or sent over SSH (AgentDeviceShim,sshDeviceScript,deviceToolMaintenance) run in other processes.Tradeoffs
The thrown error's message is generic because Node reports the errno one tick after
spawnreturns, socodeis filled in on the error object a tick later. The three extra sites got no new tests: reproducing EMFILE needs file-descriptor exhaustion.Verification
ClaudeAgentSdkQueryRunner.test.tsfail on the test commit alone (expected [ …(1) ] to deeply equal []) and pass with the fix. One mocks a spawn that fails with no pid; the other uses an already-aborted signal.vp test runon the touched test files,vp run typecheckinapps/server, andvp run check:changedall pass.🤖 Generated with Claude Code