Skip to content

[PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) - #4053

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-21_metering-origin-evidence
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-21_metering-origin-evidence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What / why

projectThinkingMass (#1320) stamps CoreMessage.thinkingTokens onto Prepared.originalMessages before noteInboundMessages fingerprints the list (src/server/prepare-anthropic.ts:201/212, src/server/budget.ts:175), and re-derives the value every turn from the previous usage report. The inbound fingerprint is a whole-message JSON.stringify (src/cache-ledger.ts), so a byte-stable client list showed positional fingerprint divergence at every signature-only reasoning message — and detectSeam's #3023 client arm booked a bili-owned unexplained miss as prov:"client" / clientInserts++ ("host churn") whenever the separate outbound-break + miss conditions held.

Fix at the evidence boundary: fingerprints are now computed over origin evidence — the message minus host-generated metering fields (GENERATED_METERING_FIELDS = ["thinkingTokens"]). Signatures, raw payloads, tool ids and unknown semantic fields stay full evidence. Miss accounting is untouched: the unexplained miss remains recorded and falls to the seam-suspect bucket — it is NOT erased and NOT assigned to a provider without evidence.

Behavior change (old → new)

Anthropic-lane sessions with signature-only thinking blocks + measured usage: when the client's resent list is otherwise byte-stable but only the proxy-projected thinkingTokens drifted between turns, an unexplained mid-history break now books line.seam=1 / seamSuspects instead of prov:"client" / clientInserts. Genuine client rewrites (signature change, text edit, insert/delete) still book the client bucket exactly as before. All other lanes/sessions are byte-identical: messages without any generated field stringify identically on the fast path, so legacy fingerprints are unchanged. InboundSlot lives under session.transient (not persisted) — no storage format or cross-restart impact.

Tests

tests/issue4043-metering-origin-evidence.test.ts — both directions pinned (#3617 gate discipline):

  • metering drift alone + separate outbound break → miss stays recorded (tr > 8192), clientInserts === 0, no provider attribution (failed pre-fix, passes post-fix);
  • metering drift with identical outbound bytes → no client attribution;
  • real signature change + outbound divergence → clientInserts === 1, prov "client" (detection power retained);
  • genuine text edit co-occurring with metering drift → still books the client bucket.

Targeted suites green locally on the rebased head (new file + cache-seam-client-insert + issue1891-seam-nobaseline + issue1320-thinking-mass + issue3769-orphan-sweep-ledger: 29/29); typecheck + build clean; full suite via CI.

Auto-merge gate (§7.4): single-module fix, regression test reproduces the original bug, pure fix:, no config/wire/kernel/persistence changes, clean diff.

Closes #4043

…evidence

projectThinkingMass (#1320) stamps CoreMessage.thinkingTokens onto Prepared.originalMessages before noteInboundMessages fingerprints the list, and re-derives the value every turn from the previous usage report — so a byte-stable client list showed positional fingerprint divergence at every signature-only reasoning message, and detectSeam's #3023 client arm booked a bili-owned miss as host churn (prov:"client" / clientInserts).

Fingerprints are now computed over origin evidence: the message minus the host-generated metering fields (GENERATED_METERING_FIELDS, currently thinkingTokens). Signatures, raw payloads, tool ids and unknown semantic fields stay full evidence; miss accounting is untouched — the unexplained miss remains recorded and falls to the seam-suspect bucket instead of being attributed to the client or a provider without evidence. Messages without any generated field stringify byte-identically to before, so unaffected sessions keep their legacy fingerprints.

Regression tests pin both directions (#3617 gate discipline): metering drift alone does not trigger the client arm; a genuine signature or text rewrite still does.
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_metering-origin-evidence (7343c0f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4840-pr.4053.9a386d3

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-pr4053.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) [PR] fix: exclude host-generated thinkingTokens from cache-seam client-origin evidence (#4043) Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

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

Union coverage 补入:重复 PR #4055/#4056 里的 capture 侧直接 pin(指纹对 thinkingTokens 波动不变)已并入本分支,标注 commit 7343c0f2f(test-only,+12 行)。本地定向验证 21/21 绿(issue4043-metering-origin-evidence / cache-seam-client-insert(#3023) / issue1320-thinking-mass)。CI 注意:master(bc4a3f8)自身红在 #3769 upgrade-compat 测试(跟踪于 #4049 家族),本 PR 红分片与其重合、失败签名逐字一致,非本 diff 引入。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复——本线程即 #4043 的修复载体;与 #4055/#4056 的重复面已在 floor 3 处置(capture 侧 pin 并入 commit 7343c0f)。
标签: bug scope/kernel p2(缺陷修复;缓存归因属会话核心逻辑;可用但归因失真)。

CI 已跑完(head 7343c0f,独立复核过日志与步骤明细),结论:本 PR 的红全部是 master 既有问题,无一由本 diff 引入。

1) 五个红 test 分片——全部红在 #3769 家族测试,与 master 自身红逐字同签名:

2) static-gates (ubuntu-latest, 24)——步骤 1–8 全绿(typecheck / kernel / pi-subagents / build 均过),仅第 9 步 check-dist-thin-install.mjs 失败(~9 分钟才挂,job 日志 blob 缺失、annotations 无错误文本);该脚本需 registry 访问做 scratch 安装,且同一 commit 的 windows-22 腿同一全绿→ 判为该腿瞬时网络抖动,非 bundle 缺依赖。

八问(对本 PR 整体):

  1. 是什么问题:host 投影的 thinkingTokens 每轮重算,把「客户端逐字稳定」的会话误记成客户端 churn,污染缓存归因报告。
  2. 什么原因:入站指纹对整条消息 JSON.stringify,把 bili 自有的计量字段也算进了证据。
  3. 影响范围/严重程度:仅 Anthropic 车道 + signature-only thinking + 客户端字节稳定的会话;归因失真(诊断层),压缩与缓存行为本身不受影响;p2。
  4. 怎么修:指纹改在「origin evidence」上计算(消息减去 host 生成计量字段);miss 记账不动,未解释 miss 仍如实落 seam-suspect 桶。
  5. 回归:审过——真客户端改写(签名变/文本编辑/插删)照旧进 client 桶;无计量字段的消息走 fast path 逐字节相同,legacy 指纹不变;无持久化格式变化。未发现回归。
  6. 缓存破坏:不涉及(InboundSlot 在 transient,不落盘)。
  7. 设计方向:不涉及。
  8. 新配置:不涉及。

判定:PR 内容就绪(CI 内 typecheck/build/kernel/组件套件全绿,本地定向 21/21 绿);红的归属 = #4049 家族(master 既有,#4058 修复在途)+ 一例疑似瞬时的 static-gates 抖动。建议 #4058 合入后对本 PR rerun-failed-jobs 取全绿信号,然后由你合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4525(master 6d7c587,合并方式 merge commit,提交保留原作者署名)。本 PR 关单收尾;若列车中对应提交出问题,回滚点为 #4525 单提交 revert。

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

Labels

bug Something isn't working p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated thinkingTokens estimates can be mistaken for client history churn

1 participant