@@ -1723,50 +1723,40 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
17231723 } ) ,
17241724 ) ,
17251725 ) ;
1726- const initialized = yield * Ref . make ( false ) ;
1727- // Codex rejects a second initialize on the shared app-server.
1728- const initializePermit = yield * Semaphore . make ( 1 ) ;
17291726 const initializedUserAgent = yield * Ref . make ( "" ) ;
1730- const ensureInitialized = initializePermit . withPermit (
1731- Effect . gen ( function * ( ) {
1732- const alreadyInitialized = yield * Ref . get ( initialized ) ;
1733- if ( alreadyInitialized ) {
1734- return ;
1735- }
1736-
1737- const userAgent = yield * client
1738- . request ( "initialize" , {
1739- clientInfo : buildCodexInitializeParams ( ) . clientInfo ,
1740- capabilities : CODEX_CLIENT_CAPABILITIES ,
1741- } )
1742- . pipe (
1743- Effect . map ( ( response ) => response . userAgent ) ,
1744- Effect . catchTags ( {
1745- // Interruption can leave Codex initialized before the local flag is set.
1746- CodexAppServerRequestError : ( error ) =>
1747- error . code === - 32600 && error . errorMessage === "Already initialized"
1748- ? Effect . succeed ( null )
1749- : Effect . fail ( error ) ,
1750- } ) ,
1751- ) ;
1752- if ( userAgent !== null ) yield * Ref . set ( initializedUserAgent , userAgent ) ;
1753- const version = userAgent && / \/ ( \S + ) / u. exec ( userAgent ) ?. [ 1 ] ;
1754- const advisory =
1755- version && adapterOptions . compatibility
1756- ? yield * adapterOptions . compatibility ( version )
1757- : undefined ;
1758- if ( advisory ?. status === "broken" ) {
1759- const target =
1760- advisory . recommendedVersion ?? advisory . recommendedRange ?? "a newer version" ;
1761- return yield * new ProviderSetupError ( {
1762- instanceId : adapterOptions . instanceId ,
1763- operation : "runtime" ,
1764- detail : `Codex ${ version } does not work with this T3 Code release. Update Codex to ${ target } , then retry.` ,
1765- } ) ;
1766- }
1767- yield * client . notify ( "initialized" , undefined ) ;
1768- yield * Ref . set ( initialized , true ) ;
1769- } ) ,
1727+ // Keep the handshake in the session scope when its first caller is interrupted.
1728+ const [ initializeFiber , invalidateInitialize ] = yield * Effect . cachedInvalidateWithTTL (
1729+ Effect . forkIn (
1730+ Effect . gen ( function * ( ) {
1731+ const userAgent = yield * client
1732+ . request ( "initialize" , {
1733+ clientInfo : buildCodexInitializeParams ( ) . clientInfo ,
1734+ capabilities : CODEX_CLIENT_CAPABILITIES ,
1735+ } )
1736+ . pipe ( Effect . map ( ( response ) => response . userAgent ) ) ;
1737+ yield * Ref . set ( initializedUserAgent , userAgent ) ;
1738+ const version = userAgent && / \/ ( \S + ) / u. exec ( userAgent ) ?. [ 1 ] ;
1739+ const advisory =
1740+ version && adapterOptions . compatibility
1741+ ? yield * adapterOptions . compatibility ( version )
1742+ : undefined ;
1743+ if ( advisory ?. status === "broken" ) {
1744+ const target =
1745+ advisory . recommendedVersion ?? advisory . recommendedRange ?? "a newer version" ;
1746+ return yield * new ProviderSetupError ( {
1747+ instanceId : adapterOptions . instanceId ,
1748+ operation : "runtime" ,
1749+ detail : `Codex ${ version } does not work with this T3 Code release. Update Codex to ${ target } , then retry.` ,
1750+ } ) ;
1751+ }
1752+ yield * client . notify ( "initialized" , undefined ) ;
1753+ } ) ,
1754+ scope ,
1755+ ) ,
1756+ Infinity ,
1757+ ) ;
1758+ const ensureInitialized = Effect . flatMap ( initializeFiber , Fiber . join ) . pipe (
1759+ Effect . tapError ( ( ) => invalidateInitialize ) ,
17701760 ) ;
17711761 const resolveThreadSkills = Effect . fn ( "CodexAdapterV2.resolveThreadSkills" ) ( function * (
17721762 selection : Pick < ModelSelection , "skillOverrides" > | undefined ,
@@ -7855,12 +7845,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
78557845 }
78567846 // thread/revert requires the thread loaded in this app-server; resume after restart or idle release.
78577847 if ( ! loaded ) {
7858- yield * assertCodexSkillOverridesUnchanged (
7859- input . modelSelection . skillOverrides ,
7860- threadInput . providerThread . nativeMetadata ?. skillConfiguration ?. overrides ,
7861- ) ;
7848+ const configured =
7849+ threadInput . providerThread . nativeMetadata ?. skillConfiguration ?. overrides ;
78627850 const skillConfiguration = yield * resolveThreadSkills (
7863- input . modelSelection ,
7851+ configured === undefined ? undefined : { skillOverrides : configured } ,
78647852 input . runtimePolicy . cwd ,
78657853 ) ;
78667854 yield * client . raw . request ( "thread/resume" , {
0 commit comments