🤖 fix: add MCP server startup timeout and surface failures#2786
🤖 fix: add MCP server startup timeout and surface failures#2786ibetitsmike wants to merge 9 commits intomainfrom
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ab14a2970
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df5be4e517
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed: reverted the stdio exec timeout back to 24h (process lifetime), since startup timeout is already handled by the Promise.race wrapper in startSingleServer. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70144207cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed: added AbortController to startSingleServer so timed-out startups now abort the in-flight impl and clean up spawned processes. Both stdio and HTTP/SSE paths have abort listeners that close transports/clients on timeout. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e70d79d00b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed: token recount after MCP warning prepend. Uses |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 187dc0abac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return instance; | ||
| const onAbort = () => { | ||
| log.debug("[MCP] Aborting stdio startup", { name }); | ||
| void cleanupStartupResources(); |
There was a problem hiding this comment.
Await cleanup before returning timed-out MCP startup
When startup is aborted, onAbort fires cleanupStartupResources() as fire-and-forget (void ...), and startSingleServer() rejects immediately on the timeout path; this means callers can proceed while stdio/client shutdown is still in flight, which can leave orphaned MCP processes/connections across retries. This also violates the repo rule in /workspace/mux/AGENTS.md to avoid void asyncFn() for observable state transitions, because the cleanup completion is part of the startup failure invariant.
Useful? React with 👍 / 👎.
| let leasedStats = existing.stats; | ||
| if (restartFailedNames.length > 0) { |
There was a problem hiding this comment.
Recompute leased MCP failure stats from filtered servers
In the leased-workspace path, stats are reused from existing.stats unless a restart attempt fails, even though the returned tool map is filtered against current enabledServers; if a previously failed server is later disabled/removed while another stream holds the lease, failedServerCount/failedServerNames stay stale and AIService will still prepend a "failed to start" warning for a server that is no longer enabled. Rebuild failure stats from the current enabled set before returning leased results.
Useful? React with 👍 / 👎.
Summary
Misconfigured MCP servers (e.g., wrong
command+argsformat) causestartSingleServer()to hang indefinitely oncreateMCPClient()/client.tools(), blocking the entire chat stream. This adds a 60s startup timeout and surfaces failures to the user via a system message warning.Background
startSingleServer()awaits MCP client creation with no timeout — a broken server config hangs foreverrunServerTest()(settings "Test" button) already has aPromise.racetimeout, but the production startup path did notImplementation
Startup timeout (
mcpServerManager.ts):MCP_STARTUP_TIMEOUT_MS = 60_000constantstartSingleServer→startSingleServerImpl, wrapped withPromise.racetimeout following the existingrunMCPToolWithDeadlinepattern (cleanup viaclearTimeout+.unref())Failure tracking (
mcpServerManager.ts):startServers()now returns{ instances, failedServerNames }MCPWorkspaceStatsextended withfailedServerNames: string[]getToolsForWorkspace()updated to propagate failuresUser-facing warning (
aiService.ts):Generated with
mux• Model:anthropic:claude-opus-4-6• Thinking:xhigh• Cost:$4.32