@@ -6614,9 +6614,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66146614 resumeThread : Effect . fn ( "CodexAdapterV2.resumeThread" ) (
66156615 function * ( threadInput ) {
66166616 const nativeThreadId = yield * getNativeThreadId ( threadInput . providerThread ) ;
6617- // Codex resumes an active goal's turns right after the response; own them before it.
6618- rootProviderThreads . set ( nativeThreadId , threadInput . providerThread ) ;
6619- goalUpdatesHeld . add ( nativeThreadId ) ;
66206617 // excludeTurns is not in the generated request schema yet.
66216618 const resume = client . raw . request ( "thread/resume" , {
66226619 threadId : nativeThreadId ,
@@ -6633,6 +6630,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66336630 : { runtimePolicy : threadInput . runtimePolicy } ) ,
66346631 } ) ,
66356632 } ) ;
6633+ // Codex resumes an active goal's turns right after the response; own them before it.
6634+ const previousRoot = rootProviderThreads . get ( nativeThreadId ) ;
6635+ rootProviderThreads . set ( nativeThreadId , threadInput . providerThread ) ;
6636+ goalUpdatesHeld . add ( nativeThreadId ) ;
66366637 const response = yield * ensureInitialized . pipe (
66376638 Effect . andThen (
66386639 resume . pipe (
@@ -6655,7 +6656,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66556656 Effect . flatMap ( decodeCodexResumeMetadata ) ,
66566657 Effect . onError ( ( ) =>
66576658 Effect . sync ( ( ) => {
6658- rootProviderThreads . delete ( nativeThreadId ) ;
6659+ if ( previousRoot === undefined ) rootProviderThreads . delete ( nativeThreadId ) ;
6660+ else rootProviderThreads . set ( nativeThreadId , previousRoot ) ;
66596661 goalUpdatesHeld . delete ( nativeThreadId ) ;
66606662 } ) ,
66616663 ) ,
0 commit comments