Skip to content

Stagger MCP server initialization and retry on timeout - #52908

Closed
yassineMouttalib wants to merge 1 commit into
zed-industries:mainfrom
yassineMouttalib:mcp-staggered-init
Closed

Stagger MCP server initialization and retry on timeout#52908
yassineMouttalib wants to merge 1 commit into
zed-industries:mainfrom
yassineMouttalib:mcp-staggered-init

Conversation

@yassineMouttalib

Copy link
Copy Markdown

When multiple MCP context servers start simultaneously during project load, the GPUI executor gets overwhelmed by concurrent process spawns and JSON-RPC handshakes. This is especially visible when using NPX to launch servers, which adds its own startup overhead — often causing timeouts as described in #38252.

While configurable timeouts were added in #45378, the root cause is that spawning multiple servers concurrently starves the executor of IO resources. This PR addresses that directly with two changes:

Staggered initialization

Wait 3 seconds after project load before starting any MCP servers, then start them sequentially with 500ms between each. This gives the executor time to settle and prevents IO starvation during the critical startup window.

Retry on timeout

When a server fails to start with a timeout error, retry up to 3 times with a 2-second delay between attempts. Non-timeout errors (including OAuth 401 responses handled by resolve_start_failure) skip the retry loop and are handled immediately.

Release Notes:

  • Improved MCP context server startup reliability by staggering server initialization and retrying on timeout

When multiple MCP context servers start simultaneously during project
load, the GPUI executor gets overwhelmed by concurrent process spawns
and JSON-RPC handshakes. This is especially problematic when using NPX
to launch servers, which adds its own startup overhead.

Two changes to improve reliability:

1. **Staggered initialization** — wait 3 seconds after project load
   before starting any MCP servers, then start them sequentially with
   500ms between each. This gives the executor time to settle and
   prevents IO starvation.

2. **Retry on timeout** — when a server fails to start with a timeout
   error, retry up to 3 times with a 2-second delay between attempts.
   Non-timeout errors (including OAuth 401s) are forwarded to
   `resolve_start_failure` immediately without retry.

Relates to zed-industries#38252.
@cla-bot

cla-bot Bot commented Apr 1, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @yassineMouttalib on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-codeowner-coordinator
zed-codeowner-coordinator Bot requested review from a team, cameron1024 and smitbarmase and removed request for a team April 1, 2026 15:48
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 1, 2026
@yassineMouttalib

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 1, 2026
@cla-bot

cla-bot Bot commented Apr 1, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@ChristopherBiscardi ChristopherBiscardi added the area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features label Apr 7, 2026
@smitbarmase

Copy link
Copy Markdown
Member

Thanks for taking the time on this.

I don't think this is the right direction. The context_server_timeout setting from #45378 already covers global default and per-server overrides (up to 10 minutes), and an affected user on #38252 confirmed it resolved the issue for them. The real cause in the npx cases is just cold-cache install exceeding the 60s default, not executor starvation, I couldn't reproduce that on a typical machine.

The stagger and 3s startup delay don't shorten install time, and the startup delay fires on every settings or registry change, not just startup. I think the right lever is the timeout setting itself, the default is probably just too low for cold npx.

The retry-on-timeout idea has some independent value (cold attempt fails, warm cache succeeds), so that could be worth pulling out separately, which is likely why it's been working for you.

I'll close this one for now. Feel free to follow up or open a new PR with just the retry-on-timeout idea, I think that's worth surfacing to users. Thanks again.

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

Labels

area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants