Skip to content

Commit 819ad28

Browse files
t3dotggclaude
andcommitted
test(server): cover row-limit guard and a blocked run below a later segment
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a1351d1 commit 819ad28

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,10 +3402,12 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
34023402
yield* moveFirstItemToRun(sharedRunId);
34033403
// A failed error below the tail still blocks folding for its run. Only the SQL columns
34043404
// change; the row sits below the window, so its payload is never decoded.
3405-
const setSecondItem = (type: string, status: string) => sql`
3405+
// A steer at 100 starts a later segment, so the error sits below the scan start too.
3406+
const setItem = (ordinal: number, type: string, status: string) => sql`
34063407
UPDATE orchestration_v2_projection_turn_items SET type = ${type}, status = ${status}
3407-
WHERE thread_id = ${threadId} AND ordinal = 2`;
3408-
yield* setSecondItem("error", "failed");
3408+
WHERE thread_id = ${threadId} AND ordinal = ${ordinal}`;
3409+
yield* setItem(100, "user_message", "completed");
3410+
yield* setItem(2, "error", "failed");
34093411
const blockedWindow = yield* projectionStore.getThreadSnapshotWindow(threadId, {
34103412
rowLimit: sqlPageLimit,
34113413
userTurnLimit: 10,
@@ -3418,7 +3420,8 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
34183420
blockedWindow.projection.turnItems.map((item) => item.ordinal),
34193421
Array.from({ length: sqlPageLimit }, (_, index) => 1001 - sqlPageLimit + index),
34203422
);
3421-
yield* setSecondItem("command_execution", "completed");
3423+
yield* setItem(2, "command_execution", "completed");
3424+
yield* setItem(100, "command_execution", "completed");
34223425
yield* sql`UPDATE orchestration_v2_projection_turn_items SET type = 'command_execution',
34233426
payload_json = json_set(payload_json, '$.type', 'command_execution')
34243427
WHERE thread_id = ${threadId} AND ordinal BETWEEN 300 AND 899`;
@@ -3479,6 +3482,16 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
34793482
});
34803483
assert.isTrue(runlessPage.hasMoreHistory);
34813484
assert.isNotNull(runlessPage.historyCursor);
3485+
// Limits SQLite reads differently from `tailRows` skip the tail bound and match main.
3486+
const windowOrdinalCount = (rowLimit: number) =>
3487+
projectionStore
3488+
.getThreadSnapshotWindow(threadId, { rowLimit, userTurnLimit: 10, deferWork: true })
3489+
.pipe(Effect.map((window) => window.projection.turnItems.length));
3490+
assert.strictEqual(yield* windowOrdinalCount(502.5), THREAD_HISTORY_TURN_SNAPSHOT_ROW_LIMIT);
3491+
yield* sql`UPDATE orchestration_v2_projection_turn_items
3492+
SET payload_json = json_set(payload_json, '$.inputIntent', 'steer')
3493+
WHERE thread_id = ${threadId} AND ordinal = 991`;
3494+
assert.strictEqual(yield* windowOrdinalCount(-1), 1000);
34823495
yield* sql`UPDATE orchestration_v2_projection_turn_items SET run_id = ${sharedRunId},
34833496
type = 'command_execution',
34843497
payload_json = json_set(payload_json, '$.type', 'command_execution', '$.runId', ${sharedRunId})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
31333133
FROM window_items
31343134
WHERE ordinal >= ${boundary.ordinal}
31353135
ORDER BY ordinal DESC, turn_item_id DESC
3136-
-- Every branch must stay <= tailRows, or rows below workStart go missing.
3136+
-- Every LIMIT here and in latest_user_turn must stay <= tailRows, or rows below workStart go missing.
31373137
LIMIT CASE
31383138
WHEN ${window.rowLimit} = 0 THEN 0
31393139
WHEN (SELECT row_count FROM latest_user_turn)

0 commit comments

Comments
 (0)