Repository navigation
fix: merge all system/developer messages into one leading message (SGLang #377) - #379
ranxianglei wants to merge 2 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-379Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr379.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] Reviewing this PR now. Diff reviewed: |
[bot] Review complete — verified independently on branch Pre-flight (re-run locally)
Code review
One caveat
LGTM from my side — merge is yours to make (I can't merge PRs). |
fix: pin acp-kernel 0.0.86 — count-triggered distillation default-off (#379)
…ranxianglei#379) Bundles kernel ranxianglei#379/ranxianglei#380: tiers.tier2Trigger 5->1000 / tier3Trigger 10->2000 and the ranxianglei#238 usage gate deleted. Count-triggered distillations reclaimed almost nothing while rewriting the wire from the fold anchor onward — the prefix-cache sawtooth root cause of ranxianglei#1249. Growth (>=growthFloor) and token-mass (>=1.5x) paths unchanged and ungated. Adds tests/kernel-tier-defaults.test.ts pinning the contract into bili's suite (kernel defaults 1000/2000; applyCompressSettings never overrides triggers — boolean tiers toggle only flips enabled). Fixes ranxianglei#1249 (with acp-kernel#379)
…ix from ranxianglei#2225) The Soft-target section still described the pre-ranxianglei#379/ranxianglei#380 shape: adaptive step clamp(round(window*5%), 20k, 50k) with a window-dependent growth floor. Current kernel constants (golden-pinned in tests/golden/wire-contract/kernel.json): nudge.growthFloor == nudge.growthCap == 50000, so the step is flat 50k at every window size and the growth gate is max(20k, 0.45*step) ~= 22.5k with the T1 path additionally requiring >= one step of compressible mass. The old text contradicted the new large-window section added alongside ranxianglei#2225.
KDD #8 still stated the pre-#2110 contract (flat 50k pinned at every window size, 'Do NOT re-scale the interval with the context window'), which this PR deliberately reverses for sub-1M windows. Rewrite the entry to the new contract: clamp(5% x window, 20k, 50k), >=1M byte-identical, and keep the surviving #379/#380 settlement (growth-driven, no usage/count proxy gates) plus the escape-hatch wording.
…5698) When a host model only partially complies with T1 compression nudges (folds a few K of the offered mass each time), decideNudge's growth cascade starves T2/T3 distillation forever: the T2 mass leg demands t2Pen > t1Eff behind a T1-first short-circuit, so a persistently high t1Eff makes the distillation slot structurally unreachable even after its own threshold passes — summary blocks accumulate monotonically until the session ceiling (#5671 production incident; #5698 root cause). T1 harvest-stall detection: - A T1 nudge fire records the offered raw mass (breakdown.pendingT1) in state.nudge.lastT1FirePending (consume-once). - On successful applyCompression, realized tokensCompressed is compared against it: a distillation fold (new tier >= 2 block) clears the stall unconditionally; otherwise a T1-shaped fold harvesting less than STALL_HARVEST_RATIO (0.5) of the offered mass latches state.nudge.t1HarvestStall, at/above ratio clears it. No-op calls are not evidence and leave the armed measurement in place. - decideNudge consumes the flag only when tiers.enabled: in the growth band a stalled T1 yields its slot to a cadence-met T2/T3 whose own mass threshold is met (the legacy "> t1Eff" demand drops for this path); in the pressure band the stall removes T1 from candidates when max(t2,t3) clears minPressureBenefit, so arbitration picks the tier that actually delivers. Reasons carry "[T1 harvest stall]". Composes with the #509 count-trigger slot rotation already on this branch: the stall override sits above the count-ready pool, explicit count triggers keep working independently of the flag, and per-tier cadence applies to the redirected slot as usual. Untouched by design: flat 50K growth cadence (KDD #8), the #379 mass-as-demand philosophy (the stall is consulted only once a higher tier's mass leg crossed its own threshold), #194 first-sight re-arm, and the minPressureBenefit gate. Compatibility: both new state fields are optional — pre-fix snapshots lack them, detection stays off, and arbitration is byte-identical (pinned). Eager lanes never latch. Tests: kernel/tests/nudge.test.ts +9 rows (core latch to slot handoff, full-compliance never latches, distillation clears, legacy absent-flag byte-identity, pressure drop/keep, cadence respect, no-op-not-evidence, count-trigger independence). Red-check: 7/9 fail without the fix.
Summary
Fixes #377 — with 2+ active ACP compressed blocks, bili rendered each block's summary as its own
role:"system"message, so the OpenAI wire carried 2+ system messages. SGLang (and vLLM with the Qwen3-family "system-first" chat template) reject that with a hard 400:The earlier #355 fix (
hoistMidSystemMessages) hoisted mid-conversation systems to a contiguous leading prefix but kept them separate — which SGLang still rejects, because its Qwen3 template guard isif message.role == 'system' and not loop.first: raise, i.e. it requires exactly one system message at index 0, not merely a leading prefix.Change
Replace
hoistMidSystemMessageswithmergeSystemMessages(src/util.ts): it collapses all system/developer messages into a single leadingsystemmessage, preserving the relative order of every other message.sysParts(the client's original system + the static compress prompt) is placed first so the stable prefix-cache anchor stays at the head across compress turns; the folded block summaries follow in their original anchor order.src/server.ts(prepareOpenai) andsrc/loop/adapter-openai.ts(buildRequest) now callcoreToOpenai(...)thenmergeSystemMessages(msgs, sysParts); the now-unusedinjectOpenaiSystemimport is dropped from both.Tests
tests/hoist-mid-system.test.ts→tests/merge-system.test.ts: unit tests rewritten for the merge (no-op, single/mid/multiple systems, sysParts-first ordering, the [Bug] ACP: ≥2 compressed blocks render as multiple system messages → SGLang (vLLM-compatible) upstreams return 400 #377 wire shape collapsing to exactly one system, non-string content JSON-stringified).tests/e2e-mid-system.test.ts: the real-proxy e2e now asserts exactly one system/developer message at index 0 in every upstream request (the [Bug] ACP: ≥2 compressed blocks render as multiple system messages → SGLang (vLLM-compatible) upstreams return 400 #377 requirement), in addition to the existing summary-marker checks.Pre-flight
npm run typecheck— cleannpm test— 863 pass, 0 fail (incl. the e2e 多段 compress 夹 user 消息时 T1 摘要 (role:system) 落在对话中部, sglang 报 400 "System message must be at the beginning" #355 real-proxy run)npm run build— success