GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): close a Location's MCP servers when it shuts down by kernel-oops · Pull Request #51730 · anomalyco/opencode

Conversation

@kernel-oops

@kernel-oops kernel-oops commented Sep 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #50758 for the reload case: old stdio MCP processes surviving a config or Location reload and overlapping with the new ones. Processes orphaned by a full service restart are a separate path and are not changed here.

Related to #51003, which this does not fix: global stdio MCP servers are still started once per Location.

Type of change

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

What does this PR do?

LocationLifecycle shutdown closes permissions, forms and RPC, but not MCP. The MCP connections only close when the Location's layer scope is finalised, and after an invalidation or reload that can happen much later: running steps keep the old Location graph borrowed until they reach a hand-off point, so the old graph's stdio MCP servers stay alive alongside the new graph's. On a busy server with frequent config or plugin reloads, those old processes pile up.

This adds Mcp.Interface.shutdown, which stops every server in the Location, marks it disabled and refuses any later start (a credential switch or other event could otherwise reconnect it), and calls it from Location shutdown right after RPC is closed. Nothing changes for a Location that is simply released: its scope still closes the connections as before; shutdown just no longer waits for that.

In-flight MCP calls on the old graph fail once it is shut down. That matches how its permissions and forms already behave at shutdown.

How did you verify your code works?

  • New test in test/mcp.test.ts (POSIX only, like the existing descendant-process test): connects a real stdio fixture server tagged with a unique argument, calls shutdown, and checks the process is gone, the server reports disabled with no tools, and a later connect does not respawn it. The respawn check fails without the new start guard.
  • bun test test/mcp.test.ts test/mcp-instructions.test.ts test/mcp-oauth.test.ts test/location-activity.test.ts test/session-remove.test.ts (107 pass) and bun run typecheck in packages/core.
  • The wiring in location-lifecycle.ts is one call; I did not add a full Location-graph test for it. Happy to add one if you point me at the preferred fixture.

Screenshots / recordings

Not a UI change.

Checklist

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01RG8UhiogA1Ho2eZRx8tn2y

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kernel-oops @claude
fix(core): close a Location's MCP servers when it shuts down
247c1d1
Location shutdown closed permissions, forms and RPC but not MCP. After an
invalidation or reload, running steps can keep the old Location graph (and so
its scope) alive long after shutdown, so its stdio MCP servers outlived it and
accumulated. MCP now has a shutdown that stops every server and refuses later
starts (such as event-driven reconnects), and Location shutdown calls it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RG8UhiogA1Ho2eZRx8tn2y
@github-actions github-actions Bot added the contributor label Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the needs:issue label Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kernel-oops kernel-oops mentioned this pull request Sep 27, 2026
Location shutdown does not close its MCP servers, so reloads leave old stdio processes running #51731
Closed
@opencode-agent opencode-agent Bot mentioned this pull request Oct 8, 2026
Background service leaks MCP server processes across reconnects and reloads #53992
Closed
@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:20
@github-actions github-actions Bot removed the needs:issue label Oct 10, 2026
@opencode-agent opencode-agent Bot mentioned this pull request Oct 10, 2026
fix(mcp): reconnect dropped servers with backoff #54378
Open
4 tasks done
@oopen oopen mentioned this pull request Oct 12, 2026
mcp: orphaned local MCP server processes accumulate after sessions end #50363
Open
This was referenced Oct 13, 2026
OpenCode serve memory grows without bound: MCP server processes are never (or incorrectly) reclaimed #55017
Closed
mcp: stdio servers fail to start after service restart due to orphaned background processes #56388
Closed
@opencode-agent opencode-agent Bot mentioned this pull request Oct 24, 2026
session: in-flight tool calls aborted (Interaction cancelled because the location shut down) #58650
Closed
@github-actions

github-actions Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Oct 27, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

server: stdio MCP child processes not terminated on service restart / config reload

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kernel-oops
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.