Skip to content

[PR] fix: re-billing for compacted thinking reclamation (#651) was misreported as an unknown cache seam; now attributed separately (#3198) | [PR] fix: 压缩思考回收(#651)的重计费被误报为未知缓存接缝,改为单独归因 (#3198) - #3300

Closed
ranxianglei wants to merge 9 commits into
masterfrom
2026-10-15_reasoning-drop-attribution

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

坏了什么

每个压缩回合关闭时,reasoning-drop(compress.reasoning.drop,默认开)会把该回合的 reasoning 从出站视图移除——这是一次已知的中段历史改写,每个回合恰好带来一次前缀重计费。此前账本把这笔 miss 记进「⚠ CACHE SEAM(疑似中段前缀断裂)」这个无归因桶,#3198 的排查正是被它吓出来的(本地实测:回合关闭请求 99%→91%,3.3K 重计费,bili.log 每请求都在打 compress-reasoning: dropped ... (#651),但 /acp-cache 只显示未知接缝)。

改动

  • src/cache-ledger.ts:新增 noteReasoningDropPlan(session, plan)——prepare-* 在 planReasoningDrop 之后上报 drop 计划;计划增长 = 有压缩回合新关闭,下一个大残差 miss 被 detectSeam 归因为新桶 prov="reasoning"(agg reasoningDropMisses/reasoningDropMissed,/acp-cache 新增「℞ COMPRESS-REASONING ROUND-CLOSE (Protected-message exemption inflates the incompressible context floor: per-compression reasoning is never reclaimable (~83.5% of measured residual) #651)」一节,写明这是 drop 的已知成本、compress.reasoning.drop=false 可关)。
  • 防误归因:进程内首次观测只记基线(重启后 dropped 视图已稳定,不该把之后的无关 miss 借记到它头上);打点消费一次即失效;120 秒窗口兜底陈旧读。
  • src/server/prepare-{openai,anthropic,responses}.ts:调用点各一行(openai chat / anthropic / responses 三条线;google 无 reasoning 概念)。
  • src/web/client.ts + src/web/i18n.ts(中英):轨迹图新增紫色桶 ℞ 压缩思考回收。
  • 新回归测试 tests/cache-seam-reasoning-drop.test.ts(4 用例:增长记账/重启基线不误借/打点只消费一次/无增长不记)。

不改的东西(有意)

证据

  • 本地:typecheck 干净;新测试 4/4;账本邻居套件(cache-seam-detector / client-insert / fuzz / probes / key·prompt·projection-switch / responses-fold·refold / abort-rewind / cache-ledger / postfold-seam)全绿;e2e codex 4 相位(前一轮跑过,本改动 prepare-* 只加一行上报,CI 复验)。

config surface

无新增/变更配置字段(只读现有 compress.reasoning.drop 并在报告里提示)。kernel 无改动。

Refs #3198

每个压缩回合关闭时,reasoning-drop 会把该回合的思考内容从出站
视图移除——这是一次已知的中段历史改写,每次回合恰好重计费一次。
此前账本把这笔 miss 记成「⚠ CACHE SEAM(疑似中段前缀断裂)」,
#3198 排查正是被这个无归因桶吓出来的。

现在 prepare-* 在 planReasoningDrop 之后上报计划
(noteReasoningDropPlan):计划增长=有回合新关闭,下一个大残差
miss 归因为 prov="reasoning" 的新桶,并在 /acp-cache 输出
「℞ COMPRESS-REASONING ROUND-CLOSE」一节(含 compress.reasoning.
drop=false 的关闭方法),网页轨迹图同步新增该颜色桶。进程内首次
观测只做基线(重启后视图已稳定,不误借归因);打点消费一次即失效,
120 秒窗口兜底。
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-15_reasoning-drop-attribution (5fb81f6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3917-pr.3300.659f7cf

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

Install instructions are refreshed on each push.

awork added 2 commits October 16, 2026 00:38
…ng is a live i18n key

The #3300 change added CAUSE_COLOR.rd / CAUSE_KEY.rd and the prov==='reasoning'
cause mapping but never pushed a legendItem() for the new bucket, so the purple
segment rendered unlabeled AND the i18n dead-key guard (#1024) failed because
t("det.leg_reasoning") was never referenced. Add the swatch mirroring its
siblings (color matches CAUSE_COLOR.rd = #8250df).
#3300 adds reasoningDropMisses/reasoningDropMissed to the cache-ledger agg,
which persists inside session.metadata, so the digest-based storage-render
snapshots drift (only the metadata section hash changes; state/blockContents/
stats unchanged). Regenerate via scripts/update-storage-render-goldens.ts.
Additive, zero-default, backward-compatible fields (backfilled on load); no
persistence version bump.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 本 PR 是把 #3198 排查结论落地成代码的实现,和它引用的两个条目都不重叠:#651 是被归因的 drop 机制本体,#3198 是排查过程;这里只动账本归因,不是对任一在途修复的重复。未见到做同样「reasoning 单独归因」的并行 PR。


我独立审了这条 PR(没有照抄 issue 侧结论),并在本地真实复现了它的两处 CI 破坏、定位根因、就地修好并推回本分支(2e102d6e3..7e5708ebf)。先说结论:功能方向对、范围克制(只把账记对,不动 drop 行为),但原版有两处会让 CI 变红的遗漏,我已补两个标注 commit 修掉。

我验证了什么

  • 拉取分支,逐行读了改动(cache-ledger 的 noteReasoningDropPlan + detectSeam 新臂、prepare-* 三条线各一行、web client/i18n、新测试)。
  • 核对了线路一致性:只有 openai/anthropic/responses 三条线调 planReasoningDrop,现在也都补了 noteReasoningDropPlan;google 线有意跳过(Gemini 要求 reasoning 往返,drop 不适用,prepare-google.ts:55 有说明)——正确。
  • 本地 npm run typecheck 干净;新回归 4 用例 + cache-seam 邻居套件(detector/client-insert/fuzz/probes/cache-ledger 全家/abort-rewind/postfold/responses-fold·refold/capped-body)全绿。
  • 关键:旧 head 上 CI 有两个红分片,我把日志拉下来逐一定位(见下两条),并用「回退 src 到 base 对比」证明了因果。

发现并已修复的两处回归(都在本分支补了 commit)

  1. i18n 死键(web 轨迹图):CAUSE_KEY 加了 rd:"det.leg_reasoning"、颜色也加了,但漏了对应的图例渲染行。后果有二:紫色 ℞ 段在图上没有图例说明;且 t("det.leg_reasoning") 从未被引用,直接触发 #1024 死键断言挂掉(这就是 CI 分片 2 的红)。修法:在图例兄弟项之间补一行 legendItem("#8250df", t("det.leg_reasoning"))(颜色对齐 CAUSE_COLOR.rd)。
  2. storage-render golden 漂移:ledger 新增的 reasoningDropMisses/reasoningDropMissed 两个计数随 ledger 一起持久化进 session.metadata,于是基于摘要的字节指纹快照漂了(只有 metadata 段 hash 变,state/blockContents/stats 不变)。我用「base 树跑该测试=5/5 绿、PR head=4/4 红」钉死了是本 PR 引起。修法:按测试自带的指引跑 scripts/update-storage-render-goldens.ts 重生成(4 个文件,只动了摘要行)。

结构化八问

  1. 是什么问题:compress-reasoning drop(Protected-message exemption inflates the incompressible context floor: per-compression reasoning is never reclaimable (~83.5% of measured residual) #651)每关一个压缩回合就会改写一次出站视图、带来一次前缀重计费,这本是已知成本;但账本把它记进了「⚠ CACHE SEAM(疑似中段断裂)」这个无归因桶,A/B experiment: ACP_RENDER_NONE=1 (renderTags=none) eliminates dsh render seams — hit rate 85.6% -> 91.2% #3198 那轮排查就是被它吓出来的。
  2. 什么原因导致的:detectSeam 没有针对这种「drop 触发的中段改写」的归因臂,所以这笔 miss 只能落到未解释残差→接缝。
  3. 影响范围与严重程度:纯可观测性/记账,不影响压缩行为或正确性。面 = 所有开了 compress.reasoning.drop(默认开)的会话在 /acp-cache 看到的归因。严重度 = 诊断体验瑕疵(每次都会误触发一轮排查),非功能故障。
  4. 怎么修复的:prepare-* 在算出 drop 计划后上报;用一个进程内 WeakMap 记「计划增长=有回合新关闭」的时间戳;detectSeam 在实质残差门槛之后消费这个戳——消费即失效、120s 窗口兜底陈旧读、首次观测只记基线(重启后 dropped 视图已稳定,不能把之后的无关 miss 借记给它)。命中就 book 成 prov="reasoning"。
  5. 是否有回归问题:审过 detectSeam 既有各臂(ttl/side/rewind/client/fold)的判定顺序保持不变,reasoning 臂插在实质残差门槛后、其它臂之前,不改变它们各自的判定;两种压缩模式都核对过(drop 改写在 plugin/proxy 两路同样发生)。唯一边界:若同一请求又恰逢模型切换(line.sw=1),会先在更早的 guard 提前 return,导致该戳没被消费、顺延到下一个 settle——极罕见复合事件下可能把下一笔 miss 误记成 reasoning,受 120s 窗口约束,属轻微记账偏差、非数据错误。另外上面两条真回归已就地修好。
  6. 是否破坏缓存:不涉及缓存失效/重试策略本身,只改账本归因与报告展示。
  7. 是否改了设计方向:不改架构/数据流,只是在既有 seam 归因体系里加一个「已知成本」桶;compress.reasoning.drop 默认值不动,留给你定。
  8. 是否引入新配置 / ⚠️持久化面披露:无新增配置字段(只读现有开关并在报告提示)。但要显式告知一处持久化面增量:ledger agg 新增 reasoningDropMisses/reasoningDropMissed 两个计数,随 ledger 持久化进 session.metadata(零默认值、加载时回填、向后兼容、无需版本号 bump)。因此 storage-render 快照需要重生成(已完成)。这落在 §7.4「持久化格式」范畴——虽是增量非破坏性,仍在这里点名供你合并前把关;如果你更希望这两个计数不落盘(每进程重置),那是另一种取舍,告诉我我再调整。

收工判定

本地 typecheck + 相关套件全绿,两处回归已修复推送。建议:rebase 到当前 master 后再合并——该分支落后 master 约 29 个提交,而且 master 已经推进了 storage-corpus(11 个文件),rebase 后 storage-render golden 需要再跑一次 update-storage-render-goldens.ts 对齐新语料。合并动作按规矩由你手动执行。

Sync master (incl. #3266 image-precompression removal) into the PR branch.
Conflict only in tests/golden/storage-render/*.json (both sides regenerated since
base): resolved by taking master's fixtures and re-running
scripts/update-storage-render-goldens.ts on the merged tree so the snapshots match
post-#3266 code plus #3300's two new persisted ledger counters. Verified on this
tree: typecheck clean; golden-storage-render + web-i18n + cache-seam-* +
cache-ledger suites 81/81 green.
ranxianglei pushed a commit that referenced this pull request Oct 15, 2026
…det.leg_reasoning was a dead i18n key (#3198)

The /acp-cache detail page paints the 'rd' cause (#8250df) on the chart and
names it in the tooltip, but the unattributed family's sub-legend never
rendered a row for it, so the catalog key #3300 added was referenced by no
rendered surface (tests/web-i18n.test.ts dead-key gate). Add the conditional
row alongside the other seam sub-causes.
ranxianglei pushed a commit that referenced this pull request Oct 15, 2026
…uckets (#3198)

detailSeam() tolerates servers predating each attribution bucket by
defaulting absent fields to zero — #3300's legend row reads
seam.reasoningDrop.count without that tolerance, so any payload whose
seam lacks the field (test fixtures, older server builds) throws during
loadDetail and the trajectory never binds (#2489 brush tests time out
in waitFor). Add the missing normalization line; behavior for current
server payloads is unchanged.
ranxianglei pushed a commit that referenced this pull request Oct 15, 2026
…the stack merge dropped them (#3198)

The merge of master into this branch silently took master's stale
storage-render goldens instead of #3300's regeneration (7e5708e), so
the digest-based snapshots failed on all four wires even though this
tree's persisted state matches #3300's digests exactly (verified by
A/B dumpStateTo against merge-base: only metadata.cacheLedger.agg
differs, and those two fields are what 7e5708e pinned). Restore the
four files verbatim from 4dee7e9; no re-run of the regen script was
needed because the digests already agree with this tree.
…uckets (#3198)

detailSeam() tolerates servers predating each attribution bucket by
defaulting absent fields to zero — the legend row added in 491d52a
reads seam.reasoningDrop.count without that tolerance, so any payload
whose seam lacks the field (test fixtures, older server builds) throws
during loadDetail and the trajectory never binds (#2489 brush tests
time out in waitFor). Add the missing normalization line; behavior for
current server payloads is unchanged.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 里两个 #2489 brush 测试超时(u24s1)的根因已定位并修复,推送 97ce469。

detailSeam()(src/web/client.ts:1073)对所有归因子桶做防御式缺省——server 早于某个桶时缺字段→0(注释自 #1609 起就是这个契约)。但 491d52a 加的 legend 行直接读 seam.reasoningDrop.count,而 reasoningDrop 没进归一化:任何 seam 里没有该字段的载荷(web 测试 fixture、旧版 server)在 loadDetail 里抛 TypeError → 轨迹图绑不上 → brush 测试 waitFor 3s 超时。本地实证:master 树 3/3 过,本分支 2/3 挂(确定性,非偶发)。

修复 = 补一行与兄弟桶同模式的归一化(reasoningDrop: { count: (raw.reasoningDrop && Number(...)) || 0, ... }),当前 server 载荷行为不变。本地 web-trajectory-brush 3/3 + web-i18n 10/10。

另注:#3311 合并时误丢了本分支的 491d52a(legend 行)和 7e5708e(金标重生成)两个 commit——已在 #3311 侧原样恢复并留言,与本分支无冲突预期(rebase 时两行自然收敛)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突处置完成。分支现在包含最新 master,文本冲突已消除(GitHub 状态 mergeable,仅剩 checks 阻塞);期间从 CI 日志里发现并确认了本 PR 自己引入的一个真实回归,已在分支上修复并通过本地 A/B 验证。

结构化八问:

  1. 是什么问题:系统转发「PR 与 master 冲突」。核对后发现分支早已通过合并提交(4dee7e9ce,父提交即当时 master 头 6ee4a2ac9)吸收了最新 master,冲突本身不存在、无需再 rebase。但逐分片比对 CI 失败集时发现:PR 在旧头 4dee7e9ce 上弄红了 tests/web-trajectory-brush.test.ts 的两个用例(4 个平台×node 组合全挂,均为 waitFor timed out),而 master 上这两个用例是绿的——这是 PR 引入的回归,不是冲突。
  2. 什么原因导致的:PR 给图例加了「压缩思考回收」一行(读 seam.reasoningDrop.count,src/web/client.ts:1505),但聚合函数 detailSeam() 没有给这个新字段做归一化。凡是不带该字段的载荷(测试 fixture、旧版本服务器响应),undefined.count 直接抛异常 → loadDetail 中途死掉 → 轨迹图永远不绑定 → harness 等待超时。因果链:漏一行归一化 → 渲染路径抛错 → 整个详情页渲染不出来。
  3. 影响范围与严重程度:只影响 web 端会话详情页的兼容路径——旧服务器(未发 reasoningDrop 字段)或任何缺字段的载荷下,详情页整体渲染失败;当前生产服务器始终带该字段,真实用户几乎无感。但所有走 fixture 的测试必挂,属必须修的真实回归,不是体验瑕疵。
  4. 怎么修复的:在 detailSeam() 里补一行归一化,与兄弟桶(providerTtl/rewinds/client)完全同构——字段缺失时默认零值(src/web/client.ts:1084,分支上的提交 97ce469ef)。对当前服务器载荷行为零变化,缺字段时优雅降级为 0 而不是抛错。
  5. 是否有回归问题:做了两侧完整失败集比对(各 12 个测试分片的日志逐个提取)。master 自身红:storage-render golden ×4(已有 test: rebaseline storage-render goldens after #3295 dropped dead image-stats fields from state.stats #3314/test: regenerate storage-render goldens after #3295 removed image stats seed fields #3320 在处理)+ AC12 多跳孙节点资格 + #1086 T5 liveness(已有 修 CI 无故变红:#1086 T5 用例的 'x'×360 填充触发 #3289 输出护栏,含 #3289 的每棵树必挂 #3317 在处理);修复后 PR 头的红只剩 {AC12, #1086 T5}——两者在 master 上同样红、与本 PR diff 无关,是 master 存量红而非本 PR 引入。本 PR 弄红的两个 feat(web): add zoom-to-selection (brush) to the session context-trajectory chart #2489 轨迹图用例在全部 4 个组合转绿;storage-render golden 在 PR 头通过(PR 自己重生成过对应 goldens)。结论:本 PR 相对 master 无新增回归。
  6. 是否破坏缓存:不涉及——改动只在 web 渲染归因展示与测试兼容层,未触碰缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及(无新 env/config/默认值)。

验证证据(本地定向复现,非全量):同一测试文件在旧头 4dee7e9ce 本地跑 1 过 2 挂(与 CI 一致),在修复头 97ce469ef 本地跑 3/3 过;CI 侧 35 项已过、剩余 4 个测试分片在跑且目前零新增失败。

判定:冲突已解决、PR 引入的回归已修复并验证,无需再次推送;剩余红灯均为 master 存量且已有对应条目跟踪(#3317、#3314/#3320)。等最后 4 个分片跑完即可合入。

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

awork added 2 commits October 16, 2026 09:03
# Conflicts:
#	tests/golden/storage-render/anthropic.json
#	tests/golden/storage-render/chat.json
#	tests/golden/storage-render/google.json
#	tests/golden/storage-render/responses.json
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决并推送,PR 状态 dirty → blocked(等待新 head 的 CI)。

发生了什么:上一轮唤醒后 master 又前进了一批合并(#3284 pi-inline、#3317 T5 filler、#3314 golden 重基线、#3312 host-plugin-notice),分支里已有的 master 合并点不再是最新 tip,GitHub 重新判了 dirty。

怎么解的:把当前 master 合进分支,共两个 merge commit——b0a94318a(含 #3284/#3317/#3314)和 faa38f7ed(操作期间 #3312 又挤进来了,补合一次)。唯一的文本冲突是 tests/golden/storage-render/{chat,anthropic,responses,google}.json:本 PR 因新增 ledger 计数器重生成过 golden(state/metadata digest 变了),master 侧 #3314 也重基线过同一批 digest 行,同一行两边改出不同值。解法不是手挑一边,而是用仓库自带脚本 scripts/update-storage-render-goldens.ts 从合并后的树重新生成——结果与本 PR 已提交的值逐字节一致(master 侧 #3314 的重基线对这个 fixture 的输出无影响),即采纳本 PR 的 digest 值。

八问:

  1. 是什么问题:PR 分支与 master 再次分叉导致的合并冲突,纯同步问题,非代码缺陷。
  2. 什么原因导致:唯一双方同时改动的文件是 storage-render golden——两边各自重基线同一批 digest 行,值不同 → 文本冲突。
  3. 影响范围与严重程度:只影响本 PR 的可合并性,零用户面影响。
  4. 怎么修复的:merge master 进分支;golden 冲突用官方脚本从合并树重新生成解决,不手改字节。
  5. 是否有回归问题:无。合入的 master 变更(pi-inline 默认关、T5 测试修、host-plugin-notice 范围调整、image-stats 移除)与本 PR 路径(cache-ledger / web seam 归因)互不相交;合并树上定向测试 30/30 通过(golden-storage-render + web-trajectory-brush + cache-seam-reasoning-drop + issue2861-host-plugin-notice),typecheck 干净。全量判定以 CI 为准。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:无(Port billion-context-pi's no-server mode: inline in-process compression lane for pi #3284 自带的 BILI_PI_INLINE 是该 PR 自己的配置面,非本次合并引入)。

已知红项说明:AC12 multi-hop、#1086 T5 liveness 在 master 上本来就是红的(各有跟踪条目),不属于本 PR。CI 在新 head faa38f7ed 上跑完转绿后即可合入。

@ranxianglei ranxianglei changed the title fix: 压缩思考回收(#651)的重计费被误报为未知缓存接缝,改为单独归因 (#3198) [PR] fix: re-billing for compacted thinking reclamation (#651) was misreported as an unknown cache seam; now attributed separately (#3198) | [PR] fix: 压缩思考回收(#651)的重计费被误报为未知缓存接缝,改为单独归因 (#3198) Oct 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant