termmate icon indicating copy to clipboard operation
termmate copied to clipboard

Agent shutdown leaves descendant processes running

Open thiblizz opened this issue 4 months ago • 0 comments

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

  1. Start an AI agent in TermMate (Claude, Codex, Pi, Antigravity, or OpenCode).
  2. Run a command that spawns a long-lived subprocess.
  3. Stop the agent or close its session.
  4. 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=True and 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.

thiblizz avatar Jul 26 '26 21:07 thiblizz