You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stopping a run leaves agent grandchildren alive (no process-group kill) #143
electron/claude.js:321-337 (same shape in kimi.js:524-542 and the codex/opencode adapters): kill() SIGTERMs only the direct CLI child. Spawns are not detached, so there is no kill(-pid) group teardown. Compare electron/devservers.js:149-175, which does group-kill correctly.
Impact
Stopping a run whose agent spawned subprocesses via its shell tool (test watchers, servers started outside the devserver feature) orphans them; they keep burning CPU and holding the worktree cwd. May be partly intentional (the devservers feature surfaces such processes), but the orphan-on-stop behavior deserves an explicit decision.
Fix direction
Spawn agent CLIs in their own process group and group-kill on stop, with an allowlist for processes the devservers feature claims.
Fixed on coder/stopping-a-run-leaves-agent-grandchildre-0e1dba.
Group kill. New electron/proc.js exports killTree(child, ms): SIGTERM the child's process group via process.kill(-pid), fall back to the bare pid, escalate to SIGKILL on an unref'd timer — the shape devservers.js:149-175 already used. All five agent-CLI spawns (agent.js, claude.js, codex.js, kimi.js, opencode.js) now pass detached: true, and the five identical 14-line kill() bodies collapse to one call each. runner.js's app-quit reaper group-kills too, and now escalates to SIGKILL where it previously sent a bare SIGTERM.
Every stop path (stopRun, stopCrew, stopAll, disposeClaudeSession, stopWorkflowEntry, IPC runs:stop, web clients) routes through a handle's kill(), so all are covered by the adapter change.
No allowlist — decided against, with evidence. Devservers are spawned in the Electron main process (ipc.js:713 → devservers.js:194), already detached and already their own process group. They are never descendants of an agent CLI, so an agent group-kill cannot reach them; no MCP or bridge path makes one a descendant either. A dev server the agent starts itself in its shell is in the agent's group and now dies on stop — which is the behaviour this issue asked for. An agent's nohup'd process still survives, as runner.js:316 documents deliberately.
Regression detached introduced, and its fix. Ctrl-C on npm run dev used to reach the CLIs because they shared the terminal's foreground process group. Detached, they are immune, and main.js had no SIGINT/SIGTERM handler — only before-quit, which a default-disposition SIGTERM skips entirely. New electron/shutdown.js (installShutdown, same shape as installCrashGuard) gives before-quit and both signals one re-entrant teardown, then process.exit(0).
Verification.electron/test/proc.test.js backgrounds a real grandchild, kills, and asserts it dies; mutating killTree to signal only the direct child makes it fail. electron/test/shutdown.test.js asserts registration on the real process; moving the handler to SIGHUP makes it fail. tsc --noEmit clean. Full electron suite: 817 pass, 11 fail — those 11 (orch-server, web-integration) fail identically on main in this sandbox because the servers cannot bind, so they are pre-existing.
Not exercised: an end-to-end Ctrl-C of npm run dev with a live GUI run. The signal handler is unit-tested, but the real Electron path was not driven.
Activity
currentbits commentedon Aug 17, 2026
Fixed on
coder/stopping-a-run-leaves-agent-grandchildre-0e1dba.Group kill. New
electron/proc.jsexportskillTree(child, ms): SIGTERM the child's process group viaprocess.kill(-pid), fall back to the bare pid, escalate to SIGKILL on an unref'd timer — the shapedevservers.js:149-175already used. All five agent-CLI spawns (agent.js,claude.js,codex.js,kimi.js,opencode.js) now passdetached: true, and the five identical 14-linekill()bodies collapse to one call each.runner.js's app-quit reaper group-kills too, and now escalates to SIGKILL where it previously sent a bare SIGTERM.Every stop path (
stopRun,stopCrew,stopAll,disposeClaudeSession,stopWorkflowEntry, IPCruns:stop, web clients) routes through a handle'skill(), so all are covered by the adapter change.No allowlist — decided against, with evidence. Devservers are spawned in the Electron main process (
ipc.js:713→devservers.js:194), already detached and already their own process group. They are never descendants of an agent CLI, so an agent group-kill cannot reach them; no MCP or bridge path makes one a descendant either. A dev server the agent starts itself in its shell is in the agent's group and now dies on stop — which is the behaviour this issue asked for. An agent'snohup'd process still survives, asrunner.js:316documents deliberately.Regression
detachedintroduced, and its fix. Ctrl-C onnpm run devused to reach the CLIs because they shared the terminal's foreground process group. Detached, they are immune, andmain.jshad no SIGINT/SIGTERM handler — onlybefore-quit, which a default-disposition SIGTERM skips entirely. Newelectron/shutdown.js(installShutdown, same shape asinstallCrashGuard) givesbefore-quitand both signals one re-entrant teardown, thenprocess.exit(0).Verification.
electron/test/proc.test.jsbackgrounds a real grandchild, kills, and asserts it dies; mutatingkillTreeto signal only the direct child makes it fail.electron/test/shutdown.test.jsasserts registration on the realprocess; moving the handler to SIGHUP makes it fail.tsc --noEmitclean. Full electron suite: 817 pass, 11 fail — those 11 (orch-server,web-integration) fail identically onmainin this sandbox because the servers cannot bind, so they are pre-existing.Not exercised: an end-to-end Ctrl-C of
npm run devwith a live GUI run. The signal handler is unit-tested, but the real Electron path was not driven.fix: group-kill agent CLI process trees on stop (#143)
fix: reap detached agent CLIs on Ctrl-C / SIGTERM (#143)
fix: group-kill agent CLI process trees on stop (#143)
fix: reap detached agent CLIs on Ctrl-C / SIGTERM (#143)