Skip to content

Commit f1c26e1

Browse files
fix(server): a Claude CLI that never boots still times out
The SDK puts no deadline on query() initialization, so waiting for boot before the registration deadline left a hung CLI waiting until Stop. Boot now gets its own five-minute deadline and fails through the same timeout error and cleanup as registration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1dc4c01 commit f1c26e1

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export const CLAUDE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_PROV
327327
const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"];
328328
// The SDK has no control-request deadline; the CLI waits up to 30 s per MCP server.
329329
const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds";
330+
const CLAUDE_BOOT_TIMEOUT = "5 minutes";
330331
// Claude can consume a subagent result before the launching turn ends, leaving
331332
// its notification with no native wake turn to answer the continuation.
332333
const CLAUDE_WAKE_TURN_START_DEADLINE = "2 minutes";
@@ -1097,10 +1098,27 @@ export const layerQueryRunner: Layer.Layer<
10971098
restore(
10981099
Effect.gen(function* () {
10991100
if (mcpServers !== undefined) {
1100-
// CLI boot takes about a minute on a host with CPUs 12x oversubscribed, so the
1101-
// deadline covers only registration. A CLI that exits rejects this wait.
1101+
const timedOut = (method: string) => () =>
1102+
Effect.logWarning("orchestration-v2.claude-mcp-registration-timeout", {
1103+
threadId: input.threadId,
1104+
providerSessionId: input.providerSessionId,
1105+
method,
1106+
}).pipe(
1107+
Effect.andThen(
1108+
Effect.fail(
1109+
queryRunnerError(new ClaudeMcpRegistrationTimeoutError(), method),
1110+
),
1111+
),
1112+
);
1113+
// The SDK leaves query() boot unbounded, and it takes about a minute on a host
1114+
// with CPUs 12x oversubscribed, so it gets its own, longer deadline.
11021115
yield* Effect.promise(() =>
11031116
queryRuntime.initializationResult().catch(() => undefined),
1117+
).pipe(
1118+
Effect.timeoutOrElse({
1119+
duration: CLAUDE_BOOT_TIMEOUT,
1120+
orElse: timedOut("initialize"),
1121+
}),
11041122
);
11051123
// Errors and mcp_status can echo headers; log only server names.
11061124
const failed = yield* Effect.tryPromise(() =>
@@ -1110,20 +1128,7 @@ export const layerQueryRunner: Layer.Layer<
11101128
Effect.orElseSucceed(() => Object.keys(mcpServers)),
11111129
Effect.timeoutOrElse({
11121130
duration: CLAUDE_MCP_REGISTRATION_TIMEOUT,
1113-
orElse: () =>
1114-
Effect.logWarning("orchestration-v2.claude-mcp-registration-timeout", {
1115-
threadId: input.threadId,
1116-
providerSessionId: input.providerSessionId,
1117-
}).pipe(
1118-
Effect.andThen(
1119-
Effect.fail(
1120-
queryRunnerError(
1121-
new ClaudeMcpRegistrationTimeoutError(),
1122-
"setMcpServers",
1123-
),
1124-
),
1125-
),
1126-
),
1131+
orElse: timedOut("setMcpServers"),
11271132
}),
11281133
);
11291134
if (failed.length > 0) {

‎apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ it.effect("does not reuse a fresh session ID after MCP registration times out",
480480
),
481481
);
482482

483-
it.effect("starts the MCP registration deadline after a slow CLI boot", () =>
483+
it.effect.each([
484+
["opens after a slow CLI boot", "120 seconds", true],
485+
["times out a CLI that never boots", "5 minutes", false],
486+
] as const)("%s", ([, bootWait, boots]) =>
484487
Effect.scoped(
485488
Effect.gen(function* () {
486489
const waiting = Promise.withResolvers<void>();
@@ -509,11 +512,11 @@ it.effect("starts the MCP registration deadline after a slow CLI boot", () =>
509512
.open({ ...resumedMcpQueryInput, options: { ...options, sessionId: resume } })
510513
.pipe(Effect.result, Effect.forkChild);
511514
yield* Effect.promise(() => waiting.promise);
512-
yield* TestClock.adjust("120 seconds");
513-
booted.resolve();
515+
yield* TestClock.adjust(bootWait);
516+
if (boots) booted.resolve();
514517
const result = yield* Fiber.join(opening);
515518

516-
assert.equal(result._tag, "Success");
519+
assert.equal(result._tag, boots ? "Success" : "Failure");
517520
if (result._tag === "Success") yield* result.success.close;
518521
}).pipe(Effect.provide(realQueryRunner)),
519522
),

0 commit comments

Comments
 (0)