@devries-cameron20 / t3code-1 / commits / 3eaebac0f9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): stop shipping delegated task results twice (#19759)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Ben Davis committed Oct 19, 2026 at 16:31 UTC 3eaebac0f94d5044d97112164c579963c41baf75
3 files changed +47 -31
apps/server/src/mcp/OrchestratorMcpService.ts
+14 -7
@@ -1453,6 +1453,13 @@ const make = Effect.gen(function* () {
1453 null);
1454 const resultTransfer = taskResultTransfer(parentProjection, childProjection, task) ?? null;
1455 const terminalStatus = terminalRun === undefined ? null : taskStatusForRun(terminalRun);
1456 + const latestTerminalSummary = canExposeTaskRunResult(terminalRun)
1457 + ? terminalRun.id === childRun?.id
1458 + ? derivedResult
1459 + : subagentResultForRun(childProjection, terminalRun).text
1460 + : null;
1461 + const resultContextTransferId = resultTransfer?.id ?? null;
1462 + const latestTerminalResultContextTransferId = resultTransferForRun(terminalRun)?.id ?? null;
1463 const response = {
1464 taskId: task.id,
1465 childThreadId: task.childThreadId,
@@ -1464,16 +1471,16 @@ const make = Effect.gen(function* () {
1471 providerInstanceId: task.providerInstanceId,
1472 model: task.model,
1473 summary: derivedResult,
1467 - resultContextTransferId: resultTransfer?.id ?? null,
1474 + resultContextTransferId,
1475 latestTerminalRunId: terminalRun?.id ?? null,
1476 latestTerminalStatus:
1477 terminalStatus !== null && isTerminalTaskStatus(terminalStatus) ? terminalStatus : null,
1471 - latestTerminalSummary: canExposeTaskRunResult(terminalRun)
1472 - ? terminalRun.id === childRun?.id
1473 - ? derivedResult
1474 - : subagentResultForRun(childProjection, terminalRun).text
1475 - : null,
1476 - latestTerminalResultContextTransferId: resultTransferForRun(terminalRun)?.id ?? null,
1478 + latestTerminalSummary:
1479 + latestTerminalSummary === derivedResult ? null : latestTerminalSummary,
1480 + latestTerminalResultContextTransferId:
1481 + latestTerminalResultContextTransferId === resultContextTransferId
1482 + ? null
1483 + : latestTerminalResultContextTransferId,
1484 hasPendingQuestion:
1485 !isTerminalTaskStatus(status) &&
1486 childControls.runtimeRequests.some(
apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
+32 -23
@@ -136,16 +136,15 @@ const delegatedTaskStatusTranscriptFile = new URL(
136 import.meta.url,
137 );
138
139 -const readDelegatedTaskStatusTranscript = Effect.fn("readDelegatedTaskStatusTranscript")(
140 - function* () {
141 - const fs = yield* FileSystem.FileSystem;
142 - const text = yield* fs.readFileString(
143 - decodeURIComponent(delegatedTaskStatusTranscriptFile.pathname),
144 - );
145 - return yield* decodeProviderReplayNdjson(text);
146 - },
147 - Effect.provide(NodeServices.layer),
148 -);
139 +const readDelegatedTaskStatusTranscript = Effect.fn("readDelegatedTaskStatusTranscript")(function* (
140 + followupResult: string,
141 +) {
142 + const fs = yield* FileSystem.FileSystem;
143 + const text = yield* fs.readFileString(
144 + decodeURIComponent(delegatedTaskStatusTranscriptFile.pathname),
145 + );
146 + return yield* decodeProviderReplayNdjson(text.replaceAll(queuedFollowupResult, followupResult));
147 +}, Effect.provide(NodeServices.layer));
148
149 interface CapturedTurn {
150 readonly instanceId: ProviderInstanceId;
@@ -1757,10 +1756,10 @@ describe("orchestrator MCP toolkit", () => {
1756 hasPendingChildRuns: false,
1757 latestTerminalRunId: delegated.childRunId,
1758 latestTerminalStatus: "completed",
1760 - latestTerminalSummary: delegatedResult,
1759 + latestTerminalSummary: null,
1760 + latestTerminalResultContextTransferId: null,
1761 });
1762 expect(delegatedStatus.resultContextTransferId).not.toBeNull();
1763 - expect(delegatedStatus.latestTerminalResultContextTransferId).not.toBeNull();
1763
1764 yield* expectOffersToStay(0);
1765
@@ -3990,11 +3989,14 @@ describe("orchestrator MCP toolkit", () => {
3989 ),
3990 );
3991
3993 - it.live("reports running and queued child follow-ups from a Codex replay transcript", () =>
3992 + it.live.each([
3993 + { label: "distinct", result: queuedFollowupResult, latestSummary: queuedFollowupResult },
3994 + { label: "identical", result: delegatedResult, latestSummary: null },
3995 + ])("reports $label child results", ({ result, latestSummary }) =>
3996 Effect.scoped(
3997 Effect.gen(function* () {
3998 const cwd = yield* checkpointWorkspace("delegated-task-status");
3997 - const rawTranscript = yield* readDelegatedTaskStatusTranscript();
3999 + const rawTranscript = yield* readDelegatedTaskStatusTranscript(result);
4000 const transcript = yield* CodexOrchestratorReplayHarness.decodeTranscript(
4001 materializeReplayTranscriptWorkspace(rawTranscript, cwd),
4002 );
@@ -4163,12 +4165,10 @@ describe("orchestrator MCP toolkit", () => {
4165 hasPendingChildRuns: false,
4166 latestTerminalRunId: delegated.childRunId,
4167 latestTerminalStatus: "completed",
4166 - latestTerminalSummary: delegatedResult,
4168 + latestTerminalSummary: null,
4169 + latestTerminalResultContextTransferId: null,
4170 });
4171 expect(delegated.resultContextTransferId).not.toBeNull();
4169 - expect(delegated.latestTerminalResultContextTransferId).toBe(
4170 - delegated.resultContextTransferId,
4171 - );
4172
4173 const delegatedChild = yield* orchestrator.getThreadProjection(delegated.childThreadId);
4174 expect(delegatedChild.thread.lineage.relationshipToParent).toBe("subagent");
@@ -4262,8 +4262,8 @@ describe("orchestrator MCP toolkit", () => {
4262 hasPendingChildRuns: true,
4263 latestTerminalRunId: delegated.childRunId,
4264 latestTerminalStatus: "completed",
4265 - latestTerminalSummary: delegatedResult,
4266 - latestTerminalResultContextTransferId: delegated.resultContextTransferId,
4265 + latestTerminalSummary: null,
4266 + latestTerminalResultContextTransferId: null,
4267 });
4268
4269 const finalSequence = yield* orchestrator.getThreadEventSequence(delegated.childThreadId);
@@ -4336,7 +4336,7 @@ describe("orchestrator MCP toolkit", () => {
4336 finishedParent.subagents.find((task) => task.id === followupTasks[1]!.id),
4337 ).toMatchObject({
4338 status: "completed",
4339 - result: queuedFollowupResult,
4339 + result,
4340 });
4341 expect(
4342 finishedParent.contextTransfers.filter(
@@ -4363,9 +4363,18 @@ describe("orchestrator MCP toolkit", () => {
4363 hasPendingChildRuns: false,
4364 latestTerminalRunId: queuedFollowup.runId,
4365 latestTerminalStatus: "completed",
4366 - latestTerminalSummary: queuedFollowupResult,
4366 + latestTerminalSummary: latestSummary,
4367 });
4368 - expect(finalStatus.latestTerminalResultContextTransferId).not.toBeNull();
4368 + const followupTransfer = finishedParent.contextTransfers.find(
4369 + (transfer) =>
4370 + transfer.type === "subagent_result" &&
4371 + transfer.sourcePoint.runId === queuedFollowup.runId,
4372 + );
4373 + expect(followupTransfer).toBeDefined();
4374 + expect(finalStatus.latestTerminalResultContextTransferId).toBe(followupTransfer?.id);
4375 + expect(finalStatus.latestTerminalResultContextTransferId).not.toBe(
4376 + delegated.resultContextTransferId,
4377 + );
4378 const read = yield* invoke("t3_thread_read", {
4379 threadId: delegated.childThreadId,
4380 limit: 100,
apps/server/src/mcp/toolkits/orchestrator/tools.ts
+1 -1
@@ -78,7 +78,7 @@ export const DelegateTaskTool = Tool.make("delegate_task", {
78
79 const TaskStatusTool = Tool.make("task_status", {
80 description:
81 - "Needs an agent running inside a T3 thread. Read a T3-owned delegated task created by this parent thread. childRunId identifies the original delegated run. workState distinguishes working, waiting_for_children, and result_available; a completed turn with live nested work is not a completed task. summary is the final task result, including provider errors on failure, and remains stable after publication. hasPendingChildRuns reports later queued or executing turns in the backing child thread, even after the task is terminal; it does not reopen the task, and task_cancel stops those turns too. Turns held in a stopped queue wait for the user and do not count. latestTerminal* provides later non-monitor turn results. Reading a terminal result acknowledges its automatic parent delivery.",
81 + "Needs an agent running inside a T3 thread. Read a T3-owned delegated task created by this parent thread. childRunId identifies the original delegated run. workState distinguishes working, waiting_for_children, and result_available; a completed turn with live nested work is not a completed task. summary is the final task result, including provider errors on failure, and remains stable after publication. hasPendingChildRuns reports later queued or executing turns in the backing child thread, even after the task is terminal; it does not reopen the task, and task_cancel stops those turns too. Turns held in a stopped queue wait for the user and do not count. latestTerminal* provides later non-monitor turn results; latestTerminalSummary and latestTerminalResultContextTransferId are independently null when they exactly repeat summary and resultContextTransferId, respectively. Reading a terminal result acknowledges its automatic parent delivery.",
82 parameters: OrchestratorMcpTaskStatusInput,
83 success: OrchestratorMcpDelegateTaskResult,
84 failure: OrchestratorMcpFailure,