@@ -2144,48 +2144,58 @@ layer("ProviderEventIngestorV2", (it) => {
21442144 } ) ,
21452145 ) ;
21462146
2147- it . effect (
2148- "moves a thread to the selection its agent reported, once and only for its instance" ,
2149- ( ) =>
2150- Effect . gen ( function * ( ) {
2151- const now = yield * DateTime . now ;
2152- const eventSink = yield * EventSink . EventSinkV2 ;
2153- const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
2154- const ingestor = yield * ProviderEventIngestor . ProviderEventIngestorV2 ;
2155- const idAllocator = yield * IdAllocator . IdAllocatorV2 ;
2156- const rootEvent = yield * threadCreatedEvent ( now ) ;
2157- yield * eventSink . write ( { events : [ rootEvent ] } ) ;
2158- const providerSessionId = yield * idAllocator . allocate . providerSession ( {
2147+ it . effect ( "applies an agent's mode change without undoing newer thread settings" , ( ) =>
2148+ Effect . gen ( function * ( ) {
2149+ const now = yield * DateTime . now ;
2150+ const eventSink = yield * EventSink . EventSinkV2 ;
2151+ const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
2152+ const ingestor = yield * ProviderEventIngestor . ProviderEventIngestorV2 ;
2153+ const idAllocator = yield * IdAllocator . IdAllocatorV2 ;
2154+ const rootEvent = yield * threadCreatedEvent ( now ) ;
2155+ if ( rootEvent . type !== "thread.created" ) throw new Error ( "Expected thread fixture" ) ;
2156+ // Saved mid-turn: a newer model and effort the reporting turn never saw.
2157+ const saved = {
2158+ ...modelSelection ,
2159+ model : "gpt-6.1-sol" ,
2160+ options : [
2161+ { id : "effort" , value : "high" } ,
2162+ { id : "mode" , value : "plan" } ,
2163+ ] ,
2164+ } ;
2165+ yield * eventSink . write ( {
2166+ events : [ { ...rootEvent , payload : { ...rootEvent . payload , modelSelection : saved } } ] ,
2167+ } ) ;
2168+ const providerSessionId = yield * idAllocator . allocate . providerSession ( {
2169+ providerInstanceId : modelSelection . instanceId ,
2170+ threadId : rootEvent . threadId ,
2171+ } ) ;
2172+ const ingest = ( instanceId : ProviderInstanceId , from : string ) =>
2173+ ingestor . ingestNormalized ( {
2174+ providerSessionId,
21592175 providerInstanceId : modelSelection . instanceId ,
21602176 threadId : rootEvent . threadId ,
2161- } ) ;
2162- const ingest = ( reported : ModelSelection ) =>
2163- ingestor . ingestNormalized ( {
2164- providerSessionId,
2165- providerInstanceId : modelSelection . instanceId ,
2177+ event : {
2178+ type : "thread_model_selection.updated" ,
2179+ driver : CODEX_DRIVER ,
21662180 threadId : rootEvent . threadId ,
2167- event : {
2168- type : "thread_model_selection.updated" ,
2169- driver : CODEX_DRIVER ,
2170- threadId : rootEvent . threadId ,
2171- modelSelection : reported ,
2172- } ,
2173- } ) ;
2174- const reported = { ...modelSelection , options : [ { id : "mode" , value : "default" } ] } ;
2175- assert . deepEqual (
2176- ( yield * ingest ( reported ) ) . map ( ( stored ) => stored . event . type ) ,
2177- [ "thread.model-selection-updated" ] ,
2178- ) ;
2179- assert . deepEqual (
2180- ( yield * projectionStore . getThread ( rootEvent . threadId ) ) . modelSelection ,
2181- reported ,
2182- ) ;
2183- assert . deepEqual ( yield * ingest ( reported ) , [ ] ) ;
2184- assert . deepEqual (
2185- yield * ingest ( { ...reported , instanceId : ProviderInstanceId . make ( "other-instance" ) } ) ,
2186- [ ] ,
2187- ) ;
2188- } ) ,
2181+ instanceId,
2182+ changes : [ { id : "mode" , from, to : "default" } ] ,
2183+ } ,
2184+ } ) ;
2185+ assert . deepEqual (
2186+ ( yield * ingest ( modelSelection . instanceId , "plan" ) ) . map ( ( stored ) => stored . event . type ) ,
2187+ [ "thread.model-selection-updated" ] ,
2188+ ) ;
2189+ assert . deepEqual ( ( yield * projectionStore . getThread ( rootEvent . threadId ) ) . modelSelection , {
2190+ ...saved ,
2191+ options : [
2192+ { id : "effort" , value : "high" } ,
2193+ { id : "mode" , value : "default" } ,
2194+ ] ,
2195+ } ) ;
2196+ assert . deepEqual ( yield * ingest ( modelSelection . instanceId , "plan" ) , [ ] ) ;
2197+ assert . deepEqual ( yield * ingest ( ProviderInstanceId . make ( "other-instance" ) , "default" ) , [ ] ) ;
2198+ } ) ,
21892199 ) ;
21902200
21912201 it . effect (
0 commit comments