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

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

fix(server): preserve completed runs when accepting child deliveries (#25666)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 01:53 UTC d033768ec73d728a1d10a75c53cf2ab195d1c867
2 files changed +67 -26
apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
+65 -25
@@ -976,24 +976,27 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
976 );
977
978 it.effect.each([
979 - { before: "running", after: "failed", capture: false },
980 - { before: "waiting", after: "completed", capture: true },
979 + { command: "acknowledge", before: "running", after: "failed", capture: false },
980 + { command: "acknowledge", before: "waiting", after: "completed", capture: true },
981 + { command: "accept", before: "waiting", after: "completed", capture: true },
982 ] as const)(
982 - "keeps a $after run that settled between task_status's acknowledge read and commit",
983 - ({ before, after, capture }) =>
983 + "keeps a $after run that settled between $command's read and commit",
984 + ({ command, before, after, capture }) =>
985 Effect.gen(function* () {
986 const orchestrator = yield* Orchestrator.OrchestratorV2;
987 const sink = yield* EventSink.EventSinkV2;
988 const now = yield* DateTime.now;
988 - const threadId = ThreadId.make(`thread:ack-settle-race-${after}`);
989 - const runId = RunId.make(`run:ack-settle-race-${after}`);
990 - const taskId = NodeId.make(`node:ack-settle-race-${after}-task`);
991 - const checkpointId = CheckpointId.make(`checkpoint:ack-settle-race-${after}`);
989 + const race = `${command}-settle-race-${after}`;
990 + const threadId = ThreadId.make(`thread:${race}`);
991 + const runId = RunId.make(`run:${race}`);
992 + const taskId = NodeId.make(`node:${race}-task`);
993 + const checkpointId = CheckpointId.make(`checkpoint:${race}`);
994 + const messageId = MessageId.make(`message:delegated-delivery:${threadId}`);
995 yield* seedParentWithTerminalTask({
996 threadId,
994 - projectId: ProjectId.make(`project:ack-settle-race-${after}`),
997 + projectId: ProjectId.make(`project:${race}`),
998 runId,
996 - rootNodeId: NodeId.make(`node:ack-settle-race-${after}-root`),
999 + rootNodeId: NodeId.make(`node:${race}-root`),
1000 taskId,
1001 deliveryState: "claimed",
1002 deliveryTaskIds: [taskId],
@@ -1003,13 +1006,35 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
1006 yield* sink.write({
1007 events: [
1008 {
1006 - id: EventId.make(`event:ack-settle-race-${after}-before`),
1009 + id: EventId.make(`event:${race}-before`),
1010 type: "run.updated",
1011 threadId,
1012 runId,
1013 occurredAt: now,
1014 payload: { ...parent, status: before },
1015 },
1016 + {
1017 + id: EventId.make(`event:${race}-message`),
1018 + type: "message.updated",
1019 + threadId,
1020 + runId,
1021 + occurredAt: now,
1022 + payload: {
1023 + id: messageId,
1024 + threadId,
1025 + runId,
1026 + nodeId: parent.rootNodeId,
1027 + role: "user",
1028 + text: "Background task finished",
1029 + attachments: [],
1030 + streaming: false,
1031 + createdBy: "agent",
1032 + creationSource: "server",
1033 + createdAt: now,
1034 + updatedAt: now,
1035 + delegatedCompletion: { parentRunId: runId, generation: 1, taskIds: [taskId] },
1036 + },
1037 + },
1038 ],
1039 });
1040 const { delegatedCompletion: _cohort, ...settledRun } = parent;
@@ -1021,19 +1046,22 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
1046 Effect.gen(function* () {
1047 if (
1048 !settled &&
1024 - input.commandType === "delegated_task.completion-delivery.acknowledge"
1049 + input.commandType ===
1050 + (command === "accept"
1051 + ? "notification.delivery.accept"
1052 + : "delegated_task.completion-delivery.acknowledge")
1053 ) {
1054 settled = true;
1027 - // The provider turn ends (or its checkpoint lands) after acknowledge read the run.
1055 + // The provider turn ends (or its checkpoint lands) after the command read the run.
1056 yield* commit({
1029 - commandId: CommandId.make(`command:ack-settle-race-${after}`),
1057 + commandId: CommandId.make(`command:${race}`),
1058 threadId,
1059 commandType: capture ? "checkpoint.capture" : "provider.event",
1060 acceptedAt: now,
1061 effects: [],
1062 events: [
1063 {
1036 - id: EventId.make(`event:ack-settle-race-${after}-settled`),
1064 + id: EventId.make(`event:${race}-settled`),
1065 type: "run.updated",
1066 threadId,
1067 runId,
@@ -1053,19 +1081,31 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
1081 ),
1082 ),
1083 () =>
1056 - orchestrator.dispatch({
1057 - type: "delegated_task.completion-delivery.acknowledge",
1058 - commandId: CommandId.make(`command:ack-settle-race-${after}:task-status`),
1059 - parentThreadId: threadId,
1060 - taskId,
1061 - observedByRunId: runId,
1062 - }),
1084 + orchestrator.dispatch(
1085 + command === "accept"
1086 + ? {
1087 + type: "notification.delivery.accept",
1088 + commandId: CommandId.make(`command:${race}:accept`),
1089 + threadId,
1090 + messageId,
1091 + }
1092 + : {
1093 + type: "delegated_task.completion-delivery.acknowledge",
1094 + commandId: CommandId.make(`command:${race}:task-status`),
1095 + parentThreadId: threadId,
1096 + taskId,
1097 + observedByRunId: runId,
1098 + },
1099 + ),
1100 (spy) => Effect.sync(() => spy.mockRestore()),
1101 );
1102 assert.isTrue(settled);
1066 - const run = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1067 - (candidate) => candidate.id === runId,
1068 - )!;
1103 + const finished = yield* orchestrator.getThreadProjection(threadId);
1104 + assert.equal(
1105 + finished.subagents.find((row) => row.id === taskId)?.completionDelivery?.state,
1106 + command === "accept" ? "delivered" : "acknowledged",
1107 + );
1108 + const run = finished.runs.find((candidate) => candidate.id === runId)!;
1109 assert.deepEqual(
1110 { status: run.status, completedAt: run.completedAt, checkpointId: run.checkpointId },
1111 { status: after, completedAt: now, checkpointId: capture ? checkpointId : null },
apps/server/src/orchestration-v2/Orchestrator.ts
+2 -1
@@ -11733,6 +11733,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11733 },
11734 },
11735 });
11736 + return parentRun.id;
11737 });
11738
11739 const dispatchUnsupported = (command: OrchestrationV2ServerCommand) =>
@@ -11907,7 +11908,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11908 break;
11909 }
11910 case "notification.delivery.accept":
11910 - yield* dispatchNotificationAccepted(command, events);
11911 + updateDelegatedCompletionOnlyRunId = yield* dispatchNotificationAccepted(command, events);
11912 break;
11913 case "prepared-run.release":
11914 yield* dispatchPreparedRunRelease(command, events, effects);