Fix: Prevent Zombie Process Accumulation (Issue #737)
This release fixes a critical issue where Claude haiku subprocesses spawned by the SDK weren't terminating properly, causing zombie process accumulation. One user reported 155 processes consuming 51GB RAM.
Root Causes Addressed
- SDK's SpawnedProcess interface hides subprocess PIDs
deleteSession()didn't verify subprocess exitabort()was fire-and-forget with no confirmation- No mechanism to track or clean up orphaned processes
Solution
- ProcessRegistry module: Tracks spawned Claude subprocesses via PID
- Custom spawn: Uses SDK's
spawnClaudeCodeProcessoption to capture PIDs - Signal propagation: Passes signal parameter to enable AbortController integration
- Graceful shutdown: Waits for subprocess exit in
deleteSession()with 5s timeout - SIGKILL escalation: Force-kills processes that don't exit gracefully
- Orphan reaper: Safety net running every 5 minutes to clean up any missed processes
- Race detection: Warns about multiple processes per session (race condition indicator)
Files Changed
src/services/worker/ProcessRegistry.ts(new): PID registry and reapersrc/services/worker/SDKAgent.ts: Use custom spawn to capture PIDssrc/services/worker/SessionManager.ts: Verify subprocess exit on deletesrc/services/worker-service.ts: Start/stop orphan reaper
Full Changelog: v9.0.7...v9.0.8
Fixes #737