fix: terminate local stdio mcp processes on disconnect / replace / rollback#26715
fix: terminate local stdio mcp processes on disconnect / replace / rollback#26715yangshuai0711 wants to merge 3 commits into
Conversation
|
This PR addresses the exact MCP process leak I've been experiencing on macOS desktop. After a few days of use, I had 27 zombie MCP processes (minimax, agentmemory, zai-mcp) consuming ~500MB, all orphaned children of the OpenCode Helper Electron process. The root cause matches this PR perfectly: disconnect/replace/defs-failure paths don't kill spawned processes, only client.close() is called. Would love to see this merged - it's a significant memory leak for desktop users who keep OpenCode running for days. Happy to help test if needed. Related: #26714 |
|
+1, this PR fixes a real memory leak affecting desktop users. I've confirmed 27+ zombie MCP processes accumulating over days (minimax, agentmemory, zai-mcp) all orphaned under OpenCode Helper. The fix in this PR covering all 4 paths (disconnect, replace, defs-fallback, disposal) would eliminate this. Hope this can get reviewed and merged soon. @thdxr |
|
+1, confirmed 27 zombie MCP processes (minimax, agentmemory, zai-mcp) leaking under OpenCode Helper on macOS desktop. This PR covers all paths needed for cleanup. Please review and merge. @thdxr |
|
+1 — confirmed 27 zombie MCP processes (minimax, agentmemory, zai-mcp) leaking under OpenCode Helper on macOS desktop. Current workaround: periodic cleanup LaunchAgent + migrated minimax to Streamable HTTP. Root fix needed for all stdio MCP types. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #26714
Related to #15808
Type of change
What does this PR do?
Local stdio MCP servers were leaking processes on disconnect, replace, and rollback. PR #15516 added descendant cleanup in the dispose handler but left three gaps:
disconnect()only calledclient.close()with no kill at alldefs()failure also skipped the killThis pulls teardown into a single
stopClient()helper that kills descendants, kills the root PID, then callsclient.close(). It is reused across all four paths: disconnect, add-replace, defs-failure rollback, and instance disposal.How did you verify your code works?
bun test test/mcp/lifecycle.test.tsinpackages/opencode— 26 pass, 0 failChecklist