Skip to content

Location shutdown does not close its MCP servers, so reloads leave old stdio processes running #51731

Description

@kernel-oops

Description

When a Location is invalidated (config change, plugin reload, opencode reload), its stdio MCP servers are not closed at Location shutdown. LocationLifecycle shutdown closes permissions, forms and RPC, but MCP connections only close when the Location's layer scope is finalised. Running steps keep the old Location graph borrowed until a hand-off point, so the old graph's MCP processes keep running alongside the replacement graph's. On a long-lived server with frequent reloads they accumulate.

This is one of the causes of the process growth in #51003 (which is mainly about global stdio servers being started once per Location); the comment there showing that reload does not reap the previous boot's MCP subprocesses is this problem.

Plugins

Any configuration with local (stdio) MCP servers.

OpenCode version

v2.0.16 (also the current v2 branch)

Steps to reproduce

  1. Configure a global local MCP server and run opencode serve.
  2. Start a session in a directory and keep a step running (or keep the Location otherwise borrowed).
  3. Trigger a Location reload (edit the config, or opencode reload).
  4. The MCP process from the old Location graph is still running next to the new one; repeat to accumulate more.

Screenshot and/or share link

n/a

Operating System

Linux

Terminal

n/a

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions