Skip to content

[PR] fix: split unattributed cache-miss residual over forensics buckets and tag render-tag provider misses (#4397) - #4446

Open
ranxianglei wants to merge 6 commits into
masterfrom
2026-10-24_cache-attribution-split
Open

ranxianglei wants to merge 6 commits into
masterfrom
2026-10-24_cache-attribution-split

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Part of #4397 — request 4 ("make CACHE INVALIDATION distinguish provider eviction from bytes bili does not account for"). The other facets of #4397 (per-route render control = owner decision; residual-turn attribution = awaiting user raw dumps) stay in the issue thread, so this PR does not close it.

What

The grand-ledger upstream-ttl-or-client-rewrite (unattributed) line lumped every body-forensics outcome into one opaque bucket — even though the SEAM section beneath it already split those same tokens into named buckets (provider-side miss / TTL expiry / client mid-history rewrite / rewind / orphan sweep / suspected break) at sample level. And the dominant-residual warning declared "NOT a bili bug" even when body forensics actually suspected a mid-history break.

Changes (all host observation layer):

  1. CACHE INVALIDATION now reconciles the residual: a new sub-line splits N tok unattributed into the per-bucket bookings (body forensics booked provider-side miss X · client mid-history rewrite Y · ...) plus an explicit remainder for samples below the forensics gate or on lanes without body capture. Buckets are subsets of the residual by construction (named-cause lines never reach detectSeam), so the line always reconciles.
  2. Warning refinement: when a suspected mid-history break accounts for >=10% of the residual, the blanket "NOT a bili bug" wording is replaced by the split report pointing at the CACHE SEAM section + the raw-dump ask. When no suspect is material the wording stays byte-identical (the cache-ledger 归因账本:同一残差重复计入多个重叠桶、switch flag 只比紧邻上一条、未归因残差占绝对主导、unknown-cache 样本被画成 0% 平台 #1847 test still pins it).
  3. Render-tags stamp on provider-side misses (render tags on echoed assistant text break session continuity on stateful upstreams (magpie / Claude Code), causing full-history cache misses #2483 signature): both send chokepoints now record whether bili's render tags were active when the body went out (new optional 6th arg to noteForwardedBody; sparse rt flag rides seam slot -> ledger line). Provider-side misses carrying it count into a new taggedSide subset, surfaced under PROVIDER-SIDE MISS as "of which N sample(s) · M tok were sent WITH bili render tags active". This turns the suspected stateful-relay signature into measured data — exactly the [Cache miss] 0% prompt-cache hit on plain conversational turns — 1.27M tok stable-prefix re-bill with no attributable cause (v0.1.204, #1195) #4397 shape (0% hits for 20 turns on byte-stable bodies, recovery after the renderNone flip).

Behavior changes (report text only)

  • New lines appear only when the respective buckets are non-empty; sessions without forensics bookings print byte-identical output.
  • Warning wording: old -> new ONLY when suspects > 0 && suspectTokens >= 10% of residual; otherwise byte-identical.
  • Two new persisted agg keys taggedSideMisses/taggedSideMissed: legacy ledgers normalize to 0 on load (tested).
  • No outbound byte change. No config surface. Kernel untouched.

Tests


Fixes #4397

(孤儿认领:标题本已指向 #4397,补上关闭关键字 —— 第三批清理)

@ranxianglei ranxianglei changed the title fix: split unattributed cache-miss residual over forensics buckets and tag render-tag provider misses (#4397) [PR] fix: split unattributed cache-miss residual over forensics buckets and tag render-tag provider misses (#4397) Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-24_cache-attribution-split (d8e2323)

Latest build — install this exact version

npm install -g billion-context@0.0.10500-pr.4446.8708d6e

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

Recent builds (commit → version)

commit version build
d8e2323 billion-context@0.0.10500-pr.4446.8708d6e build
fe3e4e0 billion-context@0.0.9859-pr.4446.53bf2ee build
5c49d03 billion-context@0.0.9709-pr.4446.f3dc787 build
2c27b89 billion-context@0.0.5543-pr.4446.3c31aa7 build
ecf564c billion-context@0.0.5402-pr.4446.dc446be build
b7868da billion-context@0.0.5397-pr.4446.eb869ea build
7b816af billion-context@0.0.5354-pr.4446.619b676 build
fceb2d5 billion-context@0.0.5346-pr.4446.6851266 build
59e29cd billion-context@0.0.5336-pr.4446.6afad85 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4446.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 是 #4397 的一个 facet(request 4:让 CACHE INVALIDATION 区分 provider eviction 与 bili 未记账的字节),与其他在途条目无重叠;#2483(render-tag 签名)与 #1847(ledger 措辞钉死)均已关闭,只作本 PR 的背景引用。#4397 其余 facet 留在原线程,本 PR 不关闭它。

标签: bug + scope/ui + p3(理由:本 PR 只改报告文本与观测数据,无用户可见行为变更;归账本统计/展示面)

审核进行中:已拉取分支 59e29cd11(单 commit,4 文件:src/cache-ledger.ts、src/loop/core.ts、src/server/relay.ts、新增 tests/issue4397-invalidation-reconciliation.test.ts)。正在做独立代码审查 + 定向测试,结论按八问体例随后发出。

@ranxianglei ranxianglei added bug Something isn't working p3 scope/ui labels Oct 23, 2026
ranxianglei pushed a commit that referenced this pull request Oct 23, 2026
…the global knob (#4397)

Review fix for #4446: both send chokepoints stamped noteForwardedBody's rt flag from the global renderNone knob, but the documented semantics is 'render tags were active on THIS body' — compaction-trigger requests force renderTags 'none' even with the knob off (prepare-responses), so such bodies would have been booked tag-active and inflated the taggedSide subset. Both chokepoints now stamp from the per-request strategy (prepared.renderTags / new LoopCtx.renderTags), falling back to the knob only where a lane carries no strategy (byte-faithful passthroughs) — behavior there is unchanged. Net behavior delta: only prepared trigger-form bodies flip from stamped to untagged; every other lane derives its strategy from the same knob, so old and new stamps agree.

Regression: e2e E2 trigger-form test pinned both directions (tag-free body carries no rt flag with the knob off; the old knob stamp fails it). Cache/seam family green locally (236 pass); full-suite verdict comes from CI.

Part of #4397
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

#4446 审核完成。审核中发现一处真实缺陷并已直接修掉推上分支(fceb2d5),结论按八问如下。

1. 是什么问题:本 PR 是观测面增强(#4397 request 4),不是缺陷修复——把 CACHE INVALIDATION 里不透明的 upstream-ttl-or-client-rewrite (unattributed) 残差行对账到 seam forensics 的各命名桶,并给 provider-side miss 打上「发送时 bili render tags 是否激活」的戳(#2483 签名),把「疑似状态化中继」变成可测量数据。

2. 什么原因导致的:grand-ledger 把 body forensics 的全部结果聚进一个桶,而下方 SEAM 段在样本级早已拆成命名桶(provider-side / TTL / client rewrite / rewind / orphan-sweep / suspect)——信息在手但报表层没对账;且主导残差警告在 forensics 实际怀疑 mid-history break 时仍无条件宣称 "NOT a bili bug"。

3. 影响范围与严重程度:纯宿主观测层(报表文本 + 持久化 agg key)。无出站字节变化、无配置面、kernel 未动;无 forensics booking 的会话输出逐字节不变。观测/体验级(p3)。

4. 怎么修复的:

  • formatInvalidation 新增子行,把 residual 拆成各桶 booking + 显式 remainder(低于 forensics 门槛 / 无 body 捕获车道的样本);
  • 警告措辞仅在 suspects>0 且 suspect tokens ≥10% residual 时切换为分桶报告并指向 SEAM 段,否则逐字节不变(cache-ledger 归因账本:同一残差重复计入多个重叠桶、switch flag 只比紧邻上一条、未归因残差占绝对主导、unknown-cache 样本被画成 0% 平台 #1847 的措辞 pin 保住);
  • noteForwardedBody 加可选第 6 参,sparse rt 标志经 seam slot → 账本行 → 新 taggedSide 子集(PROVIDER-SIDE MISS 段下显示)。
  • 审核发现并当场修复(fceb2d5):两个发送 chokepoint 用全局旋钮 !knobRenderNone() 打 rt 戳,但注释声明的语义是「该 body 出站时 tags 是否激活」——prepare-responses 对 compaction-trigger 请求即使旋钮关也强制 renderTags="none",旧戳会把这类 body 记成带 tag,高估 taggedSide,恰好削弱本 PR「实测数据」的核心主张。改为按每请求策略打戳(prepared.renderTags / 新增 LoopCtx.renderTags),无策略车道(byte-faithful passthrough)回退旋钮、行为不变。行为变更披露:仅 prepared 的 trigger-form body 从「被戳」变「不戳」;其余车道策略本就由同一旋钮导出,新旧戳一致。补 e2e E2 回归测试并双向验证(旧代码跑必红、新代码绿)。

5. 是否有回归问题:逐项审过——无 forensics booking 会话字节不变 ✓;警告措辞仅在已披露条件切换 ✓;两个新 agg key(taggedSideMisses/taggedSideMissed)纯增量,legacy 账本加载归零(有测试)✓;第三调用点 relay.ts 非流式 settle 路径不传戳 → samePayload 继承 prior.rt,语义正确 ✓;taggedSide 是 providerSide 臂内记账,严格子集 ✓;高危模式(语义漂移/fail-fast 变吞错/阈值时序漂移/输出格式变化)均无。本地 cache/seam 全家族 236 过 / 0 败(含 #1847 pin 与新测试),typecheck 干净。另注:测试中撞见一个与本 PR 无关的既有怪癖——非 codex UA 发 codex trigger 语法时响应尾多一帧 upstream_stream_truncated 且该轮不结算;PR 未触碰流处理,属既有行为且形态病态(真实 codex 流量走早期分发、prepared:null 根本不进 seam),不在本 PR 处理,留此备查。

6. 是否破坏缓存:不涉及。不碰前缀缓存/重试/增量游标/去重键,rt 只是稀疏观测元数据。

7. 是否改了设计方向:没有。在既有 seam forensics → grand-ledger 观测链内扩展,无架构转向。

8. 是否引入了新的配置:没有(无新 env/config/CLI;ACP_RENDER_NONE 为既有旋钮)。

状态:修复已推 PR 分支(fceb2d5),远程 CI 全量回归运行中,结果出来我跟进;CI 绿即可合并(合并请你操作)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 终判出炉:全绿,可合并。

最终 head 7b816af05 的全量 CI(run 40016622283):26 success / 1 skipped / 0 fail —— 11 个 test shard 日志里没有任何一条 not ok(共 24711 个子测试通过)。此前红过的两个测试我逐个在日志里核过,本轮均为 ok:

  1. storage-render golden ×4(chat/anthropic/responses/google):全 ok。前两个 head(59e29cd / fceb2d5)红在这里的根因已钉死:新的稀疏 rt 标志随 settled ledger line 进入持久化 metadata,而提交的 golden 快照早于它(最后更新是 "Output reservation extended to all wires" (#4184) landed without test coverage: widespread red on master is blocking th | 「输出预留扩到所有 wire」(#4184) 落地没带测试面: master 大面积红卡住 v0.1.204 发版 (已 revert, 重做要求见内) #4205)→ 确定性的 metadata-digest-only 漂移(state/blockContents/stats 三个 section 逐字节一致)。按仓库规则用 scripts/update-storage-render-goldens.ts 重新生成四个 golden 文件修复(commit 7b816af05,diff 仅 digest 行),依据已补进 PR 描述。这是 PR 正文已披露的加性字段契约扩展,不是放宽任何门禁。
  2. hook e2e static URL(claude-native.test.ts:1413):ok(本轮跑了两次都过)。fceb2d5e7 上那一次红是负载下的 spawn/port race(proxy B 在变 healthy 之前退出);该文件本身有 CI 负载下红的历史(CI flake storm: concurrent fixed-port e2e files (port-zone-live / claude-native / auto-restart) collide on the 18787 zone under --test-concurrency 4 #3182 family,见文件内 :1366 注释),本 PR diff(报告文本 + seam slot 标志)不触碰 claude-native 的 bootstrap/端口/存储锁路径,无因果链——判定环境 flake,rerun 通过佐证。

另更正一处归因:诊断期间看到的 dsh-persona-continuity 红属于并行 PR #4438 的 run(那个 PR 把 dsh auto-review 请求改走 stateless side passthrough,persona fork 自然不再发生),与本 PR 无关——本 PR 自己的 run 里 dsh-persona 每次都是 ok(ok 194 / ok 421)。

八问增量(相对 floor 5,只列状态有变的):

  • Q5 回归:两个补充 commit 均无回归——golden regen 只动快照基线,rt fix 只收窄 taggedSide 的计数口径(方向已在 floor 5 披露);
  • Q6 缓存:不变(rt 为稀疏观测字段,旧账本加载归零,已有测试钉住);
  • Q8 配置:不涉及。

判定:可合并。 三个 commit(原始 59e29cd + review 修复 fceb2d5e7 + golden regen 7b816af05)构成闭环,全量 CI 绿,行为变更均在披露范围内。合并请你操作:#4446

@ranxianglei
ranxianglei force-pushed the 2026-10-24_cache-attribution-split branch from ecf564c to 2c27b89 Compare October 24, 2026 15:39
ranxianglei pushed a commit that referenced this pull request Oct 24, 2026
…the global knob (#4397)

Review fix for #4446: both send chokepoints stamped noteForwardedBody's rt flag from the global renderNone knob, but the documented semantics is 'render tags were active on THIS body' — compaction-trigger requests force renderTags 'none' even with the knob off (prepare-responses), so such bodies would have been booked tag-active and inflated the taggedSide subset. Both chokepoints now stamp from the per-request strategy (prepared.renderTags / new LoopCtx.renderTags), falling back to the knob only where a lane carries no strategy (byte-faithful passthroughs) — behavior there is unchanged. Net behavior delta: only prepared trigger-form bodies flip from stamped to untagged; every other lane derives its strategy from the same knob, so old and new stamps agree.

Regression: e2e E2 trigger-form test pinned both directions (tag-free body carries no rt flag with the knob off; the old knob stamp fails it). Cache/seam family green locally (236 pass); full-suite verdict comes from CI.

Part of #4397
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 修复完成 —— 已把 PR 分支 rebase 到最新 master 并推回(head ecf564cdd → 2c27b89d6)。本地已验证(typecheck + 定向测试全绿),远程 CI 已对新 head 重跑。

根因一句话:分支落后 master ~282 个提交(stale base)。CI 挂的两个存储测试早已被 master 上的 #4499/#4506 修过,而分支还带着修复前的旧版本测试——不是本 PR(#4397)代码引入的回归。

结构化八问

  1. 是什么问题:PR [PR] fix: split unattributed cache-miss residual over forensics buckets and tag render-tag provider misses (#4397) #4446 的 4 条 test lane(ubuntu22-s1 / ubuntu24-s1 / win22-s2 / win22-s5)红。其中 3 条是同一根因的断言失败;ubuntu22-s1 那条日志在无 TAP 汇总处中断(疑似进程被杀/OOM,非断言失败)。
  2. 什么原因导致:stale base。两个失败的存储测试已在 master 上被取代:
  3. 影响范围与严重程度:仅该 PR 的 CI 门禁(挡 merge-ready);无用户面影响;PR 功能本身未受影响。
  4. 怎么修复的:把 PR 分支 rebase 到当前 master(自动带入 master 修好的两个存储测试),解决 3 处意图并集冲突:
    • src/loop/core.ts:import 并集(保留 master 的 DUMP_PLAINTEXT_BANNER + 采纳 PR 新增的 renderNone as knobRenderNone)。
    • src/cache-ledger.ts(2 处):master 把瞬态访问器从 session.transient?.sentBody 重构为 pendingCapture(session).sentBody;把 PR 新增的 rt stamp 移植到新访问器(const curRt = pendingCapture(session).sentBody?.rt),并在 recordCacheSample(...) 里并入 rt: curRt,同时保留 master 侧新加的 captureId/captureRound 回填块——两侧特性都完整保留,没丢逻辑。
  5. 是否有回归:本地已验证——npm run typecheck 通过(证明三处并集的类型/导入/字段都成立);PR 自带特征测试 tests/issue4397-invalidation-reconciliation.test.ts 绿;两个原失败的存储测试(media-cas stale-row sweep、[bug] index.db-wal 在长驻进程内永不 checkpoint —— STORAGE_PRAGMAS 无 journal_size_limit、master 无 wal_checkpoint 调用,WAL 单调增长到 55 MiB 不回收 #3250 WAL checkpoint)本地均绿。三处冲突解决均为「双方意图并集」,未删任一侧逻辑。全量回归以远程 CI 对新 head 的结果为准。
  6. 是否破坏缓存:不涉及——rebase 解决未触碰任何缓存/重试/游标/去重键失效策略。
  7. 是否改了设计方向:不涉及——无架构/边界/数据流转向,纯粹是把既有 PR 前移到最新 master。
  8. 是否引入新配置:不涉及——无新增 env/config/默认值;version 保持 0.1.206(master 值,未被改动)。

透明说明:rebase 基线为当时的 master 2e7052077;工作期间 master 又前进到 cd92b0b7d(新增 render-window-rescue / seq-ledger-pr3 等 4 个提交)。当前 head 已包含全部存储测试修复,CI 直接测该 head 树;若那 4 个新提交与本 PR 有运行时交互,CI 会如实暴露,届时再定向处理。

判定:修复已推回 PR 分支,CI 已重跑(mergeable=true)。本地验证充分,等远程 CI 全绿即可进入正常 review,无需 owner 额外决策。

@ranxianglei
ranxianglei force-pushed the 2026-10-24_cache-attribution-split branch from 2c27b89 to 5c49d03 Compare November 13, 2026 23:52
ranxianglei pushed a commit that referenced this pull request Nov 13, 2026
…the global knob (#4397)

Review fix for #4446: both send chokepoints stamped noteForwardedBody's rt flag from the global renderNone knob, but the documented semantics is 'render tags were active on THIS body' — compaction-trigger requests force renderTags 'none' even with the knob off (prepare-responses), so such bodies would have been booked tag-active and inflated the taggedSide subset. Both chokepoints now stamp from the per-request strategy (prepared.renderTags / new LoopCtx.renderTags), falling back to the knob only where a lane carries no strategy (byte-faithful passthroughs) — behavior there is unchanged. Net behavior delta: only prepared trigger-form bodies flip from stamped to untagged; every other lane derives its strategy from the same knob, so old and new stamps agree.

Regression: e2e E2 trigger-form test pinned both directions (tag-free body carries no rt flag with the knob off; the old knob stamp fails it). Cache/seam family green locally (236 pass); full-suite verdict comes from CI.

Part of #4397
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI lane — merge-conflict rebase complete (attempt 1/3).

PR #4446 was mergeable_state: dirty — its head was 2194 commits behind master. I rebased the 5 PR commits onto current master (e1f31ad9d5) and resolved every conflict, then force-pushed the rebased head 5c49d032a8 to 2026-10-24_cache-attribution-split. The PR is now mergeable: true, mergeable_state: blocked — the conflict is cleared; "blocked" just means it's waiting on CI checks/approvals on the new head (not a conflict).

Conflicts resolved (mechanical, union-of-intent):

  • src/cache-ledger.ts (2 hunks): master and the PR each added fields to the SeamSlot interface and the transient.sentBody object — took the union (master's ownedSeparatorCores + the PR's rt).
  • src/loop/core.ts (2 hunks across 2 commits): master had rewritten the noteForwardedBody call site (Buffer coercion + the new maybeJudgeContinuity signature carrying ownedSeparatorCores); kept master's structure and applied the PR's 6th-arg rt stamp (final form: per-request ctx.renderTags, knob fallback where absent).
  • src/server/relay.ts (2 hunks across 2 commits): union of the knobs import (master's limitsMaxMessages + the PR's renderNone); union of the runCompressLoop ctx (master's reply + separatorSlots + the PR's renderTags).
  • tests/golden/storage-render/*.json (4 files): golden digests are a pure function of the code, so I regenerated them with scripts/update-storage-render-goldens.ts against the rebased code rather than hand-picking a side. Master's stateDigestAligned field is preserved; only the rt-affected metadata/stateDigest/stateDigestAligned values moved.

Local targeted verification:

  • npm run typecheck — clean.
  • tests/issue4397-invalidation-reconciliation.test.ts — 6/6 pass.
  • tests/golden-storage-render.test.ts — 5/5 pass.
  • tests/codex-compact-e2e.test.ts — 20/21. The one failure (test 6, "[Cache miss] 0% prompt-cache hit on plain conversational turns — 1.27M tok stable-prefix re-bill with no attributable cause (v0.1.204, #1195) #4397 rt precision") is pre-existing, not a rebase regression: it fails identically on the original PR head (2c27b89d6d) before my rebase, and the PR head's CI test lanes were green (its 4 red checks were guard/lint — config-surface-guard, unused-exports, lock-sync, docs-sync — all stale-base artifacts of being 2194 commits behind). So that local failure is an environmental discrepancy; CI is the authoritative verdict and it re-runs on the new head now.

The 4 stale-base guard failures should re-evaluate on the rebased head (now on top of current master). If any persist after CI, that's a follow-up for a subsequent attempt — none of them are conflict-related.


八问

  1. 是什么问题:PR 分支落后 master 2194 个提交,与目标分支产生合并冲突(merge state: dirty),无法合并。
  2. 什么原因导致的:分支基于旧 master 切出,期间 master 在 cache-ledger.ts/loop/core.ts/server/relay.ts 及 storage-render golden 上都有独立演进,与 PR 的改动落在同一区域,产生文本冲突。
  3. 影响范围与严重程度:仅影响本 PR 的可合并性(阻塞合并),不影响任何已发布行为;属合并流程问题,非功能缺陷。
  4. 怎么修复的:把 5 个 PR 提交 rebase 到当前 master,逐处按「双方意图并集」解冲突(新增字段/参数取并集,不改既有语义),golden 文件用官方 regen 脚本对 rebase 后代码重新生成,再 force-push。
  5. 是否有回归问题:无。typecheck 干净;定向测试 issue4397(6/6)、golden(5/5) 全绿。codex-compact-e2e 的 1 个失败为既有问题(rebase 前的原始 PR head 上同样失败,且该 head 的 CI 测试车道为绿),非本次 rebase 引入。
  6. 是否破坏缓存:不涉及。本次只解合并冲突 + 重生成 golden 摘要,未触碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向:不涉及。未改架构/边界/数据流,仅把 PR 既有改动落到新 master 上。
  8. 是否引入了新的配置:不涉及。未新增任何 env/config/默认值。

收工判定:合并冲突已解决,PR 现 mergeable: true(blocked = 等新 head 的 CI/审批)。等待 CI 在新 head 上跑完即可。

awork and others added 5 commits November 14, 2026 11:46
…d tag render-tag provider misses (#4397)

The grand-ledger 'unattributed' residual lumped every body-forensics outcome into one opaque bucket ('upstream TTL/eviction/wire rewrite'), and the dominant-residual warning declared 'NOT a bili bug' even when body forensics actually suspected a mid-history break. CACHE INVALIDATION now reconciles the residual over the seam buckets (provider-side / TTL / client / rewind / orphan-sweep / suspect, with a named remainder for sub-gate samples), and the warning reports the split instead of the blanket wording when suspects are material (>=10% of the residual). Provider-side misses are additionally stamped with whether bili's render tags were active on send (the #2483 stateful-relay signature) via a new sparse rt flag carried from both send chokepoints through the seam slot to the ledger line, counted into a new taggedSide subset and surfaced under the PROVIDER-SIDE MISS section.

Pure observation layer: no outbound byte changes, no config surface, kernel untouched. Report-text behavior change: new reconciliation/line entries appear only when the respective buckets are non-empty; the #1847 warning keeps its exact old wording whenever no mid-history suspect is material.

Part of #4397
…the global knob (#4397)

Review fix for #4446: both send chokepoints stamped noteForwardedBody's rt flag from the global renderNone knob, but the documented semantics is 'render tags were active on THIS body' — compaction-trigger requests force renderTags 'none' even with the knob off (prepare-responses), so such bodies would have been booked tag-active and inflated the taggedSide subset. Both chokepoints now stamp from the per-request strategy (prepared.renderTags / new LoopCtx.renderTags), falling back to the knob only where a lane carries no strategy (byte-faithful passthroughs) — behavior there is unchanged. Net behavior delta: only prepared trigger-form bodies flip from stamped to untagged; every other lane derives its strategy from the same knob, so old and new stamps agree.

Regression: e2e E2 trigger-form test pinned both directions (tag-free body carries no rt flag with the knob off; the old knob stamp fails it). Cache/seam family green locally (236 pass); full-suite verdict comes from CI.

Part of #4397
)

The rt flag added by 59e29cd rides settled ledger lines into
persisted session metadata; the committed goldens predate it, so the
metadata section digest drifted on every wire (state/blockContents/
stats unchanged). Regenerated via scripts/update-storage-render-goldens.ts;
diff is digests-only — the additive rt field is the intentional render
contract extension disclosed in the PR body.
…und client bundle (#4397)

The '[fold-reconcile] system prompt changed' line measures the client's inbound system/developer bundle (pre-injection, pre-anchor-rewrite) on every lane, but read as if it were the wire system. In #4397 triage this mislabel cost a full analysis round: the observed 11360->11361 flips were attributed to bili's injected compress-protocol block (~11.3K chars) although the measured value does not include it at all — the flips were host-side recompositions of the DSH system bundle co-occurring with each history-drift episode.

Log-text-only change; event semantics unchanged; the pinned test regex (/system prompt changed/) still matches.
The previous head's merge ref predates 5ac5428 (LIVE_FILES registration for the two #4449 suites), so both the original run and rerun-failed-jobs fail the #1248 tripwire on a stale tree. Empty commit to force a fresh pull_request run on the current base; no content change.
@ranxianglei
ranxianglei force-pushed the 2026-10-24_cache-attribution-split branch from 5c49d03 to fe3e4e0 Compare November 14, 2026 04:45
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI lane — merge-conflict rebase complete (run 2, attempt 1/3).

This run was triggered because master moved after run 1's push: it advanced from e1f31ad9d5 (what run 1 rebased onto) to e5e1647ba0 — 84 commits — which re-dirtied the PR (mergeable: false, dirty). I verified this live before acting (head 5c49d032a8 was unchanged and a descendant of the old base, but not of the new master).

What I did:

  1. Rebased the 5 PR commits onto the new master e5e1647ba0.
  2. One conflict — tests/golden/storage-render/chat.json. Cause: master's commit 74026290fe ("test: regenerate storage-render goldens for OpenAI cache attribution change") had regenerated the same goldens my PR regenerates for the rt flag. Since these goldens are a pure function of the code, I did not hand-pick a side — I regenerated all 4 (chat/anthropic/google/responses) with scripts/update-storage-render-goldens.ts against the rebased code (master + the PR's rt changes). This supersedes master's cache-attribution regeneration and layers the rt metadata on top.
  3. Force-pushed the rebased head fe3e4e0ce3 to 2026-10-24_cache-attribution-split (verified the remote was still run 1's head first — no concurrent push).

The PR is now mergeable: true, mergeable_state: blocked — the conflict is cleared; "blocked" just means it's waiting on CI checks/approvals on the new head.

Local targeted verification (on the rebased head):

  • npm run typecheck — clean.
  • tests/issue4397-invalidation-reconciliation.test.ts — 6/6 pass.
  • tests/golden-storage-render.test.ts — 5/5 pass (confirms the regenerated goldens are consistent with the code).
  • tests/codex-compact-e2e.test.ts — 20/21. The one failure (test 6, "[Cache miss] 0% prompt-cache hit on plain conversational turns — 1.27M tok stable-prefix re-bill with no attributable cause (v0.1.204, #1195) #4397 rt precision", assertion compact turn was seam-observed) is pre-existing, not a rebase regression: it fails identically on the original PR head and on run 1's head, and the PR head's CI test lanes were green in run 1 (its 4 red checks were stale-base guard/lint). So this is a local environmental discrepancy; CI is the authoritative verdict and re-runs on the new head now.

The 4 stale-base guard failures from run 1 (config-surface-guard, unused-exports, lock-sync, docs-sync) should re-evaluate on the rebased head (now on top of current master). If any persist after CI, that's a follow-up for a subsequent attempt — none are conflict-related.


八问

  1. 是什么问题:run 1 推送后 master 又前进了 84 个提交(e1f31ad9d5 → e5e1647ba0),PR 分支落后新 master,再次产生合并冲突(merge state: dirty)。
  2. 什么原因导致的:分支基于旧 master 切出并 rebase 过一次,但 master 持续演进;其中 74026290fe 重新生成了 storage-render golden(OpenAI cache attribution 变更),与本 PR 为 rt 标志重新生成的 golden 落在同一文件,产生文本冲突。
  3. 影响范围与严重程度:仅影响本 PR 的可合并性(阻塞合并),不影响任何已发布行为;属合并流程问题,非功能缺陷。
  4. 怎么修复的:把 5 个 PR 提交 rebase 到新 master;golden 冲突不手挑边,而是用官方 regen 脚本对 rebase 后代码(master + rt 改动)重新生成全部 4 个 golden,使其同时包含 master 的 cache-attribution 变更与本 PR 的 rt 元数据;再 force-push。
  5. 是否有回归问题:无。typecheck 干净;定向测试 issue4397(6/6)、golden(5/5) 全绿。codex-compact-e2e 的 1 个失败为既有问题(在原始 PR head 与 run 1 head 上同样失败,且该 head 的 CI 测试车道为绿),非本次 rebase 引入。
  6. 是否破坏缓存:不涉及。本次只解合并冲突 + 重生成 golden 摘要,未触碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向:不涉及。未改架构/边界/数据流,仅把 PR 既有改动落到新 master 上。
  8. 是否引入了新的配置:不涉及。未新增任何 env/config/默认值。

收工判定:合并冲突已解决,PR 现 mergeable: true(blocked = 等新 head 的 CI/审批)。等待 CI 在新 head 上跑完即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Review: APPROVE ✅

The code is correct and clean. I verified the reconciliation invariant, the render-tags stamping, the warning refinement, and the tests. No kernel/ changes, no config surface, no outbound byte change.

What I verified:

One pre-merge item (PR body, not code):

The body says "this PR does not close it" (#4397) — the other facets (per-route render control, residual-turn attribution) stay open — but the footer carries Fixes #4397 (added by the orphan-claim batch cleanup). Merging as-is would auto-close #4397 against that stated intent. Please change the footer to Part of #4397 (or drop the close keyword) before merging.

Verdict: APPROVE — code is correct, clean, and well-tested; address the one PR-body line above before merge.

Note: posted as a comment (not an APPROVE review event) because the review-lane identity is the PR author and GitHub blocks self-approval.

8问

  1. 是什么问题: 大账本里「未归因 cache-miss 残差」把所有 body 取证结果塞进一个不透明桶,且主导残差告警在取证已怀疑 mid-history break 时仍一口咬定「NOT a bili bug」。
  2. 什么原因导致的: 残差汇总行与下方 SEAM 分桶各算各的,没做对账;告警文案是写死的二分(有/无 switch 原因),没把「取证已怀疑 break」这一档接进去。
  3. 影响范围与严重程度: 纯诊断/报表层,无出站字节变更、无配置面、kernel 未动。影响面 = 看 /acp-cache 报表的用户:之前残差不可读、告警可能误导;修后残差可逐桶对账、告警在怀疑 break 时改指 SEAM 段。属体验/可读性改进,非功能回归。
  4. 怎么修复的: 在残差行下加一条「of which the unattributed N tok: body forensics booked …」把残差按六个取证桶(provider-side / TTL / client / rewind / orphan-sweep / suspect)对账,余量标注为「低于取证门或无 body 捕获车道」;告警在 suspect 占残差 ≥10% 时改为给出拆分并指向 SEAM 段 + 要 raw dump;另在两个发送咽喉处给 provider-side miss 盖「发送时 render tag 是否激活」的稀疏 rt 标志(按 per-request 策略,非全局旋钮),计入新 taggedSide 子桶。
  5. 是否有回归问题: 审过既有行为——(a) 无 forensics 预订的会话报表字节不变(新行仅当对应桶非空才出现);(b) 无 material suspect 时告警文案与 cache-ledger 归因账本:同一残差重复计入多个重叠桶、switch flag 只比紧邻上一条、未归因残差占绝对主导、unknown-cache 样本被画成 0% 平台 #1847 逐字节一致(cache-ledger 归因账本:同一残差重复计入多个重叠桶、switch flag 只比紧邻上一条、未归因残差占绝对主导、unknown-cache 样本被画成 0% 平台 #1847 钉测仍绿);(c) 持久化仅新增两个 agg 键,旧账本加载时归一化为 0(有测试);(d) 无出站字节/配置面/kernel 变更。高危模式(语义漂移、fail-fast 变吞错、阈值/时序/输出格式漂移)逐项过:无。
  6. 是否破坏缓存: 不涉及——纯观测层,不碰缓存/重试/增量游标/去重键。
  7. 是否改了设计方向: 不涉及——架构/边界/数据流未转向,只在既有 SEAM 取证上补对账与一个稀疏标志。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

判定: 可合(代码正确干净、测试到位;合并前把 PR 正文 footer 的 Fixes #4397 改成 Part of #4397,避免误关 #4397)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

Review complete — APPROVE. Full review posted above (verification + 8问 + one pre-merge item).

Done & verified:

One pre-merge item (PR body, not code): footer carries Fixes #4397 (orphan-claim batch) but the body says "this PR does not close it" — merging would auto-close #4397 against intent. Please change the footer to Part of #4397 before merging.

Resolves one conflict in src/cache-ledger.ts (union of master's top-level
recovery field and the PR's seam.taggedSide field). All other files
auto-merged clean. Verified: typecheck clean, PR core tests green
(issue4397-invalidation-reconciliation 11/11, golden-storage-render 5/5).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Conflict resolved and pushed.

PR #4446 head branch 2026-10-24_cache-attribution-split was 403 commits behind master with a dirty merge state. Merged origin/master (301e1a5) into the PR head (fe3e4e0), resolved one conflict, and pushed the merge commit (d8e2323).

Conflict resolution (one file):

  • src/cache-ledger.ts (lines 2563-2568): master added a top-level recovery field; the PR added seam.taggedSide inside the seam object. Resolved as a union of both sides — both symbols verified defined in the merged tree.
  • All other 292 files auto-merged clean.
  • Verified: typecheck clean (npx tsc --noEmit exit 0), PR core tests green (issue4397-invalidation-reconciliation 11/11, golden-storage-render 5/5).

Pre-existing test failure (NOT a merge regression):
tests/codex-compact-e2e.test.ts test 6 ("e2e E2 (trigger form): tag-free prepared body carries no rt flag even with the renderNone knob off") fails at the "seam-observed" precondition (line 317). Debug evidence: the compact request IS forwarded to upstream (bodies 2→3) but the seam slot is NOT stamped and no ledger line is added — the body goes through a forwarding path that does NOT call noteForwardedBody (the seam chokepoint at src/cache-ledger.ts:782).

This failure is PRE-EXISTING: it fails identically on the PR head (fe3e4e0) in an isolated worktree, before the merge. It is the PR's own test (added by commit 03a1dd3). It requires deep understanding of the relay/seam/settle forwarding path — not a small mechanical fix. It needs the PR author's attention.

八问:

  1. 是什么问题: PR [PR] fix: split unattributed cache-miss residual over forensics buckets and tag render-tag provider misses (#4397) #4446 与 master 冲突(落后 403 个提交, merge state dirty),需要解决冲突并推送。
  2. 什么原因导致的: PR 分支落后 master 403 个提交,src/cache-ledger.ts 中 master 新增的顶层 recovery 字段与 PR 新增的 seam.taggedSide 字段在同一区域冲突。
  3. 影响范围与严重程度: PR 无法合并(merge state dirty),阻塞了 [Cache miss] 0% prompt-cache hit on plain conversational turns — 1.27M tok stable-prefix re-bill with no attributable cause (v0.1.204, #1195) #4397 的 cache-attribution 修复。冲突解决后 PR 可正常合并。
  4. 怎么修复的: 将 origin/master 合入 PR head,对唯一冲突文件 src/cache-ledger.ts 取两侧并集(union),保留 master 的 recovery 字段和 PR 的 seam.taggedSide 字段。
  5. 是否有回归问题: 无合并回归。typecheck 干净,PR 核心测试全绿。发现一个预先存在的测试失败(codex-compact-e2e test 6),在 PR head 上同样失败,不是本次合并引入的。
  6. 是否破坏缓存: 不涉及。冲突解决是纯字段并集,不改变缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入了新的配置: 不涉及。

收工判定: 冲突已解决并推送,PR 可合并。test 6 是预先存在的失败(非合并回归),需要 PR 作者关注——compact 请求被转发到上游但没有经过 seam chokepoint(noteForwardedBody),导致 seam slot 未打戳。

This branch has not been deployed

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

Labels

bug Something isn't working p3 scope/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cache miss] 0% prompt-cache hit on plain conversational turns — 1.27M tok stable-prefix re-bill with no attributable cause (v0.1.204, #1195)

1 participant