Repository navigation
[PR] fix: cache report misattributes bili's projected thinking-token meter as a client seam break (#4054) - #4056
ranxianglei wants to merge 1 commit into
Conversation
… own projected reasoning-meter (#4054) detectSeam's #3023 client arm fingerprints each inbound message's full JSON. One of those fields is bili's own projection (#1320 projectThinkingMass, budget.ts:175 — its sole writer; no wire codec fills it from client bytes). When that projection wobbles between two requests it flips a mid-history message's fingerprint and books a SEPARATE outbound break as prov:"client" (clientInserts+1), blaming the host even though the client changed nothing. Strip the projected field (top level only) before hashing in noteInboundMessages, so the client view reflects client bytes only. Genuine content changes (signature/text/tool args) still flip the fingerprint. Behavior change: a sample whose only inbound diff is the projected meter now falls back from prov:"client" to the legacy seam bucket — fewer false positives. Regression tests adopt #4042's three cache-metering cases verbatim plus one direct pin that the fingerprint is invariant to the projected meter. Fixes #4054
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4838-pr.4056.9f4a0fcThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4056.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 审核完成——结论:本 PR 作为 #4053 的重复关闭,修复收敛于 #4053(本 PR 的直接 pin 测试已并入其分支)。八问:
行为变更披露(旧→新):唯一 inbound 差异为投影计量的样本,归因从 判定:本 PR 关闭(与 #4053 重复,先来后到:#4053 20:20Z 早于本 PR 20:51Z);#4055 亦已按重复关闭。建议 #4053 在其增量 CI 对 master 红基线干净后合并(红分片按「与 master 同签名对消」判读)。 |
|
(ai: vllm-qwen/qwen3.8-27b) 作为 PR #4053 的重复关闭——同症状 + 同机制 + 同根因:
本 PR 的独特增量(capture 侧直接 pin:指纹对计量波动不变)已并入 #4053 分支,标注 commit |
…ojected meter fluctuation (union coverage from dup PRs ranxianglei#4055/ranxianglei#4056) (cherry picked from commit 7343c0f)
What & why — Fixes #4054
The cache report (
/acp-cache, web session page) booked a cache break as a client-side mid-history rewrite (prov:"client",clientInserts+1) when the only inbound change between two requests was bili's own projected thinking-token meter (thinkingTokens). The client had changed nothing — the diagnosis wrongly blamed the host.Root cause (verified vs master bc4a3f8)
detectSeam's #3023 client arm compares per-message fingerprints captured bynoteInboundMessages(src/cache-ledger.ts), which hashed each message's fullJSON.stringify(m)— includingthinkingTokens. That field is written in exactly one place repo-wide:projectThinkingMass(src/server/budget.ts:175); no wire codec fills it from client bytes. It depends on last-turn usage / local estimate, so it fluctuates between requests → a mid-history signature-only message's fingerprint flips →firstDivergentInboundMsgreturns that index → the break books asprov:"client", masking the real cause (the independent outbound change / provider-side / TTL).Trigger surface: anthropic wire lane + signature-only thinking blocks (Claude Code round-trip extended thinking) + meter/estimate wobble.
Fix
Strip the top-level
thinkingTokensbefore hashing innoteInboundMessages(newstripProjectedMeterhelper), so the client view reflects client bytes only. Real content changes (signature/text/tool args) still flip the fingerprint — control case 3 proves detection is preserved. Single module (src/cache-ledger.ts); no kernel/wire/config/persistence change.Behavior change (old → new)
A sample whose only inbound diff is the projected meter now falls back from
prov:"client"to the legacy seam bucket (line.seam=1, unattributed). Direction is safe: fewer false positives; the miss is still recorded honestly (trunchanged, billing unaffected). No effect on compression decisions.Tests
tests/issue4054-cache-metering.test.tsadopts #4042's three cache-metering cases verbatim (loopback-only, no network) plus one direct pin that the fingerprint is invariant tothinkingTokensfluctuation. Verified RED→GREEN locally: without the fix cases 1 & 4 fail, with it all four pass; existingcache-seam-client-insert.test.ts(#3023) andissue1320-thinking-mass.test.tsstay green. Full-suite verdict = remote CI.Auto-merge gate (§7.4)
Single-module scoped fix · regression test reproduces the bug and now passes · typecheck + build green locally · touches none of config schema / persistence / wire shape /
kernel/· purefix:· clean diff · references issue · does not touch load-bearing infra. Meets all eight conditions.Closes #4054