Skip to content

Commit cf9e45d

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 48595c7 commit cf9e45d

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
@@ -2202,3 +2202,65 @@ describe("OrchestratorMcpService provider resolution", () => {
22022202
);
22032203
});
22042204
});
2205+
2206+
describe("OrchestratorMcpService.waitForThread", () => {
2207+
it.effect("waits under the common 60-second tool-call limit unless timeoutMs is given", () =>
2208+
Effect.gen(function* () {
2209+
const threadId = ThreadId.make("thread:mcp-wait");
2210+
const shell = liveThreadShell(threadId);
2211+
const requestedTimeouts = yield* Ref.make<ReadonlyArray<number>>([]);
2212+
const scope: McpInvocationScope = {
2213+
environmentId: EnvironmentId.make("environment:mcp-wait"),
2214+
requestNamespace: "provider-session:mcp-wait",
2215+
thread: {
2216+
threadId,
2217+
providerSessionId: "provider-session:mcp-wait",
2218+
providerInstanceId: ProviderInstanceId.make("codex"),
2219+
},
2220+
client: undefined,
2221+
capabilities: new Set(["orchestration"]),
2222+
issuedAt: 1,
2223+
};
2224+
2225+
yield* Effect.gen(function* () {
2226+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
2227+
const defaulted = yield* service.waitForThread(scope, { threadId });
2228+
yield* service.waitForThread(scope, { threadId, timeoutMs: 5_000 });
2229+
assert.deepStrictEqual(defaulted, {
2230+
threadId,
2231+
runId: null,
2232+
status: "idle",
2233+
timedOut: true,
2234+
});
2235+
assert.deepStrictEqual(yield* Ref.get(requestedTimeouts), [50_000, 5_000]);
2236+
}).pipe(
2237+
Effect.provide(
2238+
OrchestratorMcpService.layer.pipe(
2239+
Layer.provide(
2240+
Layer.mergeAll(
2241+
NodeServices.layer,
2242+
Layer.mock(ThreadManagementService.ThreadManagementService)({
2243+
getThreadShell: () => Effect.succeed(shell),
2244+
getThreadRecords: () => Effect.succeed(idleThreadProjection(shell)),
2245+
waitForThread: (input) =>
2246+
Ref.update(requestedTimeouts, (timeouts) => [
2247+
...timeouts,
2248+
input.timeoutMs,
2249+
]).pipe(Effect.as({ threadId, run: null, timedOut: true })),
2250+
}),
2251+
ServerSettings.layerTest(),
2252+
Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
2253+
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
2254+
list: () => Effect.succeed([]),
2255+
}),
2256+
Layer.mock(ProjectService.ProjectService)({}),
2257+
Layer.mock(SecretRequests.SecretRequests)({}),
2258+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
2259+
),
2260+
),
2261+
),
2262+
),
2263+
);
2264+
}),
2265+
);
2266+
});

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

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

9898
const DEFAULT_WAIT_TIMEOUT_MS = 10 * 60 * 1_000;
99+
// Under the 60-second tool-call limit of the Claude app and other MCP clients, so a
100+
// t3_thread_wait without timeoutMs returns timedOut=true instead of failing in the client.
101+
const DEFAULT_THREAD_WAIT_TIMEOUT_MS = 50_000;
99102
const MAX_WAIT_TIMEOUT_MS = 60 * 60 * 1_000;
100103
// Events that can make a delegated task terminal: the parent's task record,
101104
// and the child's runs, nested tasks, and pending provider background work.
@@ -2598,7 +2601,7 @@ const make = Effect.gen(function* () {
25982601
...(input.runId === undefined ? {} : { runId: input.runId }),
25992602
timeoutMs: Math.min(
26002603
MAX_WAIT_TIMEOUT_MS,
2601-
Math.max(1, input.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS),
2604+
Math.max(1, input.timeoutMs ?? DEFAULT_THREAD_WAIT_TIMEOUT_MS),
26022605
),
26032606
})
26042607
.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
@@ -248,7 +248,7 @@ const ThreadSendTool = Tool.make("t3_thread_send", {
248248

249249
const ThreadWaitTool = Tool.make("t3_thread_wait", {
250250
description:
251-
"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.",
251+
"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.",
252252
parameters: OrchestratorMcpThreadWaitInput,
253253
success: OrchestratorMcpThreadWaitResult,
254254
failure: OrchestratorMcpFailure,

0 commit comments

Comments
 (0)