@@ -4,12 +4,14 @@ import { assert, it } from "@effect/vitest";
44import { AgentScope } from "@t3tools/shared/AgentScope" ;
55import {
66 EnvironmentId ,
7+ MessageId ,
78 type ModelSelection ,
89 type OrchestrationV2AppThread ,
910 type OrchestrationV2DomainEvent ,
1011 type OrchestrationV2ProviderCapabilities ,
1112 type OrchestrationV2ProviderSession ,
1213 type OrchestrationV2ProviderThread ,
14+ type OrchestrationV2TurnItem ,
1315 type Project ,
1416 ProjectId ,
1517 ProviderDriverKind ,
@@ -2985,6 +2987,93 @@ it.effect("ProviderSessionManagerV2 persists session-scoped runtime requests wit
29852987 } ) ,
29862988) ;
29872989
2990+ it . effect ( "ProviderSessionManagerV2 persists a dropped steer without a run" , ( ) =>
2991+ Effect . gen ( function * ( ) {
2992+ const state = yield * Ref . make ( emptyState ) ;
2993+ const effect = Effect . gen ( function * ( ) {
2994+ const eventSink = yield * EventSink . EventSinkV2 ;
2995+ const idAllocator = yield * IdAllocator . IdAllocatorV2 ;
2996+ const manager = yield * ProviderSessionManager . ProviderSessionManagerV2 ;
2997+ const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
2998+ const now = yield * DateTime . now ;
2999+ const projectId = yield * idAllocator . allocate . project ( {
3000+ fixtureName : "provider-session-manager-dropped-steer" ,
3001+ } ) ;
3002+ const threadId = yield * idAllocator . allocate . thread ( {
3003+ fixtureName : "provider-session-manager-dropped-steer" ,
3004+ projectId,
3005+ } ) ;
3006+ const providerSessionId = yield * idAllocator . allocate . providerSession ( {
3007+ providerInstanceId : modelSelection . instanceId ,
3008+ threadId,
3009+ } ) ;
3010+ const messageId = MessageId . make ( "message:provider-session-manager-dropped-steer" ) ;
3011+ const steer : OrchestrationV2TurnItem = {
3012+ createdBy : "user" ,
3013+ creationSource : "web" ,
3014+ id : idAllocator . derive . userTurnItem ( { messageId } ) ,
3015+ threadId,
3016+ runId : null ,
3017+ nodeId : null ,
3018+ providerThreadId : null ,
3019+ providerTurnId : null ,
3020+ nativeItemRef : null ,
3021+ parentItemId : null ,
3022+ ordinal : 1 ,
3023+ status : "completed" ,
3024+ title : null ,
3025+ startedAt : now ,
3026+ completedAt : now ,
3027+ updatedAt : now ,
3028+ type : "user_message" ,
3029+ messageId,
3030+ inputIntent : "steer" ,
3031+ text : "never read" ,
3032+ attachments : [ ] ,
3033+ } ;
3034+ yield * eventSink . write ( {
3035+ events : [
3036+ yield * makeThreadCreatedEvent ( { idAllocator, threadId, now } ) ,
3037+ {
3038+ id : yield * idAllocator . allocate . event ( { threadId } ) ,
3039+ type : "turn-item.updated" ,
3040+ threadId,
3041+ occurredAt : now ,
3042+ payload : steer ,
3043+ } ,
3044+ ] ,
3045+ } ) ;
3046+ yield * manager . open ( {
3047+ threadId,
3048+ providerSessionId,
3049+ modelSelection,
3050+ runtimePolicy,
3051+ } ) ;
3052+ const afterSequence = yield * eventSink . latestSequence ( { threadId } ) ;
3053+ const persistedFiber = yield * eventSink . stream ( { threadId, afterSequence } ) . pipe (
3054+ Stream . filter ( ( stored ) => stored . event . type === "turn-item.updated" ) ,
3055+ Stream . take ( 1 ) ,
3056+ Stream . runCollect ,
3057+ Effect . forkScoped ,
3058+ ) ;
3059+ const adapterEvents = ( yield * Ref . get ( state ) ) . eventQueues . get ( String ( providerSessionId ) ) ;
3060+ assert . isDefined ( adapterEvents ) ;
3061+ yield * Queue . offer ( adapterEvents ! , {
3062+ type : "steer.discarded" ,
3063+ driver : CODEX_DRIVER ,
3064+ threadId,
3065+ messageId,
3066+ } ) ;
3067+ yield * Fiber . join ( persistedFiber ) ;
3068+
3069+ const stored = yield * projectionStore . getTurnItem ( { threadId, itemId : steer . id } ) ;
3070+ assert . equal ( stored ?. status , "cancelled" ) ;
3071+ } ) ;
3072+
3073+ yield * effect . pipe ( Effect . provide ( layerTest ( { state, idleTimeoutMs : 1000 } ) ) ) ;
3074+ } ) ,
3075+ ) ;
3076+
29883077it . effect (
29893078 "ProviderSessionManagerV2 opens one shared runtime, broadcasts events, and detaches threads independently" ,
29903079 ( ) =>
0 commit comments