fix: kill agent-spawned bash trees and dev servers on dashboard shutdown

TUI quit ('q'/Ctrl+C) bypassed signal handlers via process.exit(0), and
neither shutdown path closed the HTTP server, so server.close()'s
stopAllDevServers() listener never ran. In-flight agent bash commands
(spawned detached for their own pgroup) were also never aborted, so
their subprocess trees — including vitest workers — survived as orphans.

Route the TUI quit through SIGINT so the registered shutdown handler
runs, await stopAllDevServers() in both shutdown paths, and abort
in-flight bash on every active agent session at the start of the
runtime drain so killProcessTree reaches every grandchild.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-25 14:13:30 -07:00
parent bcc642eaa6
commit c235705d7c
6 changed files with 109 additions and 3 deletions

View File

@@ -838,6 +838,22 @@ export class InProcessRuntime
runtimeLog.log("MissionExecutionLoop stopped");
}
// 7b. Abort in-flight bash subprocess trees on every active agent
// session. Each bash command was spawned with `detached: true` (own
// process group), so killing the worker alone leaks vitest / npm / build
// grandchildren as orphans. This call routes through pi-coding-agent's
// AbortController -> killProcessTree, taking down the whole subtree.
// Sessions are intentionally NOT disposed here so near-complete steps
// can still wrap up during the drain window below.
if (this.executor) {
try {
this.executor.abortAllSessionBash();
runtimeLog.log("Aborted in-flight bash subprocesses on active sessions");
} catch (err) {
runtimeLog.warn(`Failed to abort in-flight bash subprocesses: ${err}`);
}
}
// 8. Wait for active tasks to complete (30 second timeout)
const shutdownTimeout = 30000;
const startTime = Date.now();