GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mcp): reconnect dropped servers with backoff by afonsoft · Pull Request #52943 · anomalyco/opencode

Conversation

@afonsoft

@afonsoft afonsoft commented Oct 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #52237
Closes #52564

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When an MCP server connection drops (client.onclose), the server is marked failed and stays dead until the app restarts or the user manually reconnects. Same for servers that fail to connect at startup. There is no recovery path.

This PR adds automatic reconnect with exponential backoff:

  • scheduleReconnect forks a retry loop per server (deduped via a reconnects map on instance State). Each attempt re-runs createAndStore; the loop retries while the status stays failed with Schedule.exponential("1 second") (jittered, capped at 10 attempts).
  • Triggered from three paths: unexpected onclose, failed initial create at state init, and failed createAndStore (add/connect/finishAuth).
  • Stops cleanly when: config removed or enabled === false, status is no longer failed (connected, disabled, needs_auth, needs_client_registration — auth-required states never spin), disconnect() interrupts the fiber, or instance disposal interrupts all pending reconnects in the finalizer.
  • disconnect() also cancels any in-flight reconnect so an explicit user disconnect can't be raced by a retry.

How did you verify your code works?

  • bun typecheck + bun turbo typecheck across the monorepo — clean.
  • bun test test/mcp/ — 66/66 pass.
  • New regression test reconnects after the local server process exits: kills the spawned stdio fixture (process.kill(pid)), then polls until status returns to connected with a different transport pid and tools are re-listed.
  • Relaxed remote timeout aborts both real HTTP transport attempts to assert the first two requests (["POST","GET"]) — the reconnect loop legitimately issues further attempts afterward.

Screenshots / recordings

N/A — server-side behavior.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devin-ai-integration @afonsoft
fix(mcp): reconnect dropped servers with backoff
0abccb4
Co-Authored-By: Afonso Dutra Nogueira Filho <[email protected]>
@afonsoft

afonsoft commented Oct 3, 2026

Copy link
Copy Markdown
Author

cc @Hona @Brendonovich — could you review and approve? Adds MCP auto-reconnect: dropped or failed-at-startup servers now retry with exponential backoff (10 attempts), instead of staying failed until restart.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

afonsoft reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@afonsoft
Merge branch 'dev' into mcp-reconnect
0d6bbae
@r266-tech

r266-tech commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Scope check for #52237: that report is from V2 (2.0.20), while this PR currently targets dev and changes packages/opencode/src/mcp/index.ts.

On current V2 63b7de94, the server MCP handler calls the separate packages/core/src/mcp/index.ts service. This patch does not change that implementation. The reconnect regression needs to exercise that V2 path before the reported V2 issue can be considered covered; the current contribution guide also asks for V2 bases.

This is a source/target review; I have not independently run the reconnect test or reproduced the sleep/wake failure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Oct 3, 2026
📊 AI CLI 工具社区动态日报 2026-10-04 litang9/big_model_radar#493
Open
@ggbdpq ggbdpq mentioned this pull request Oct 4, 2026
[FEATURE]: MCP observability surface — process-level status, lifecycle endpoints, and a TUI panel #53065
Closed
1 task done
@opencode-agent opencode-agent Bot mentioned this pull request Oct 7, 2026
[FEATURE]: Double click to retry on MCP Error #53780
Open
1 task done
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
@afonsoft afonsoft mentioned this pull request Oct 10, 2026
fix(mcp): reconnect dropped servers with backoff #54378
Open
4 tasks done
@huzaifaasim017 huzaifaasim017 mentioned this pull request Oct 28, 2026
mcp: remote MCP servers that fail once are never retried until service restart #52237
Open
@GoeppertVB GoeppertVB mentioned this pull request Nov 6, 2026
mcp: remote server latched as failed after one transient DNS error (no retry/backoff) #62369
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

mcp: remote MCP servers that fail once are never retried until service restart mcp: no reconnect after network change/socket reset; stale Error until server process is killed

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@afonsoft @r266-tech @thdxr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.