Skip to content
TypeScript

fix(server): Claude MCP timeouts preserve the native session (#25660)

Julius Marmingefe867b86c89e
diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts
index 9d9ae2e646c..049f8e9a692 100644
--- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts
@@ -93,12 +93,14 @@ const isProviderTurnStartError = Schema.is(ProviderTurnStartError);
/**
* Claude refuses these before it reads the prompt: replacing a process running background work,
- * or launch arguments whose appended system prompt cannot be read.
+ * launch arguments whose appended system prompt cannot be read, or MCP registration that never
+ * answers while the query opens.
*/
const PROMPT_REFUSAL_TAGS = [
"ClaudeBackgroundWorkBlocksQueryReplacementError",
"ClaudeAppendSystemPromptFileError",
"ClaudeAppendSystemPromptMissingValueError",
+ "ClaudeMcpRegistrationTimeoutError",
] as const;
const refusedBeforePrompt = (error: unknown): boolean =>
diff --git a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
index 452509bb97b..0fd20175046 100644
--- a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
+++ b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
@@ -36,6 +36,7 @@ import * as SqlClient from "effect/sql/SqlClient";
import * as SqlitePersistence from "../../persistence/Sqlite.ts";
import { CommandPolicyCapabilityUnsupportedError } from "../CommandPolicy.ts";
import {
+ ClaudeAgentSdkQueryRunnerError,
ClaudeAppendSystemPromptFileError,
ClaudeBackgroundWorkBlocksQueryReplacementError,
ClaudeProviderCapabilitiesV2,
@@ -404,6 +405,12 @@ const waitForIdle = Effect.fn("ProviderSwitchTest.waitForIdle")(function* (
return idle;
});
+// Same tag as the adapter's unexported error raised when Claude never answers setMcpServers.
+class ClaudeMcpRegistrationTimeoutError extends Schema.TaggedError<ClaudeMcpRegistrationTimeoutError>()(
+ "ClaudeMcpRegistrationTimeoutError",
+ {},
+) {}
+
describe("orchestration v2 provider switching", () => {
it.live.each([
"compact-native",
@@ -1311,6 +1318,13 @@ describe("orchestration v2 provider switching", () => {
it.live.each([
["background work", new ClaudeBackgroundWorkBlocksQueryReplacementError()],
["an unreadable append file", new ClaudeAppendSystemPromptFileError({ path: "missing.md" })],
+ [
+ "an MCP registration timeout",
+ new ClaudeAgentSdkQueryRunnerError({
+ method: "setMcpServers",
+ cause: new ClaudeMcpRegistrationTimeoutError(),
+ }),
+ ],
] as const)("keeps the native session after turns refused for %s", ([, refusalCause]) =>
Effect.scoped(
Effect.gen(function* () {