Skip to content

Commit 2192e52

Browse files
committed
fix(mcp): default t3_thread_wait to 50 seconds so clients don't time out first
t3_thread_wait sends nothing until the run ends or the timeout elapses, and it defaulted to 10 minutes. The Claude app aborts a tool call after about 60 seconds and shows a bare "MCP tool call failed", so a wait without timeoutMs on a longer run always failed, even though the run and the server were fine. Default to 50 seconds instead: such a call now returns timedOut=true and the caller waits again. An explicit timeoutMs still works up to the 60-minute cap.
1 parent 35086ee commit 2192e52

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,3 +2671,65 @@ describe("OrchestratorMcpService provider resolution", () => {
26712671
);
26722672
});
26732673
});
2674+
2675+
describe("OrchestratorMcpService.waitForThread", () => {
2676+
it.effect("waits under the common 60-second tool-call limit unless timeoutMs is given", () =>
2677+
Effect.gen(function* () {
2678+
const threadId = ThreadId.make("thread:mcp-wait");
2679+
const shell = liveThreadShell(threadId);
2680+
const requestedTimeouts = yield* Ref.make<ReadonlyArray<number>>([]);
2681+
const scope: McpInvocationScope = {
2682+
environmentId: EnvironmentId.make("environment:mcp-wait"),
2683+
requestNamespace: "provider-session:mcp-wait",
2684+
thread: {
2685+
threadId,
2686+
providerSessionId: "provider-session:mcp-wait",
2687+
providerInstanceId: ProviderInstanceId.make("codex"),
2688+
},
2689+
client: undefined,
2690+
capabilities: new Set(["orchestration"]),
2691+
issuedAt: 1,
2692+
};
2693+
2694+
yield* Effect.gen(function* () {
2695+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
2696+
const defaulted = yield* service.waitForThread(scope, { threadId });
2697+
yield* service.waitForThread(scope, { threadId, timeoutMs: 5_000 });
2698+
assert.deepStrictEqual(defaulted, {
2699+
threadId,
2700+
runId: null,
2701+
status: "idle",
2702+
timedOut: true,
2703+
});
2704+
assert.deepStrictEqual(yield* Ref.get(requestedTimeouts), [50_000, 5_000]);
2705+
}).pipe(
2706+
Effect.provide(
2707+
layerOrchestratorService.pipe(
2708+
Layer.provide(
2709+
Layer.mergeAll(
2710+
NodeServices.layer,
2711+
Layer.mock(ThreadManagementService.ThreadManagementService)({
2712+
getThreadShell: () => Effect.succeed(shell),
2713+
getThreadRecords: () => Effect.succeed(idleThreadProjection(shell)),
2714+
waitForThread: (input) =>
2715+
Ref.update(requestedTimeouts, (timeouts) => [
2716+
...timeouts,
2717+
input.timeoutMs,
2718+
]).pipe(Effect.as({ threadId, run: null, timedOut: true })),
2719+
}),
2720+
ServerSettings.layerTest(),
2721+
Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
2722+
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
2723+
list: () => Effect.succeed([]),
2724+
}),
2725+
Layer.mock(ProjectService.ProjectService)({}),
2726+
Layer.mock(SecretRequests.SecretRequests)({}),
2727+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
2728+
),
2729+
),
2730+
),
2731+
),
2732+
);
2733+
}),
2734+
);
2735+
});

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ import * as Metrics from "../observability/Metrics.ts";
108108
import * as SecretRequests from "../secrets/SecretRequests.ts";
109109

110110
const DEFAULT_WAIT_TIMEOUT_MS = 10 * 60 * 1_000;
111+
// Under the 60-second tool-call limit of the Claude app and other MCP clients, so a
112+
// t3_thread_wait without timeoutMs returns timedOut=true instead of failing in the client.
113+
const DEFAULT_THREAD_WAIT_TIMEOUT_MS = 50_000;
111114
const MAX_WAIT_TIMEOUT_MS = 60 * 60 * 1_000;
112115
const TASK_WAKE_EVENTS = [
113116
{ thread: "parent", eventType: "subagent.updated" },
@@ -2756,7 +2759,7 @@ const make = Effect.gen(function* () {
27562759
...(input.runId === undefined ? {} : { runId: input.runId }),
27572760
timeoutMs: Math.min(
27582761
MAX_WAIT_TIMEOUT_MS,
2759-
Math.max(1, input.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS),
2762+
Math.max(1, input.timeoutMs ?? DEFAULT_THREAD_WAIT_TIMEOUT_MS),
27602763
),
27612764
})
27622765
.pipe(Effect.mapError(threadManagementFailure));

‎apps/server/src/mcp/toolkits/orchestrator/tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const ThreadSendTool = Tool.make("t3_thread_send", {
247247

248248
const ThreadWaitTool = Tool.make("t3_thread_wait", {
249249
description:
250-
"Wait for a T3 thread run to reach a terminal durable state. Without runId, the latest run at call time is selected; an idle thread returns immediately. Timeout does not interrupt work, so call again or use t3_thread_read/list after timedOut=true. Waiting reports status only and does not acknowledge a delegated result.",
250+
"Wait for a T3 thread run to reach a terminal durable state. Without runId, the latest run at call time is selected; an idle thread returns immediately. The call sends no response until the run ends or timeoutMs elapses (default 50 seconds, below the 60-second tool-call limit of many MCP clients); keep any timeoutMs below your client's limit. Timeout does not interrupt work, so call again or use t3_thread_read/list after timedOut=true. Waiting reports status only and does not acknowledge a delegated result.",
251251
parameters: OrchestratorMcpThreadWaitInput,
252252
success: OrchestratorMcpThreadWaitResult,
253253
failure: OrchestratorMcpFailure,

0 commit comments

Comments
 (0)