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 — feat: retry failed MCP servers on context resync by jeremyruppel · Pull Request #30489 · coder/coder

Conversation

@jeremyruppel

@jeremyruppel jeremyruppel commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Stacked on #30484.

The agent only reconnects workspace MCP servers when .mcp.json changes, so a server that is down when the agent first connects (for example, a dev server like Storybook started after the workspace is up) stays unavailable until the config file is touched.

agentcontext.Manager.Resync now calls a new agentmcp.Manager.Reconnect before resolving. Reconnect re-runs the last MCP reload even when the config is unchanged, so servers that failed to connect are retried; connected servers keep their session because their config is unchanged. This makes coder exp chat context refresh (no argument) and the agent's POST /api/v0/context/resync retry failed servers. Resync is only called on explicit user request today, so no background traffic is added.

Not covered here: a server that restarts after it connected keeps its stale session, since its config is unchanged.

Plan and decisions

Problem

  1. Never connected. A server that is down at the first reload is listed as failed to connect until the config file changes, because startReloadIfNeeded short-circuits when SnapshotChanged is false.
  2. Connected, then dead. A server that restarts after connecting keeps its stale ClientSession; classifyServers keeps it because its config is unchanged. Out of scope for this PR.

Current wiring

  • Reload triggers: once after startup scripts (agent/agent.go) and the .mcp.json fsnotify watcher.
  • After a reload changes the catalog, the agent pushes context and coderd live-syncs MCP rows into every bound chat, so new tools reach chats on their next turn without a chat refresh.
  • coder exp chat context refresh (no argument) calls the agent socket ResyncContext, which runs agentcontext.Manager.Resync. Before this PR, Resync re-read the MCP catalog but did not reconnect.
  • The UI "Refresh context" button calls chatd.RefreshChatContext, which is DB-only (re-pin) and never reaches the agent.

Options considered

Trigger Latency Cost Decision
A. Periodic agent ticker while a server is unhealthy Up to one interval Periodic dials to dead servers Rejected
B. On-demand via agent Resync (CLI, agent HTTP route) Immediate None unless invoked This PR
C. On-demand via UI "Refresh context", running the same agent resync as the CLI Immediate None unless clicked Follow-up PR
D. Per-turn nudge from chatd Next turn One agent request per turn, fleet-wide Rejected

Implementation choices

  • Reconnect clears the stored config file snapshot and calls Reload, rather than adding a force flag to the reload path. SnapshotChanged then reports a change, the singleflight reload runs, and installServers writes a fresh snapshot. False-positive reloads were already documented as safe.
  • No backoff or retry state.

Follow-up (C)

Make the existing "Refresh context" button run the same agent resync as the CLI (coderd calls the agent's /api/v0/context/resync, then re-pins), and render it when MCP server issues exist.


Generated by Coder Agents on behalf of @jeremyruppel.

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot assigned jeremyruppel Oct 7, 2026
@jeremyruppel
jeremyruppel marked this pull request as ready for review October 7, 2026 22:12
@jeremyruppel
jeremyruppel requested review from DanielleMaywood, ibetitsmike and mafredri October 7, 2026 22:13
@jeremyruppel
jeremyruppel added this pull request to stack #30490 October 7, 2026 22:23
DanielleMaywood
DanielleMaywood reviewed Oct 12, 2026
View reviewed changes
Comment thread agent/agentcontext/manager.go Resolved

Uh oh!

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

DanielleMaywood
DanielleMaywood approved these changes Oct 12, 2026
View reviewed changes
@jeremyruppel
jeremyruppel force-pushed the agentmcp-reconnect-failed-servers branch from 22fa2eb to e26d783 Compare October 12, 2026 19:41
Base automatically changed from fix-agentmcp-http-standalone-sse to main October 12, 2026 20:01
jeremyruppel added 2 commits October 12, 2026 16:01
@jeremyruppel
feat: retry failed MCP servers on context resync
2da0e3f
The agent only reconnected workspace MCP servers when .mcp.json changed,
so a server that was down at startup (for example, a dev server started
after the agent) stayed unavailable. Resync now re-runs the MCP reload
first, so `coder exp chat context refresh` and the agent's
/api/v0/context/resync retry failed servers. Connected servers keep
their session.

Generated by Coder Agents.
@jeremyruppel
fix(agent/agentcontext): trim MCPReconnect doc comment
39e5820
@jeremyruppel
jeremyruppel force-pushed the agentmcp-reconnect-failed-servers branch from e26d783 to 39e5820 Compare October 12, 2026 20:01
@jeremyruppel
jeremyruppel merged commit 281b838 into main Oct 21, 2026
29 checks passed

Uh oh!

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

@jeremyruppel
jeremyruppel deleted the agentmcp-reconnect-failed-servers branch October 21, 2026 13:28
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielleMaywood DanielleMaywood DanielleMaywood approved these changes
@mafredri mafredri Awaiting requested review from mafredri
@ibetitsmike ibetitsmike Awaiting requested review from ibetitsmike

Uh oh!

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

Assignees

@jeremyruppel jeremyruppel

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

@jeremyruppel @DanielleMaywood
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 01402503 — 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.