termmate
termmate copied to clipboard
Agent shutdown leaves descendant processes running
Summary
Stopping an AI agent may leave descendant processes (shell commands, tools, MCP servers) running on Windows, macOS, and Linux, causing resource leaks and interfering with subsequent sessions.
Steps to reproduce
- Start an AI agent in TermMate (Claude, Codex, Pi, Antigravity, or OpenCode).
- Run a command that spawns a long-lived subprocess.
- Stop the agent or close its session.
- Check the running processes.
Actual behavior
Descendant processes may continue running after the agent stops.
Expected behavior
All processes within the agent's managed process boundary should terminate.
Suggested fix
Centralize subprocess management by reusing OpenCode's existing implementation across all agents:
- Linux/macOS: Use
start_new_session=Trueand terminate the process group (SIGTERM→SIGKILL), even if the parent has exited. - Windows: Use Job Objects with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, assigning processes before execution. - Cleanup: Ensure reliable, idempotent termination on stop, restart, disconnect, and plugin unload without affecting unrelated processes or shared services.
Keep the implementation minimal, dependency-free, and centralized.