Skip to content
This repository was archived by the owner on May 28, 2026. It is now read-only.
This repository was archived by the owner on May 28, 2026. It is now read-only.

MCP server processes not terminated on agent session end #132

Description

@a4xrbj1

Steps to reproduce

  1. Run a multi-agent session with MCP servers configured (e.g. MongoDB MCP)
  2. Let the session complete, or kill the coordinator
  3. Run ps aux | grep mcp-server

Expected behavior

All MCP server processes are terminated when the agent session or coordinator that spawned them exits.

MCP server processes remain running indefinitely. After several multi-agent runs, 20+ orphaned instances were found:

ps aux | grep mongodb-mcp-server
andreaswest  53222  ... node .../mongodb-mcp-server --readOnly --connectionString mongodb://localhost:27017/worker
andreaswest  25472  ... node .../mongodb-mcp-server
andreaswest  21498  ... node .../mongodb-mcp-server --readOnly --connectionString mongodb://localhost:27017/worker
# ... 18 more instances

All orphaned processes had PPID 1 (reparented to launchd), confirming the parent agent process exited without cleaning up its children.

Impact

  • Sustained high CPU and memory usage between sessions
  • fseventsd thrashing from open file handles across worktrees
  • System load average remained elevated (25+) long after all sessions were stopped
  • Required manual pkill -f mongodb-mcp-server to recover

Suggested fix

Agent teardown (session-end hook, coordinator stop, and crash recovery paths) should explicitly terminate any MCP server child processes. A process group kill (kill -TERM -<pgid>) on the spawned process group would catch all descendants. Alternatively, tracking spawned MCP PIDs in the .overstory/ SQLite DB and killing them on cleanup would also work.

A ov clean command that kills known orphaned MCP/agent processes would also be a useful complement.

Workaround

pkill -f mongodb-mcp-server

Actual behavior

Summary

When agent sessions end (normally or via crash/interrupt), MCP server child processes are not terminated. They accumulate as orphaned processes reparented to launchd, consuming memory and CPU indefinitely.

overstory version

0.9.1

Bun version

1.3.10

Operating system

macOS 26.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agent-lifecycleAgent identity, sessions, checkpoint/resume, slingbugSomething isn't workingdifficulty:moderateRequires understanding of 1-2 subsystemsfocus:reliabilityStall detection, recovery, cleanup, session DB hygienepriority:mediumUseful but not urgent, well-scoped

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions