Skip to content

[PR] refactor: extract prepare*/inject* pipelines into src/server/ (#1440) - #1449

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_server-prepare-extract
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_server-prepare-extract

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Second cut of the #1440 server.ts disassembly plan. Moves the per-wire prepare pipelines (request-body → Prepared) and the inject helpers out of src/server.ts into six new files under src/server/:

New file Contents
prepare-shared.ts Prepared type + shared helpers (imageBillingFor, withReasoningDrop, effectiveTokenCount, effectiveAbsorbBlock, reapOrphansLogged, stripKernelSummaries, …)
prepare-anthropic.ts prepareAnthropic, prepareCountTokens, Anthropic reasoning-pair warning
prepare-openai.ts prepareOpenai, OpenAI warn helpers, wiredrop warn cluster (WARNED_WIREDROP_KEY_CAP, _resetWireDropWarningsForTest)
prepare-google.ts prepareGoogle, prepareGoogleCountTokens
prepare-responses.ts prepareResponses, prepareResponsesCompact, repairResponsesAssistantOrdering, resolvePromptCacheKey, shouldInjectPromptCacheKey, FORCE_TEXT_PROTOCOL
inject.ts injectTool (+ its shared injection plumbing)

Discipline

  • Pure move: every moved line is byte-identical to master (verified by an automated purity check in both directions — zero foreign lines in new files, zero modified lines left behind in server.ts). Only sanctioned deltas: added export keywords where cross-file use requires it, single-quote specifier rewrites in the new files' own import blocks, and the test-import updates below.
  • Export discipline: only symbols actually used across module boundaries are exported; everything else stays internal (the refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) #1443 unused-export gate will police this going forward).
  • Five test files updated to import moved symbols from their new locations (codex-official, count-tokens, fix-1205-file-parts, issue564-responses-ordering, reasoning-echo) — import lines only.

Behavior change disclosure

Verification (rebased head)

  • npm run typecheck — clean
  • npm test — 2839 pass / 0 fail / 12 skip (identical to master baseline)
  • npm run build — success, import annotations OK
  • Purity check — see above

Refs #1440

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_server-prepare-extract (901492e)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1449

Each push to this PR publishes a new version under the pr-1449 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1449.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

Review: #1449 (cut 2 of the #1440 disassembly — prepare*/inject* extract)

Verdict: ✅ mergeable. Branch is fresh — single commit 901492e0 directly on current master (825f1529), 0 commits behind, nothing to rebase.

① Direction

Sound continuation of the #1440 plan: pure-move is the right strategy for this hot file, and it follows the pattern cut 1 established (src/server/{observability,context-window,side-request,budget}.js). Scope is refactor-only — no config schema, persistence, wire-shape, cross-repo dependency, or version changes.

Purity — independently re-verified (not taken on faith)

I ran my own two-directional, line-level mechanical check against origin/master:

  • new files → master: every non-import line in the six new files exists verbatim in master's src/server.ts. Only deltas: 20 declaration lines gaining an export prefix (sanctioned) + 15 new header comment lines (note 1 below).
  • master → new files: every removed non-import line from server.ts landed in a new file verbatim or with added export . Sole exception: the dead _wireDropWarnSetForTest (3 lines) — verified it has zero references on master beyond its definition, so its death is clean.
  • imports: every name imported by the new files exists in master's server.ts import set for the same module (checked import type statements too); zero dropped import names; server.ts gained exactly 6 lines, all value imports from the six new modules.
  • module graph: DAG — prepare-* → {prepare-shared, inject}, no back edges. No circular-init risk.
  • tests & inventory: the five declared test files changed import lines only (verified line-by-line); changed-file inventory is exactly the 12 declared files, nothing else.

② Regression review — existing behaviors on touched paths

Behavior Conclusion
Per-wire prepare pipelines (anthropic/openai/google/responses + count-tokens variants) Preserved — byte-identical move
Tool/system injection (injectTool + per-protocol variants, FORCE_TEXT_PROTOCOL) Preserved — byte-identical move
Prompt-cache key resolve/inject Preserved — byte-identical move
Wiredrop warn cluster + reasoning-pair warns Preserved — byte-identical move; only the dead test accessor dies
Export surface (13 symbols leave server.ts) No dangling consumer: the only users outside server.ts were the 5 updated test files. No re-export shim added — unlike cut 1, no other src module consumes these symbols, and dist/index.js is a self-contained bundle, so the surface is safe
Wire/message shape, config, persistence, session identity, update.ts Untouched

Both compression modes reasoned about: the move touches neither mode's carrier path differently — plugin-mode suppression and proxy-mode acp_summary handling live in code paths that moved byte-identically.

Pre-flight (local, on 901492e0)

  • npm run typecheck — clean
  • npm test — 2839 pass / 0 fail / 12 skip (matches your claimed baseline exactly)
  • npm run build — success, dist-import-annotations: OK
  • CI on 901492e0 — all 13 checks green (unit ×4 platforms/node versions, version-guard, e2e, real codex/opencode/dsh/pi lanes, hermetic registry e2e, build-artifact)

Notes (non-blocking)

  1. The 15 provenance header-comment lines at the top of the new files are new content, not listed in the PR's sanctioned-delta inventory. The "every moved line byte-identical" claim still holds (they're not moved lines), but the next purity gate (refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) #1443) should whitelist leading doc comments or future cuts will trip on this.
  2. Import-block restructuring is broader than "single-quote specifier rewrites": name lists were split across files and separate import type statements merged into plain imports (e.g. CompressSettings/ProxyOptions were import type { … } from "./config.js" on master). Runtime-neutral (the bundler erases type-only names; typecheck confirms) and inside the declared import-block zone — just flagging in case the purity checker gets stricter later.

中文摘要:纯移动重构——把 prepare/inject 管线从 server.ts 原样拆入 src/server/ 六个新文件,我独立做了双向逐行纯度校验(零外来行、零漏行、导入名无丢失无新增),行为零变更,测试与 CI 全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。

@ranxianglei ranxianglei changed the title refactor: extract prepare*/inject* pipelines into src/server/ (#1440) [PR] refactor: extract prepare*/inject* pipelines into src/server/ (#1440) Oct 24, 2026
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