Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MessageId,
type ModelSelection,
NodeId,
ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS,
ORCHESTRATOR_MCP_RUNNING_TASK_NEXT,
TurnItemId,
type OrchestrationV2Run,
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -2037,7 +2037,7 @@ const make = Effect.gen(function* () {
requestedTimeoutMs: number | undefined,
): Effect.fn.Return<OrchestratorMcpDelegateTaskResult, OrchestratorMcpFailure> {
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
Expand Down Expand Up @@ -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 } : {}),
Expand Down
5 changes: 2 additions & 3 deletions apps/server/src/peer/PeerForwarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,15 @@ 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,
runId: boxRun,
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", {
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/peer/PeerForwarding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type EnvironmentId,
OrchestratorMcpFailure,
ORCHESTRATOR_MCP_MAX_WAIT_TIMEOUT_MS,
type OrchestratorMcpEnvironmentLinksResult,
OrchestratorMcpThreadInterruptInput,
OrchestratorMcpThreadInterruptResult,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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),
),
},
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 6245,
"codexAdditionalContextBytes": 7639,
"mcpToolListJsonBytes": 57321
"mcpToolListJsonBytes": 57353
}
16 changes: 16 additions & 0 deletions packages/contracts/src/orchestratorMcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Schema from "effect/Schema";
import {
OrchestratorMcpDelegateTaskInput,
OrchestratorMcpDelegateTaskResult,
OrchestratorMcpThreadWaitInput,
OrchestratorMcpThreadWaitResult,
} from "./orchestratorMcp.ts";

Expand Down Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions packages/contracts/src/orchestratorMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
Loading