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