Stop waiting for slow MCP servers in Workhorse
What does this MR do and why?
Workhorse sets up every MCP server before a Duo session starts and waits however long that takes. Behind the timeout_dap_mcp_setup_in_workhorse flag, Workhorse now stops waiting for servers after 10 seconds of setup and starts the run without the tools of any server that isn't ready.
Design notes
Why the wait stops at the deadline, rather than only putting a deadline on the context. A context deadline on Connect and ListTools doesn't limit how long setup takes. After the deadline, go-sdk sends notifications/cancelled, which waits up to 5 s. When initialize fails, Connect then closes the session, and that close sends a DELETE on a context with no deadline. In a test with a 0.5 s deadline and a server that never answers, setup took 35.5 s: 0.5 + 5 + 30 s, where 30 s is the external transport's response header timeout. For the GitLab and Orbit servers, that last wait is proxyHeadersTimeout, 5 minutes by default. So newMcpManager stops waiting at the deadline and goes on without the servers that aren't ready. A setup that is still running finishes in the background and closes its own session. All servers share one deadline because they are set up concurrently. With the flag off, nothing changes.
The context passed to Connect can be cancelled after setup. go-sdk keeps the session's lifetime separate from it (StreamableClientTransport.Connect detaches it, and jsonrpc2.NewConnection drops its Done). The new test calls a tool after a setup with a deadline to prove it.
No deadline on CallTool in this MR. A deadline that passes after the response headers arrive, while a JSON body is still being read, makes go-sdk fail the connection: every later call to that server fails for the rest of the run. v1.7.0 and v1.8.0 behave the same way. This is another trigger of #638180, and the reconnect fix proposed there covers it, so the CallTool deadline follows that fix.
References
- Related to #636597
- #638180: why
CallToolhas no deadline yet - A cap on connections to each external MCP server (
MaxConnsPerHost) comes in a later MR: it applies to the whole Workhorse process, so it can't go behind this per-user flag. - Rollout issue: #639713
Screenshots or screen recordings
No UI changes. This is the chat during the GDK validation below.
| Run | Screenshot |
|---|---|
| Flag off, 10 s after sending | ![]() |
| Flag off, 37 s | ![]() |
| Flag off, 60 s | ![]() |
| Flag off, answer after 62 s | ![]() |
| Flag on, 6 s after sending | ![]() |
| Flag on, answer after 13 s | ![]() |
Flag on, gitlab_search still works |
![]() |
How to set up and validate locally
- Start a local server that accepts connections and never answers:
nc -lk 9999. - Turn on AI Catalog MCP servers:
Feature.enable(:ai_catalog_mcp_servers). - Add an AI Catalog MCP server with URL
http://127.0.0.1:9999/mcpand no authentication, add it to a custom agent, and enable that agent in a project. - With the flag off (
Feature.disable(:timeout_dap_mcp_setup_in_workhorse)), start an agentic chat with the agent. The session doesn't start until the external server's setup gives up, as onmaster. - Enable the flag:
Feature.enable(:timeout_dap_mcp_setup_in_workhorse). - Start a new chat with the agent. The session starts about 10 seconds later without that server's tools, and
log/workhorse.log(orgdk tail gitlab-workhorse) hasFailed to initialize MCP serverwithcontext deadline exceededfor it. - Ask the agent to use a GitLab MCP tool. It works, so the other servers' tools are unaffected.
Results in GDK
Run on master (77f1da6978b4) with this MR's commits, Claude Sonnet 5.5, and a custom agent with one AI Catalog MCP server that accepts connections and never answers.
| Run | Time to the answer | Workhorse log |
|---|---|---|
| Flag off | About 62 s on "finding an answer" | calling "initialize": ... net/http: timeout awaiting response headers after 30 s, then 30 s more for the closing DELETE |
| Flag on | About 13 s | failed to initialize MCP session stalled_mcp__mr_270188_validation_: context deadline exceeded after 10 s |
Flag on, then gitlab_search |
Works, "1 action taken" |
With the flag off, the chat shows no error. It waits on "finding an answer" for about a minute and then answers without that server's tools.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.






