Repository navigation
[PR] fix: stop stale session input baselines outliving their measurement context (#2683) - #2725
ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3351-pr.2725.2b406e0This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2725.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review #2725 — fix: stop stale session input baselines outliving their measurement context (#2683) 结论:可合(人工合并——触及 meter 决策路径与默认值语义,按 §7.4 属 human-only 层;不满足 auto-merge)。 结构化八问
行为变更披露(旧→新 + 原因)
测试有效性(④):真 e2e(startServer+fetch,非 mock 判定)。已做牙齿验证:恢复 base 版 src、保留 PR 测试 → G1/G2/#1498-F2 全部失败,G3 两侧都过 → 测试确实复现原 bug,非恒真断言。#1498-F2 从 验证证据:PR head 58/58 定向测试绿(typecheck 干净);rebase 模拟——cherry-pick 到最新 master( diff 整洁度(⑤):8 个文件全部与本 PR 目的直接相关,无跑题文件、无空白噪声。 收工判定:代码、测试、既有行为审计均通过;可合,等 CI 绿灯后由人工合并。 |
…ontext (#2683) Two producers of one mechanism family - session input baselines that outlive the context that measured them: 1. armFailureShrink adopted the char-count UPPER BOUND of the outbound payload as session.stats.lastInputTokens (a 1.7-4x over-reading). The #1498-F1 bound floor predates the #1492/#1839 reader quarantine: no processTurn feed passes an estimate-grade arm into any kernel band anymore, so the bound's only live effect was phantom mass - inflated preflight budgets / output headroom / displays surviving a model or window change until the next usage report (live case: 441,193 armed against a 202,885-token payload; after a 1M->400k model switch the meter read 142% and two ~3-minute emergency folds ran on a payload already at 62% of the new window). The arm now adopts the billing- caliber reading (k-scaled chars/4 + wire overhead + image reserve), and its log names the provenance. 2. A usage-grade baseline measured under model X kept deciding requests for model Y (only ORIGIN changes demoted it, #1933 F2): after a mid-session model switch the foreign bill pinned the preflight loop's decisionTokens above the fold target forever - folding until budget exhaustion although the payload fit. A real model change (both sides known; unknown->known never counts) now retires the trusted-grade baseline at the per-request model-stamp site, before prepare sizes the nudge and before the trigger runs; the next usage report re-anchors. Estimate-grade values survive the switch (byte-scale properties of the payload); same-model window moves keep the bill valid, so genuine overflow still folds. Behavior changes (old -> new): - armed value on a no-usage failure: char-count upper bound -> billing- caliber estimate (it may now land BELOW a future bill on dense JSON/CJK routes where chars/4 undercounts, #553; acceptable because estimate-grade values are quarantined from every decision floor and k closes most of the gap where route+model provenance matches) - usage/overflow-arm baseline + usage anchor across a model switch: trusted verbatim -> retired until the next usage report (forensic state preserved: cumulative inputTokens meter, last-usage timestamp, calibration ring, cache-ledger history) Tests: tests/issue2683-cross-model-baseline.test.ts (new: G1 cross-model retirement e2e - zero summary calls + re-anchor; G2 arm scale band [chars/8, char-count) + provenance clause; G3 control - same-model over-window bill still folds via its floor), re-scaled #1498-F2 assertion in tests/issue1493-arm-outbound-payload.test.ts, and updated pins in tests/context-provenance-outbound.test.ts.
5599b6b to
5a8b5cb
Compare
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #2683 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
(ai: vllm-qwen/qwen3.8-27b) 判断:关闭有误 —— #2683 的修复不在 master 上。 已按你的留言 reopen 并续上(见文末 #4583)。 证据(2026-10-24 对 master
即 #2683 的两个 producer 至今都在 master 上活动,以 completed 关闭 = 修复被丢弃。 已做:
八问(要点,完整版见首轮 review):
行为变更提醒(old→new,详见 PR 正文):arm 值从 char-count 上界 → 计费口径估算;真实模型切换时 trusted 基线立即退役、下一次 usage report 重新锚定。 若你当时关闭的本意是「暂不修」,请再把 #4583 关掉即可——决定权在你。 |
Closes #2683
What
Two producers of ONE mechanism family — session input baselines that outlive the context that measured them — each verified against the issue's live logs and reproduced with e2e fixtures:
The failure arm adopts a bound, not a reading.
armFailureShrink(no-usage relay 5xx / network failure) persisted the char-count UPPER BOUND of the outbound payload (estimateCoreMessagesUpperclass, 1.7–4× real) assession.stats.lastInputTokens. The fix: arm emergency shrink on outbound payload size, not raw body (#1493) #1498-F1 bound floor was justified by the kernel's tool-result truncation loop consuming the arm as remaining depth (arm emergency shrink on upstream failure to break relay-5xx deadlock #604 rescue) — but since the emergency shrink / preflight 的本地估算用错了视图:超长会话(客户端历史 127 万,压缩后 outbound 仅 ~16 万)在上游失败无 usage report 时,bili 按原始历史估算 #1492/任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839 reader quarantine NOprocessTurnfeed passes an estimate-grade arm into any band (preflight runsnoEmergencyTruncate; every decision floor gates on source), so the bound's only live effect was phantom mass: inflated preflight entry budgets, responses-lane output headroom, displays — surviving model/window changes until the next usage report. (Issue's live case: 441,193 armed against a 202,885-token payload.)→ The arm now adopts the same billing-caliber reading the preflight trigger uses (k̂-scaled chars/4 + wire overhead + image reserve), and its log names the provenance:
(k̂-calibrated outbound reading)/(raw outbound reading)(issue proposal feat: OpenAI Responses API support (/v1/responses) #4).Trusted baselines survive model switches. A usage report measured under model X kept deciding requests for model Y — only ORIGIN changes demoted it (DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 F2). After a mid-session switch the foreign bill pinned the preflight loop's
decisionTokensabove the fold target forever (the floor survives folding — folding shrinks the payload, not the bill) → folds until summary-budget exhaustion although the payload fit. (Issue's live case: 566,322 billed under a 1M-window model judged against a 400k window → two ~3-minute emergency folds at 62% of new-window occupancy.)→ A real model change (both sides known; unknown→known never counts) now retires the trusted-grade baseline at the per-request model-stamp site — before prepare sizes the nudge and before the trigger runs — logged with both models and the retired value. The next usage report re-anchors. Precedents: [Bug] 上下文展示估算 206K,usage 返回后为 98K:希望校准估算并区分安全上界 #2117 B already gates k̂ by model ("a factor learned on another model acts as absent"); DSH 分叉会话后触发大量 preflight overflow compress #2383 names foreign-model baselines untrusted for regime selection.
Behavior changes (old → new)
inputTokensmeter, last-usage timestamp (contextTokensAt), calibration ring, cache-ledger history. Same-model window moves do NOT retire (the bill stays valid → genuine overflow still folds); estimate-grade arms survive (byte-scale property of the payload).Config surface
None — no new env/config/CLI keys.
Both compression modes
Retirement sits at the request-handling chokepoint before prepare/trigger, so it applies identically in plugin mode and proxy mode (the mode split happens downstream). The arm-caliber change affects both modes equally (both consume
outboundPayloadBreakdown). No wire-shape change: message rebuild, system handling, tool injection,acp_summary, preflight protocol all untouched — only session-state bookkeeping values.Tests
tests/issue2683-cross-model-baseline.test.ts: G1 cross-model retirement e2e (566K billed under claude-a → claude-b turn makes ZERO summarization calls, no phantom(566000/…)meter, re-anchored to the real 6K bill); G2 no-usage network failure arms inside[chars/8, char-count)with the provenance clause, retry forwards without folding; G3 control — a SAME-MODEL over-window bill STILL FOLDS via its trusted floor (floor semantics preserved for genuine overflow).#1498-F2assertion intests/issue1493-arm-outbound-payload.test.ts(raw-view measurement pinned at chars/4 scale; char-count adoption now explicitly forbidden).tests/context-provenance-outbound.test.ts(cross-model authority loss vs same-model retention; fixture growth sized so the billing-caliber arm still outgrows the fixture bill and the replace-stale-usage mechanic keeps firing).Known side effect (disclosed): a host that mixes multiple models under one UN-FORKED session id will see freshly established baselines wiped at each switch — self-healing (the next usage report re-anchors within one round trip); persona-style hosts are forked per KDD#9 and unaffected.