Skip to content

mcp: no reconnect after network change/socket reset; stale Error until server process is killed #52564

Closed as duplicate

Description

@MusharrafSakran

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

  1. Have a running opencode serve --service process with MCP servers connected at cold start (server log: mcp connected server=context7 tools=2, plus other remote and uvx-based local servers).
  2. 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>
    
  3. Quit the TUI and relaunch (opencode -s <sessionID>), or attach new CLIs (opencode --auto). Observed three CLI attach events within one minute.
  4. 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 Error for every server whose connection predated the network change, indefinitely, even though all affected hosts are reachable from the same machine at that moment (verified with curl).
  • 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.json holding valid, unexpired access tokens for them (v1-era store). Full re-auth via opencode mcp auth <name> was required per server. A mcp-auth.json.bak exists 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.

Activity

  1. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Please use the Bug Report template and put the bug description in its required Description field; the current body uses a Summary heading instead. The reproduction steps and system details are already helpful.

    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:

    • #52561: Identical report; it was closed as superseded by this issue.
    • #52237: Remote MCP connections remain failed after sleep/network interruptions and recover only after restarting the service.
    • #25287: Remote MCP socket/connection errors have no transport-level retry or recovery.
    • #29190: Remote MCP connections that drop after idle periods have no automatic reconnection.
    • #42875: OAuth token loss and re-authentication issue related to the additional context.

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    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.

  3. rekram1-node commented on Oct 1, 2026

    @rekram1-node
    Contributor

    Yeah will fix.

  4. MusharrafSakran commented on Oct 1, 2026

    @MusharrafSakran
    Author

    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.

  5. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    Thanks for updating the issue. The report now includes the required Description, reproduction context, and system details.

  6. neriousy commented on Oct 20, 2026

    @neriousy
    Member

    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.

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