opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[Bug] Web UI spawns duplicate MCP server waves during active session

Open kokucoding opened this issue 2 days ago • 1 comments

Environment

  • OpenCode version: 1.1.16
  • OS: Linux (Contabo VPS)
  • Access: opencode web --port 4096 via Cloudflare tunnel

Bug Description

The Web UI spawns multiple complete waves of all configured MCP servers during a single session, causing duplicate tool responses (e.g., speak tool speaks twice).

Evidence

Process snapshot showing duplicates:

Web UI (PID 1103894) children:

WAVE 1 (08:49:33):
  1104065 memory-mcp
  1104066 tunnel-mcp
  1104067 speak-mcp      ← First instance
  1104073 port-manager-mcp
  ...

WAVE 2 (10:33:58 - 1hr 44min later):
  1110223 memory-mcp     ← Duplicate!
  1110224 tunnel-mcp     ← Duplicate!
  1110225 speak-mcp      ← Duplicate!
  1110226 port-manager-mcp
  ...

All 8 MCP types spawned twice, totaling 16 processes from one Web UI instance.

Steps to Reproduce

  1. Start opencode web --port 4096
  2. Access via browser, start a conversation
  3. Wait ~30 minutes or make additional requests
  4. Check: pstree -p $(pgrep -f "opencode web")
  5. Observe: Multiple instances of each MCP type

Expected Behavior

Each MCP server should spawn exactly once per Web UI instance.

Actual Behavior

MCPs spawn in waves (observed 2+ waves), causing:

  • Duplicate tool responses (speak speaks twice)
  • Resource waste (double memory/CPU usage)
  • Confusion about which instance handles requests

Workaround

Periodic cleanup script that kills duplicate MCPs (keeping lowest PID).

Related Issues

  • #6633 - MCP not terminated after session (different: orphans on exit)
  • #7261 - MCP orphans after crash (different: our duplicates spawn while running)

kokucoding avatar Jan 18 '26 09:01 kokucoding

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

  • #6633: [Bug] MCP processes not terminated after session ends - covers process lifecycle management but focused on exit cleanup
  • #7261: v1.1.6 still has memory bloat - heap not released + MCP orphan processes - mentions orphaned MCP processes accumulating across sessions with similar symptoms
  • #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation - covers related process spawning and cleanup issues in MCP lifecycle

The core issue appears to be in the MCP lifecycle management during Web UI sessions, specifically how MCPs are spawned and managed over time. Feel free to ignore if your specific case involves different circumstances.

github-actions[bot] avatar Jan 18 '26 09:01 github-actions[bot]