@@ -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 } )
0 commit comments