fix: kill process tree on agent completion to prevent zombies

Added _kill_process_tree call in _read_output finally block to ensure
child processes (Claude CLI) are cleaned up when agents complete or fail.
This prevents accumulation of zombie processes that was causing 78+
Python processes when max concurrency was set to 5.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
mmereu
2026-01-24 11:18:28 +01:00
parent 45289ef0d2
commit 795bd5f92a

View File

@@ -632,6 +632,12 @@ class ParallelOrchestrator:
print(f"[Feature #{feature_id}] {line}", flush=True) print(f"[Feature #{feature_id}] {line}", flush=True)
proc.wait() proc.wait()
finally: finally:
# CRITICAL: Kill the process tree to clean up any child processes (e.g., Claude CLI)
# This prevents zombie processes from accumulating
try:
_kill_process_tree(proc, timeout=2.0)
except Exception as e:
debug_log.log("CLEANUP", f"Error killing process tree for {agent_type} agent", error=str(e))
self._on_agent_complete(feature_id, proc.returncode, agent_type, proc) self._on_agent_complete(feature_id, proc.returncode, agent_type, proc)
def _on_agent_complete( def _on_agent_complete(