Principle:777genius Agent teams ai Team Process Lifecycle
| Knowledge Sources | |
|---|---|
| Domains | Process_Management, Team_Management |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Pattern for safely terminating multi-process CLI team trees with platform-aware kill semantics that prevent cleanup-side-effects from newer CLI versions.
Description
Team Process Lifecycle termination addresses the challenge of killing a spawned CLI process and all its descendants without triggering undesired cleanup side effects. Newer Claude CLI versions (>=2.1.x) handle SIGTERM gracefully and run cleanup that deletes team files (config.json, inboxes/, tasks/). Using SIGKILL (uncatchable) prevents this destructive cleanup.
Key considerations:
- SIGKILL over SIGTERM: SIGTERM allows the child to run cleanup code that may delete team files; SIGKILL is uncatchable and prevents this.
- Platform-aware tree kill: On Unix, the process-group identity captured at spawn time identifies descendants even after the root PID exits. On Windows, `taskkill` accepts only a PID, so a reused PID is unsafe.
- Exit confirmation: A timeout-bounded wait confirms the process tree is dead before resources are released.
- stdin.end() prohibition: EOF on stdin triggers the same cleanup as SIGTERM in some CLI versions.
Usage
Use this principle when designing process termination for external CLI processes that have destructive cleanup handlers. Applicable to any system where graceful shutdown of a child process causes unintended side effects.
Theoretical Basis
The termination follows a confirm-before-release pattern:
# Abstract algorithm (NOT real implementation)
async def kill_team_process_and_wait(child):
if not child or not child.pid:
return
if child.already_exited:
if platform != "win32":
await kill_tree_and_wait(child, "SIGKILL")
return
exit_confirmed = Promise()
child.on("close", exit_confirmed.resolve)
child.on("exit", exit_confirmed.resolve)
kill_process_tree(child, "SIGKILL") # Uncatchable
try:
await with_timeout(exit_confirmed, timeout=5000)
except Timeout:
# Force PID-based kill as fallback
kill_tree_and_wait(child, "SIGKILL")