@@ -2907,6 +2907,176 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
29072907 } ) ,
29082908 ) ;
29092909
2910+ it . effect ( "keeps an open question's row in the window after the run kept working" , ( ) =>
2911+ Effect . gen ( function * ( ) {
2912+ const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
2913+ const sql = yield * SqlClient . SqlClient ;
2914+ const now = yield * DateTime . now ;
2915+ const nowIso = DateTime . formatIso ( now ) ;
2916+ const threadId = ThreadId . make ( "thread:open-question-window" ) ;
2917+ yield * projectionStore . apply ( {
2918+ id : EventId . make ( "event:open-question-window:thread" ) ,
2919+ type : "thread.created" ,
2920+ threadId,
2921+ occurredAt : now ,
2922+ payload : {
2923+ createdBy : "user" ,
2924+ creationSource : "web" ,
2925+ id : threadId ,
2926+ projectId : ProjectId . make ( "project:open-question-window" ) ,
2927+ title : "Open question window" ,
2928+ providerInstanceId,
2929+ modelSelection,
2930+ runtimeMode : "full-access" ,
2931+ interactionMode : "default" ,
2932+ branch : null ,
2933+ worktreePath : null ,
2934+ activeProviderThreadId : null ,
2935+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
2936+ forkedFrom : null ,
2937+ createdAt : now ,
2938+ updatedAt : now ,
2939+ archivedAt : null ,
2940+ settledOverride : null ,
2941+ settledAt : null ,
2942+ lastVisitedAt : null ,
2943+ deletedAt : null ,
2944+ } ,
2945+ } ) ;
2946+ for ( let ordinal = 10 ; ordinal <= 300 ; ordinal += 1 ) {
2947+ const id = `turn-item:open-question-window:${ ordinal } ` ;
2948+ yield * sql `
2949+ INSERT INTO orchestration_v2_projection_turn_items (
2950+ turn_item_id, thread_id, run_id, node_id, provider_thread_id, provider_turn_id,
2951+ parent_item_id, ordinal, type, status, updated_at, payload_json
2952+ ) VALUES (
2953+ ${ id } , ${ threadId } , NULL, NULL, NULL, NULL, NULL, ${ ordinal } ,
2954+ 'command_execution', 'completed', ${ nowIso } ,
2955+ ${ encodeUnknownJsonString ( {
2956+ id,
2957+ threadId,
2958+ runId : null ,
2959+ nodeId : null ,
2960+ providerThreadId : null ,
2961+ providerTurnId : null ,
2962+ nativeItemRef : null ,
2963+ parentItemId : null ,
2964+ ordinal,
2965+ status : "completed" ,
2966+ title : `command ${ ordinal } ` ,
2967+ input : `echo ${ ordinal } ` ,
2968+ output : "ok" ,
2969+ exitCode : 0 ,
2970+ startedAt : nowIso ,
2971+ completedAt : nowIso ,
2972+ updatedAt : nowIso ,
2973+ type : "command_execution" ,
2974+ } ) }
2975+ )
2976+ ` ;
2977+ }
2978+ const requestId = RuntimeRequestId . make ( "request:open-question-window" ) ;
2979+ const nodeId = NodeId . make ( "node:open-question-window" ) ;
2980+ const itemId = TurnItemId . make ( "turn-item:open-question-window:question" ) ;
2981+ yield * projectionStore . apply ( {
2982+ id : EventId . make ( "event:open-question-window:node" ) ,
2983+ type : "node.updated" ,
2984+ threadId,
2985+ nodeId,
2986+ occurredAt : now ,
2987+ payload : {
2988+ id : nodeId ,
2989+ threadId,
2990+ runId : null ,
2991+ parentNodeId : null ,
2992+ rootNodeId : nodeId ,
2993+ kind : "user_input_request" ,
2994+ status : "waiting" ,
2995+ countsForRun : false ,
2996+ providerThreadId : null ,
2997+ providerTurnId : null ,
2998+ nativeItemRef : null ,
2999+ runtimeRequestId : requestId ,
3000+ checkpointScopeId : null ,
3001+ startedAt : now ,
3002+ completedAt : null ,
3003+ } ,
3004+ } ) ;
3005+ const request = {
3006+ id : requestId ,
3007+ nodeId,
3008+ providerTurnId : null ,
3009+ nativeRequestRef : null ,
3010+ kind : "user_input" as const ,
3011+ status : "pending" as const ,
3012+ responseCapability : { type : "message" as const } ,
3013+ createdAt : now ,
3014+ resolvedAt : null ,
3015+ } ;
3016+ yield * projectionStore . apply ( {
3017+ id : EventId . make ( "event:open-question-window:request" ) ,
3018+ type : "runtime-request.updated" ,
3019+ threadId,
3020+ nodeId,
3021+ occurredAt : now ,
3022+ payload : request ,
3023+ } ) ;
3024+ yield * projectionStore . apply ( {
3025+ id : EventId . make ( "event:open-question-window:item" ) ,
3026+ type : "turn-item.updated" ,
3027+ threadId,
3028+ nodeId,
3029+ occurredAt : now ,
3030+ payload : {
3031+ id : itemId ,
3032+ type : "user_input_request" ,
3033+ threadId,
3034+ runId : null ,
3035+ nodeId,
3036+ providerThreadId : null ,
3037+ providerTurnId : null ,
3038+ nativeItemRef : null ,
3039+ parentItemId : null ,
3040+ ordinal : 5 ,
3041+ status : "waiting" ,
3042+ title : null ,
3043+ startedAt : now ,
3044+ completedAt : null ,
3045+ updatedAt : now ,
3046+ requestId,
3047+ responseMode : "message" ,
3048+ questions : [ { id : "choice" , header : "Choice" , question : "Continue?" , options : [ ] } ] ,
3049+ } ,
3050+ } ) ;
3051+
3052+ const questionRows = ( snapshot : {
3053+ readonly projection : { readonly turnItems : ReadonlyArray < { readonly id : string } > } ;
3054+ } ) => snapshot . projection . turnItems . filter ( ( item ) => item . id === itemId ) . length ;
3055+ const open = yield * projectionStore . getThreadSnapshotWindow ( threadId , { rowLimit : 76 } ) ;
3056+ assert . strictEqual ( questionRows ( open ) , 1 ) ;
3057+ const bounded = buildBoundedThreadProjection ( {
3058+ policy : { ...THREAD_HISTORY_PAGE_POLICY , maxUserTurns : undefined , maxItems : 50 } ,
3059+ projection : open . projection ,
3060+ snapshotSequence : open . snapshotSequence ,
3061+ } ) ;
3062+ assert . strictEqual ( questionRows ( bounded ) , 1 ) ;
3063+ assert . isFalse (
3064+ bounded . projection . visibleTurnItems . some ( ( row ) => row . sourceItemId === itemId ) ,
3065+ ) ;
3066+
3067+ yield * projectionStore . apply ( {
3068+ id : EventId . make ( "event:open-question-window:resolved" ) ,
3069+ type : "runtime-request.updated" ,
3070+ threadId,
3071+ nodeId,
3072+ occurredAt : now ,
3073+ payload : { ...request , status : "resolved" , resolvedAt : now } ,
3074+ } ) ;
3075+ const answered = yield * projectionStore . getThreadSnapshotWindow ( threadId , { rowLimit : 76 } ) ;
3076+ assert . strictEqual ( questionRows ( answered ) , 0 ) ;
3077+ } ) ,
3078+ ) ;
3079+
29103080 it . effect ( "scopes actionable provider state to the requested bounded thread" , ( ) =>
29113081 Effect . gen ( function * ( ) {
29123082 const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
0 commit comments