Skip to content

opencode run: MCP child processes not terminated on exit (orphan leak) #15808

Closed

Description

@the3asic

Summary

opencode run spawns MCP server processes (e.g., mcp-searxng, mcp-tavily, sequential-thinking, etc.) but does not terminate them when the run session exits. These processes get reparented to PID 1 and persist indefinitely, causing significant memory leaks over time.

Reproduction

  1. Configure MCP servers in opencode.json (e.g., mcp-searxng)
  2. Run opencode run "any prompt" — MCP servers are spawned as child processes
  3. After opencode run completes and exits, check: ps -eo pid,ppid,args | grep mcp-searxng
  4. The MCP processes are still alive with PPID=1 (orphaned)

Impact

In a cron-based setup (e.g., heartbeat scripts calling opencode run every 30 minutes), orphaned MCP processes accumulate rapidly:

  • Each mcp-searxng process consumes ~61MB RSS
  • ~90 opencode run invocations/day = ~5.5GB/day leaked
  • Observed: 301 orphaned mcp-searxng processes consuming ~18GB before manual cleanup

Environment

  • OpenCode version: 1.3.0
  • OS: Ubuntu 20.04 (ARM64, Oracle Cloud)
  • MCP servers configured: searxng, tavily, sequential-thinking, zhipu-vision, github-search, websearch

Expected Behavior

opencode run should send SIGTERM to all spawned MCP child processes before exiting (or use a process group so they all terminate together).

Current Workaround

Cron script that periodically kills orphaned MCP processes (PPID=1):

#!/usr/bin/env bash
MCP_PATTERNS="mcp-searxng|mcp-tavily|sequential-thinking|github-search|zhipu-vision|websearch"
while IFS= read -r line; do
    pid=$(echo "$line" | awk '{print $1}')
    ppid=$(echo "$line" | awk '{print $2}')
    [ "$ppid" = "1" ] && kill "$pid" 2>/dev/null
done < <(ps -eo pid,ppid,args | grep -E "$MCP_PATTERNS" | grep -v grep)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 3, 2026
  2. github-actions commented on Mar 3, 2026

    @github-actions
    Contributor

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

    If your issue is specifically about the opencode run (non-interactive/headless) command not cleaning up MCP subprocesses, and none of the above cover that exact path, please clarify that distinction so maintainers can triage accordingly.

  3. nexxeln commented on Mar 3, 2026

    @nexxeln
    Contributor

    fixed in #15516

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions