@@ -41,7 +41,10 @@ import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderS
4141import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts" ;
4242import * as SqlitePersistence from "../persistence/Sqlite.ts" ;
4343import * as ServerSettings from "../serverSettings.ts" ;
44- import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts" ;
44+ import {
45+ CodexProviderCapabilitiesV2 ,
46+ normalizeCodexThreadLoadModelSelection ,
47+ } from "./Adapters/CodexAdapterV2.ts" ;
4548import * as EventSink from "./EventSink.ts" ;
4649import * as EventStore from "./EventStore.ts" ;
4750import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
@@ -422,6 +425,7 @@ const makeProviderAdapter = Effect.fnUntraced(function* (
422425 state : Ref . Ref < TestProviderRuntimeState > ,
423426 options : {
424427 readonly failEventStream ?: boolean ;
428+ readonly normalizeThreadLoadModelSelection ?: ( selection : ModelSelection ) => ModelSelection ;
425429 readonly capabilities ?: OrchestrationV2ProviderCapabilities ;
426430 readonly extensionStatuses ?: OrchestrationV2ProviderSession [ "extensionStatuses" ] ;
427431 readonly mcpConfigs ?: Ref . Ref <
@@ -508,6 +512,9 @@ const makeProviderAdapter = Effect.fnUntraced(function* (
508512 instanceId : ProviderInstanceId . make ( "codex" ) ,
509513 driver : CODEX_DRIVER ,
510514 providerSessionId : input . providerSessionId ,
515+ ...( options . normalizeThreadLoadModelSelection === undefined
516+ ? { }
517+ : { normalizeThreadLoadModelSelection : options . normalizeThreadLoadModelSelection } ) ,
511518 get providerSession ( ) {
512519 return session ;
513520 } ,
@@ -576,6 +583,7 @@ function layerTest(input: {
576583 readonly idleTimeoutMs : number ;
577584 readonly maxIdlePinMs ?: number ;
578585 readonly failEventStream ?: boolean ;
586+ readonly normalizeThreadLoadModelSelection ?: ( selection : ModelSelection ) => ModelSelection ;
579587 readonly capabilities ?: OrchestrationV2ProviderCapabilities ;
580588 readonly extensionStatuses ?: OrchestrationV2ProviderSession [ "extensionStatuses" ] ;
581589 readonly mcpConfigs ?: Ref . Ref <
@@ -618,6 +626,9 @@ function layerTest(input: {
618626 const layerRegistry = Layer . unwrap (
619627 makeProviderAdapter ( input . state , {
620628 failEventStream : input . failEventStream ?? false ,
629+ ...( input . normalizeThreadLoadModelSelection === undefined
630+ ? { }
631+ : { normalizeThreadLoadModelSelection : input . normalizeThreadLoadModelSelection } ) ,
621632 ...( input . capabilities === undefined ? { } : { capabilities : input . capabilities } ) ,
622633 ...( input . extensionStatuses === undefined
623634 ? { }
@@ -3626,9 +3637,15 @@ it.effect("ProviderSessionManagerV2 persists session-scoped runtime requests wit
36263637 } ) ,
36273638) ;
36283639
3629- it . effect (
3630- "ProviderSessionManagerV2 opens one shared runtime, broadcasts events, and detaches threads independently" ,
3631- ( ) =>
3640+ it . effect . each ( [
3641+ { name : "default load key" , normalizeThreadLoadModelSelection : undefined } ,
3642+ {
3643+ name : "Codex load key" ,
3644+ normalizeThreadLoadModelSelection : normalizeCodexThreadLoadModelSelection ,
3645+ } ,
3646+ ] ) (
3647+ "ProviderSessionManagerV2 opens one shared runtime, broadcasts events, and detaches threads independently ($name)" ,
3648+ ( { normalizeThreadLoadModelSelection } ) =>
36323649 Effect . gen ( function * ( ) {
36333650 const state = yield * Ref . make ( emptyState ) ;
36343651 const settings = yield * ServerSettings . ServerSettingsService . pipe (
@@ -3734,6 +3751,7 @@ it.effect(
37343751 yield * resumeSecondThread ;
37353752 yield * resumeSecondThread ;
37363753 assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 1 ) ;
3754+ let resumeCount = 1 ;
37373755 const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
37383756 const appThread = ( yield * projectionStore . getThreadProjection ( secondThreadId ) ) . thread ;
37393757 const turnEvents = ( yield * Ref . get ( state ) ) . eventQueues . get ( String ( providerSessionId ) ) ;
@@ -3793,21 +3811,22 @@ it.effect(
37933811 threadDisposition : "reusable" ,
37943812 } ) ;
37953813 yield * Fiber . join ( terminal ) ;
3796- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 1 , `${ effort } effort reloaded Codex` ) ;
3814+ if ( normalizeThreadLoadModelSelection === undefined && index > 0 ) resumeCount ++ ;
3815+ assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , resumeCount , `${ effort } effort reload` ) ;
37973816 }
37983817 yield * secondRuntime . resumeThread ( {
37993818 providerThread : secondProviderThread ,
38003819 threadId : secondThreadId ,
38013820 modelSelection : { ...modelSelection , model : "gpt-5.4-mini" } ,
38023821 runtimePolicy,
38033822 } ) ;
3804- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 2 ) ;
3823+ assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , ++ resumeCount ) ;
38053824 yield * resumeSecondThread ;
3806- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 3 ) ;
3825+ assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , ++ resumeCount ) ;
38073826 // regression: #26722 a Linked environments change reloads only the idle thread's tools.
38083827 yield * settings . updateSettings ( { linkedEnvironmentsEnabled : true } ) ;
38093828 yield * resumeSecondThread ;
3810- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 4 ) ;
3829+ assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , ++ resumeCount ) ;
38113830 assert . deepEqual ( ( yield * Ref . get ( state ) ) . unloadedNativeThreadIds , [ "native-thread" ] ) ;
38123831 const subscribe = firstRuntime . subscribeEvents ;
38133832 assert . isDefined ( subscribe ) ;
@@ -3840,16 +3859,10 @@ it.effect(
38403859 runtimePolicy,
38413860 } ) ;
38423861 yield * resumeSecondThread ;
3843- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 5 ) ;
3862+ assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , ++ resumeCount ) ;
38443863
38453864 assert . deepEqual ( ( yield * Ref . get ( state ) ) . unloadedNativeThreadIds , [ "native-thread" ] ) ;
38463865
3847- const otherDriver = ProviderDriverKind . make ( "claudeAgent" ) ;
3848- const otherProviderThread = {
3849- ...secondProviderThread ,
3850- driver : otherDriver ,
3851- nativeThreadRef : { driver : otherDriver , nativeId : "native-other" , strength : "strong" } ,
3852- } satisfies OrchestrationV2ProviderThread ;
38533866 const reloadCases = [
38543867 {
38553868 name : "other model options" ,
@@ -3866,15 +3879,6 @@ it.effect(
38663879 selection : modelSelection ,
38673880 policy : { ...runtimePolicy , interactionMode : "plan" } ,
38683881 } ,
3869- ...[ "medium" , "high" ] . map ( ( effort ) => ( {
3870- name : `non-Codex ${ effort } effort` ,
3871- providerThread : otherProviderThread ,
3872- selection : {
3873- ...modelSelection ,
3874- options : [ { id : "reasoningEffort" , value : effort } ] ,
3875- } ,
3876- policy : runtimePolicy ,
3877- } ) ) ,
38783882 ] satisfies ReadonlyArray < {
38793883 name : string ;
38803884 providerThread : OrchestrationV2ProviderThread ;
@@ -3912,6 +3916,9 @@ it.effect(
39123916 layerTest ( {
39133917 state,
39143918 idleTimeoutMs : 1000 ,
3919+ ...( normalizeThreadLoadModelSelection === undefined
3920+ ? { }
3921+ : { normalizeThreadLoadModelSelection } ) ,
39153922 serverSettingsLayer : Layer . succeed ( ServerSettings . ServerSettingsService , settings ) ,
39163923 } ) ,
39173924 ) ,
0 commit comments