Repository navigation
refactor(server): extract forward() relay zone into src/server/relay module (#1440 P2 cut 4) - #2429
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2657-pr.2429.612d2fbThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2429.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到。这是 #1440 P2 cut 4 的已实现 PR(分支 按
完成后按结构化八问给结论。 |
[bot] 🏷 核验完成 — 可合(mergeable)。 这是 #1440 P2 cut 4 的已实现 PR,我按 结构化八问
证据(本地独立复现,非只看 PR 描述)
判定纯移动、零行为变更、无回归、diff 干净最小化、CI 全绿、本地独立复现一致。建议合并(合并动作留给人工)。我未做任何代码改动,也未新立 issue(未发现新问题)。 |
…module (#1440 P2 cut 4)
87519a1 to
1f3b145
Compare
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.169-master.7d5ed5b # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
#1440 P2 cut 4 (final cut of the four-cut plan): extract the upstream relay zone —
export async function forward(...)(1388 lines) and its private recovery companionasync function resolveFakeCompletion(...)(60 lines, the #371 fake-completion retry loop) — fromsrc/server.tsintosrc/server/relay.ts. Pure move: zero behavior change. Monolith 4465 → 2938 lines (−1527); the monolith is under 3k for the first time since the god-file audit.What co-moves (and what stays)
The zone closes over two module-private helpers whose ONLY runtime callers live inside
forward()— they travel as privates (no exports added):inferWireProtocol(path)— wire-protocol inference for passthrough compat-role rewritesarmFailureShrink(...)— the arm emergency shrink on upstream failure to break relay-5xx deadlock #604/任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839/[Bug]Preflight compression uses raw-history estimate instead of compressed-payload size — 42–203s stall per request, saves ~1K tokens #1493 load-bearing arm (records an outbound-payload-sized estimate when an upstream 5xx never reports usage; stays ESTIMATE-grade, killed at the reader while any usage-grade anchor exists)resolveFakeCompletionstays PRIVATE in relay.ts — onlyforwardcalls it.prepareCountTokens(the count-tokens dispatcher at the zone boundary) stays in the monolith.New cross-file surface (exports added in src/server.ts)
Exactly what
tsc --noEmitdemands for the moved bodies, nothing more (unused-exports gate verifies each is consumed):registerRequestAbort,buildForwardTarget,outboundPayloadBreakdownexportaddsexport { forward } from "./server/relay.js";forward's only caller issrc/server/handle.ts(cut 3), which keeps importing it from"../server.js"with zero edits; future consumers likewise untouchedtype Prepared(already exported)import typein relay.ts — no runtime cycle contributionrelay.ts carries its own import block (~115 specifiers, direct from their own modules, e.g.
effectiveAbsorbBlockfrom./prepare-responses.js). Theserver.ts ↔ relay.tsruntime edge is the same cycle class already production-proven by cuts 1–3 (admin.ts,handle.ts, theprepare-*modules): every binding consumed across the edge is a hoisted function declaration or an already-initialized const, no TDZ exposure.Verification
git diff -U0— 1506 removed lines matched byte-identical among the 1587 added; every remaining delta sanctioned and enumerated: (a) 3exportkeyword adds, (b) 1 re-export line, (c) the 55-line relay.ts import header, (d) 43 removed / 22 rewritten import lines in server.ts (specifiers whose only uses lived in the zone — tsc-driven), (e) blank-line normalization: 0 needed, (f) R3 leading-exportremoval: 0 (forwardstays exported). Comments traveled byte-for-byte.npx tsc --noEmitclean ·npm run build(tsup) clean ·npm run check:unused-exportsclean (relay.ts staged; 2 pre-existing waivers)Why this PR touches tests/side-lane-invariants.test.ts (lane-guard)
Four moved lines read
prepared.sidePassthrough(plus one prose "side requests") — the CI lane-guard greps the diff for those substrings and requires a genuine change to one of the four waived lane suites. Test (H) does exactly what the guard wants, honestly: it assertssrc/server/relay.tsneither importsside-request.jsnor names any engine symbol (resolveSideLane|demoteGate|SideLaneDecision|demotedSide|sideRequestLike|SIDE_REQUEST_MAX_TOKENS|isSideRequest|stripLeakedBiliTools|hasLeakedBiliToolsOnly|restoreOutputBudget|sideRequestGuard). The.sidePassthroughfield reads are deliberately ALLOWED — the relay consumes an already-made lane DECISION carried on thePreparedit receives; that is data flow, not coupling, and the test comment says so.Sequence
Fourth (and final) extraction of the #1440 P2 four-cut plan, on top of merged cuts 1–3 (#2284, #2368, #2424). Remaining approved scope after this: P3 items —
runLaunch's ~29 copied client branches and the plugin-install XInstall/XRemove/XStatus registry (each its own PR).