Skip to content

refactor(launcher): collapse per-client route-discovery copy into shared family helpers (#1440 P3) - #2453

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-09_launcher-route-discovery
Oct 9, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-09_launcher-route-discovery

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Pure-restructure of per-client route discovery in src/launcher.ts (discoverRoutes) — P3-A of the redundancy audit (#1440). The four copy-paste client families are collapsed into shared module-private helpers; no behavior change.

  • interface DiscoverAcc + three private helpers (no new exports):
    • relayWrapRoute(acc, cfgRaw, fallback, key) — relay-wrap semantics (claude/codebuddy/gemini/iflow/antigravity), byte-for-byte.
    • addStaticHosts(acc, hosts, stripPort) — static-host whitelist semantics (qoder/trae/jcode/qwen/copilot/amp/crush/zed).
    • addProxyUrlSet(acc, urls, keyPrefix, skipWrappedLoopback, anonCountsAll) — proxy URL-set walk with loopback carve-out (dsh/kimi/mcode/aider).
  • URL collection stays at each call site; every branch-leading comment moved VERBATIM above its new call site.
  • Bespoke branches untouched except local refs swapped to acc.*: classify closure, pi/opencode/omp one-liners, codebuddy modelUrls MITM loop, hermes, goose, codex else-branch, crush/zed custom-baseUrls https-only loops, kimi/mcode/aider fallback loops.
  • Net −106 lines in one file (src/launcher.ts, +161/−267).

Documented deviation from the naive helper signature

addProxyUrlSet takes a 5th parameter anonCountsAll: dsh increments its dsh-<n> counter for every unique parseable URL before the loopback test, while kimi/mcode/aider increment only inside it. A 4-param helper cannot reproduce both counter behaviors exactly.

Verification (zero behavior change proven, not assumed)

  • Canonical-JSON snapshot equivalence: discoverRoutes over all 24 launch clients × (empty config + 117 targeted fixtures exercising every family variant: wrapped loopbacks, port-suffixed hosts incl. host:443, mixed URL ordering/dups, kimi provider/modelUrls/envUrls matrix, empty-fallback cases, crush/zed baseUrls, goose customProviders, codex classify variants) → 141/141 entries byte-identical before vs after (diff empty; re-run independently by the reviewer).
  • Gates: tsc --noEmit clean, npm run build clean, check:unused-exports clean (run on the staged file).
  • Tests: 11 route/launch-related suites → 414 pass / 0 fail / 2 pre-existing platform skips locally; reviewer re-ran the core subset (launcher 292, discover + route-passthrough + kimi-native 57) independently, all green. CI authoritative for sandbox-network cases.

Out of scope (queued follow-ups)

resolveClientCommand (~9 per-client ifs) and the heterogeneous runLaunch per-client blocks are intentionally NOT touched here — each gets its own review-sized PR. This PR is deliberately a single-file, single-function surface so the equivalence proof stays mechanical.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-09_launcher-route-discovery (a0aee93)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2724-pr.2453.f685385

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-pr2453.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

[bot] 🏷 Review 结论:可合(对当前 master 64443f9 mergeable=true、无冲突;唯一红 CI 是无关的既有 flake,详见下)。独立验证全部完成,证据如下。

结构化八问

  1. 是什么问题:非 bug 修复,是 audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 冗余审计的 P3-A——把 discoverRoutes 里四族客户端逐份手写的 URL 分类逻辑收敛为三个模块私有 helper(relayWrapRoute / addStaticHosts / addProxyUrlSet)。纯重构、零行为变更、单文件净 −106 行。
  2. 什么原因导致的:不适用(无缺陷)。重复的来源是三类 URL 分类状态机(protocol split → dedupe → loopback carve-out → 计数器)在 4~8 处各自手写;其中 dsh 与 kimi/mcode/aider 的计数器时序本就微妙不同(dsh 在 loopback 测试之前计数),直接去重必须参数化——这正是文档化偏差(anonCountsAll 第 5 参)的由来,必要性成立。
  3. 影响范围与严重程度:若有漂移会波及全部 24 个 launcher 客户端的路由发现(MITM 白名单 / env rewrite / httpEnvRoutes),属高影响面;已证明零漂移(见 Q5)→ 无外部影响。
  4. 怎么修复的:抽出共享累加器 DiscoverAcc;各分支保留自己的 URL 收集,调对应 helper,用 flag 钉死每族语义(dsh=skipWrapped=false, countsAll=true,kimi/mcode=(true,false),aider=(false,false);stripPort 矩阵 qoder/qwen=false,trae/jcode/copilot/amp/crush/zed=true)。crush/zed 自定义 baseUrls 循环刻意保持 bespoke(不做 unwrapUpstream)。注释 VERBATIM 上移,无新导出。
  5. 是否有回归问题:未发现回归。既有行为清单逐项结论:
    • 三个 helper 逐一与改动前代码做行级语义比对:全部分支等价(含 unparseable URL、ftp:// 非 http 协议、host:443、wrapped loopback、空 fallback);
    • 等价证明我独立重跑(未复用作者脚本):master@64443f9 与 PR head f733e1b 两个 worktree 各跑一套自写 differential harness——24 客户端 × (空配置 + 63 个定向 fixture:mixed ordering/dups、kimi providers/modelUrls/envUrls 三源矩阵、判别 dsh 计数位置的混合列表、crush/zed baseUrls、goose customProviders、codex classify 变体、0.0.0.0 vs ::1 等)→ 87/87 条目 canonical JSON 字节级一致,diff 为空;
    • 本地门禁:typecheck ✓、build ✓、check:unused-exports ✓;13 个 route/launch 套件定向跑 440 pass / 0 fail / 2 pre-existing skips;
    • 高危模式逐项过:无阈值/时序/输出格式漂移(输出对象字节一致)、无 fail-fast 变吞错、无默认值变更。审中注意到的一处微观差异(qwen 原分支无空串 guard,helper 带 host &&)经 harness 实证无行为差别(QWEN_DEFAULT_MODEL_HOSTS 无空条目)。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/游标/去重键;rewriteKeys/seen 为函数内请求级局部状态,语义不变。
  7. 是否改了设计方向:否——同架构、同调用图、代码严格变少、无新导出、无新配置面。
  8. 是否引入新配置:无。

CI 状态

其他观察(不阻塞本 PR)

测试有效性与 diff 整洁度

  • 测试有牙:launcher.test.ts / launcher-gemini-family.test.ts 共 118 处 deepEqual 直接钉住 discoverRoutes 输出全形(wrapped→httpsRewrites、clean→httpsDomains、httpEnvRoutes、空配置空值),重构后全绿;我的 harness 额外覆盖了套件未钉住的家族边缘。纯重构 PR 此覆盖度恰当,无需新增测试。
  • diff:单 commit f733e1b、单文件 src/launcher.ts(+161/−267),无无关改动、无空白 churn、无 lockfile/生成物波动。干净。

判定:可合。 flake lane re-run 转绿后即可由人合并(合并权在人,我不代操作)。

@ranxianglei
ranxianglei force-pushed the 2026-10-09_launcher-route-discovery branch from f733e1b to a0aee93 Compare October 9, 2026 13:46
@ranxianglei
ranxianglei merged commit bf2b48b into master Oct 9, 2026
24 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.192-master.bf2b48b (rolling master tag).

npm install -g billion-context@0.0.192-master.bf2b48b  # 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.

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.

1 participant