Repository navigation
fix(preflight): trust only upstream-evidenced baselines in the entry meter (#2313) - #2316
ranxianglei wants to merge 3 commits into
Conversation
The preflightCompress entry meter trusted lastInputTokens regardless of its source, while every other decision site in the request path gates it on usage/overflow-arm provenance (#1492). An estimate-sourced value is a one-way ratchet written by failed turns and post-rebuild anchors — in incident #2313 it pinned the round-0 kernel view at ~10.3M phantom scale for 12 h while the folded view the gate actually judges drained underneath, and the #1933 F3 depth budgets scaled off the same phantom (raw inbound list) instead of the view being folded. - entry meter now gated on lastInputTokensSource (usage/overflow-arm); the empty-input exception mirrors the per-round floor (a transform-failed outbound IS raw) - depth budgets decided at first measurement on the folded view; a payload that already fits never pays for the decision
Unit-level direct preflightCompress runs shaped like the incident: a session whose prior folds hide most history behind blocks, with an estimate-sourced ratcheted lastInputTokens. Proves the new code raises depth budgets on honest scale (~1.x, uncapped) and fits the window, stays silent for payloads that already fit, and keeps the legacy cap on the trusted-floor path. Verified against stashed old code: the two phantom-scale tests fail there, the trusted-floor test passes both sides.
) compress.modelContextLimit / outputHeadroomMaxPct as operator levers when a long session re-folds without converging before the client gives up; en+zh. Fact-checked: the headroom reservation applies to pinned windows too (reserveOutputHeadroom call site in src/server.ts), so both levers are documented rather than just the pin.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2449-pr.2316.03efc33This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2316.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR Review: #2316 — provenance-gate the preflight entry meter (#2313)验证方式:拉取分支 结构化七问1. 是什么问题:preflight 入口计量器(round-0 kernel 视图 2. 什么原因导致的(两个机制,均已在代码中核实):
3. 怎么修复的:入口基线改用与同函数内 per-round floor 相同的来源谓词门控(空输入例外镜像 floor:transform 失败的出站即是 raw);预算决策从循环前移到首次实际管线测量处,改在折叠视图( 4. 是否有回归问题:逐项审过 diff 触碰路径的既有行为:
5. 是否破坏缓存:不涉及。无线变化;skip-set 键仍是 content-fingerprinted refs;transient-retry 预算逻辑未动;prefix-cache 稳定性不受影响。summary-call 预算语义不变,只是输入变诚实。 6. 是否改了设计方向:不涉及架构转向。本修复是把入口计量器拉回既有的 #1492 provenance 纪律与 #1933 F3 意图("预算随实际剩余工作量缩放")。更深的死锁破局机制(forward-once probe / livelock counter / CALIBRATION_CLAMP_MIN clamp 放宽)刻意保持 out-of-scope,仍作为 #2313 的开放设计问题等 owner 拍板。 7. 是否引入了新的配置:不涉及。仅文档新增:CONFIGURATION.md en + zh-CN 的 测试有效性(质量关)三个测试各钉一个独立行为:T1 estimate 级幻影不得封顶预算 + 读数落在折叠尺度(~1.2x 正则);T2 usage 级基线仍 floor(legacy 上限保留);T3 收敛载荷零成本(无 raise 日志、0 调用、0 折叠)。fixture 真实(block 隐藏 raw 历史 + 可折中段 + 保护尾部)。非恒真断言——A/B 证实它们在旧代码上恰好按预期失败。 diff 整洁度干净:4 文件,每行都与目的相关(fix / 回归测试 / 双语档同步),无空白重排、无 lockfile、无生成物。无配置面变更。 热文件提示(§7.2)#2310、#2311(Responses summary 提取修复)也动 判定可合。 代码正确、最小化、测试有牙、行为变更全部披露;CI 除上述 master 既有红灯外全绿。建议:合并 #2316;unused-export 清理走一个带标注的一行小修(可搭 #2310 的车——它本来就动 launcher.ts,作为独立标注 commit)。 |
Partially addresses #2313 — the metering defect behind the 12-hour stuck-preflight incident, plus the operator-recovery-lever documentation. The core deadlock-breaker mechanism (forward-once probe vs livelock counter) is presented as a design question at the end and awaits owner direction, so this PR references #2313 without closing it.
What changed
src/preflight.ts— two provenance/scale defects at thepreflightCompressentry:lastInputTokensregardless of source, while every other decision site in the request path gates on usage/overflow-arm provenance (emergency shrink / preflight 的本地估算用错了视图:超长会话(客户端历史 127 万,压缩后 outbound 仅 ~16 万)在上游失败无 usage report 时,bili 按原始历史估算 #1492). An estimate-sourced value is a one-way ratchet written by failed turns and post-rebuild anchors. In the incident it pinned the round-0 view at ~10.3M phantom scale for 12 h while the folded view the gate actually judges drained underneath. Now gated (baselineTrusted), with the empty-input exception mirroring the per-round floor (a transform-failed outbound IS raw).estimateCoreMessages(messages)over the full re-sent history — which stays at full-history scale forever because prior server-side folds hide content behind blocks. Budgets are now decided at first measurement on the folded view being judged; a payload that already fits never pays for the decision.Tests —
tests/issue2313-preflight-entry-meter.test.ts: unit-level directpreflightCompressruns shaped like the incident (prior folds hiding most history + estimate-sourced ratchetedlastInputTokens). Verified against stashed old code: the two phantom-scale tests fail there, the trusted-floor test passes both sides (legacy cap preserved).Docs — CONFIGURATION.md en+zh:
compress.modelContextLimit/outputHeadroomMaxPctas recovery levers for a stuck fold loop. Fact-checked: the headroom reservation applies to pinned windows too (reserveOutputHeadroomcall site in src/server.ts), so both levers are documented rather than just the pin.Behavior changes (old → new)
tokenCount): rawlastInputTokensregardless of source → gated on usage/overflow-arm source (estimate-sourced reads as unknown/0). Only sessions with estimate-sourced baselines are affected; usage/overflow-arm sessions are unchanged.[preflight] payload ~N tokwarn log now reports folded-view scale instead of phantom scale (log-wording change — this was the line that misdiagnosed the incident).No wire/message-shape changes, no config schema changes, no persistence changes, no
kernel/changes.Config surface
None added. Docs-only note about existing fields (
compress.modelContextLimit,compress.outputHeadroomMaxPct).Pre-flight
typecheck clean; targeted run of all 29 preflight-related suites: 149/149 pass; new suite 3/3 pass (and discriminates old code via the stash check). Full regression delegated to CI per local-test discipline.
Core deadlock-breaker — design question for owner
This PR removes the metering lie that made the incident's numbers uninterpretable and kept the budgets capped while the real payload was near the wall. If client patience still runs out before folding converges at honest scale, the structural fix is one of:
Plus human-gated calibration clamp widening (
CALIBRATION_CLAMP_MIN0.25, src/cache-ledger.ts) — necessary but not sufficient alone (learning needs a forward).结构化七问(中文结论)
lastInputTokens是失败回合与重建锚写下的单向棘轮(source="estimate"),但 preflight 入口计量器没做来源门控(请求路径上其他所有决策点都门控,emergency shrink / preflight 的本地估算用错了视图:超长会话(客户端历史 127 万,压缩后 outbound 仅 ~16 万)在上游失败无 usage report 时,bili 按原始历史估算 #1492);DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 F3 的深度预算又按原始入站列表(永不下降的全历史尺度)缩放。两层叠加:计量说谎 + 预算按谎言缩放。判定:本 PR 可合并(单模块、纯 fix+test+docs、带回归测试、全绿于当前 master head);#2313 的核心机制待 owner 选定方向后再立后续 PR。