@@ -3400,6 +3400,25 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
34003400 straddledOrdinals ,
34013401 ) ;
34023402 yield * moveFirstItemToRun ( sharedRunId ) ;
3403+ // A failed error below the tail still blocks folding for its run. Only the SQL columns
3404+ // change; the row sits below the window, so its payload is never decoded.
3405+ const setSecondItem = ( type : string , status : string ) => sql `
3406+ UPDATE orchestration_v2_projection_turn_items SET type = ${ type } , status = ${ status }
3407+ WHERE thread_id = ${ threadId } AND ordinal = 2` ;
3408+ yield * setSecondItem ( "error" , "failed" ) ;
3409+ const blockedWindow = yield * projectionStore . getThreadSnapshotWindow ( threadId , {
3410+ rowLimit : sqlPageLimit ,
3411+ userTurnLimit : 10 ,
3412+ deferWork : true ,
3413+ } ) ;
3414+ assert . isFalse (
3415+ blockedWindow . projection . visibleTurnItems . some ( ( row ) => row . item . deferredWork ) ,
3416+ ) ;
3417+ assert . deepEqual (
3418+ blockedWindow . projection . turnItems . map ( ( item ) => item . ordinal ) ,
3419+ Array . from ( { length : sqlPageLimit } , ( _ , index ) => 1001 - sqlPageLimit + index ) ,
3420+ ) ;
3421+ yield * setSecondItem ( "command_execution" , "completed" ) ;
34033422 yield * sql `UPDATE orchestration_v2_projection_turn_items SET type = 'command_execution',
34043423 payload_json = json_set(payload_json, '$.type', 'command_execution')
34053424 WHERE thread_id = ${ threadId } AND ordinal BETWEEN 300 AND 899` ;
@@ -3436,15 +3455,15 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
34363455 {
34373456 using copy = new NodeSqlite . DatabaseSync ( copyPath ) ;
34383457 yield * sql `VACUUM INTO ${ copyPath } ` ;
3458+ assert . isNotEmpty ( windowStatements ) ;
34393459 const windowSteps = ( ) =>
3440- windowStatements
3441- . filter ( ( [ query ] ) => / b l o c k e d _ r u n s A S M A T E R I A L I Z E D | v i s i b l e _ t a i l A S / . test ( query ) )
3442- . reduce ( ( steps , [ query , params ] ) => {
3443- const statement = copy . prepare ( query ) ;
3444- statement . all ( ...( params as ReadonlyArray < NodeSqlite . SQLInputValue > ) ) ;
3445- return steps + statement . stat ( "vmStep" ) ;
3446- } , 0 ) ;
3460+ windowStatements . reduce ( ( steps , [ query , params ] ) => {
3461+ const statement = copy . prepare ( query ) ;
3462+ statement . all ( ...( params as ReadonlyArray < NodeSqlite . SQLInputValue > ) ) ;
3463+ return steps + statement . stat ( "vmStep" ) ;
3464+ } , 0 ) ;
34473465 const fullSteps = windowSteps ( ) ;
3466+ assert . isAbove ( fullSteps , 0 ) ;
34483467 copy . exec (
34493468 "DELETE FROM orchestration_v2_projection_turn_items WHERE ordinal BETWEEN 2 AND 498" ,
34503469 ) ;
0 commit comments