@@ -36,7 +36,8 @@ import {
3636 OrchestrationV2ProviderGoal ,
3737 parseGoalCommand ,
3838 ProviderDriverKind ,
39- type ProviderSetupError ,
39+ ProviderSetupError ,
40+ type ServerProviderCompatibilityAdvisory ,
4041} from "@t3tools/contracts" ;
4142import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens" ;
4243import { AgentScope } from "@t3tools/shared/AgentScope" ;
@@ -1548,7 +1549,7 @@ export type CodexAdapterV2DriverEnv =
15481549
15491550export const createCodexAdapterV2 = Effect . fn ( "CodexAdapterV2.createCodexAdapterV2" ) ( function * (
15501551 { instanceId, environment, enabled, config } : ProviderAdapterDriverCreateInput < CodexSettings > ,
1551- hooks : Pick < CodexAdapterV2Options , "onUsageLimits" | "resolveRuntime" > = { } ,
1552+ hooks : Pick < CodexAdapterV2Options , "onUsageLimits" | "resolveRuntime" | "compatibility" > = { } ,
15521553) {
15531554 const clientFactory = yield * CodexAppServerClientFactory ;
15541555 const continuationRequests = yield * ProviderContinuationRequests . ProviderContinuationRequests ;
@@ -1599,6 +1600,9 @@ export interface CodexAdapterV2Options {
15991600 readonly clientFactory : CodexAppServerClientFactoryShape ;
16001601 readonly onUsageLimits ?: ManagedServerProvider [ "applyUsageLimits" ] ;
16011602 readonly resolveRuntime ?: Effect . Effect < CodexEffectiveRuntime , ProviderSetupError , Scope . Scope > ;
1603+ readonly compatibility ?: (
1604+ version : string ,
1605+ ) => Effect . Effect < ServerProviderCompatibilityAdvisory | undefined > ;
16021606 readonly crypto : Crypto . Crypto ;
16031607 readonly fileSystem : FileSystem . FileSystem ;
16041608 readonly idAllocator : IdAllocator . IdAllocatorV2 [ "Service" ] ;
@@ -1705,24 +1709,41 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
17051709 return ;
17061710 }
17071711
1708- yield * client
1712+ const userAgent = yield * client
17091713 . request ( "initialize" , {
17101714 clientInfo : buildCodexInitializeParams ( ) . clientInfo ,
17111715 capabilities : CODEX_CLIENT_CAPABILITIES ,
17121716 } )
17131717 . pipe (
1718+ Effect . map ( ( response ) => response . userAgent ) ,
17141719 Effect . catchTags ( {
17151720 // Interruption can leave Codex initialized before the local flag is set.
17161721 CodexAppServerRequestError : ( error ) =>
17171722 error . code === - 32600 && error . errorMessage === "Already initialized"
1718- ? Effect . void
1723+ ? Effect . succeed ( null )
17191724 : Effect . fail ( error ) ,
17201725 } ) ,
17211726 ) ;
1727+ const version = userAgent && / \/ ( \d + \. \d + \. \d + ) / u. exec ( userAgent ) ?. [ 1 ] ;
1728+ const advisory =
1729+ version && adapterOptions . compatibility
1730+ ? yield * adapterOptions . compatibility ( version )
1731+ : undefined ;
1732+ if ( advisory ?. status === "broken" ) {
1733+ const target =
1734+ advisory . recommendedVersion ?? advisory . recommendedRange ?? "a newer version" ;
1735+ return yield * new ProviderSetupError ( {
1736+ instanceId : adapterOptions . instanceId ,
1737+ operation : "runtime" ,
1738+ detail : `Codex ${ version } does not work with this T3 Code release. Update Codex to ${ target } , then retry.` ,
1739+ } ) ;
1740+ }
17221741 yield * client . notify ( "initialized" , undefined ) ;
17231742 yield * Ref . set ( initialized , true ) ;
17241743 } ) ,
17251744 ) ;
1745+ // A failed open is discarded, so the next turn spawns the updated binary.
1746+ if ( adapterOptions . compatibility !== undefined ) yield * ensureInitialized ;
17261747 const now = yield * DateTime . now ;
17271748 const session = providerSession ( {
17281749 providerSessionId : input . providerSessionId ,
0 commit comments