Skip to content

[PR] fix: cache report misattributes bili's projected thinking-token meter as a client seam break (#4054) - #4056

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_cache-metering-prov-client
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_cache-metering-prov-client

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 by noteInboundMessages (src/cache-ledger.ts), which hashed each message's full JSON.stringify(m) — including thinkingTokens. 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 → firstDivergentInboundMsg returns that index → the break books as prov:"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 thinkingTokens before hashing in noteInboundMessages (new stripProjectedMeter helper), 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 (tr unchanged, billing unaffected). No effect on compression decisions.

Tests

tests/issue4054-cache-metering.test.ts adopts #4042's three cache-metering cases verbatim (loopback-only, no network) plus one direct pin that the fingerprint is invariant to thinkingTokens fluctuation. Verified RED→GREEN locally: without the fix cases 1 & 4 fail, with it all four pass; existing cache-seam-client-insert.test.ts (#3023) and issue1320-thinking-mass.test.ts stay 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/ · pure fix: · clean diff · references issue · does not touch load-bearing infra. Meets all eight conditions.

Closes #4054

… 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
@ranxianglei ranxianglei changed the title fix: cache report misattributes bili's projected thinking-token meter as a client seam break (#4054) [PR] fix: cache report misattributes bili's projected thinking-token meter as a client seam break (#4054) Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_cache-metering-prov-client (51f7410)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4838-pr.4056.9f4a0fc

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

(ai: vllm-qwen/qwen3.8-27b)

查重:重复——本 PR 与 #4053、#4055 是 100% 重复(同症状 + 同机制 + 同根因),对应 issue #4054 与 #4043 重复。

处置(正在执行):

  1. 保留 [PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) #4053 为唯一修复 PR,并把本 PR 与 [PR] Stop bili's own thinking-mass projection from faking client-side cache-break attribution #4055 里多出的「指纹对计量波动不变」直接 pin 测试并入其分支(标注 commit,取并集覆盖);
  2. [PR] Stop bili's own thinking-mass projection from faking client-side cache-break attribution #4055 与本 PR([PR] fix: cache report misattributes bili's projected thinking-token meter as a client seam break (#4054) #4056) 打重复标签关闭;
  3. issue Cache report blames the client for a cache break when the only inbound change is bili's own projected thinking-token meter #4054 作为 Generated thinkingTokens estimates can be mistaken for client history churn #4043 的重复关闭(注:Cache report blames the client for a cache break when the only inbound change is bili's own projected thinking-token meter #4054 自己的查重写「无」,漏了早 7 分钟已存在的 Generated thinkingTokens estimates can be mistaken for client history churn #4043/[PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) #4053——同根因红风暴防线要求出站前先查)。

CI 状态:master(bc4a3f8)自 10-20 16:47Z 起本身是红的——失败签名恰好一条测试:tests/issue3769-upgrade-compat.test.ts 的 "upgraded pre-fold-gate state keeps rotation-hidden orphans hidden end-to-end (#3769)"(断言 'record hydrates before the upgrade turn'),已有跟踪家族 #3997/#4039/#4041/#4049/#4051,不再另立项。三个 PR 挂的分片与 master 红分片完全重合,且我已核对 #4053 失败分片日志里的失败签名与 master 逐字一致(not ok 1039,同一测试名)——不是修复引入的。

标签:bug / claude-code / scope/ui / p3(诊断归因缺陷:只影响缓存报告的归因展示,不影响计费/压缩决策;触发面 = anthropic lane + signature-only thinking 块)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

审核完成——结论:本 PR 作为 #4053 的重复关闭,修复收敛于 #4053(本 PR 的直接 pin 测试已并入其分支)。八问:

  1. 是什么问题:两次请求之间 inbound 唯一差异是 bili 自己投影的 thinkingTokens 计量时,缓存报告(/acp-cache)把该次缓存断裂记为「客户端中途改写历史」(prov:"client",clientInserts+1),错误归咎宿主。
  2. 什么原因导致的:noteInboundMessages(src/cache-ledger.ts)对每条消息做全量 JSON 指纹,含 thinkingTokens;该字段全仓唯一写入点是 [bug] anthropic wire: signature-only thinking blocks missing from compressible estimate — savings receipts overstate, nudge stays idle (claude native) #1320 投影 projectThinkingMass(src/server/budget.ts:175,在 capture 前原地写到 originalMessages 上),值每轮重推 → 只含签名的消息指纹翻转 → detectSeam 的 [Enhancement][cache-ledger] attribute client-side mid-history insertions to a client bucket — seam forensics currently blame bili for host churn (found in #2997) #3023 client 臂据此归因。客户端实际没改任何东西。
  3. 影响范围与严重程度:触发面 = anthropic lane + signature-only thinking 块(Claude Code extended thinking 往返)+ 计量波动(+ 大未解释 miss + 独立 outbound break)。严重度 p3:仅诊断归展示性失真,不影响 miss 记账(tr)/计费/压缩决策。
  4. 怎么修复的:指纹前剥掉顶层 thinkingTokens,让客户端视图只反映客户端字节。三个 PR 实现形态不同([PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) #4053 具名 permitlist 常量 + helper / [PR] Stop bili's own thinking-mass projection from faking client-side cache-break attribution #4055 内联三元 / 本 PR 独立 helper),保留 [PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) #4053(可扩展纪律,与 fix(responses): keep persona-scoped sessions stable across instruction drift #1104/fix: invert the Responses instructions fingerprint into a codex/claude-only allowlist #1107 的 evidence-permitlist 风格一致),本 PR 的直接 pin 已并入(commit 7343c0f2f)。
  5. 是否有回归问题:未发现破坏。逐项审过既有行为:字段缺席时 fast path 保持旧指纹逐字节一致(InboundSlot 只在 session.transient,无存储/wire 影响);真实客户端改写(签名/文本编辑/tool args)仍会翻转指纹(控制用例 + 直接 pin 双向钉死);detectSeam 其他臂不变;修复在 ledger 侧、与车道无关,plugin/proxy 两模式同时成立。CI:本 PR 挂的分片与 master 既有红([Bug] MCP failed compression record rotation prematurely rewrites the history prefix, triggering expensive cache recompu | [Bug] MCP 失败压缩记录轮换提前改写历史前缀,触发大额缓存重算 #3769 upgrade-compat 测试,Two #3769 storage regression tests flake across CI shards on master and unrelated PRs #4049 家族跟踪)完全重合,失败签名已逐字核对一致——非修复引入。
  6. 是否破坏缓存:否。不触碰运行时前缀缓存、重试策略、增量游标;指纹只是 ledger 内部比较键,变更仅消除误报。
  7. 是否改了设计方向:否。沿用既有 evidence-permitlist 纪律(具名白名单,未来宿主生成字段按名加入)。
  8. 是否引入新配置:无。

行为变更披露(旧→新):唯一 inbound 差异为投影计量的样本,归因从 prov:"client" 变为落回 legacy seam 桶(line.seam=1 未归因)。方向安全:误报减少;miss 仍诚实记录(tr 不变、计费不受影响)。

判定:本 PR 关闭(与 #4053 重复,先来后到:#4053 20:20Z 早于本 PR 20:51Z);#4055 亦已按重复关闭。建议 #4053 在其增量 CI 对 master 红基线干净后合并(红分片按「与 master 同签名对消」判读)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

作为 PR #4053 的重复关闭——同症状 + 同机制 + 同根因:

本 PR 的独特增量(capture 侧直接 pin:指纹对计量波动不变)已并入 #4053 分支,标注 commit 7343c0f2f(union coverage)。完整审核结论(八问 + 行为变更披露)见镜像 issue #4056 线程;后续进度看 #4053。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working claude-code duplicate This issue or pull request already exists p3 scope/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache report blames the client for a cache break when the only inbound change is bili's own projected thinking-token meter

1 participant