Repository navigation
fix: reuse each lane's own proxy instead of spawning one per host process when mitm domains are configured - #3551
ranxianglei wants to merge 1 commit into
Conversation
…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
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4200-pr.3551.48219ebThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3551.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 收到,开始独立复审本 PR。先给查重结论: 查重:不重复。 本条是 #3436 的修复 PR,与 #3540 构成同根因姊妹 PR(同一症状「配了 mitm 域名后每进程一代理」、同一机制「attach 侧 want ≠ record 侧 tier」,设计不同:#3551 单决策点改 正在做的事(独立重做,不复读 issue 侧结论):
结构化八问结论稍后补在同一条线程。 |
…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).
|
(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 — #3540 also closes the facet this PR left open: native 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. |
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 amitm-domains-mismatchand 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 ofopts.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)
mitm.domainsor inheritedBILI_MITM_DOMAINS: OLD = fresh proxy per host process (the bug) → NEW = attach to the existing same-lane instance. Reason: the design intent was always reuse (无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394/实例治理伞形:身份/验活/attach-or-spawn/优雅退出/状态卫生 —— 合并修复 #394 #403 #407 #414 #410 #406 #417/Launcher proxy reuse (ensureProxyRunning) breaks per-run isolation: shared-fate lifecycle + no code/client identity in compatibility check #1225); the mismatch was an expression asymmetry, not a policy.Verification
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).npm run typecheckclean;npm run buildgreen (dist-external-zod gate OK).