Skip to content

Commit b7d4da3

Browse files
fix(orchestration): distinguish missing refs from interrupted turns
1 parent cb9d9c2 commit b7d4da3

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

‎apps/server/src/orchestration/projector.test.ts‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,103 @@ describe("orchestration projector", () => {
372372
}),
373373
);
374374

375+
effectIt.effect.each([null, "ready", "interrupted", "stopped"] as const)(
376+
"replaces a missing checkpoint without inventing interruption for a %s session",
377+
(sessionStatus) =>
378+
Effect.gen(function* () {
379+
const now = "2026-09-04T23:00:00.000Z";
380+
const threadId = "thread-placeholder";
381+
const event = (sequence: number, type: OrchestrationEvent["type"], payload: unknown) =>
382+
makeEvent({
383+
sequence,
384+
type,
385+
payload,
386+
aggregateKind: "thread",
387+
aggregateId: threadId,
388+
occurredAt: now,
389+
commandId: `placeholder-${sequence}`,
390+
});
391+
let model = yield* projectEvent(
392+
createEmptyReadModel(now),
393+
event(1, "thread.created", {
394+
threadId,
395+
projectId: "project-1",
396+
title: "Placeholder",
397+
modelSelection: { instanceId: "codex", model: "test" },
398+
runtimeMode: "full-access",
399+
interactionMode: "default",
400+
branch: null,
401+
worktreePath: null,
402+
createdAt: now,
403+
updatedAt: now,
404+
}),
405+
);
406+
const checkpoint = {
407+
threadId,
408+
turnId: "turn-placeholder",
409+
checkpointTurnCount: 1,
410+
checkpointRef: "provider-diff:placeholder",
411+
files: [],
412+
assistantMessageId: "assistant:placeholder",
413+
completedAt: now,
414+
};
415+
if (sessionStatus === "interrupted" || sessionStatus === "stopped") {
416+
model = yield* projectEvent(
417+
model,
418+
event(2, "thread.session-set", {
419+
threadId,
420+
session: {
421+
threadId,
422+
status: "running",
423+
providerName: "codex",
424+
runtimeMode: "full-access",
425+
activeTurnId: "turn-placeholder",
426+
lastError: null,
427+
updatedAt: now,
428+
},
429+
}),
430+
);
431+
}
432+
model = yield* projectEvent(
433+
model,
434+
event(3, "thread.turn-diff-completed", {
435+
...checkpoint,
436+
status: "missing",
437+
}),
438+
);
439+
if (sessionStatus !== null) {
440+
model = yield* projectEvent(
441+
model,
442+
event(4, "thread.session-set", {
443+
threadId,
444+
session: {
445+
threadId,
446+
status: sessionStatus,
447+
providerName: "codex",
448+
runtimeMode: "full-access",
449+
activeTurnId: null,
450+
lastError: null,
451+
updatedAt: now,
452+
},
453+
}),
454+
);
455+
}
456+
model = yield* projectEvent(
457+
model,
458+
event(5, "thread.turn-diff-completed", {
459+
...checkpoint,
460+
status: "ready",
461+
checkpointRef: "refs/t3/checkpoints/thread-placeholder/turn/1",
462+
}),
463+
);
464+
expect(model.threads[0]?.latestTurn?.state).toBe(
465+
sessionStatus === "interrupted" || sessionStatus === "stopped"
466+
? "interrupted"
467+
: "completed",
468+
);
469+
}),
470+
);
471+
375472
it("updates canonical thread runtime mode from thread.runtime-mode-set", async () => {
376473
const createdAt = "2026-02-23T08:00:00.000Z";
377474
const updatedAt = "2026-02-23T08:00:05.000Z";

‎apps/server/src/orchestration/projector.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function retainThreadActivities(activities: OrchestrationThread["activities"]) {
6464

6565
function checkpointStatusToLatestTurnState(status: "ready" | "missing" | "error") {
6666
if (status === "error") return "error" as const;
67-
if (status === "missing") return "interrupted" as const;
67+
// Match SQL and client projections: a missing git ref is not an interruption.
6868
return "completed" as const;
6969
}
7070

0 commit comments

Comments
 (0)