Repository navigation
refactor(server): extract proxy request pipeline handle() into src/server/handle.ts (#1440 P2 cut 3) - #2424
Conversation
…rver/handle.ts (#1440 P2 cut 3)
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2627-pr.2424.c3ddac2This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2424.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2424 review 结论:纯移动已字节级验证成立,CI 全绿,无回归 — 可合。 结构化八问1. 是什么问题:不是缺陷,是计划内重构(#1440 P2 cut 3):把 ~2000 行的请求管线主函数 2. 什么原因导致的: 3. 影响范围与严重程度:纯结构性变更,声称零行为变化。若做错了会波及每一条代理请求——但下述验证未发现任何行为差异。 4. 怎么修复的:字节级相同搬移(非重写)+ 最小接口化。具体:
5. 是否有回归问题:无。逐项核查结果:
6. 是否破坏缓存:不涉及——prefix cache / persist / 游标逻辑完全未触碰(字节级同一性覆盖此点)。 7. 是否改了设计方向:无转向——沿用 #1440 P2 既定提取模式(拆模块 + 最小导出面 + 边界测试)。一处合理演化:pipeline 模块天然消费 side-lane 公共 API,故 (G) 用白名单而非禁导入,且注释说明了与 (F) 的关系。 8. 是否引入了新的配置:不涉及——无 config/env/CLI 变化。 判定可合。 head CI 已全绿;分支虽落后 master 11 个提交但已验证干净自动合并(#2401/#2421 与其触碰路径无交集),GitHub 合并时可直接处理。按 §7.4,refactor 类归人工合并,请 owner 直接 merge:#2424 小问题检查:未发现需要顺手修的项(测试 (G) 的导入正则只匹配单行 import,若未来有人把该 import 折成多行, |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.157-master.d189be5 # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
#1440 P2 cut 3: extract the proxy request pipeline
async function handle(...)(1991 lines incl. comments at merge base) fromsrc/server.tsintosrc/server/handle.ts. Pure move: zero behavior change. Monolith 6436 → 4446 lines (−1990). This is the largest single extraction of the four-cut plan (handle()was ~40% of the file).Why the new file's imports look the way they do
handle()closed over 120+ module-scope identifiers inserver.ts. After the move it carries its own import block: path-rewired copies of the groups it actually uses (./x.js→../x.js), plus a value/type import line from"../server.js"for the 14 symbols listed below. The two-way runtime edge (server.ts ↔ server/handle.ts) is the same cycle class already production-proven by cut 2'sprepare-*modules and byserver.ts ↔ admin.ts: every binding consumed across the edge is a hoisted function declaration or an already-initialized const, no TDZ exposure. Cut 4 will re-homeforward(below) intorelay.ts, at which point this edge shrinks naturally.New cross-file surface (exports added in src/server.ts)
14 symbols total — exactly what
tscdemands for the moved body, nothing more (unused-exports gate verifies each is consumed):forward,preflightCompressIfNeeded,isPreflightFailFast,logRequestCost,googlePathKind,resignSettingsFor,scrubAnthropicPck,scrubCompatDrop,forwardUpstreamUrl,googleModelFromPathheadroomFallbackLogged,headroomEffectiveLogged,nonConversationRelayWarned,NON_CONVERSATION_RELAY_WARN_CAPforwardis cut 4's territory (it goes torelay.tstogether withresolveFakeCompletion); exporting it now is the minimal unblock rather than widening this PR.Verification
git diff -U0— deleted zone (1991 lines incl. junction blank) vs the new file's body matches exactly modulo the single sanctionedexportprefix; added side = 1 import line + 14 export-prefixed def-lines only. Comments traveled byte-for-byte.dist/index.js; repo has no per-module dist files by existing convention). check:unused-exports: clean (3 pre-existing waivers).Why this PR also touches tests/side-lane-invariants.test.ts (lane-guard)
handle()drives the side-lane engine mid-pipeline for real —demoteGate(),stripLeakedBiliTools(),isSideRequest(),resolveSideLane()call sites live in the moved zone. Moving them out ofsrc/server.tsfires the lane-guard grep by design, so the guard requires a genuine side-lane suite update alongside. Added test (G) pins the boundary of the extracted module:handle.tsmust (a) reference none of the engine's internal identifiers (all 11 verified absent:SIDE_REQUEST_MAX_TOKENS,SideLaneDecision, …) and (b) import fromside-request.jsONLY the public entry points{hasLeakedBiliToolsOnly, isSideRequest, resolveSideLane, demoteGate, stripLeakedBiliTools, restoreOutputBudget, sideRequestGuard}— the allowlist includesrestoreOutputBudget/sideRequestGuardbecause their call sites already lived insidehandle()before this move (moved, not newly coupled). The test deliberately does NOT extend (F)'s doesNotMatch list tohandle.ts: unlike cut 2's prepare/inject modules, the pipeline legitimately consumes the lane API.Rebase note
Rebased onto master after upstream merges (#2409 claude-fork-lineage restructured the parent-link block INSIDE
handle(), among others); the zone was re-extracted verbatim from the fresh base including those edits, and the affected suites were run green above.