@devries-cameron20 / t3code-1 / commits / f03ce68691
Fork 0

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

fix(server): self-settle survives a delegated wake cancelled before it started (#39221)

Julius Marminge committed Nov 19, 2026 at 09:22 UTC f03ce68691014011a68e2339a414a550a51b604f
2 files changed +12 -3
apps/server/src/orchestration-v2/ThreadManagementService.test.ts
+6 -2
@@ -697,6 +697,9 @@ it.effect.each([
697 { status: "completed" as const, followUp: "steered-notification", settles: false },
698 // Send now cancels the queued run; its message joins the run that asked to settle.
699 { status: "completed" as const, followUp: "promoted-to-steer", settles: true },
700 + // A delegated-completion wake cancelled unstarted because the turn already took the result.
701 + { status: "completed" as const, followUp: "cancelled-delegated", settles: true },
702 + { status: "completed" as const, followUp: "stopped-delegated", settles: false },
703 ])("settleAfterRun handles $status with $followUp follow-up", ({ status, followUp, settles }) =>
704 Effect.gen(function* () {
705 const projectId = ProjectId.make("project:thread-management:settle-after-run");
@@ -715,6 +718,7 @@ it.effect.each([
718 ordinal: 2,
719 status: "running" as OrchestrationV2Run["status"],
720 userMessageId: MessageId.make("follow-up"),
721 + startedAt: followUp === "stopped-delegated" ? "2026-01-01T00:00:00.000Z" : null,
722 };
723 const dispatched: Array<string> = [];
724 // The notification starts after the completed run was observed, before settlement commits.
@@ -747,7 +751,7 @@ it.effect.each([
751 runId: followUp === "promoted-to-steer" ? runId : followUpId,
752 role: "user" as const,
753 ...(followUp.endsWith("notification") ? { notification: {} } : {}),
750 - ...(followUp === "delegated" ? { delegatedCompletion: {} } : {}),
754 + ...(followUp.endsWith("delegated") ? { delegatedCompletion: {} } : {}),
755 },
756 { id: MessageId.make("reply"), runId: followUpId, role: "assistant" as const },
757 ...(followUp === "steered-notification"
@@ -811,7 +815,7 @@ it.effect.each([
815 ? "failed"
816 : followUp === "held-notification"
817 ? "queued"
814 - : followUp === "promoted-to-steer"
818 + : followUp === "promoted-to-steer" || followUp.endsWith("ed-delegated")
819 ? "cancelled"
820 : "completed";
821 yield* Queue.offer(events, {
apps/server/src/orchestration-v2/ThreadManagementService.ts
+6 -1
@@ -68,6 +68,7 @@ import * as ProviderSessionManager from "./ProviderSessionManager.ts";
68 import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts";
69 import { DispatchModeLimit, exceededDispatchModeLimit } from "./DispatchModeLimit.ts";
70 import { projectTurnItemForDetail } from "./WireProjection.ts";
71 +import { cancelledBeforeStart } from "./RestartBackgroundNote.ts";
72 import * as LegacyV1ThreadImporter from "./legacy/LegacyV1ThreadImporter.ts";
73 import * as ServerSettings from "../serverSettings.ts";
74 import { ThreadWorktreeRestore } from "../workspace/restoreMissingWorktree.ts";
@@ -1191,9 +1192,13 @@ const make = Effect.gen(function* () {
1192 )
1193 )
1194 return false;
1195 + // A wake cancelled before it started (its result was already read in-turn) did nothing.
1196 if (
1197 following.some(
1196 - (candidate) => candidate.status !== "queued" && candidate.status !== "completed",
1198 + (candidate) =>
1199 + candidate.status !== "queued" &&
1200 + candidate.status !== "completed" &&
1201 + !cancelledBeforeStart(candidate),
1202 )
1203 )
1204 return true;