From e1b791250dd3eb67d0ab87e04e1664e0cc98ed65 Mon Sep 17 00:00:00 2001 From: Gabby Welson Date: Wed, 21 Oct 2026 16:41:43 -0700 Subject: [PATCH 1/2] test(server): Claude open waits out startup hooks longer than 90 seconds Claude Code answers mcp_set_servers only after SessionStart hooks finish. This test holds that answer for 10 minutes and fails on the current 90-second registration deadline. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index b231fbfca9d98..5c16c78729537 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -1741,10 +1741,13 @@ describe("ClaudeAdapterV2 native fork", () => { ); }); +// With `answerSetServers` off, the CLI holds its mcp_set_servers answer until +// `answerHeldSetServers`, as Claude Code does while SessionStart hooks run. function makeFakeClaudeCli(answerSetServers = true) { const spawns: Array = []; const controlRequests: Array = []; const stdins: Array = []; + const held = Promise.withResolvers<() => void>(); const spawn = (options: SpawnOptions): SpawnedProcess => { spawns.push(options); const stdin = new NodeStream.PassThrough(); @@ -1770,13 +1773,15 @@ function makeFakeClaudeCli(answerSetServers = true) { if (frame.type !== "control_request") continue; controlRequests.push(frame.request); const setServers = frame.request.subtype === "mcp_set_servers"; - if (setServers && !answerSetServers) continue; const response = { subtype: "success", request_id: frame.request_id, response: setServers ? { added: [], removed: [], errors: {} } : {}, }; - stdout.write(`${JSON.stringify({ type: "control_response", response })}\n`); + const answer = () => + stdout.write(`${JSON.stringify({ type: "control_response", response })}\n`); + if (setServers && !answerSetServers) held.resolve(answer); + else answer(); } }); stdin.on("end", () => { @@ -1787,7 +1792,7 @@ function makeFakeClaudeCli(answerSetServers = true) { }; // The SDK closes the CLI by ending its stdin. const closed = () => stdins.length > 0 && stdins.every((stdin) => stdin.writableEnded); - return { spawn, spawns, controlRequests, closed }; + return { spawn, spawns, controlRequests, closed, answerHeldSetServers: held.promise }; } describe("ClaudeAdapterV2 MCP credential channel", () => { @@ -1839,6 +1844,19 @@ describe("ClaudeAdapterV2 MCP credential channel", () => { assert.notInclude(spawned, "dummy-mcp-credential"); }), ); + + it.effect("waits for a CLI whose startup hooks outlast 90 seconds", () => + Effect.gen(function* () { + const cli = makeFakeClaudeCli(false); + const opening = yield* openWith(cli).pipe(Effect.forkChild); + const answer = yield* Effect.promise(() => cli.answerHeldSetServers); + yield* TestClock.adjust("10 minutes"); + answer(); + const session = yield* Fiber.join(opening); + assert.isFalse(cli.closed()); + yield* session.close; + }), + ); }); describe("ClaudeAdapterV2 native session identity", () => { From 1b54c505227402960aecb3d69ccff30f7337a424 Mon Sep 17 00:00:00 2001 From: Gabby Welson Date: Wed, 21 Oct 2026 16:41:45 -0700 Subject: [PATCH 2/2] fix(server): Claude turns in fresh worktrees no longer fail behind slow startup hooks Claude Code holds its answer to mcp_set_servers until startup finishes, including SessionStart hooks. A repo hook that sets up a new worktree can take minutes, so the 90-second registration deadline failed those turns with "Claude Code did not answer the MCP server registration." Drop the deadline. Hook and MCP server timeouts already bound the wait, the SDK rejects the request if the CLI exits, and Stop interrupts it. Fixes #23151 Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 97ebde00ac277..8b88cd6c81d5e 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -300,9 +300,6 @@ export const CLAUDE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_PROV const DEFAULT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({}); // Entry extensions the Claude SDK runs through node instead of executing. const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"]; -// The SDK puts no deadline on control requests. The CLI answers -// mcp_set_servers once each server connected or hit its own 30 s timeout. -const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds"; // Claude can consume a subagent result before the launching turn ends, leaving // its notification with no native wake turn to answer the continuation. const CLAUDE_WAKE_TURN_START_DEADLINE = "2 minutes"; @@ -947,6 +944,10 @@ export const layerQueryRunner: Layer.Layer< restore( Effect.gen(function* () { if (mcpServers !== undefined) { + // No deadline: the CLI answers only after startup, including SessionStart + // hooks that may run for minutes in a fresh worktree. Hook and server + // timeouts bound that wait, a CLI exit rejects the request, and Stop + // interrupts it. // Error texts and the CLI's mcp_status response can echo the headers, so // only server names are logged. const failed = yield* Effect.tryPromise(() => @@ -954,16 +955,6 @@ export const layerQueryRunner: Layer.Layer< ).pipe( Effect.map((result) => Object.keys(result.errors)), Effect.orElseSucceed(() => Object.keys(mcpServers)), - Effect.timeoutOrElse({ - duration: CLAUDE_MCP_REGISTRATION_TIMEOUT, - orElse: () => - Effect.fail( - queryRunnerError( - "Claude Code did not answer the MCP server registration.", - "setMcpServers", - ), - ), - }), ); if (failed.length > 0) { yield* Effect.logWarning("orchestration-v2.claude-mcp-servers-unavailable", {