@@ -59,7 +59,10 @@ import { handoffWindowsTrayForUpdate, planWindowsTrayUpdate } from "../src/updat
5959import { bootRestoreProbe , launcherUsableAfterNpmUpdate , transactionalNpmUpdate } from "../src/update/transactional-install.mjs" ;
6060import { manualUpdateFailureGuidance , npmUpdateFailureGuidance } from "../src/update/update-failure-guidance.mjs" ;
6161import {
62+ captureCodexCliTransportEnv ,
63+ CODEX_CLI_TRANSPORT_ENV_KEYS ,
6264 CODEX_CLI_VERSION_MANAGER_ROOT_ENV_SLOTS ,
65+ codexCliInspectionLookupSeeds ,
6366 isCodexCliUpdateInspectionArgv ,
6467} from "../src/update/codex-cli-update-launch-policy.mjs" ;
6568import {
@@ -1192,26 +1195,56 @@ function createNodeLaunchContext() {
11921195 : configuredCodexCliPath ;
11931196 const preBunPath = typeof process . env . PATH === "string" ? process . env . PATH : null ;
11941197 const preBunPathExt = typeof process . env . PATHEXT === "string" ? process . env . PATHEXT : null ;
1198+ // HOME and NODE_PATH seed the candidate Node module lookup the update
1199+ // inspection models, so they are proof-bound here for the same reason as
1200+ // PATH: the live environment could have been rewritten after selection. They
1201+ // stay in the inherited environment regardless — the child may need them for
1202+ // its own work; only the snapshot copy is optional.
1203+ const preBunHome = typeof process . env . HOME === "string" ? process . env . HOME : null ;
1204+ const preBunNodePath = typeof process . env . NODE_PATH === "string" ? process . env . NODE_PATH : null ;
11951205 const preBunCodexCliManagerRoots = Object . fromEntries (
11961206 CODEX_CLI_VERSION_MANAGER_ROOT_ENV_SLOTS . flatMap ( name => {
11971207 const value = process . env [ name ] ;
11981208 return typeof value === "string" && value !== "" ? [ [ name , value ] ] : [ ] ;
11991209 } ) ,
12001210 ) ;
1211+ // Proxy/CA settings are captured once, here, before Bun can add project dotenv
1212+ // values. They are part of the required selection snapshot, so they count
1213+ // against the context budget below before any optional lookup seed does.
1214+ const preBunTransportEnv = captureCodexCliTransportEnv ( process . env ) ;
12011215 const launchProof = randomBytes ( 32 ) . toString ( "base64url" ) ;
1202- const launchContext = JSON . stringify ( {
1216+ const serializeContext = lookupSeeds => JSON . stringify ( {
12031217 version : 1 ,
12041218 proof : launchProof ,
12051219 anthropicEnvSlots : preBunAnthropicSlots ,
12061220 codexCliInspectionEnv : codexCliUpdateInspection ? {
12071221 codexCliPath : preBunCodexCliPath ,
12081222 path : preBunPath ,
12091223 pathExt : preBunPathExt ,
1224+ home : lookupSeeds . home ,
1225+ nodePath : lookupSeeds . nodePath ,
12101226 managerRoots : preBunCodexCliManagerRoots ,
1227+ transportEnv : preBunTransportEnv ,
1228+ // The published Codex entrypoint selects its native backing by the arch of
1229+ // the Node that runs it; a Bun override or PATH fallback can run another
1230+ // arch under Rosetta, so this Node launcher's arch is the bound value.
1231+ arch : process . arch ,
12111232 configDir : configDir ( ) ,
12121233 } : null ,
12131234 } ) ;
1214- // The inspection snapshot above already carries PATH, PATHEXT, and the manager-root slots as
1235+ let launchContext = serializeContext ( { home : preBunHome , nodePath : preBunNodePath } ) ;
1236+ // The lookup seeds are optional: a Windows inspection never models the global
1237+ // Node lookup, and an oversized NODE_PATH must not push the serialized
1238+ // context past the reader's limit — that would discard the whole selection
1239+ // snapshot, while dropped seeds merely leave the fallback lane unverifiable
1240+ // and fail only the content observation closed.
1241+ const lookupSeeds = codexCliInspectionLookupSeeds (
1242+ process . platform , preBunHome , preBunNodePath , launchContext . length ,
1243+ ) ;
1244+ if ( lookupSeeds . home !== preBunHome || lookupSeeds . nodePath !== preBunNodePath ) {
1245+ launchContext = serializeContext ( lookupSeeds ) ;
1246+ }
1247+ // The inspection snapshot above already carries PATH, PATHEXT, manager roots and proxy/CA settings as
12151248 // proof-bound values, and `inspectCodexCliInstall` reads them from that snapshot rather than
12161249 // from the live environment. Inheriting them again would spend the 32,767-character Windows
12171250 // environment block twice, so a large-but-valid shell environment could stop the Bun child
@@ -1224,7 +1257,8 @@ function createNodeLaunchContext() {
12241257 const inheritedEnv = { ...process . env } ;
12251258 if ( codexCliUpdateInspection ) {
12261259 const snapshotted = new Set (
1227- [ "PATH" , "PATHEXT" , ...CODEX_CLI_VERSION_MANAGER_ROOT_ENV_SLOTS ] . map ( name => name . toLowerCase ( ) ) ,
1260+ [ "PATH" , "PATHEXT" , ...CODEX_CLI_VERSION_MANAGER_ROOT_ENV_SLOTS ,
1261+ ...CODEX_CLI_TRANSPORT_ENV_KEYS ] . map ( name => name . toLowerCase ( ) ) ,
12281262 ) ;
12291263 for ( const name of Object . keys ( inheritedEnv ) ) {
12301264 if ( snapshotted . has ( name . toLowerCase ( ) ) ) delete inheritedEnv [ name ] ;
0 commit comments