Skip to content

[PR] fix: classify marker-migrated tail appends as append, not mid-history rewrite (#4133) - #4139

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_cache-seam-cc-marker
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_cache-seam-cc-marker

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4133

What was wrong

Client-managed rolling cache_control breakpoints (dsh profile web / Claude Code style: the ephemeral mark moves onto the newest message every turn) mutate the PREVIOUS last message's bytes on every pure tail append — the mark leaves it. Raw byte LCP therefore stops inside that message, before its array close bracket, and both diagnostic surfaces misread the pair as a mid-history rewrite:

The upstream wire is stable (isolation experiments in #4133: pure append / stripped markers / migrated markers all hold ~99.7% hit rate). This is an observation/classification defect only — no wire change, no cache impact. bili's own cumulative marking (#1637) never produces this; only client-managed rolling marks do.

How it is fixed

Both surfaces now judge survival modulo cache_control migration:

  • new eqModCacheControl: deep element equality ignoring cache_control keys at any depth (key order stays significant, parity with the existing JSON.stringify comparators);
  • the body-stability ladder gains a gated would-be-"mid" rescue: only when append/head/tail all failed are both full bodies parsed and the shared message prefix compared cc-blind — all shared elements equal ⇒ append, not mid. Healthy pairs never pay for the parse;
  • seamLcp reports a cc-blind twin index msgIndexCc (extra pass bounded by the trailing cc-only-differing elements; zero work when strict equality held), and the [obs] detectSeam: tail-append turns are misattributed as local prefix breaks (msgIndex == prevMsgs is already computed but unused) #2059 arm uses it.

Real content rewrites keep their flags — a content change at any shared index fails the cc-blind comparison exactly as before (negative-control tests pin both directions).

Behavior changes (disclosed)

Surface Old New
/acp-cache + report stability.mid / line bs marker-migrated pure tail appends counted as mid-history rewrites (⚠ "real prefix rewrites") counted under tail-append (bs="append")
detectSeam attribution such pairs with a big unexplained miss booked as seam suspects (+ first-occurrence warn log) booked provider-side (ttl/side), same as clean appends since #2059
seam event payload msgIndex only additive msgIndexCc field (strict vs cc-blind divergence index)

No change to: wire bytes, compression behavior, fold/switch/restart/rewind/client attribution arms, thresholds (±64 / 1 KiB / arrClose), or any other class's reach into pairs that were already classified correctly — the rescue only runs where the old code said "mid".

Tests

New tests/issue4133-cache-seam-cc-marker.test.ts (5 tests): rolling-mark append → append (was mid); marker reshuffle without growth → append; REAL mid rewrite ± marker migration → still mid/still seam-suspect (negative controls); detectSeam provider-side vs seam-suspect split. Negative control verified against pre-fix code: 4/5 fail there (the 5th is the over-correction guard).

Local targeted suites green: new file + cache-seam-detector, cache-seam-client-insert, cache-ledger, issue2868-byte-lcp-utf8, issue2131-seam-capped-body-attribution, compress-observability, issue1547-nonstream-cache-ledger, cache-ledger-{effort,key,prompt,projection}-switch — 137 pass / 0 fail. Typecheck + build clean. Full-suite verdict: CI on this head.

… rewrite (#4133)

Client-managed rolling cache_control breakpoints (dsh / Claude Code style)
move the ephemeral mark onto the newest message every turn, mutating the
previous last message's bytes on every pure tail append. Raw byte LCP stops
inside that message, before its array close bracket, so both diagnostic
surfaces misread the pair as a mid-history rewrite:

- the per-call body-stability ladder classes it "mid" (247/287 requests in
  the #4128 session);
- detectSeam's #2059 tail-append arm sees msgIndex == prevMsgs-1 instead of
  prevMsgs and books a seam suspect on top of a big unexplained miss.

Both surfaces now judge survival modulo cache_control migration: the ladder
gains a gated would-be-"mid" rescue (shared message prefix compared with
cache_control keys ignored at any depth) and seamLcp reports a cc-blind twin
index (msgIndexCc) that the #2059 arm uses. Real content rewrites keep their
flags (negative-control tests pin both directions).
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_cache-seam-cc-marker (ded3b96)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4929-pr.4139.e1cdda8

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: classify marker-migrated tail appends as append, not mid-history rewrite (#4133) [PR] fix: classify marker-migrated tail appends as append, not mid-history rewrite (#4133) Oct 21, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 按失败签名(bodyClass="mid" / seam suspect / cache_control 迁移 / tail-append 误判)检索 open+closed PR:无并行修复。相关但不同机制:#3479(同一分类阶梯上的「in-unit growth」问题,#3476)、#2061(已合入的 #2059 provider-side 臂——本 PR 扩展的正是这条臂)。#4133 接单时已查重无立项。

开始独立审核(diff 已拉取:单 commit ded3b96a2,2 文件 +245/-33;CI guard 类全绿、6 个 test shard 在跑)。按规范走方向关→回归清点→代码/测试有效性→定向本地验证,结论稍后以八问形式给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

标签: bug / dsh / scope/ui / p2(诊断分类缺陷,dsh profile web 滚动断点场景,仅观察面,与 #4133 定级一致)

Review 结论(head ded3b96a2,独立审核,不复述 PR 描述)

⓪/① 方向关:#4133 要修的是「客户端滚动 cache_control 断点导致的纯尾追加被两个诊断面误判为 mid-history rewrite」。我独立验证了方向:根因在判定口径(两处以原始字节 LCP / 严格元素相等作为「前缀存活」的唯一判据,未把合法的 cc 迁移当作等价),修复打在判定层而非在传输路径上过滤/改写 payload——litmus test 通过:同一根因换个标记形态再现时,cc-blind 比较依然成立。不是治标。

八问:

  1. 是什么问题:客户端自管滚动 cache_control(dsh profile web / Claude Code 式)每轮把 ephemeral mark 挪到最新消息上,纯尾追加时上一条末消息的字节必然被改写(mark 离开)。body-stability ladder 的原始字节 LCP 停在那条消息内部(数组右括号之前)→ 落 would-be-mid 分支记 bs="mid"([Bug] anthropic lane: cache-hit % halved when the upstream relays an OpenAI-semantics backend (billing_usage.semantic=openai, input_tokens inclusive) #4128 会话 247/287);detectSeam [obs] detectSeam: tail-append turns are misattributed as local prefix breaks (msgIndex == prevMsgs is already computed but unused) #2059 arm 看到 msgIndex == prevMsgs-1 而非 prevMsgs → 伴大 miss 时再记 seam suspect。上游 wire 实际稳定(cache-seam: pure tail-append misclassified as mid-history rewrite (cache_control marker migration breaks byte-LCP) #4133 隔离实验三组均 ~99.7% 命中)。纯观察误分类。
  2. 什么原因导致:判定口径缺 modulo-cache_control 维度——cc 迁移是客户端合法行为,但被判据读成了内容改写。因果链:滚动 mark → 末消息字节变 → 字节 LCP/严格比较提前停 → 两个面各自误分类。
  3. 影响范围与严重程度:仅使用客户端自管滚动断点的会话的诊断读数;wire 字节、压缩行为、真实命中率零影响。严重度:诊断噪音/误报(单会话 86% 请求被标成 mid + 虚假 seam suspect),无可用性影响。
  4. 怎么修复的:两个面统一改为「modulo cc 迁移」判存活。ladder:新增 gated rescue——append/head/tail 全失败才解析双 full body、cc-blind 比较共享消息前缀,全等 ⇒ append(健康对不付解析成本);seamLcp:新增 msgIndexCc 孪生索引(从严格 i 起第二遍,cc-blind 弱于严格 ⇒ msgIndexCc ≥ msgIndex 恒成立,严格相等时零额外工作),[obs] detectSeam: tail-append turns are misattributed as local prefix breaks (msgIndex == prevMsgs is already computed but unused) #2059 arm 改用之。
  5. 是否有回归问题(逐项清点既有行为):
  6. 是否破坏缓存:否。wire 不变、压缩/fold/reconcile 不变,provider prefix cache 与 bili 存储策略零接触;效果是让诊断信号更准(减少假 mid/假 seam suspect)。
  7. 是否改了设计方向:否。架构/边界/数据流不变,只给既有观察面补一个判定维度。
  8. 是否引入新配置:否。无新 env/config/默认值。

行为变更(旧→新,PR 已披露,我核实无误):① /acp-cache report stability.mid/⚠"real prefix rewrites" 行:marker-migrated 纯尾追加从计 mid-history rewrite 改为计 tail-append(bs="append")——原因:这些对的 wire 前缀实际稳定,旧类是误读;② detectSeam:此类对伴大 miss 从 seam suspect(+首次 warn log)改为 provider-side(ttl/side),与 #2059 以来 clean append 一致;③ seam event payload additive msgIndexCc。其余类别(fold/switch/restart/rewind/client/orphan-sweep)对原本就分对的 pair 无任何触及。

测试有效性(④):tests/issue4133-cache-seam-cc-marker.test.ts 5 个用例走真实 settle/detectSeam 入口、断言有牙。我独立跑了负控制:把该文件放到 pre-fix master 代码上执行,4/5 红(t1 rolling-mark append 得 mid、t2 reshuffle 得 mid、t4 被记 seamSuspects、t5 msgIndexCc undefined),t3(真 mid rewrite ± marker 迁移仍 mid/still suspect)绿——与 PR 声明逐字一致,bug 回归必被抓;t3 正是防过矫 guard。无需 e2e:本改动无 wire 变化,单元级经真实入口已钉住行为。

diff 整洁度与代码质量(⑤/⑤b):单 commit、2 文件(+245/-33),每行都服务于本目的(helper + 两处调用点 + 接口字段 + 注释 + 测试),无跑题、无 whitespace churn。命名达意(eqModCacheControl/ccBlindSharedPrefix/msgIndexCc)、无死代码、错误处理完整(JSON.parse 失败保守返回 false 且有注释说明为何保守)、无魔法数字(复用既有阈值常量)、注释讲 why(引 #4133/#2059/#2339 背景)、风格与文件既有一致、无新依赖。

验证证据:

  • 本地定向(PR head):149 pass / 0 fail——PR 清单超集(另加 cache-seam-fuzz/probes、abort-rewind-cache-seam、responses-fold/refold-cache-seam、issue2131-body-stability-visibility);typecheck clean;build 由 CI build-artifact job 覆盖(success)
  • CI(ded3b96a2)全绿:6/6 test shards(ubuntu/windows × node 22/24 × 3 balanced shards)+ 全部 guard jobs(kernel-guard / version-guard / config-surface-guard / lane-guard / static-gates ubuntu+windows 等)success
  • 负控制:pre-fix master 上新测试 4/5 红(见上)

判定:可合并。方向对(修判定口径这一根因)、回归清点干净、测试有牙且负控制实证、CI 全绿。请自行合并:#4139

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 dsh p2 scope/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache-seam: pure tail-append misclassified as mid-history rewrite (cache_control marker migration breaks byte-LCP)

1 participant