diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 58a7cee936497..d1bae5d859d65 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -2023,7 +2023,7 @@ const make = Effect.gen(function* () { hasPendingChildRuns: false, providerInstanceId: task.providerInstanceId, model: task.model, - executedModel: null, + executedModel: task.executedModel ?? null, summary: task.result, resultContextTransferId: null, latestTerminalRunId: null, diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 5257330e2cb5d..0160ae21423e4 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -10075,6 +10075,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio remoteChild, status: command.status, result: command.result, + ...(command.executedModel === undefined ? {} : { executedModel: command.executedModel }), completedAt: now, updatedAt: now, }; diff --git a/apps/server/src/peer/RemoteDelegation.test.ts b/apps/server/src/peer/RemoteDelegation.test.ts index eeef7bf05a36e..90c6eb83baae5 100644 --- a/apps/server/src/peer/RemoteDelegation.test.ts +++ b/apps/server/src/peer/RemoteDelegation.test.ts @@ -1441,6 +1441,11 @@ it.effect("a task's result is its own run's whole last reply, not a later run's" expect(task?.result).toBe( `Requested model gpt-5.4; the provider reported running gpt-5.4-mini.\n\n${long}`, ); + const status = yield* a.call("task_status", { taskId }); + expect(status.structuredContent).toMatchObject({ + status: "completed", + executedModel: "gpt-5.4-mini", + }); // Every wait was for the run the launch started. const waits = yield* Ref.get(thread.waitedFor); expect(waits.length).toBeGreaterThan(0); @@ -1464,6 +1469,7 @@ it.effect("a task whose thread there waits on its own task ends with the answer const delegated = yield* delegateToBox(a); // The task's run there ends after delegating a review of its own. + yield* Ref.set(thread.executedModel, "gpt-5.4-mini"); yield* Ref.set(thread.nested, true); yield* Ref.set(thread.reply, "Started a review; I will answer when it reports."); yield* Ref.set(thread.status, "completed"); @@ -1481,6 +1487,11 @@ it.effect("a task whose thread there waits on its own task ends with the answer status: "completed", result: "The review found two issues; both are fixed.", }); + const status = yield* a.call("task_status", { taskId: delegated.taskId }); + expect(status.structuredContent).toMatchObject({ + status: "completed", + executedModel: null, + }); }), ).pipe(Effect.provide(NodeHttpServer.layerTest)), ); diff --git a/apps/server/src/peer/RemoteDelegation.ts b/apps/server/src/peer/RemoteDelegation.ts index 932b012969e36..8fcd240e70577 100644 --- a/apps/server/src/peer/RemoteDelegation.ts +++ b/apps/server/src/peer/RemoteDelegation.ts @@ -539,6 +539,7 @@ const make = Effect.gen(function* () { result: string, stoppedThere: "ran-out" | "stopped" | undefined, stopCount?: number, + executedModel?: string, ) { const attempt = yield* random.uuidV4(); yield* threads @@ -551,6 +552,7 @@ const make = Effect.gen(function* () { result, ...(stoppedThere === undefined ? {} : { stoppedThere }), ...(stopCount === undefined ? {} : { stopCount }), + ...(executedModel === undefined ? {} : { executedModel }), }) .pipe( Effect.catch((error) => @@ -642,7 +644,8 @@ const make = Effect.gen(function* () { afterPosition = read.nextPosition; } reply = error ?? reply; - if (reply === undefined) return undefined; + const executedModel = run?.executedModel ?? undefined; + if (reply === undefined) return { text: undefined, executedModel }; let text = reply.text ?? ""; let textOffset = reply.textTruncated ? (reply.nextTextOffset ?? null) : null; while (textOffset !== null) { @@ -657,7 +660,10 @@ const make = Effect.gen(function* () { text += part.text ?? ""; textOffset = part.textTruncated ? (part.nextTextOffset ?? null) : null; } - return run === undefined ? text : withExecutedModelNote(text, run.model, run.executedModel); + return { + text: run === undefined ? text : withExecutedModelNote(text, run.model, run.executedModel), + executedModel, + }; }); /** @@ -823,8 +829,8 @@ const make = Effect.gen(function* () { yield* complete( parentThreadId, taskId, - reply === undefined ? "failed" : "completed", - reply ?? "The thread in the linked environment has no run to follow.", + reply.text === undefined ? "failed" : "completed", + reply.text ?? "The thread in the linked environment has no run to follow.", "ran-out", ); return yield* settled(parentThreadId, taskId); @@ -860,8 +866,10 @@ const make = Effect.gen(function* () { parentThreadId, taskId, terminalStatus(resultRun.status), - result ?? noReply, + result.text ?? noReply, "ran-out", + undefined, + result.executedModel, ); return yield* settled(parentThreadId, taskId); }); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 44e9aa8290e9a..38d2e98ef72c2 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -935,6 +935,7 @@ export const OrchestrationV2Subagent = Schema.Struct({ title: Schema.NullOr(Schema.String), model: Schema.NullOr(Schema.String), modelSelection: Schema.optional(ModelSelection), + executedModel: Schema.optional(Schema.String), completionWake: Schema.optional(Schema.Literals(["always", "settled_only"])), completionDelivery: Schema.optional(OrchestrationV2DelegatedCompletionTaskDelivery), // The run whose unfinished task was cancelled, committed with its Stop. @@ -3692,6 +3693,7 @@ const OrchestrationV2InternalCommand = Schema.Union([ taskId: NodeId, status: Schema.Literals(["completed", "failed", "cancelled", "interrupted"]), result: Schema.String, + executedModel: Schema.optional(Schema.String), /** * `ran-out`: the run there ended by itself; `stopped`: a stop from here reached it. Either * sets `remoteChild.stoppedThere` on a task this report completes. On a task already