Skip to content

fix(opencode): terminate local MCP process trees#37731

Open
flowluap wants to merge 1 commit into
anomalyco:devfrom
flowluap:mcp-process-cleanup
Open

fix(opencode): terminate local MCP process trees#37731
flowluap wants to merge 1 commit into
anomalyco:devfrom
flowluap:mcp-process-cleanup

Conversation

@flowluap

Copy link
Copy Markdown

Issue for this PR

Closes #26714

Related to #30123. This fixes the in-process POSIX teardown paths; complete Windows tree containment still requires a Job Object or equivalent.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

SDK client close stops the direct MCP process but may leave descendants alive. This routes disconnect, replacement, failed setup, and instance disposal through one cleanup path. On POSIX it snapshots descendants, sends SIGTERM leaf-first, waits 500 ms, escalates survivors, closes the transport, and verifies the process set again.

How did you verify your code works?

  • bun test test/mcp/lifecycle.test.ts --timeout 20000: 25 pass
  • MCP OAuth suites: 32 pass
  • bun typecheck
  • Five-run benchmark: median disconnect 4002.98 ms -> 694.85 ms
  • Baseline retained two descendants; patched runs retained none and both observed SIGTERM

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local stdio MCP servers leak processes on disconnect / replace / rollback

1 participant