@@ -2342,10 +2342,26 @@ const make = Effect.gen(function* () {
23422342 operation : "create-thread" ,
23432343 index,
23442344 } ) ;
2345+ const threadId = stableThreadId ( {
2346+ scope,
2347+ requestKey : key ,
2348+ index,
2349+ } ) ;
23452350 const isRetryOfAcceptedCreation = yield * threadManagement . hasReceipt ( commandId ) ;
2351+ const committedThread = isRetryOfAcceptedCreation
2352+ ? yield * threadManagement
2353+ . getThreadShell ( threadId )
2354+ . pipe ( Effect . mapError ( threadManagementFailure ) )
2355+ : null ;
23462356 const target = yield * resolveTargetRechecking ( {
23472357 parent,
2348- target : request . target ,
2358+ target :
2359+ committedThread === null
2360+ ? request . target
2361+ : {
2362+ ...request . target ,
2363+ providerInstanceId : committedThread . modelSelection . instanceId ,
2364+ } ,
23492365 providers,
23502366 skipProjectEnablementFilter : isRetryOfAcceptedCreation ,
23512367 } ) ;
@@ -2358,11 +2374,6 @@ const make = Effect.gen(function* () {
23582374 parent . thread . interactionMode ,
23592375 request . interactionMode ,
23602376 ) ;
2361- const threadId = stableThreadId ( {
2362- scope,
2363- requestKey : key ,
2364- index,
2365- } ) ;
23662377 yield * assertTargetEnabledForProject ( parent , commandId , target ) ;
23672378 const title = threadTitle ( {
23682379 parentTitle : parent . thread . title ,
@@ -2394,8 +2405,9 @@ const make = Effect.gen(function* () {
23942405 ) ,
23952406 ) ;
23962407 // A receipt can appear after target resolution; use the committed thread's selection.
2397- const resolvedModelSelection = ( yield * loadProjection ( threadId ) ) . thread
2398- . modelSelection ;
2408+ const resolvedModelSelection = ( yield * threadManagement
2409+ . getThreadRecords ( threadId , [ ] )
2410+ . pipe ( Effect . mapError ( threadManagementFailure ) ) ) . thread . modelSelection ;
23992411 if ( request . prompt !== undefined ) {
24002412 yield * threadManagement
24012413 . dispatch ( {
@@ -2422,10 +2434,12 @@ const make = Effect.gen(function* () {
24222434 } )
24232435 . pipe (
24242436 Effect . mapError ( ( error ) =>
2425- failure (
2426- "orchestration_error" ,
2427- `Unable to start thread ${ index + 1 } : ${ errorMessage ( error ) } ` ,
2428- ) ,
2437+ error . _tag === "ThreadManagementProviderInstanceDisabledError"
2438+ ? threadManagementFailure ( error )
2439+ : failure (
2440+ "orchestration_error" ,
2441+ `Unable to start thread ${ index + 1 } : ${ errorMessage ( error ) } ` ,
2442+ ) ,
24292443 ) ,
24302444 ) ;
24312445 }
0 commit comments