@@ -725,19 +725,18 @@ describe("orchestration v2 provider switching", () => {
725725 }
726726 if ( reasoningScenario && replaceNative ) {
727727 const replaced = yield * orchestrator . getThreadProjection ( threadId ) ;
728- assert . equal (
729- replaced . runs . at ( - 1 ) ?. status ,
730- scenario . includes ( "small" ) ? "failed" : "completed" ,
731- ) ;
728+ assert . equal ( replaced . runs . at ( - 1 ) ?. status , "completed" ) ;
732729 const target = replaced . providerThreads . find (
733730 ( thread ) => thread . providerInstanceId === CLAUDE_MODEL_SELECTION . instanceId ,
734731 ) ! ;
735732 assert . isNull ( target . contextUsage ) ;
736733 assert . equal ( yield * Ref . get ( generation ) , 2 ) ;
737- assert . equal (
738- ( yield * Ref . get ( capturedTurns ) ) . at ( - 1 ) ! . driver ,
739- scenario . includes ( "small" ) ? CODEX_DRIVER : CLAUDE_DRIVER ,
740- ) ;
734+ assert . equal ( ( yield * Ref . get ( capturedTurns ) ) . at ( - 1 ) ! . driver , CLAUDE_DRIVER ) ;
735+ if ( scenario . includes ( "small" ) ) {
736+ const handoff = replaced . contextHandoffs . at ( - 1 ) ! ;
737+ assert . equal ( handoff . deferred , true ) ;
738+ assert . isUndefined ( handoff . delivery ) ;
739+ }
741740 return ;
742741 }
743742 if ( replaceNative ) {
@@ -1191,12 +1190,13 @@ describe("orchestration v2 provider switching", () => {
11911190 ) ,
11921191 ) ;
11931192
1194- it . live ( "keeps the native session after turns refused before reaching the provider ", ( ) =>
1193+ it . live . each ( [ false , true ] ) ( "reuses native sessions after refused turns (%s) ", ( deferred ) =>
11951194 Effect . scoped (
11961195 Effect . gen ( function * ( ) {
11971196 const cwd = yield * checkpointWorkspace ( "refused-start-keeps-native" ) ;
11981197 const capturedTurns = yield * Ref . make < ReadonlyArray < CapturedTurn > > ( [ ] ) ;
11991198 const refuseStarts = yield * Ref . make ( 0 ) ;
1199+ let modelWindow = 32_000 ;
12001200 const generation = yield * Ref . make ( 0 ) ;
12011201 const registry = ProviderAdapterRegistry . layerFromAdapters ( [
12021202 makeTestAdapter ( {
@@ -1207,6 +1207,7 @@ describe("orchestration v2 provider switching", () => {
12071207 responseByRunOrdinal : { } ,
12081208 capturedTurns,
12091209 refuseStarts,
1210+ ...( deferred ? { getModelContextWindow : ( ) => modelWindow } : { } ) ,
12101211 nativeThreadGeneration : generation ,
12111212 } ) ,
12121213 ] ) ;
@@ -1253,8 +1254,35 @@ describe("orchestration v2 provider switching", () => {
12531254 worktreePath : null ,
12541255 } ) ;
12551256 assert . equal ( yield * run ( 1 ) , "completed" ) ;
1256- yield * Ref . set ( refuseStarts , 2 ) ;
1257+ yield * Ref . set ( refuseStarts , deferred ? 1 : 2 ) ;
12571258 assert . equal ( yield * run ( 2 ) , "failed" ) ;
1259+ if ( deferred ) {
1260+ modelWindow = 16_000 ;
1261+ assert . equal ( yield * run ( 3 ) , "completed" ) ;
1262+ const first = ( yield * orchestrator . getThreadProjection ( threadId ) ) . contextHandoffs ;
1263+ assert . lengthOf ( first , 1 ) ;
1264+ assert . equal ( first [ 0 ] ! . deferred , true ) ;
1265+ assert . equal ( yield * run ( 4 ) , "completed" ) ;
1266+ const later = ( yield * orchestrator . getThreadProjection ( threadId ) ) . contextHandoffs ;
1267+ assert . lengthOf ( later , 1 ) ;
1268+ assert . equal ( later [ 0 ] ! . id , first [ 0 ] ! . id ) ;
1269+ assert . equal ( later [ 0 ] ! . deferred , true ) ;
1270+
1271+ modelWindow = 32_000 ;
1272+ assert . equal ( yield * run ( 5 ) , "completed" ) ;
1273+ const delivered = ( yield * orchestrator . getThreadProjection ( threadId ) ) . contextHandoffs ;
1274+ assert . lengthOf ( delivered , 1 ) ;
1275+ assert . equal ( delivered [ 0 ] ! . id , first [ 0 ] ! . id ) ;
1276+ assert . isUndefined ( delivered [ 0 ] ! . deferred ) ;
1277+ assert . equal ( delivered [ 0 ] ! . delivery ?. status , "inline" ) ;
1278+ const accepted = ( yield * Ref . get ( capturedTurns ) ) . at ( - 1 ) ! ;
1279+ assert . equal ( accepted . text . split ( "Request 2" ) . length - 1 , 1 ) ;
1280+ assert . equal ( yield * run ( 6 ) , "completed" ) ;
1281+ assert . notInclude ( ( yield * Ref . get ( capturedTurns ) ) . at ( - 1 ) ! . text , "Request 2" ) ;
1282+ assert . lengthOf ( ( yield * orchestrator . getThreadProjection ( threadId ) ) . contextHandoffs , 1 ) ;
1283+ assert . equal ( yield * Ref . get ( generation ) , 1 ) ;
1284+ return ;
1285+ }
12581286 assert . equal ( yield * run ( 3 ) , "failed" ) ;
12591287 assert . equal ( yield * run ( 4 ) , "completed" ) ;
12601288
0 commit comments