@@ -113,7 +113,6 @@ import {
113113 isCodexAppServerApprovalPolicyAllowedByRequirements ,
114114 isCodexSandboxExecServerEnabled ,
115115 readCodexPluginConfig ,
116- resolveCodexPluginsPolicy ,
117116 resolveCodexComputerUseConfig ,
118117 resolveCodexAppServerRuntimeOptions ,
119118 shouldAutoApproveCodexAppServerApprovals ,
@@ -127,7 +126,6 @@ import {
127126import {
128127 buildDynamicTools ,
129128 createCodexDynamicToolBuildStageTracker ,
130- disableCodexPluginThreadConfig ,
131129 filterCodexDynamicToolsForAllowlist ,
132130 formatCodexDynamicToolBuildStageSummary ,
133131 includeForcedCodexDynamicToolAllow ,
@@ -181,11 +179,6 @@ import {
181179} from "./native-hook-relay.js" ;
182180import { registerCodexNativeSubagentMonitor } from "./native-subagent-monitor.js" ;
183181import { describeCodexNotificationCorrelation } from "./notification-correlation.js" ;
184- import { buildCodexPluginAppCacheKey } from "./plugin-app-cache-key.js" ;
185- import {
186- buildCodexPluginThreadConfigInputFingerprint ,
187- shouldBuildCodexPluginThreadConfig ,
188- } from "./plugin-thread-config.js" ;
189182import { isCodexAppServerProfilerEnabled } from "./profiler-flag.js" ;
190183import {
191184 assertCodexTurnStartResponse ,
@@ -214,7 +207,6 @@ import {
214207 buildTurnCollaborationMode ,
215208 buildTurnStartParams ,
216209 codexDynamicToolsFingerprint ,
217- resolveCodexNativeHookRelayBindingReuse ,
218210 type CodexAppServerThreadLifecycleBinding ,
219211 type CodexContextEngineThreadBootstrapProjection ,
220212} from "./thread-lifecycle.js" ;
@@ -802,58 +794,16 @@ export async function runCodexAppServerAttempt(
802794 timeoutMs : params . timeoutMs ,
803795 timeoutFloorMs : options . startupTimeoutFloorMs ,
804796 } ) ;
805- const nativeHookRelayPluginThreadConfigRequired =
806- ! nativeToolSurfaceEnabled || shouldBuildCodexPluginThreadConfig ( pluginConfig ) ;
807- const nativeHookRelayPluginThreadConfigPluginConfig = nativeToolSurfaceEnabled
808- ? pluginConfig
809- : disableCodexPluginThreadConfig ( pluginConfig ) ;
810- const nativeHookRelayPluginAppCacheKey = nativeHookRelayPluginThreadConfigRequired
811- ? buildCodexPluginAppCacheKey ( {
812- appServer,
813- agentDir,
814- authProfileId : startupAuthProfileId ,
815- accountId : startupAuthAccountCacheKey ,
816- envApiKeyFingerprint : startupEnvApiKeyCacheKey ,
817- } )
818- : undefined ;
819- const nativeHookRelayResolvedPluginPolicy = nativeHookRelayPluginThreadConfigRequired
820- ? resolveCodexPluginsPolicy ( nativeHookRelayPluginThreadConfigPluginConfig )
821- : undefined ;
822- const nativeHookRelayBindingReuse = resolveCodexNativeHookRelayBindingReuse ( {
823- binding : startupBinding ,
824- attemptParams : buildActiveRunAttemptParams ( ) ,
825- agentId : sessionAgentId ,
826- dynamicTools : toolBridge . specs ,
827- nativeCodeModeEnabled : nativeToolSurfaceEnabled ,
828- userMcpServersEnabled : nativeToolSurfaceEnabled ,
829- mcpServersFingerprint : bundleMcpThreadConfig . fingerprint ,
830- mcpServersFingerprintEvaluated : bundleMcpThreadConfig . evaluated ,
831- environmentSelection : undefined ,
832- contextEngineProjection,
833- pluginThreadConfig : nativeHookRelayPluginThreadConfigRequired
834- ? {
835- enabled : true ,
836- inputFingerprint : buildCodexPluginThreadConfigInputFingerprint ( {
837- pluginConfig : nativeHookRelayPluginThreadConfigPluginConfig ,
838- appCacheKey : nativeHookRelayPluginAppCacheKey ! ,
839- } ) ,
840- enabledPluginConfigKeys : nativeHookRelayResolvedPluginPolicy ?. pluginPolicies
841- . filter ( ( plugin ) => plugin . enabled )
842- . map ( ( plugin ) => plugin . configKey )
843- . toSorted ( ) ,
844- }
845- : undefined ,
846- } ) ;
847- try {
848- emitCodexAppServerEvent ( params , {
849- stream : "codex_app_server.lifecycle" ,
850- data : { phase : "startup" } ,
851- } ) ;
797+ const buildNativeHookRelayFinalConfigPatch = (
798+ decision : { action : "resume" ; binding : CodexAppServerThreadBinding } | { action : "start" } ,
799+ ) => {
800+ nativeHookRelay ?. unregister ( ) ;
852801 nativeHookRelay = createCodexNativeHookRelay ( {
853802 options : options . nativeHookRelay ,
854- generation : nativeHookRelayBindingReuse . generation ,
803+ generation :
804+ decision . action === "resume" ? decision . binding . nativeHookRelayGeneration : undefined ,
855805 generationMismatchGraceMs :
856- nativeHookRelayBindingReuse . canReuseBinding && ! nativeHookRelayBindingReuse . generation
806+ decision . action === "resume" && ! decision . binding . nativeHookRelayGeneration
857807 ? CODEX_NATIVE_HOOK_RELAY_TTL_GRACE_MS
858808 : undefined ,
859809 events : nativeHookRelayEvents ,
@@ -868,15 +818,24 @@ export async function runCodexAppServerAttempt(
868818 turnStartTimeoutMs : params . timeoutMs ,
869819 signal : runAbortController . signal ,
870820 } ) ;
871- const nativeHookRelayConfig = nativeHookRelay
872- ? buildCodexNativeHookRelayConfig ( {
873- relay : nativeHookRelay ,
874- events : nativeHookRelayEvents ,
875- hookTimeoutSec : options . nativeHookRelay ?. hookTimeoutSec ,
876- } )
877- : options . nativeHookRelay ?. enabled === false
878- ? buildCodexNativeHookRelayDisabledConfig ( )
879- : undefined ;
821+ return {
822+ configPatch : nativeHookRelay
823+ ? buildCodexNativeHookRelayConfig ( {
824+ relay : nativeHookRelay ,
825+ events : nativeHookRelayEvents ,
826+ hookTimeoutSec : options . nativeHookRelay ?. hookTimeoutSec ,
827+ } )
828+ : options . nativeHookRelay ?. enabled === false
829+ ? buildCodexNativeHookRelayDisabledConfig ( )
830+ : undefined ,
831+ nativeHookRelayGeneration : nativeHookRelay ?. generation ,
832+ } ;
833+ } ;
834+ try {
835+ emitCodexAppServerEvent ( params , {
836+ stream : "codex_app_server.lifecycle" ,
837+ data : { phase : "startup" } ,
838+ } ) ;
880839 const startupResult = await startCodexAttemptThread ( {
881840 attemptClientFactory,
882841 appServer,
@@ -892,8 +851,7 @@ export async function runCodexAppServerAttempt(
892851 effectiveWorkspace,
893852 dynamicTools : toolBridge . specs ,
894853 developerInstructions : promptBuild . developerInstructions ,
895- finalConfigPatch : nativeHookRelayConfig ,
896- nativeHookRelayGeneration : nativeHookRelay ?. generation ,
854+ buildFinalConfigPatch : buildNativeHookRelayFinalConfigPatch ,
897855 bundleMcpThreadConfig,
898856 nativeToolSurfaceEnabled,
899857 sandboxExecServerEnabled,
0 commit comments