Repository navigation
fix: native lanes reuse the shared proxy instead of spawning one per process (#3436) - #3540
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4226-pr.3540.31c598eThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3540.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复(与 #3308/#3318 的 over-window refusal 机制不同源;#1365/#2924/#2187/#928 相邻但根因不同)。但发现一个必须处理的冲突:#3436 下有两个在途 PR 都声称 Closes #3436——本 PR(#3540,native 调用点补传 compat 字段)和 #3551(改 |
…e raw union server.ts records [] when mitm is disabled even with domains configured, but nativeAttachCompat used resolveMitmDomains which ignores the BILI_MITM / file mitm.enabled gate — on such machines every native process still failed the mitm-domains-mismatch cell and spawned its own proxy. New config.resolveEffectiveMitmDomains applies loadOptions' enabled gate on top of the same file-first/env-second union; regression test pins disabled→[] and default-enabled→union.
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复(首条回复已述)。结论先行:方向正确,实现成立;我独立验证时找到一个边界缺陷已直接修进本分支(commit 方向关(审原 issue)#3436 的根因判断我独立复核后确认成立:attach 判定( 独立验证证据(不是复读 PR 描述)
发现并已直接修复的缺陷(小问题直接修,commit
|
| 既有行为 | 结论 |
|---|---|
| 默认空配置机器(无任何 domains/windows 配置) | 保持:before/after 都是 want [] vs record [] → attach,字节级不变 |
| 不同配置的进程隔离(lane/host/passthrough/fingerprint/domains/windows/maxOutputs 任一不同 → 各起 proxy,#1225/#1232/#1335 契约) | 保持:只补了输入,未放宽任何比对;test 2 钉死不同 domains 不 attach |
| 配置了 MITM/windows 的机器上 native 多进程 | 有意变更(PR 已披露 old→new:N→1 归并)——披露准确,我复核无误;我的 fix commit 进一步把 disabled-mitm 机器也纳入收敛(old: 恒 spawn → new: attach) |
| wire/message-shape、kernel/、config surface、persistence、端口语义(zcode/claude strictPort 路径) | 不涉及:零触碰,无新 env/config key |
测试有效性
三个新测试是真断言:fake deps 驱动真实 ensureProxyRunning,断言 spawnCalls/attached/watcher 注册数,能抓住 attach 机制回归和 helper 契约漂移。诚实声明局限:单测钉不住「10 个 native 模块确实 spread 了 helper」(它们是副作用 bootstrap,import 级不可测)——这层靠本次代码审查逐点核对(10/10)+ CI e2e native 套件兜底,可接受。
diff 整洁度 & 代码质量
12 文件 +109/-19,每一行都在目的内;无空白 churn、无 lockfile/version 变动;命名达意、docstring 带 #3436 出处、无死代码。达标。
⚠️ 与 #3551 的关系(需要 owner 拍板)
#3551 后到,同样声称 Closes #3436,设计不同(判定层修 mitm cell:resolveRecordedMitmDomains 收口进 instanceCompatible)。独立对比:
| 维度 | #3540(本 PR,含我的 fix commit) | #3551 |
|---|---|---|
| owner floor-4 方案 A | ✅ 按批准实现 | ✅ 等价达成(判定层视角) |
| floor-4 第 2 点:同批对齐 windows/maxOutputs | ✅ 三字段全对齐 | ❌ 只动 mitm cell——配了 BILI_LAUNCHER_MODEL_* 的机器 native 车道仍然每进程 spawn,不满足验收 |
BILI_MITM=0 边界 |
✅(我的 56a191a21 吸收其 enabled-gate 思路) |
✅ |
| CLI 车道 facet(routes 列表缺 config-file 基础层) | ❌ 未覆盖 | ✅ 顺带修掉 |
| 回归面 | 小:只改 10 个调用点输入,共享比较器不动 | 中:改所有车道(含 CLI)共用的判定函数 |
| CI | 重跑中(新 head 56a191a21,gates 已过,test lanes in_progress) |
全绿 |
建议:合并 #3540,关闭 #3551 为 superseded——它的独有贡献已被吸收:enabled-gate → 我的 fix commit;CLI facet + 「三 cell 统一收口到判定层」的加固方向 → 已立 #3557([no-dispatch],带来源标记,含两面残留缺陷 + 机制加固备注)。判定层收口是更稳的长期形态,但那是 follow-up 重构,不应阻塞本次可用性修复(可用性 > 优雅)。若你更想以 #3551 架构为准,请在 thread 里说一声,我把 windows/maxOutputs 对齐补进去再反转建议。
结构化八问
- 是什么问题:native 车道启动时 attach 判定拿不到运行中 proxy 实际记录的三个配置字段,导致配置了 MITM/windows 的机器上每个 native 进程各 spawn 一个 proxy,实例只增不减、端口逐个漂移。
- 什么原因导致的:
ensureProxyRunning的 attach 侧入参(10 个 native 调用点)与 spawn child 实际记录到 session metadata 的值脱节——child 从 ambient env + spawn 覆写拿到完整三字段并记录,attach 侧却从不传,逐字段比对必败于mitm-domains-mismatch。根因在判据输入缺失,不在比较逻辑本身。 - 影响范围与严重程度:所有配置了
mitm.domains(文件或 env)或BILI_LAUNCHER_MODEL_*的机器上跑多个 native 进程的用户;资源泄漏类(实例累积、端口漂移、日志刷屏),功能不受损,长时间使用体验明显恶化(报告者 1.5h 挂 15 个实例)。 - 怎么修复的:单一共享 helper
nativeAttachCompat()提供与 record 侧同源的三字段值,spread 进全部 10 个 native 调用点;review 中发现的 disabled-mitm 边界用resolveEffectiveMitmDomains(叠加 enabled 门控)补齐。 - 是否有回归问题:无意外回归。默认空配置行为字节级不变;隔离契约(不同配置 → 各起 proxy)保持且有测试钉住;唯一变更即披露的 N→1 归并 + 我补充的 disabled-mitm 收敛。高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。
- 是否破坏缓存:不涉及(无缓存/重试/游标/去重键触碰)。
- 是否改了设计方向:不改。仍在「调用点对齐输入」路线内;判定层收口的长期形态立 [no-dispatch] Residual attach-criteria mismatches after the #3436 fix: CLI lanes and kimi cross-path still spawn extra proxies #3557 跟踪,等 native lanes suspected of not reusing instances: one proxy per process, instances only grow (v0.1.197 / opencode v2) | [Bug?] native 车道疑似不复用实例:一进程一代理,实例只增不减(v0.1.197 / opencode v2) #3436 收敛后再决策。
- 是否引入了新的配置:无。复用既有
BILI_MITM_DOMAINS/BILI_LAUNCHER_MODEL_*,无新 env/config/flag。
判定:fix commit 已推、本地定向绿;等 CI test lanes 在新 head 上转绿即可合并(§7.4:触碰 #1225/#1623 compat 契约且跨 10+ 文件,人工合并)。合并前请一并处置 #3551(建议 supersede 关闭)。
…process (#3436) Native bootstraps (opencode, opencode-native, dsh, omp, pi, zcode x2, kimi x2, claude) passed no mitmDomains/modelWindows/modelMaxOutputs to ensureProxyRunning, so every live candidate failed instanceCompatible's mitm-domains-mismatch cell and each process spawned a fresh proxy: instances only grew and ports drifted. Add nativeAttachCompat() in launcher.ts (computes the three fields from the same env a spawned child inherits) and spread it into all 10 native call sites, so attach-side == record-side exactly. Zero change to what the proxy does; only the attach decision now sees the values. kimi keeps its config.toml modelWindows override after the spread. Regression tests pin same-config attach, different-domains spawn, and spawn-side==record-side convergence.
…e raw union server.ts records [] when mitm is disabled even with domains configured, but nativeAttachCompat used resolveMitmDomains which ignores the BILI_MITM / file mitm.enabled gate — on such machines every native process still failed the mitm-domains-mismatch cell and spawned its own proxy. New config.resolveEffectiveMitmDomains applies loadOptions' enabled gate on top of the same file-first/env-second union; regression test pins disabled→[] and default-enabled→union.
(ai: vllm-qwen/qwen3.8-27b) 补充:CI 判定 —— 已转绿(确认为 flake,非回归)唯一红过的分片 两次失败签名(均为实时敏感测试,且都与本 PR 的代码路径无交集):
判定为环境性而非本 PR 引入的证据链:
flaky 测试本身已按规范单独立项跟踪:#3571([no-dispatch],带来源标记)——核心是把那个零松弛的墙钟断言改成状态型/fake-timer 型。不阻塞本 PR。 最终判定(不变,现已被 CI 解锁)可合并 —— head 56a191a CI 全绿。按 §7.4 需人工合并(触碰 #1225/#1623 attach 兼容契约、跨 10 个 native lane)。建议维持前述结论:合并 #3540,关闭 #3551 为 superseded(其独有贡献已被吸收:mitm-disabled gate 在本 PR 的 56a191a commit 中;CLI lane 面 + 决策点强化由 #3557 跟踪)。 |
56a191a to
dcfba3c
Compare
…ecords Consolidate the #3436 fix into the single decision point (instanceCompatible) instead of spreading compat fields across ten native call sites (this branch's original design): each of the three config cells now wants the value a child spawned from these opts will RECORD — resolveRecordedMitmDomains for the mitm tier (loadOptions' file-first/env-second union under its enabled gate; the caller's explicit list when the launcher injects it at spawn time, ambient inheritance otherwise) and, for windows/max-outputs, the same parse the child applies to its BILI_LAUNCHER_MODEL_* env. Every attach path funnels through instanceCompatible (main probe, starter-poll, squatter check, findLiveAttachableInstance behind zcode handoff / watchdog drift-repair), so one projection covers all lanes: native lanes that pass nothing, CLI lanes whose explicit list missed the config-file layer, and the minimal-opts paths a call-site spread cannot reach (kimi MCP watchdog respawn, zcode drift repair). Call sites revert to their pre-#3436 shape; kimi's two proxy paths share ONE windows source (kimiConfigModelWindows) so a respawn presents the same map as the original proxy (#3557 facet 2). Supersedes #3551 (its resolveRecordedMitmDomains + hermetic regression suite absorbed here); closes #3557 (facet 1 was a misread of extMitmHosts — the recorded tier never includes DEFAULT_MITM_DOMAINS/discovery layers; facet 2 fixed by the shared kimi windows source).
dcfba3c to
4338f14
Compare
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.567-master.cb02753 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…N.md In-passing fix found while reviewing #3737: since the #3540 merge, master has carried two adjacent BILI_ALLOW_DSH_COMPACTION detail rows — one with the #3384/#2490 output-budget paragraph but a stale pre-#3354 scope note, one with the current #3354-overlay scope note (the overlay marks preset-nested rows at any depth, pinned by tests/issue3354-dsh-compaction-disable.test.ts). Merge them into one canonical row keeping both unique paragraphs; the new BILI_DSH_AUTHORED_COMPACTION row from #3733 now sits in a single place.
Closes #3436
What & why
Native lanes spawned one proxy per process instead of reusing the shared instance — instances grew without bound and ports drifted (+1 each). Root cause:
instanceCompatiblecompares attach-side opts against what the running proxy records, but native bootstraps leftmitmDomains/modelWindows/modelMaxOutputsunset while the child records resolved values, so every live candidate failed and each host process spawned its own proxy (user log:another bili instance×103, 15 instances in 1.5h).Fix
The compatibility check now wants, for each tier, exactly what the spawned child records — resolved centrally in
instanceCompatible, so every attach path (main probe / starter-poll / squatter check /findLiveAttachableInstance) and both native and CLI lanes are covered by one change, with no per-call-site edits:resolveRecordedMitmDomains(passed?, env)(src/config.ts): file-first / env-second union, gated onBILI_MITM/config.mitm.enabled. A disabled mitm records[]and wants[], so configured-but-disabled domains no longer cause a permanent mismatch.recordedModelMap(passed, env.BILI_LAUNCHER_MODEL_*, parser)(src/launcher.ts): an explicit non-empty caller value wins; otherwise the value is parsed from the same ambient env a spawned child inherits.Native bootstraps therefore need no changes (they pass nothing, and the check resolves the recorded tier from env); the kimi config.toml path is handled explicitly.
Zero runtime change: children already inherit and use these env values (
stripInheritedProxystrips only http/https/all/no_proxy, not theBILI_*vars). Only the attach decision now sees the same values the proxy actually runs with.BILI_MITM_DOMAINS) or configured model windows / max-outputs — or with mitm disabled but domains still set — each native process spawned its own proxy; instances accumulated without bound.No new config/env/flag. No wire/message-shape change. No
kernel/touch.Tests
tests/issue3436-native-proxy-reuse.test.tscovers same-config attach, the caller-env layer, CLI file-first ordering, the disabled-tier[]↔[]case, default-empty, and genuine-mismatch spawn; plus kimi-path coverage. Local: typecheck clean; the #3436 suite is green (full-suite verdict left to CI).查重 / consolidation
Not a duplicate of any open item. This consolidates the parallel work in #3551 (same #3436 root cause): its decision-point mitm resolution is adopted here and extended to the model-window / max-output tiers, which #3551 left open. #3551 is closed as the folded duplicate.
Closes
Closes #3436 · Closes #3557
#3557's two residual facets (CLI-lane config-file mitm tier; kimi cross-path model-windows) are both resolved by this branch's decision-point consolidation (
4338f14e) — every attach path funnels throughinstanceCompatible, which now projects all three cells onto what the spawned child records. Independently verified in #3557.