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..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 d2908fa42db8c..4f12cd33022c7 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,21 @@ 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(); + 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", () => { 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..fa33c665ddeb1 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,7 @@ export const OrchestratorMcpThreadWaitInput = Schema.Struct({ environmentId: OrchestratorMcpEnvironmentTarget, threadId: ThreadId, runId: Schema.optional(RunId), - timeoutMs: Schema.optional(Schema.Finite), + timeoutMs: Schema.optional(OrchestratorMcpWaitTimeoutMs), untilDelegatedWorkSettled: Schema.optional( Schema.Boolean.annotate({ description: