Visitar URL original
feat: retry failed MCP servers on context resync by jeremyruppel · Pull Request #30489 · coder/coder · GitHub
Skip to content

feat: retry failed MCP servers on context resync - #30489

Open
jeremyruppel wants to merge 1 commit into
fix-agentmcp-http-standalone-ssefrom
agentmcp-reconnect-failed-servers
Open

jeremyruppel wants to merge 1 commit into
fix-agentmcp-http-standalone-ssefrom
agentmcp-reconnect-failed-servers

Conversation

@jeremyruppel

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.

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
jeremyruppel marked this pull request as ready for review October 7, 2026 22:12
@jeremyruppel
jeremyruppel added this pull request to stack #30490 October 7, 2026 22:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant