Problem
Each active agent session can launch its own MCP server process tree. Closing, cancelling, or replacing a session must tear down the processes owned by that session. Otherwise memory use grows across sessions, which is especially damaging on 8 GB Macs.
A machine audit observed roughly 20 Node processes using about 804 MB alongside several Codex sessions. The lifecycle contract should guarantee that session-owned MCP children do not survive their owner.
Required behavior
- Track every MCP process or process group launched for a session.
- On session close, cancellation, failure, replacement, or normal app shutdown: send graceful termination, wait for a bounded timeout, then force-kill survivors.
- Never kill explicitly shared/global MCP services; ownership and reference counting must be unambiguous.
- Reap orphaned Chitauri-owned MCP processes during startup recovery.
- Emit structured lifecycle logs with session ID, server name, PID/process group, signal, timeout, and final status.
- Keep teardown idempotent and safe under concurrent close/restart paths.
Acceptance criteria
- Integration test launches a real child process, closes the owning session, and verifies the full process tree exits.
- Cancellation, failure, replacement, and app-shutdown paths are covered.
- Shared MCP services remain alive until their final owner releases them.
- Repeating open/close five times produces no growth in MCP process count or resident memory.
- macOS packaged-app verification confirms there are no session-owned Node/MCP children after the session closes.
Problem
Each active agent session can launch its own MCP server process tree. Closing, cancelling, or replacing a session must tear down the processes owned by that session. Otherwise memory use grows across sessions, which is especially damaging on 8 GB Macs.
A machine audit observed roughly 20 Node processes using about 804 MB alongside several Codex sessions. The lifecycle contract should guarantee that session-owned MCP children do not survive their owner.
Required behavior
Acceptance criteria