fix(worker): kill spawned claude trees when the worker dies

Spawned claude processes were only torn down on graceful cancellation
(Process.Kill(entireProcessTree)). A hard worker death — Task Manager
End Task, crash, OS restart, installer update — ran no cleanup, orphaning
the claude->node->conhost tree, which lingered and piled up across
restarts.

Assign every spawned claude process to a Windows Job Object with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE. The worker holds the only handle, so
when it terminates for any reason the OS tears down the whole job. No-op
on non-Windows; best-effort with a one-time warning if the Win32 calls
fail.
This commit is contained in:
Mika Kuns
2026-06-26 16:11:53 +02:00
parent 3eea2b7c96
commit faf6104645
3 changed files with 159 additions and 0 deletions
@@ -46,6 +46,7 @@ public sealed class ClaudeProcess : IClaudeProcess
using var process = new Process { StartInfo = psi };
process.Start();
ProcessJobObject.Assign(process, _logger);
await process.StandardInput.WriteAsync(prompt);
process.StandardInput.Close();