@devries-cameron20 / t3code-1 / commits / 11c425b4b6
Fork 0

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

fix(server): task_status no longer reports a restart-continued task as cancelled (#32414)

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

Jolymmiles committed Nov 15, 2026 at 08:35 UTC 11c425b4b6b35dce4510d40028a4aa8f37a3879e
2 files changed +95 -9
apps/server/src/mcp/OrchestratorMcpService.test.ts
+63 -2
@@ -259,6 +259,8 @@ describe("OrchestratorMcpService", () => {
259 const parentThreadId = ThreadId.make("thread:mcp-restart-parent");
260 const childThreadId = ThreadId.make("thread:mcp-restart-child");
261 const taskId = NodeId.make("node:mcp-restart-task");
262 + const cutRunId = RunId.make("run:mcp-restart-child");
263 + const continuationRunId = RunId.make("run:mcp-restart-continuation");
264 const dispatched = yield* Ref.make(0);
265 let awaitsRestart = true;
266 let readFails = true;
@@ -284,10 +286,12 @@ describe("OrchestratorMcpService", () => {
286 thread: { id: childThreadId, title: "Child" },
287 runs: [
288 {
287 - id: RunId.make("run:mcp-restart-child"),
289 + id: cutRunId,
290 ordinal: 1,
291 status: "cancelled",
292 delegatedTaskId: taskId,
293 + startedAt: DateTime.makeUnsafe("2026-10-03T10:00:00Z"),
294 + completedAt: DateTime.makeUnsafe("2026-10-03T10:05:00Z"),
295 },
296 { id: RunId.make("run:mcp-restart-later"), ordinal: 2, status: "running" },
297 ],
@@ -299,12 +303,17 @@ describe("OrchestratorMcpService", () => {
303 runtimeRequests: [],
304 turnItems: [],
305 } as unknown as OrchestrationV2ThreadProjection;
306 + let childRuns = childProjection.runs;
307 const layerDependencies = Layer.mergeAll(
308 NodeServices.layer,
309 NodeCrypto.layer,
310 Layer.mock(ThreadManagementService.ThreadManagementService)({
311 getThreadRecords: (threadId) =>
307 - Effect.succeed(threadId === parentThreadId ? parentProjection : childProjection),
312 + Effect.succeed(
313 + threadId === parentThreadId
314 + ? parentProjection
315 + : { ...childProjection, runs: childRuns },
316 + ),
317 delegatedTaskResultPending: () =>
318 readFails
319 ? Effect.fail(new OrchestratorProjectionError({ threadId: childThreadId }))
@@ -344,11 +353,63 @@ describe("OrchestratorMcpService", () => {
353 assert.equal(held.status, "running");
354 assert.equal(held.workState, "working");
355 assert.isNull(held.summary);
356 + assert.isNull(held.latestTerminalRunId);
357 + assert.isNull(held.latestTerminalStatus);
358 assert.equal(yield* Ref.get(dispatched), 0);
359 +
360 + const continuationRun = {
361 + id: continuationRunId,
362 + ordinal: 3,
363 + status: "running",
364 + delegatedTaskId: taskId,
365 + startedAt: DateTime.makeUnsafe("2026-10-03T10:06:00Z"),
366 + restartContinuationOfRunId: cutRunId,
367 + } as unknown as (typeof childRuns)[number];
368 + childRuns = [...childProjection.runs, continuationRun];
369 + const continuing = yield* service.taskStatus(scope, taskId);
370 + assert.equal(continuing.status, "running");
371 + assert.isNull(continuing.latestTerminalRunId);
372 + assert.isNull(continuing.latestTerminalStatus);
373 +
374 + // A second restart cut the continuation, and its own continuation declined.
375 + childRuns = [
376 + ...childProjection.runs,
377 + {
378 + ...continuationRun,
379 + status: "cancelled",
380 + completedAt: DateTime.makeUnsafe("2026-10-03T10:10:00Z"),
381 + },
382 + ];
383 awaitsRestart = false;
384 const settled = yield* service.taskStatus(scope, taskId);
385 assert.equal(settled.status, "cancelled");
386 + assert.equal(settled.latestTerminalRunId, continuationRunId);
387 + assert.equal(settled.latestTerminalStatus, "cancelled");
388 assert.equal(yield* Ref.get(dispatched), 1);
389 +
390 + // A continuation cancelled before it started leaves the cut run as the result.
391 + childRuns = [
392 + ...childProjection.runs,
393 + { ...continuationRun, status: "cancelled", startedAt: null },
394 + ];
395 + const unstarted = yield* service.taskStatus(scope, taskId);
396 + assert.equal(unstarted.latestTerminalRunId, cutRunId);
397 + assert.equal(unstarted.latestTerminalStatus, "cancelled");
398 +
399 + // That unstarted continuation was itself continued, so the whole chain is still live.
400 + childRuns = [
401 + ...childProjection.runs,
402 + { ...continuationRun, status: "cancelled", startedAt: null },
403 + {
404 + ...continuationRun,
405 + id: RunId.make("run:mcp-restart-continuation-2"),
406 + ordinal: 4,
407 + restartContinuationOfRunId: continuationRunId,
408 + },
409 + ];
410 + const chained = yield* service.taskStatus(scope, taskId);
411 + assert.isNull(chained.latestTerminalRunId);
412 + assert.isNull(chained.latestTerminalStatus);
413 }).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
414 }),
415 );
apps/server/src/mcp/OrchestratorMcpService.ts
+32 -7
@@ -701,17 +701,38 @@ function pageIncludesTerminalTaskResult(input: {
701 function latestTerminalResultRun(
702 projection: Pick<OrchestrationV2ThreadProjection, "messages" | "runs">,
703 delegatedRun: OrchestrationV2Run | undefined,
704 + awaitingContinuationRun: OrchestrationV2Run | undefined,
705 ): OrchestrationV2Run | undefined {
706 const monitorRunIds = new Set(
707 projection.messages
708 .filter((message) => message.notification?.source.kind === "monitor")
709 .map((message) => message.runId),
710 );
711 + // A restart-cut run, and each cut run before it in the chain, has no outcome while a
712 + // continuation is pending, live, or ran to a result.
713 + const runsById = new Map(projection.runs.map((run) => [run.id, run]));
714 + const supersededRunIds = new Set<RunId>();
715 + const supersede = (runId: RunId | undefined) => {
716 + let id = runId;
717 + while (id !== undefined && !supersededRunIds.has(id)) {
718 + supersededRunIds.add(id);
719 + id = runsById.get(id)?.restartContinuationOfRunId;
720 + }
721 + };
722 + supersede(awaitingContinuationRun?.id);
723 + for (const run of projection.runs) {
724 + if (
725 + !ThreadManagementService.isTerminalRunStatus(run.status) ||
726 + (run.status !== "rolled_back" && run.startedAt !== null)
727 + )
728 + supersede(run.restartContinuationOfRunId);
729 + }
730 return projection.runs
731 .filter(
732 (run) =>
733 ThreadManagementService.isTerminalRunStatus(run.status) &&
734 !monitorRunIds.has(run.id) &&
735 + !supersededRunIds.has(run.id) &&
736 run.status !== "rolled_back" &&
737 (run.id === delegatedRun?.id || run.startedAt !== null),
738 )
@@ -1674,7 +1695,6 @@ const make = Effect.gen(function* () {
1695 )
1696 .pipe(Effect.mapError(threadManagementFailure));
1697 const childRun = delegatedTaskRun(childControls, task);
1677 - const terminalRun = latestTerminalResultRun(childControls, childRun);
1698 const progress = delegatedTaskProgress(childControls);
1699 const followupRuns =
1700 childRun?.delegatedTaskId === task.id ? delegatedTaskRuns(childControls, task.id) : undefined;
@@ -1688,6 +1708,17 @@ const make = Effect.gen(function* () {
1708 : delegatedTaskAwaitsWork(followupRuns, childControls)
1709 ? "waiting_for_children"
1710 : "result_available";
1711 + const heldForRestart =
1712 + task.result === null &&
1713 + taskWorkState === "result_available" &&
1714 + (yield* threadManagement
1715 + .delegatedTaskResultPending(task.childThreadId, childRun?.delegatedTaskId)
1716 + .pipe(Effect.mapError(threadManagementFailure)));
1717 + const terminalRun = latestTerminalResultRun(
1718 + childControls,
1719 + childRun,
1720 + heldForRestart ? taskResultRun : undefined,
1721 + );
1722 const resultRunIds = [
1723 ...new Set(
1724 [taskResultRun?.id, terminalRun?.id].filter((id): id is RunId => id !== undefined),
@@ -1706,12 +1737,6 @@ const make = Effect.gen(function* () {
1737 messages: [...childControls.messages, ...resultRecords.messages],
1738 turnItems: resultRecords.turnItems,
1739 };
1709 - const heldForRestart =
1710 - task.result === null &&
1711 - taskWorkState === "result_available" &&
1712 - (yield* threadManagement
1713 - .delegatedTaskResultPending(task.childThreadId, childRun?.delegatedTaskId)
1714 - .pipe(Effect.mapError(threadManagementFailure)));
1740 const workState =
1741 task.result !== null ? "result_available" : heldForRestart ? "working" : taskWorkState;
1742 const runStatus = taskStatusForRun(taskResultRun ?? childRun);