Skip to content

mcp: local stdio MCP child process leaks per session, never killed on session close #53722

Description

@Glaicer

Summary

Every ended opencode session leaves its local (stdio) MCP server child process running. The child's stdio is never closed and the process is never killed or disposed, so one ~90–110MB child accumulates per session under the long-running opencode serve --service process. After 8 sessions this was ~800MB of RSS held by idle MCP children; the memory was only reclaimed by rebooting.

Environment

  • opencode version: 2.0.24
  • OS: Fedora 44 (Linux 7.2.8-200.fc44.x86_64 x86_64)
  • Terminal: ghostty (TERM=xterm-256color, COLORTERM=truecolor; TERM_PROGRAM=Orca when embedded)
  • Shell: zsh (/usr/bin/zsh)

Reproduction

  1. Configure a local stdio MCP server, e.g.:

    "mcp": {
      "servers": {
        "codegraph": { "type": "local", "command": ["codegraph", "serve", "--mcp"] }
      }
    }
  2. Open the TUI and start a session; the MCP child process spawns, parented by opencode serve --service.

  3. Exit the TUI / end the session.

  4. The child is still running:

    $ ps -eo pid,ppid,rss,etime,args | grep "serve --mcp"
    

    One child is left behind per session, consistently (every session close).

Expected Behavior

When a session ends, its MCP client is disposed: the child's stdio pipes are closed and the child process is terminated.

Actual Behavior

The child keeps running with its stdio held open. Live evidence captured while writing this report:

  • opencode serve --service (up 6h41m) had 8 codegraph serve --mcp children, 88–109MB RSS each (~808MB total), elapsed times 1min–1h05m — one per session opened. Only 2 TUI client processes were alive at that moment, so at least 7 of the 8 belonged to already-ended sessions.
  • 3 older children from a previous service lifetime were re-parented to systemd --user (PPID 1525): 141MB RSS (elapsed 1d04h), 331MB, and 155MB — i.e. the children survive even the death of the service itself and keep holding memory until manually killed or the machine reboots.

Additional Context

  • The observed MCP server is codegraph serve --mcp (Node.js stdio server), but the leak looks like it is in opencode's disposal of local MCP children rather than server-specific behavior. Only one local MCP was enabled; remote MCP servers have no child process and are presumably unaffected.
  • Frequency: 100% of session closes.
  • Workaround: none found so far — memory growth was only stopped by rebooting.

Activity

  1. opencode-agent commented on Oct 7, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and measurements! This looks like the same problem as #50363: local stdio MCP servers start once per session under the background service (opencode serve --service) and keep running after the session ends. Someone there has already confirmed it on Linux with v2.0.24 and the same symptoms (one leftover MCP process per closed session). #51249 reports it on Windows, and #50758 / #50780 cover child processes that keep running after the service stops or restarts.

    Please follow #50363 for updates; adding your codegraph serve --mcp numbers there would help. The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. github-actions commented on Oct 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. opencode-agent commented on Oct 8, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #50363, since there's been no reply saying how this differs. That issue covers the same problem: under opencode serve --service, each session starts its own local stdio MCP server process, and it keeps running after the session ends. It has already been confirmed there on Linux with v2.0.24.

    Please follow #50363 for updates. Your codegraph serve --mcp measurements would be useful there. If your problem turns out to be different, reply here and we can reopen this.

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