Skip to content

Commit 5c87054

Browse files
t3dotggclaude
andcommitted
fix(server): keep the last finished turn's checkpoint in every window
Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent e96113e commit 5c87054

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,28 @@ const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {
16151615
});
16161616
}
16171617
}
1618+
// No row or node of this run is in the window.
1619+
const settledCheckpointId = CheckpointId.make("checkpoint:settled-leaf-nodes:earlier-run");
1620+
yield* store.apply({
1621+
id: EventId.make("event:settled-leaf-nodes:earlier-run-checkpoint"),
1622+
type: "checkpoint.captured",
1623+
threadId,
1624+
occurredAt: now,
1625+
payload: {
1626+
id: settledCheckpointId,
1627+
threadId,
1628+
scopeId: CheckpointScopeId.make("scope:settled-leaf-nodes:root"),
1629+
runId: RunId.make("run:settled-leaf-nodes:earlier"),
1630+
nodeId: NodeId.make("node:settled-leaf-nodes:earlier-root"),
1631+
parentCheckpointId: null,
1632+
ordinalWithinScope: 1,
1633+
appRunOrdinal: 1,
1634+
ref: CheckpointRef.make("refs/t3/settled-leaf-nodes/1"),
1635+
status: "ready",
1636+
files: [],
1637+
capturedAt: now,
1638+
},
1639+
});
16181640
const nodeNames = (records: { readonly nodes: ReadonlyArray<{ readonly id: string }> }) =>
16191641
records.nodes
16201642
.map((node) => node.id.replace("node:settled-leaf-nodes:", ""))
@@ -1644,6 +1666,11 @@ const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {
16441666
liveWindow.plans.map((plan) => plan.id),
16451667
[PlanId.make("plan:settled-leaf-nodes:active-run-todo")],
16461668
);
1669+
// Clients show the diff of the last finished turn from this record.
1670+
assert.deepEqual(
1671+
liveWindow.checkpoints.map((checkpoint) => checkpoint.id),
1672+
[settledCheckpointId],
1673+
);
16471674

16481675
const subagents = [
16491676
["delivered", settledRun, "completed", "delivered"],

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
31103110
SELECT 1 FROM orchestration_v2_projection_run_attempts
31113111
WHERE run_id = live.run_id AND status = 'superseded'
31123112
)
3113-
ORDER BY live.ordinal ASC LIMIT 1
3113+
ORDER BY +live.ordinal ASC LIMIT 1
31143114
), visible_tail AS (
31153115
SELECT ordinal FROM (
31163116
SELECT ordinal FROM eligible
@@ -3851,6 +3851,13 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
38513851
WHERE thread_id = ${threadId}
38523852
AND (status IN ('pending','capturing')
38533853
OR (run_id IS NULL AND ordinal_within_scope = 0 AND status = 'ready')
3854+
-- The diff of the last finished turn stays in reach while a long run is at work.
3855+
OR checkpoint_id = (
3856+
SELECT checkpoint_id FROM orchestration_v2_projection_checkpoints
3857+
WHERE thread_id = ${threadId} AND status = 'ready'
3858+
AND app_run_ordinal IS NOT NULL
3859+
ORDER BY app_run_ordinal DESC LIMIT 1
3860+
)
38543861
OR checkpoint_id IN (SELECT value FROM json_each(${cohortCheckpointIds}))
38553862
OR run_id IN (SELECT value FROM json_each(${cohortRunIds}))
38563863
OR node_id IN (SELECT value FROM json_each(${cohortNodeIds})))

0 commit comments

Comments
 (0)