@devries-cameron20 / t3code Mirror · read-only / commits / 86e2cb21c9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(server): Claude turns on busy hosts no longer time out registering MCP tools (#30166)

Co-authored-by: chief-archivist <thecradlearchives@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Theo Browne <me@theo.li>

dw3105 committed Nov 12, 2026 at 00:55 UTC 86e2cb21c909b1f5000d4d947a3dad5df88a4477
2 files changed +85 -16
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+31 -16
@@ -343,6 +343,7 @@ export const CLAUDE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_PROV
343 const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"];
344 // The SDK has no control-request deadline; the CLI waits up to 30 s per MCP server.
345 const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds";
346 +const CLAUDE_BOOT_TIMEOUT = "5 minutes";
347 // Claude can consume a subagent result before the launching turn ends, leaving
348 // its notification with no native wake turn to answer the continuation.
349 const CLAUDE_WAKE_TURN_START_DEADLINE = "2 minutes";
@@ -619,10 +620,12 @@ export class ClaudeCodeRootRefusalError extends Schema.TaggedError<ClaudeCodeRoo
620
621 class ClaudeMcpRegistrationTimeoutError extends Schema.TaggedError<ClaudeMcpRegistrationTimeoutError>()(
622 "ClaudeMcpRegistrationTimeoutError",
622 - {},
623 + { phase: Schema.Literals(["initialize", "setMcpServers"]) },
624 ) {
625 override get message(): string {
625 - return "Claude timed out while registering its MCP tools. Retry the turn; if it keeps failing, check Claude and the server logs.";
626 + return this.phase === "initialize"
627 + ? "Claude timed out while starting up. Retry the turn; if it keeps failing, check Claude and the server logs."
628 + : "Claude timed out while registering its MCP tools. Retry the turn; if it keeps failing, check Claude and the server logs.";
629 }
630 }
631
@@ -1311,6 +1314,31 @@ export const layerQueryRunner: Layer.Layer<
1314 restore(
1315 Effect.gen(function* () {
1316 if (mcpServers !== undefined) {
1317 + const timedOut = (phase: ClaudeMcpRegistrationTimeoutError["phase"]) => () =>
1318 + Effect.logWarning("orchestration-v2.claude-mcp-registration-timeout", {
1319 + threadId: input.threadId,
1320 + providerSessionId: input.providerSessionId,
1321 + phase,
1322 + }).pipe(
1323 + Effect.andThen(
1324 + Effect.fail(
1325 + queryRunnerError(
1326 + new ClaudeMcpRegistrationTimeoutError({ phase }),
1327 + phase,
1328 + ),
1329 + ),
1330 + ),
1331 + );
1332 + // The SDK leaves query() boot unbounded, and it takes about a minute on a host
1333 + // with CPUs 12x oversubscribed, so it gets its own, longer deadline.
1334 + yield* Effect.promise(() =>
1335 + queryRuntime.initializationResult().catch(() => undefined),
1336 + ).pipe(
1337 + Effect.timeoutOrElse({
1338 + duration: CLAUDE_BOOT_TIMEOUT,
1339 + orElse: timedOut("initialize"),
1340 + }),
1341 + );
1342 // Errors and mcp_status can echo headers; log only server names.
1343 const failed = yield* Effect.tryPromise({
1344 try: () => queryRuntime.setMcpServers(mcpServers),
@@ -1320,20 +1348,7 @@ export const layerQueryRunner: Layer.Layer<
1348 Effect.orElseSucceed(() => Object.keys(mcpServers)),
1349 Effect.timeoutOrElse({
1350 duration: CLAUDE_MCP_REGISTRATION_TIMEOUT,
1323 - orElse: () =>
1324 - Effect.logWarning("orchestration-v2.claude-mcp-registration-timeout", {
1325 - threadId: input.threadId,
1326 - providerSessionId: input.providerSessionId,
1327 - }).pipe(
1328 - Effect.andThen(
1329 - Effect.fail(
1330 - queryRunnerError(
1331 - new ClaudeMcpRegistrationTimeoutError(),
1332 - "setMcpServers",
1333 - ),
1334 - ),
1335 - ),
1336 - ),
1351 + orElse: timedOut("setMcpServers"),
1352 }),
1353 );
1354 if (failed.length > 0) {
apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts
+54
@@ -254,6 +254,7 @@ it.effect("reopens a stalled MCP registration before delivering the resumed prom
254 if (typeof prompt === "string") throw new Error("Expected streaming input");
255 prompts.push(prompt);
256 return {
257 + initializationResult: async () => ({}),
258 setMcpServers: prompts.length === 1 ? firstRegistration : secondRegistration,
259 close: prompts.length === 1 ? firstClose : secondClose,
260 [Symbol.asyncDispose]: async () => {
@@ -360,6 +361,7 @@ it.effect.each([true, false])("only retries after confirmed process exit: %s", (
361 cleanupProgress.resolve("retry");
362 }
363 return {
364 + initializationResult: async () => ({}),
365 setMcpServers: () => {
366 registrationStarted.resolve();
367 return first
@@ -410,6 +412,7 @@ it.effect("stops retrying MCP registration after two timeouts and reports the ca
412 const querySpy = vi.spyOn(ClaudeSdk, "query").mockImplementation(() => {
413 const started = querySpy.mock.calls.length === 1 ? firstRegistration : secondRegistration;
414 return {
415 + initializationResult: async () => ({}),
416 setMcpServers: () => {
417 started.resolve();
418 return new Promise<ClaudeSdk.McpSetServersResult>(() => {});
@@ -450,6 +453,7 @@ it.effect("cancels a stalled registration without retrying or retaining its prom
453 const querySpy = vi.spyOn(ClaudeSdk, "query").mockImplementation(
454 () =>
455 ({
456 + initializationResult: async () => ({}),
457 setMcpServers: () => {
458 registrationStarted.resolve();
459 return new Promise<ClaudeSdk.McpSetServersResult>(() => {});
@@ -480,6 +484,7 @@ it.effect("does not reuse a fresh session ID after MCP registration times out",
484 const querySpy = vi.spyOn(ClaudeSdk, "query").mockImplementation(
485 () =>
486 ({
487 + initializationResult: async () => ({}),
488 setMcpServers: () => {
489 registrationStarted.resolve();
490 return new Promise<ClaudeSdk.McpSetServersResult>(() => {});
@@ -507,6 +512,55 @@ it.effect("does not reuse a fresh session ID after MCP registration times out",
512 ),
513 );
514
515 +it.effect.each([
516 + ["opens after a slow CLI boot", "120 seconds", true],
517 + ["times out a CLI that never boots", "5 minutes", false],
518 +] as const)("%s", ([, bootWait, boots]) =>
519 + Effect.scoped(
520 + Effect.gen(function* () {
521 + const waiting = Promise.withResolvers<void>();
522 + const booted = Promise.withResolvers<void>();
523 + const querySpy = vi.spyOn(ClaudeSdk, "query").mockImplementation(
524 + () =>
525 + ({
526 + initializationResult: () => {
527 + waiting.resolve();
528 + return booted.promise;
529 + },
530 + // The CLI answers control requests only after it has booted.
531 + setMcpServers: async () => {
532 + waiting.resolve();
533 + await booted.promise;
534 + return { added: ["t3-code"], removed: [], errors: {} };
535 + },
536 + close: vi.fn(),
537 + [Symbol.asyncDispose]: async () => {},
538 + }) as unknown as ClaudeSdk.Query,
539 + );
540 + yield* Effect.addFinalizer(() => Effect.sync(() => querySpy.mockRestore()));
541 + const runner = yield* ClaudeAgentSdkQueryRunner;
542 + const { resume, ...options } = resumedMcpQueryInput.options;
543 + const opening = yield* runner
544 + .open({ ...resumedMcpQueryInput, options: { ...options, sessionId: resume } })
545 + .pipe(Effect.result, Effect.forkChild);
546 + yield* Effect.promise(() => waiting.promise);
547 + yield* TestClock.adjust(bootWait);
548 + if (boots) booted.resolve();
549 + const result = yield* Fiber.join(opening);
550 +
551 + assert.equal(result._tag, boots ? "Success" : "Failure");
552 + if (result._tag === "Success") yield* result.success.close;
553 + else
554 + assert.equal(
555 + makeProviderFailure({
556 + cause: { _tag: "ProviderAdapterTurnStartError", cause: result.failure },
557 + }).message,
558 + "Claude timed out while starting up. Retry the turn; if it keeps failing, check Claude and the server logs.",
559 + );
560 + }).pipe(Effect.provide(realQueryRunner)),
561 + ),
562 +);
563 +
564 function fakeClaudeCli(script: string): string {
565 const dir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-claude-cli-"));
566 const cli = NodePath.join(dir, "claude");