From 4626a059d956cc87e4981b11ecc2a6e29be154fd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 29 Jul 2026 02:34:29 +0200 Subject: [PATCH] fix(checkpoints): retain thread-start baseline after failed runs Co-authored-by: codex --- .../CheckpointCaptureService.ts | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index a25c1b607c..492e907fb2 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -92,12 +92,21 @@ export const layer: Layer.Layer< const capturedAt = yield* DateTime.now; const baselineOrdinalWithinScope = Math.max(0, run.ordinal - 1); - const baselineCheckpoint = projection.checkpoints.some( - (candidate) => - candidate.scopeId === scope.id && - candidate.ordinalWithinScope === baselineOrdinalWithinScope && - candidate.status === "ready", - ) + const hasReadyCheckpoint = (ordinalWithinScope: number) => + projection.checkpoints.some( + (candidate) => + candidate.scopeId === scope.id && + candidate.ordinalWithinScope === ordinalWithinScope && + candidate.status === "ready", + ); + const threadStartCheckpoint = + baselineOrdinalWithinScope === 0 || hasReadyCheckpoint(0) + ? null + : yield* checkpoints.materializeBaselineCheckpoint({ + scope, + ordinalWithinScope: 0, + }); + const baselineCheckpoint = hasReadyCheckpoint(baselineOrdinalWithinScope) ? null : yield* checkpoints.materializeBaselineCheckpoint({ scope, @@ -119,6 +128,20 @@ export const layer: Layer.Layer< acceptedAt: capturedAt, effects: [], events: [ + ...(threadStartCheckpoint === null + ? [] + : [ + { + id: yield* ids.allocate.event({ threadId: input.threadId, commandId }), + type: "checkpoint.captured" as const, + threadId: input.threadId, + nodeId: threadStartCheckpoint.nodeId, + driver: providerThread.driver, + providerInstanceId: run.providerInstanceId, + occurredAt: capturedAt, + payload: threadStartCheckpoint, + }, + ]), ...(baselineCheckpoint === null ? [] : [