From 8ed894dbca3a3a9c7f190921690795df87e76b1f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 03:27:00 +0000 Subject: [PATCH 1/3] fix(server): reject wait timeouts above the 45 s cap instead of shortening them t3_thread_wait and delegate_task in wait mode accepted any timeoutMs but quietly cut it to 45 s, so a caller asking for 600 s got timedOut after 45 s with no sign its timeout was shortened. Both input schemas now carry the cap, so a longer timeout fails validation with a clear message, and the cap is one shared constant the server clamps also use. Fixes pingdotgg/t3code#39353 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/OrchestratorMcpService.ts | 6 +++--- apps/server/src/peer/PeerForwarding.test.ts | 5 ++--- apps/server/src/peer/PeerForwarding.ts | 4 ++-- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.test.ts | 11 +++++++++++ packages/contracts/src/orchestratorMcp.ts | 12 ++++++++++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 977756e99e14d..3ab8beae593e6 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -5,6 +5,7 @@ import { MessageId, type ModelSelection, NodeId, + ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT, TurnItemId, type OrchestrationV2Run, @@ -141,7 +142,6 @@ import * as RemoteDelegation from "../peer/RemoteDelegation.ts"; // Return recoverable handles before common MCP client timeouts expire. const DEFAULT_WAIT_TIMEOUT_MS = 30_000; -const MAX_WAIT_TIMEOUT_MS = 45_000; const DEFAULT_SECRET_REQUEST_TIMEOUT_MS = 10 * 60 * 1_000; const MAX_SECRET_REQUEST_TIMEOUT_MS = 60 * 60 * 1_000; const TASK_WAKE_EVENTS = [ @@ -2037,7 +2037,7 @@ const make = Effect.gen(function* () { requestedTimeoutMs: number | undefined, ): Effect.fn.Return { const timeoutMs = Math.min( - MAX_WAIT_TIMEOUT_MS, + ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS, Math.max(1, requestedTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS), ); const upgradeWake = threadManagement @@ -3664,7 +3664,7 @@ const make = Effect.gen(function* () { threadId: input.threadId, ...(input.runId === undefined ? {} : { runId: input.runId }), timeoutMs: Math.min( - MAX_WAIT_TIMEOUT_MS, + ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS, Math.max(1, input.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS), ), ...(input.untilDelegatedWorkSettled === true ? { untilDelegatedWorkSettled: true } : {}), diff --git a/apps/server/src/peer/PeerForwarding.test.ts b/apps/server/src/peer/PeerForwarding.test.ts index a70c0d25792b8..e279af6ebf3f0 100644 --- a/apps/server/src/peer/PeerForwarding.test.ts +++ b/apps/server/src/peer/PeerForwarding.test.ts @@ -466,7 +466,6 @@ it.effect("keeps a forwarded wait short and its retries scoped to the caller", ( const waited = yield* a.call("thread:laptop-full", "t3_thread_wait", { environmentId: box.environmentId, threadId: boxThread, - timeoutMs: 600_000, }); expect(waited.structuredContent).toEqual({ threadId: boxThread, @@ -474,8 +473,8 @@ it.effect("keeps a forwarded wait short and its retries scoped to the caller", ( status: "completed", timedOut: false, }); - // One capped piece, so the caller's MCP request returns before its client times out. - expect((yield* Ref.get(seen)).waits.map(({ timeoutMs }) => timeoutMs)).toEqual([45_000]); + // One bounded piece, so the caller's MCP request returns before its client times out. + expect((yield* Ref.get(seen)).waits.map(({ timeoutMs }) => timeoutMs)).toEqual([30_000]); const send = (caller: string, clientRequestId: string) => a.call(caller, "t3_thread_send", { diff --git a/apps/server/src/peer/PeerForwarding.ts b/apps/server/src/peer/PeerForwarding.ts index 080f701c45cb2..35ad40a441e80 100644 --- a/apps/server/src/peer/PeerForwarding.ts +++ b/apps/server/src/peer/PeerForwarding.ts @@ -1,6 +1,7 @@ import { type EnvironmentId, OrchestratorMcpFailure, + ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS, type OrchestratorMcpEnvironmentLinksResult, OrchestratorMcpThreadInterruptInput, OrchestratorMcpThreadInterruptResult, @@ -31,7 +32,6 @@ import * as PeerMcpClient from "./PeerMcpClient.ts"; // Match local waits: return before MCP client timeouts and T3 Connect's ~100 s idle drop. const DEFAULT_WAIT_TIMEOUT_MS = 30_000; -const MAX_WAIT_TIMEOUT_MS = 45_000; type Scope = McpInvocationContext.McpInvocationScope; @@ -225,7 +225,7 @@ const make = Effect.gen(function* () { { ...input, timeoutMs: Math.min( - MAX_WAIT_TIMEOUT_MS, + ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS, Math.max(1, input.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS), ), }, diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 5f44bd54c29f8..38643d3917c1d 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 6245, "codexAdditionalContextBytes": 7639, - "mcpToolListJsonBytes": 57321 + "mcpToolListJsonBytes": 57383 } diff --git a/packages/contracts/src/orchestratorMcp.test.ts b/packages/contracts/src/orchestratorMcp.test.ts index d2908fa42db8c..755356016f92f 100644 --- a/packages/contracts/src/orchestratorMcp.test.ts +++ b/packages/contracts/src/orchestratorMcp.test.ts @@ -4,6 +4,7 @@ import * as Schema from "effect/Schema"; import { OrchestratorMcpDelegateTaskInput, OrchestratorMcpDelegateTaskResult, + OrchestratorMcpThreadWaitInput, OrchestratorMcpThreadWaitResult, } from "./orchestratorMcp.ts"; @@ -69,6 +70,16 @@ describe("orchestrator MCP contracts", () => { ).toThrow(); }); + it("rejects wait timeouts above the 45 s cap instead of shortening them", () => { + const decodeThreadWaitInput = Schema.decodeUnknownSync(OrchestratorMcpThreadWaitInput); + const wait = { threadId: "thread-child-1" }; + expect(decodeThreadWaitInput({ ...wait, timeoutMs: 45_000 }).timeoutMs).toBe(45_000); + expect(() => decodeThreadWaitInput({ ...wait, timeoutMs: 600_000 })).toThrow(); + const task = { task: "Report.", mode: "wait" }; + expect(decodeDelegateTaskInput({ ...task, timeoutMs: 45_000 }).timeoutMs).toBe(45_000); + expect(() => decodeDelegateTaskInput({ ...task, timeoutMs: 600_000 })).toThrow(); + }); + it("decodes a running-task next written by another version", () => { const next = "Completion wakes this thread, so end your turn. Do not wait on it or poll it."; expect( diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index d7c607744d4a7..0825aae106694 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -168,6 +168,12 @@ export const OrchestratorMcpTerminalDelegatedTaskStatus = Schema.Literals([ export type OrchestratorMcpTerminalDelegatedTaskStatus = typeof OrchestratorMcpTerminalDelegatedTaskStatus.Type; +// Waits return before common MCP client deadlines; callers wait again with the returned handle. +export const ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS = 45_000; +const OrchestratorMcpWaitTimeoutMs = Schema.Finite.check( + Schema.isLessThanOrEqualTo(ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS), +); + export const OrchestratorMcpDelegateTaskInput = Schema.Struct({ task: OrchestratorMcpPrompt, // Some providers send the whole target object as JSON text. @@ -188,7 +194,7 @@ export const OrchestratorMcpDelegateTaskInput = Schema.Struct({ "Default 'async'. 'wait' only if this turn needs the result. A question or approval ends the wait.", }), ), - timeoutMs: Schema.optional(Schema.Finite).annotate({ + timeoutMs: Schema.optional(OrchestratorMcpWaitTimeoutMs).annotate({ description: "Mode 'wait' only. At most 45 s. A timeout does not cancel the child.", }), clientRequestId: Schema.optional(OrchestratorMcpClientRequestId), @@ -580,7 +586,9 @@ export const OrchestratorMcpThreadWaitInput = Schema.Struct({ environmentId: OrchestratorMcpEnvironmentTarget, threadId: ThreadId, runId: Schema.optional(RunId), - timeoutMs: Schema.optional(Schema.Finite), + timeoutMs: Schema.optional(OrchestratorMcpWaitTimeoutMs).annotate({ + description: "At most 45 s.", + }), untilDelegatedWorkSettled: Schema.optional( Schema.Boolean.annotate({ description: From cbb87b899e91769451448de671443d6404b40ae2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 05:43:10 +0000 Subject: [PATCH 2/3] fix(contracts): keep wait timeout cap out of MCP tool schemas The cap now rejects through a custom filter, which emits no JSON Schema maximum, so the MCP tool list stays within the agent context budget. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 38643d3917c1d..5f44bd54c29f8 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 6245, "codexAdditionalContextBytes": 7639, - "mcpToolListJsonBytes": 57383 + "mcpToolListJsonBytes": 57321 } diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index 0825aae106694..7512a1cdad116 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -170,8 +170,13 @@ export type OrchestratorMcpTerminalDelegatedTaskStatus = // Waits return before common MCP client deadlines; callers wait again with the returned handle. export const ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS = 45_000; +// A custom filter adds no `maximum` to the tool schema, which counts against the agent context budget. const OrchestratorMcpWaitTimeoutMs = Schema.Finite.check( - Schema.isLessThanOrEqualTo(ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS), + Schema.makeFilter( + (timeoutMs) => + timeoutMs <= ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS || + `timeoutMs is at most ${ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS}; wait again with the returned handle.`, + ), ); export const OrchestratorMcpDelegateTaskInput = Schema.Struct({ @@ -586,9 +591,7 @@ export const OrchestratorMcpThreadWaitInput = Schema.Struct({ environmentId: OrchestratorMcpEnvironmentTarget, threadId: ThreadId, runId: Schema.optional(RunId), - timeoutMs: Schema.optional(OrchestratorMcpWaitTimeoutMs).annotate({ - description: "At most 45 s.", - }), + timeoutMs: Schema.optional(OrchestratorMcpWaitTimeoutMs), untilDelegatedWorkSettled: Schema.optional( Schema.Boolean.annotate({ description: From f541bef21874a994b10e97caaba7754b4f2e13a5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 05:59:17 +0000 Subject: [PATCH 3/3] fix(contracts): advertise the 45 s wait cap in MCP tool schemas Restore Schema.isLessThanOrEqualTo so t3_thread_wait and delegate_task publish maximum: 45000 on timeoutMs, matching what they enforce. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.test.ts | 5 +++++ packages/contracts/src/orchestratorMcp.ts | 7 +------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 5f44bd54c29f8..57f57c6d688ff 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 6245, "codexAdditionalContextBytes": 7639, - "mcpToolListJsonBytes": 57321 + "mcpToolListJsonBytes": 57353 } diff --git a/packages/contracts/src/orchestratorMcp.test.ts b/packages/contracts/src/orchestratorMcp.test.ts index 755356016f92f..4f12cd33022c7 100644 --- a/packages/contracts/src/orchestratorMcp.test.ts +++ b/packages/contracts/src/orchestratorMcp.test.ts @@ -78,6 +78,11 @@ describe("orchestrator MCP contracts", () => { const task = { task: "Report.", mode: "wait" }; expect(decodeDelegateTaskInput({ ...task, timeoutMs: 45_000 }).timeoutMs).toBe(45_000); expect(() => decodeDelegateTaskInput({ ...task, timeoutMs: 600_000 })).toThrow(); + for (const input of [OrchestratorMcpThreadWaitInput, OrchestratorMcpDelegateTaskInput]) { + expect(JSON.stringify(Schema.toJsonSchemaDocument(input).schema)).toContain( + '"timeoutMs":{"anyOf":[{"type":"number","maximum":45000}', + ); + } }); it("decodes a running-task next written by another version", () => { diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index 7512a1cdad116..fa33c665ddeb1 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -170,13 +170,8 @@ export type OrchestratorMcpTerminalDelegatedTaskStatus = // Waits return before common MCP client deadlines; callers wait again with the returned handle. export const ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS = 45_000; -// A custom filter adds no `maximum` to the tool schema, which counts against the agent context budget. const OrchestratorMcpWaitTimeoutMs = Schema.Finite.check( - Schema.makeFilter( - (timeoutMs) => - timeoutMs <= ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS || - `timeoutMs is at most ${ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS}; wait again with the returned handle.`, - ), + Schema.isLessThanOrEqualTo(ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS), ); export const OrchestratorMcpDelegateTaskInput = Schema.Struct({