Skip to content

[PR] fix: strip inherited internal launcher channels from child envs (#3521) - #3549

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-17_strip-inherited-launcher-channels
Oct 20, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-17_strip-inherited-launcher-channels

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3521

What & why

Launcher child processes inherited bili's INTERNAL spawn channels from the parent environment. stripInheritedProxy removed only the http(s)_proxy family, and the proxy-child spawn site injects the current launch's channels only when the options supply them — it never removes stale inherited values. So an earlier launch that left BILI_LAUNCHER_MODEL_WINDOWS (or BILI_LAUNCHER_LANE, BILI_LAUNCHER_MODEL_MAX_OUTPUTS, BILI_STRICT_PORT) in a long-lived host's or test harness's env handed those stale values to every subsequent proxy child regardless of its own options. The child recorded them in its instance file / registry marker, so the next launch with different (e.g. empty) options failed attach with model-windows-mismatch / lane-mismatch, spawned a replacement, and died on the same-lane twin holding the sticky port (twin-collision → "proxy child exited before becoming healthy") — exactly the reported log sequence.

Fix

  • stripInheritedProxy now also strips the four internal channels (INTERNAL_LAUNCHER_CHANNEL_VARS) — covers the proxy-child spawn site plus every client env that already went through it.
  • New exported stripInternalLauncherChannels strips ONLY the channels (user's own proxy vars stay intact) and is applied to the client branches whose base env passes through verbatim because bili does not route them via proxy envs: dsh/kimi/mcode/aider when no providers route through the proxy, codex direct-URL, claude direct-URL and claude MITM.
  • The spawn site re-injects exactly what the current options supply — unchanged.

Behavior change (disclosed)

Old: any of the four internal channel vars present in the parent env reached EVERY child the launcher builds (proxy child + all clients), even when the current launch did not request them. New: they never cross a process boundary by inheritance; only values from the current launch's options reach children. Safe because none of the four has a documented user-facing path (CONFIGURATION.md marks them "Only the launcher sets it — no user configuration" / spawn channel; strict-port opt-in goes through programmatic opts.strictPort from explicit port config). User-facing env (BILI_MITM_DOMAINS as the config twin of mitm.domains, the user's own proxy vars) is untouched. Self-restart (src/restart.ts) deliberately inherits env across the upgrade handover and does not use these functions — unchanged.

Tests

  • New unit test: stripInheritedProxy strips all four channels, keeps BILI_MITM_DOMAINS/PATH/HOME.
  • New regression test: polluted parent env + empty launch options → spawned proxy env contains none of the four; explicit options are still injected fresh on top. Both tests verified to FAIL on the pre-fix code.
  • Targeted suites green locally (launcher / port-zone / hermes-native / claude-native / dsh-native / kimi-native / launcher-max-outputs / codex-overlay-env / issue2954-launcher-clobber: 525 pass, 0 fail); typecheck + build clean. Full-suite verdict: CI.

…envs (#3521)

An earlier spawn could leave BILI_LAUNCHER_LANE / BILI_LAUNCHER_MODEL_WINDOWS /
BILI_LAUNCHER_MODEL_MAX_OUTPUTS / BILI_STRICT_PORT in the parent environment
(long-lived desktop hosts, test harnesses). The proxy-child spawn env spreads
process.env and only conditionally ADDS the current options' channels, so the
stale values rode into the child, got recorded in its instance file, and made
every later launch with different options fail attach (model-windows-mismatch)
and die on the twin-collision path.

stripInheritedProxy now also removes the four internal channels; a new
stripInternalLauncherChannels covers the client lanes whose base env passes
through verbatim (dsh/kimi/mcode/aider without routable providers, codex and
claude direct-URL mode), where the user's own proxy vars must stay intact.
User-facing vars (e.g. BILI_MITM_DOMAINS) are untouched.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_strip-inherited-launcher-channels (b4e08c6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4198-pr.3549.10c8b73

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3549.tgz
npm install -g package

Install instructions are refreshed on each push.

…sthrough contract

Unused-exports CI gate flagged the new helper (all refs internal to
src/launcher.ts). Add the unit test that pins the contract the
verbatim-passthrough client lanes depend on: only the four internal
channels are removed, the user's own proxy vars survive.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 独立检索 open+closed issue/PR(inherited launcher channels / model-windows-mismatch / BILI_LAUNCHER_MODEL_WINDOWS):无同症状同机制的在途条目。#3521 楼层 2 声称「Implemented in PR #3510」——已核实 #3510 实为「fix: restore native ACP injection across DSH and Codex」(open),与 launcher 通道继承无关,不构成重复。最近邻 #3436/#3540 是 attach 侧空选项问题(机制相反),已在 #3521 楼层区分。

审核独立性声明:本 PR 是上一会话的工作,本轮未复用其分析结论,对 PR body 的每项声明都重新对照代码独立核验过:全部 ~24 处 env 构造点逐一 grep 清点、spawn 点注入顺序、captureInheritedProxyEnv 捕获清单、四个变量的全仓消费者、CONFIGURATION.md 分类、claude strict-port(#964)路径。以下为独立结论。

① 原 issue 方向:正确。#3521 定位的是 spawn 侧环境构造(spawn env 由 process.env 展开、消毒只剥 proxy 家族、通道注入只增不删)——是产生污染字节的生产者,不是 attach 拒绝这一表面现象。修法打在源头,符合「疏不堵」。

② 回归审查(逐项过 diff 触碰路径的既有行为):

  • stripInheritedProxy 语义扩展(proxy 家族剥离不变 + 新增四通道):覆盖全部既有调用点(pi/dsh/kimi/mcode/aider/qoder/trae/jcode/gemini/iflow/qwen/antigravity/copilot/amp/crush/zed/codebuddy/codex/claude + proxy 子进程 spawn 点 + line 5631 的 pi handle 路径);用户自有 proxy 变量经 captureInheritedProxyEnv 以 BILI_INHERITED_* 回注——已核捕获清单仅含 proxy 家族四键,不会把通道变量带回去。保持 + 披露变更。
  • 七个原样透传 base env 的 client 分支(dsh/kimi/mcode/aider 无可路由 provider、codex direct-URL、claude direct-URL/MITM)改走 stripInternalLauncherChannels:只删四个键,其余全保留;四个变量在 client 侧零消费者(grep 全 src/:仅 src/server.ts:983/993、src/server/context-window.ts:35/56 消费)。安全。
  • BILI_MITM_DOMAINS(用户面 config twin):不动,有测试钉住。保持。
  • self-restart(src/restart.ts):跨升级换代有意继承 env、不走这两个函数;升级替换进程保留自己 launch 时的通道值(同一启动,语义正确)。不变。
  • claude SessionStart hook 的 strict-port([native] claude: three-mode alignment (proxy / launcher / native plugin) + runtime-info #964):已核实走程序化参数(src/claude-native-bootstrap.ts:485 strictPort: plan.strict → spawn 点 line 4256 注入子进程 env),不依赖从 claude 宿主环境继承;全仓 grep 无任何脚本/shell 路径以继承方式设 BILI_STRICT_PORT。不受影响。
  • 手动 bili start:剥离只作用于 launcher 构造的子进程 env,不动 launcher 自身 process.env,手动直跑不受影响。保持。
  • 高危模式逐项:无语义漂移超出披露范围、无 fail-fast 变吞错、instance file 格式不变(记录字段相同,只是值干净)、无阈值/时序/输出格式变化。未发现回归。

③ 代码审查:INTERNAL_LAUNCHER_CHANNEL_VARS 具名常量单一定义,stripInheritedProxy 组合调用 stripInternalLauncherChannels(单一事实源);helper 纯函数、浅拷贝、不改输入;spawn 点顺序正确(先 strip → capture → 按当前选项条件重注入,line 4240–4257,当前选项必胜);注释讲为什么(cite #3521 + CONFIGURATION.md + 失败链)。通过。

④ 测试有效性:三个新测试都有牙——(a) stripInternalLauncherChannels 单测钉死「只删四通道、用户代理变量两种大小写 + PATH 存活」契约;(b) stripInheritedProxy 单测钉住 BILI_MITM_DOMAINS 保留;(c) ensureProxyRunning 回归测试模拟完整复现链(污染父 env → 子进程记录所交值 → 下一次不同选项启动 lane-mismatch 强制重生),核心断言 spawns[0] 不含任何通道变量在未修复代码上必失败(判别性断言成立),并验证当前选项「替换而非合并」地新鲜注入。小缺口(非阻塞):七个 client 分支的一行替换没有逐分支新测试,但 helper 本身已被单测钉住、各 lane 既有套件覆盖 env 构造,可接受。

⑤/⑤b diff 整洁度与代码规范:2 文件 +146/-8,每行都与 #3521 相关,无无关改动/空白漂移;命名达意、无死代码、无重复、风格一致。外部提交从严清单全项过(内部提交自查同标准)。


结构化八问

  1. 是什么问题:bili launcher 把父环境里上一次启动残留的四个内部通道变量(BILI_LAUNCHER_LANE / BILI_LAUNCHER_MODEL_WINDOWS / BILI_LAUNCHER_MODEL_MAX_OUTPUTS / BILI_STRICT_PORT)原样带给它构建的所有子进程;proxy 子进程把它们记进 instance file,后续用不同选项的启动在 attach 处被拒(model-windows-mismatch/lane-mismatch)、再生成后撞同 lane twin 退出——长驻宿主/测试 harness 下间歇性启动失败。
  2. 什么原因导致的:spawn env 由 process.env 展开而来,旧消毒 stripInheritedProxy 只剥 http(s)_proxy 家族,而通道注入是「有当前选项才加」——只增不删,陈旧继承值无人移除。
  3. 影响范围与严重程度:触发条件特定——父环境带着四个变量之一(长驻桌面宿主、测试框架、嵌套启动)且后续启动选项与之不同;命中表现为间歇性启动失败(attach 拒绝 + twin-collision 退出)。常规一次性 shell 使用不受影响。中等严重度(特定条件下可用性受损)。
  4. 怎么修复的:进程边界统一消毒——stripInheritedProxy 同时剥四通道(覆盖所有既有调用点含 spawn 点);新增 stripInternalLauncherChannels 只剥通道、保留用户自有 proxy 变量,用于七个原样透传的 client 分支;spawn 点照旧只重新注入当前选项的值。
  5. 是否有回归问题:审了上述 ② 的全部既有行为(proxy 变量透传、MITM domains、self-restart、claude strict-port、手动 bili start、instance file 格式),均保持或为披露的有意变更;未发现回归。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:没有——同一架构,边界处多一道既有类型的消毒步骤。
  8. 是否引入了新的配置:没有。

行为变更披露(旧→新):旧——父环境中出现的四个内部通道值会到达 launcher 构建的所有子进程,即使当前启动未请求;新——这些值永不通过继承跨界,只有当前启动选项的值到达子进程。依据:四者均无文档化用户路径(CONFIGURATION.md:1851–1852 标注 "Only the launcher sets it — no user configuration",:1629 归入 per-process spawn channel);strict-port 的用户 opt-in 走程序化 opts.strictPort。

判定:可合。 CI 在 head b4e08c666 全绿(40 check runs:28 success / 12 skipped / 0 fail;分支直接基于当前 master,无 stale-base 风险)。等待人工合并。

@ranxianglei
ranxianglei merged commit 3754ef2 into master Oct 20, 2026
40 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.662-master.3754ef2 (rolling master tag).

npm install -g billion-context@0.0.662-master.3754ef2  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei ranxianglei changed the title fix: strip inherited internal launcher channels from child envs (#3521) [PR] fix: strip inherited internal launcher channels from child envs (#3521) Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[launcher] Inherited launcher channels can poison the next spawn with model-windows-mismatch

1 participant