Repository navigation
fix(launcher): pin codex routing via overlay-generated .env (#1802) - #1806
Merged
Merged
Conversation
codex's load_dotenv() calls set_var() unconditionally for every non-CODEX_ key of $CODEX_HOME/.env AFTER the launcher's spawn env is set, so a user .env pointing HTTP(S)/ALL_PROXY at e.g. socks5h silently re-routed the client off bili after start — and codex's custom-CA rustls HTTP stack cannot speak SOCKS at all, so every aux request (Apps MCP, model list, plugin dir) died while the model WebSocket leg (separate stack, SOCKS-capable) kept working. The launcher now generates the overlay .env itself: managed keys (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY/SSL_CERT_FILE/ BILLION_CONTEXT_PROXY, case-insensitive) are rewritten to this launch's values, every other user line is preserved verbatim, pre-existing shared symlink/hardlink .env entries are migrated to an owned 0600 file, and the real home's .env is never touched nor merged back into. The overlay is now built on every platform for routed launches (decoupled from MCP injection), and the MCP server definition rides its merged config.toml everywhere instead of POSIX-only inline -c args.
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1799-pr.1806.632e5c1This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1806.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Owner
Author
This was referenced Oct 1, 2026
added 2 commits
October 1, 2026 10:29
…non-routing launches (#1802) prepareCodexHome only listed .env among refresh-generated files when it was actually generating one. A launch that skipped generation (direct-URL mode, or the unreadable-.env fail-closed branch) after a routed launch therefore let refreshOverlayHome treat the previous launch's owned .env as user data and merge it back into the real home: the user's ~/.codex/.env was replaced by bili's generated file pinning the STALE port of the earlier launch, with the original demoted to .env.bili-conflict. .env is now always refresh-protected; non-generating launches reconcile the overlay entry back to shared state (drop owned residue, re-link from the real home). Two regression tests added: routed->direct mode switch keeps the real .env byte-identical (inode check), and an unreadable real .env after a routed launch leaves the real home intact.
…review) NTFS carries no POSIX mode bits; stat reports 0o666 for regular files on Windows, so the assertion broke both windows-latest CI jobs on the PR head. Test-only change, no behavior change.
Owner
Author
[bot] 🏷 Review 完成。结论:可合并——CI 在 head 结构化七问
review 期间向分支补的两个 commit(均已推送):
分支仅落后 master 一个 release commit(纯版本号),无语义漂移,mergeable 无冲突。 判定:可合并。 合并动作按规范由人执行:#1806 |
) The fake-upstream suite always pre-baked the proxy into base_url, so the #1802 seam (codex load_dotenv overriding the launcher's proxy env with the user's own $CODEX_HOME/.env socks5h lines) was structurally invisible. Drive the REAL launcher (dist/index.js codex exec) against a plain base_url with a hostile .env planted in the real home. Red on master (codex exits 1, rustls cannot speak socks5h), green with the overlay-owned generated .env: turn succeeds through bili, overlay .env pins HTTP_PROXY to the launch origin, user vars survive, real .env stays byte-identical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
bili codexon Windows: Apps MCP / model list / plugin-dir requests all failed with connection errors while normal conversation worked. Root cause (verified against source and the reporter's A/B matrix on their machine):load_dotenv()(codex-rs/arg0/src/lib.rs, rust-v0.159.3) callsset_var()unconditionally for every non-CODEX_-prefixed key of$CODEX_HOME/.envafter the launcher's spawn env is set. A user.envpointingHTTP_PROXY/HTTPS_PROXY/ALL_PROXYat e.g.socks5h://…silently re-routes codex off bili after start.SSL_CERT_FILEset, codex's HTTP client switches to rustls (custom_ca.rs), and its reqwest build has nosocksfeature — so the socks5h proxy URL falls through to the generic path and the custom-CA HTTP leg dies instantly. The model WebSocket uses a different stack that does speak SOCKS → conversation kept working..envwith the real home via symlink/hardlink, so the launcher had no seam to protect the injected routing.Fix
The launcher now generates the overlay
.envitself:HTTP_PROXY,HTTPS_PROXY,ALL_PROXY,NO_PROXY,SSL_CERT_FILE,BILLION_CONTEXT_PROXY(matched case-insensitively, original key spelling preserved on rewrite) — are pinned to THIS launch's values; every other user line is preserved verbatim (comments, order, quoting); absent managed keys are appended;SSL_CERT_FILEis written with forward slashes (dotenv escape safety).0600(it carries the user's secrets verbatim). Pre-existing shared symlink/hardlink entries are migrated to an owned file first. The real home's.envis never touched, never merged back into (existing generated-file exclusion inrefreshOverlayHomecovers both loops; pinned by tests).config.tomlon all platforms (it already did on Windows since [bug] Windows: codex MCP injection -c value loses its quotes through cmd.exe when node lives under a spaced path #681 because cmd.exe cannot transmit inline-cvalues embedding spaced/quoted paths); POSIX-only inline-cargs are dropped — one mechanism instead of two.buildCodexMcpArgsremoved (no remaining consumers).Behavior changes (explicit)
bili codexCODEX_HOME~/.codex; MCP via inline-cargs (when enabled)<~/.codex>-bilioverlay on every routed launch; MCP via merged config.toml.envlives where codex reads it$CODEX_HOME/.enveffect underbili codex(routed mode)NO_PROXY(routed mode)localhost,127.0.0.1,::1<CODEX_HOME>-bili/.env, mode 0600BILI_LAUNCHER_DIRECT=1).env; win32+MCP overlay as before; POSIX+MCP now also overlay-based like routed mode)Real-home state (auth, sessions, config.toml,
.env) is never modified; overlay entries stay shared links. Sessions/auth recorded through the overlay resolve forever (persistent overlay, never deleted — same guarantee as the dsh/pi overlays).Regression review (existing behaviors walked)
.envgeneration (intended). ✓.envstays shared — byte-identical behavior. ✓buildCodexEnvspawn env (HTTPS_PROXY/SSL_CERT_FILE/BILLION_CONTEXT_PROXY) unchanged — belt-and-suspenders retained when the overlay cannot be built (degraded warning now also names the lost.envprotection). ✓refreshOverlayHomesemantics:.envadded to the generated-files set is excluded from BOTH the merge-back loop and the link loop; draft pattern..env.<pid>.tmphandled byisGeneratedDraft. ✓.env: fail-closed — keeps legacy sharing + loud warning instead of generating a substitute that would drop the user's variables. ✓Tests
New
tests/codex-overlay-env.test.ts(12 tests, all pass): socks override upper/lower/mixed case, quoted/export-prefixed lines, comments+user vars preserved, no-user-file, Windows backslash→slash CA path, generated file private+0600 with real file byte/inode-intact, symlink migration, hardlink migration (nlink back to 1), port regeneration across launches, no merge-back into real home, MCP-disabled decoupling, direct-mode legacy sharing. ExistingprepareCodexHome/prepareCodexMcpInjectiontests updated to the unified all-platform behavior.Pre-flight on this head:
npm run typecheckclean · full suite 3464 pass / 0 fail / 19 skip ·npm run buildOK. Real-client coverage rides CI's e2e-codex (real codex through bili, incl. the 426 WS fast-fallback → HTTP POST path the reporter observed).Fixes #1802