Skip to content

fix: reuse each lane's own proxy instead of spawning one per host process when mitm domains are configured - #3551

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-17_issue3436-native-proxy-reuse
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-17_issue3436-native-proxy-reuse

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3436

What was broken

Every native host process (dsh/opencode/omp/pi/claude bootstraps) spawned its OWN bili proxy even when a healthy same-lane instance was already running — user log: "another bili instance" ×103, 15 instances stacked over 1.5h.

Root cause (mechanism): the attach compatibility check compared the caller's raw opts.mitmDomains ?? [] against the tier the running instance RECORDED at boot — and those two expressions are different. The child records its resolved whitelist (config-file mitm.domains ∪ inherited BILI_MITM_DOMAINS, file-first order, [] when mitm disabled); native bootstraps pass NO domains at all, so the attach side wanted []. Whenever the operator had configured ANY mitm domain (common for dsh MITM setups), every attach was a mitm-domains-mismatch and every process fell through to spawn. CLI lanes passed route-derived lists missing the same base tier, so they mis-converged whenever the file/env layer was non-empty too — same mechanism, second facet.

Fix (one line at the decision point)

New resolveRecordedMitmDomains(passed?, env?) in src/config.ts computes EXACTLY what a spawned child will record: the loadOptions file-first/env-second tier evaluated against the env the child will see (the launcher's explicit list when it overrides BILI_MITM_DOMAINS at spawn time, otherwise the inherited value; [] when mitm is disabled — mirroring the enabled expression).

instanceCompatible (src/launcher.ts) now wants that value instead of opts.mitmDomains ?? []. Because every attach path funnels through this one check (ensureProxyRunning main probe, starter-poll retry, squatter check, findLiveAttachableInstance for zcode handoff / watchdog drift-repair), the single change covers all of them. No call site changed; the spawn env injection is untouched (a spawned child still receives exactly what the lane explicitly listed, so its recorded tier is byte-identical to before).

Behavior change (old → new)

Verification

  • New tests/issue3436-native-proxy-reuse.test.ts (6 cases, hermetic XDG config/state homes, fake clock): core regression (file tier set → attaches, pre-fix this was the mismatch), caller-env layer, CLI-shape explicit list wants file layer prepended in record order, mitm-disabled records/wants [], default-empty anchor, genuine-mismatch-still-refuses anchor. 6/6 green (~0.5s).
  • Sibling suites on the rebased head: tests/launcher.test.ts + instance-governance + issue2954-launcher-clobber + issue2187-launcher-slow-start + port-zone + fix-1012-inherited-aux-egress = 359/359 green (pre-rebase) and 322/322 across launcher/issue2954/new-file post-rebase; npm run typecheck clean; npm run build green (dist-external-zod gate OK).
  • No kernel changes, no config surface changes (no new env/config fields — the helper reuses existing resolution semantics).

…records

instanceCompatible compared the caller's raw opts.mitmDomains ?? [] against the tier the running instance RECORDED (config-file mitm.domains ∪ inherited BILI_MITM_DOMAINS, resolved by the child at boot). Native-lane bootstraps pass no domains at all, so any configured tier made every attach a mitm-domains-mismatch and every host process spawned its own proxy (user log: another bili instance ×103, 15 instances in 1.5h). CLI lanes passed route-derived lists missing the same base tier, so they mis-converged whenever the file/env layer was non-empty too.

The compat check now wants exactly what a spawned child would record via resolveRecordedMitmDomains (new, config.ts): the loadOptions file-first/env-second tier evaluated against the env the child will see (explicit list when the spawn overrides BILI_MITM_DOMAINS, inherited value otherwise; [] when mitm is disabled). One line at the decision point covers every attach path (ensureProxyRunning, starter-poll, findLiveAttachableInstance); call sites and the spawn env injection are untouched.

Closes #3436
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_issue3436-native-proxy-reuse (a2ef9dc)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4200-pr.3551.48219eb

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-pr3551.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收到,开始独立复审本 PR。先给查重结论:

查重:不重复。 本条是 #3436 的修复 PR,与 #3540 构成同根因姊妹 PR(同一症状「配了 mitm 域名后每进程一代理」、同一机制「attach 侧 want ≠ record 侧 tier」,设计不同:#3551 单决策点改 instanceCompatible,#3540 在 10 个 native 调用点补传三项)。同家族剩余面(CLI 车道 routes 列表缺文件基础层、kimi 两路径 model-windows 口径)已在 #3557([no-dispatch])跟踪,不在本 PR 范围内。

正在做的事(独立重做,不复读 issue 侧结论):

  1. 逐行核对 record 侧(server.ts 实例记录)与 attach 侧(resolveRecordedMitmDomains)是否逐字节同口径,含 BILI_MITM=0 + domains 非空的边缘(floor 9 发现的那一面在本设计里是否已覆盖);
  2. 清点 instanceCompatible 的全部调用入口(主探测/starter-poll/squatter/zcode handoff/watchdog 漂移修复)是否真的全部汇进同一检查;
  3. 核对 floor 4 第 2 点(modelWindows/modelMaxOutputs 两格)在本 PR 里的状态——fix: native lanes reuse the shared proxy instead of spawning one per process (#3436) #3540 最新提交 56a191a21 已补 enabled 门,两个 PR 的完整度对比需要重新评估;
  4. 定向跑新测试文件 + launcher 同族套件,查 CI 状态。

结构化八问结论稍后补在同一条线程。

ranxianglei pushed a commit that referenced this pull request Oct 17, 2026
…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).
@ranxianglei

Copy link
Copy Markdown
Owner Author

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

Consolidating this into #3540 (first-come for #3436) rather than merging two parallel PRs against the same root cause.

Your decision-point fix — resolveRecordedMitmDomains recomputing the recorded mitm tier centrally in instanceCompatible (covers native and CLI lanes plus the disabled case) — is adopted verbatim in #3540's head (dcfba3ccd). It's strictly more correct and lower-churn than per-caller passing, so that's the approach shipping.

#3540 also closes the facet this PR left open: native modelWindows / modelMaxOutputs (via nativeAttachCompat() spread into the 10 native call sites). Without it, a configured model-window value still made every candidate fail model-windows-mismatch, so the per-process spawn would have continued for those users.

Closing this as the folded duplicate so #3436 has a single, complete PR. Your mitm work is preserved in the merged code and credited in #3540's description. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant