Skip to content

Commit 2bcb551

Browse files
test(server): task_status acknowledge no longer reverts a run that settled mid-commit (red)
Refs #24743 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dd5b540 commit 2bcb551

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

‎apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,104 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
974974
);
975975
}),
976976
);
977+
978+
it.effect.each([
979+
{ before: "running", after: "failed", capture: false },
980+
{ before: "waiting", after: "completed", capture: true },
981+
] as const)(
982+
"keeps a $after run that settled between task_status's acknowledge read and commit",
983+
({ before, after, capture }) =>
984+
Effect.gen(function* () {
985+
const orchestrator = yield* Orchestrator.OrchestratorV2;
986+
const sink = yield* EventSink.EventSinkV2;
987+
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}`);
992+
yield* seedParentWithTerminalTask({
993+
threadId,
994+
projectId: ProjectId.make(`project:ack-settle-race-${after}`),
995+
runId,
996+
rootNodeId: NodeId.make(`node:ack-settle-race-${after}-root`),
997+
taskId,
998+
deliveryState: "claimed",
999+
deliveryTaskIds: [taskId],
1000+
now,
1001+
});
1002+
const parent = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
1003+
yield* sink.write({
1004+
events: [
1005+
{
1006+
id: EventId.make(`event:ack-settle-race-${after}-before`),
1007+
type: "run.updated",
1008+
threadId,
1009+
runId,
1010+
occurredAt: now,
1011+
payload: { ...parent, status: before },
1012+
},
1013+
],
1014+
});
1015+
const { delegatedCompletion: _cohort, ...settledRun } = parent;
1016+
const commit = sink.commitCommand;
1017+
let settled = false;
1018+
yield* Effect.acquireUseRelease(
1019+
Effect.sync(() =>
1020+
vi.spyOn(sink, "commitCommand").mockImplementation((input) =>
1021+
Effect.gen(function* () {
1022+
if (
1023+
!settled &&
1024+
input.commandType === "delegated_task.completion-delivery.acknowledge"
1025+
) {
1026+
settled = true;
1027+
// The provider turn ends (or its checkpoint lands) after acknowledge read the run.
1028+
yield* commit({
1029+
commandId: CommandId.make(`command:ack-settle-race-${after}`),
1030+
threadId,
1031+
commandType: capture ? "checkpoint.capture" : "provider.event",
1032+
acceptedAt: now,
1033+
effects: [],
1034+
events: [
1035+
{
1036+
id: EventId.make(`event:ack-settle-race-${after}-settled`),
1037+
type: "run.updated",
1038+
threadId,
1039+
runId,
1040+
occurredAt: now,
1041+
payload: {
1042+
...settledRun,
1043+
status: after,
1044+
completedAt: now,
1045+
checkpointId: capture ? checkpointId : null,
1046+
},
1047+
},
1048+
],
1049+
});
1050+
}
1051+
return yield* commit(input);
1052+
}),
1053+
),
1054+
),
1055+
() =>
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+
}),
1063+
(spy) => Effect.sync(() => spy.mockRestore()),
1064+
);
1065+
assert.isTrue(settled);
1066+
const run = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1067+
(candidate) => candidate.id === runId,
1068+
)!;
1069+
assert.deepEqual(
1070+
{ status: run.status, completedAt: run.completedAt, checkpointId: run.checkpointId },
1071+
{ status: after, completedAt: now, checkpointId: capture ? checkpointId : null },
1072+
);
1073+
}),
1074+
);
9771075
});
9781076

9791077
const reconcileCommandId = (name: string) => CommandId.make(`command:runtime-reconcile:${name}`);

0 commit comments

Comments
 (0)