Repository navigation
mcp: no reconnect after network change/socket reset; stale Error until server process is killed #52564
Copy link
Copy link
Closed as duplicate
Closed as duplicate
Copy link
Description
Description
MCP servers that lose their connections (e.g., a network change such as joining a VPN resets their sockets) are never reconnected: the long-lived opencode serve --service server performs zero reconnect attempts when new CLI/TUI clients attach, and the TUI shows Error for those servers indefinitely. The only recovery is killing the server process to force a cold start.
Environment
- opencode version: 2.0.21
- OS: Darwin 25.2.0 (macOS, arm64)
- Terminal: Apple_Terminal, TERM=xterm-256color
- Shell: /bin/zsh
- Install/channel: latest (https://opencode.ai/v2/install)
- Active plugins: one local file plugin auto-loaded from
~/.config/opencode/plugins/ - Architecture note: a long-lived server (
opencode serve --service) holds all MCP state; TUI/CLI invocations attach to it (--auto,-s <session>).
Reproduction
- Have a running
opencode serve --serviceprocess with MCP servers connected at cold start (server log:mcp connected server=context7 tools=2, plus other remote anduvx-based local servers). - Change networks mid-session — in my case, join a VPN. Existing MCP sockets die. Server log shows (server name redacted):
level=WARN message="mcp http request failed" errors=[{"message":"The socket connection was closed unexpectedly","code":"ECONNRESET"}] server=<remote-mcp-server> - Quit the TUI and relaunch (
opencode -s <sessionID>), or attach new CLIs (opencode --auto). Observed three CLI attach events within one minute. - Check MCP status in the TUI.
Expected Behavior
After a connection loss or when a new client attaches, the server retries failed/disconnected MCP servers (with backoff), and the TUI status recovers without manual process kills.
Actual Behavior
- After the socket reset, the log contains no MCP reconnect attempts at all — no
mcp connect failed, no retry — across multiple CLI reattach events. - The TUI shows
Errorfor every server whose connection predated the network change, indefinitely, even though all affected hosts are reachable from the same machine at that moment (verified withcurl). - New sessions attached to the same server do not trigger MCP re-init.
- The only recovery found:
kill <serve --service PID>, then relaunch — a fresh server cold-starts all MCP connections successfully. - Corollary confusion: because the server survives TUI restarts, "I restarted opencode" does not restart MCP state at all.
Additional Context
- Related auth issue: after upgrading v1 → v2.0.21, remote OAuth MCP servers went to
needs_auth(requires a login before it can register a client) despite~/.local/share/opencode/mcp-auth.jsonholding valid, unexpired access tokens for them (v1-era store). Full re-auth viaopencode mcp auth <name>was required per server. Amcp-auth.json.bakexists alongside, suggesting a store migration that didn't carry the tokens forward. - Servers that (re)connected after the network change (via
mcp auth) were healthy; every connection established before the change stayed dead forever — consistent with missing retry/keepalive recovery. - Reproducible consistently across the network-change scenario; 100% of pre-existing connections were affected.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
github-actions commentedon Oct 1, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
Please edit this issue to address the above within 72 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Oct 1, 2026
Thanks for updating the report. It still needs the Bug Report template’s required Description field: the body currently uses Summary instead. Please use the Bug Report template and put the bug description under Description. The reproduction steps and system details are helpful; please keep them.
rekram1-node commentedon Oct 1, 2026
Yeah will fix.
MusharrafSakran commentedon Oct 1, 2026
Template compliance: description moved to the required Description field as requested.
On the possible duplicates: this looks like the same failure class as #52237, with one additional data point that may help the fix — in my case the trigger was a network change (VPN join) resetting sockets mid-session, and CLI/TUI reattach events did not trigger any MCP re-init (three attach events, zero reconnect attempts in the log). Happy to provide more logs if useful.
github-actions commentedon Oct 1, 2026
Thanks for updating the issue. The report now includes the required Description, reproduction context, and system details.
neriousy commentedon Oct 20, 2026
Thanks for the report. We're tracking MCP connections failing to recover after network interruptions in #52237, so I'm closing this as a duplicate. Please follow that issue for updates.