Skip to content

[PR] fix: reject signature-only non-local snapshot-render seams that truncate recent history (#5632) - #5639

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-04_snapshot-seam-sig-depth-gate
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-04_snapshot-seam-sig-depth-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What / Why

buildView 的 seam 对齐(snapshot-render D 车道出站前缀渲染的核心)用 MIN_SEAM_RUN = 2 作门槛,但回溯链的 run++ 对 byId 快路径 和 identity-signature 回退 两类命中都计数。于是两条相邻 uncovered 旧行的字节级孪生体(宿主重铸了 id → byId 必 miss、走 bySig)落在深位时刚好凑满 run=2,join 被钉在深位,join 之上的所有更新行被静默丢弃——出站 wire 上模型看到「远古前缀 + 重复旧消息」,丢失全部真正最近的历史。

#3812 只拦 run<2(单匹配)、#4052 只排除 covered 行绑定;两道门都不覆盖 run≥2 的纯签名深位双重复。

来源:分析 #5576(Native-Identity Fastpath)时发现。

Fix

给 run 记录「是否含 byId 锚点」(idAnchor)。新增一道深度门:当 seam 纯签名(run 内无任何 exact-id 单元格)且非局部(丢弃的行数 gapAbove > run)且 run < 3 时,降级到 legacy 直传。等价表述:签名-only seam 必须满足其一才允许丢弃历史——带 ≥1 个 exact-id 佐证 / join 贴近 transcript 尾(局部)/ run≥3。局部 seam 保持现状不变。

行为变更(old → new)

run=2 的纯签名 deep seam(丢弃行数 > run、无 id 佐证):

  • 旧:渲染出被截断的视图(丢失近期历史)。
  • 新:降级 legacy 直传(reason="seam-unverified-depth"),下一轮客户端重发即自愈。

这是本修复本身,不是副作用。凡 id 佐证 / 局部 / run≥3 的 seam,行为完全不变。

范围澄清(与 issue 原文的一处出入)

issue 原文说该 aligner 同时服务 D 车道与 #5576 的 v6 canonical watermark 车道。当前 master 中 #5576 已合入,fastpath.ts 改用独立机制(元素计数 T + ledger tail-id 宽度 + head 校验,见 fastpath-scan.ts),不再走 id/sig 回溯链——因此本缺陷只存在于 D 车道 buildView,v6 车道不受此门影响。修复范围就是 src/server/snapshot-render.ts 一处。(已 grep 确认 fastpath.ts/fastpath-scan.ts 无 run/consecutive/backward-chain 门。)

Tests

tests/snapshot-render-chain.test.ts 新增 4 例(#3617 正反成对,构成新门的完整真值表):

  1. 构造形状(纯签名深位双重复)→ 降级 seam-unverified-depth;
  2. 同形状但带一个 exact-id 佐证 → 正常渲染(id 锚点任意深度可信);
  3. run=2 纯签名局部 seam → 仍渲染(钉住局部 carve-out;若有人删掉门的 locality 条件会在此红);
  4. run=3 纯签名非局部 seam → 仍渲染(钉住「签名-only 阈值提到 3」语义)。

既有 #4052/#3812 用例全绿。本地定向跑(snapshot-render-chain / snapshot-render / snapshot-shadow 三文件共 27 pass)+ npm run typecheck 干净;全量回归以远程 CI test 车道为准。

Config surface

未新增任何 config / env / CLI 字段。

Closes #5632

…ry (#5632)

MIN_SEAM_RUN (=2) counted consecutive chain matches of EITHER class (byId fast path or identity-signature fallback). Two adjacent uncovered old rows whose byte-identical twins sit at the client tail boundary (host re-minted their ids => byId miss, bySig hit) therefore reached run=2 and pinned the join deep in the transcript -- silently dropping every genuinely-recent row above it from the outbound view.

Track whether the run carries an exact-id cell (idAnchor). A seam resting solely on signatures may not drop more transcript rows than it verified (gapAbove > run) unless it is id-anchored or reaches MIN_NONLOCAL_SIG_SEAM_RUN (=3). Local seams (join at/near the transcript end) keep today's behavior. Preserves #3812 (lone-match rejection, checked first) and #4052 (covered-row bind exclusion, untouched). Degrade instead of guess -- the safe direction.

Regression tests (both directions, #3617): the constructed shape degrades to legacy; an id-corroborated twin of the same shape renders; a local run=2 pure-sig seam still renders; a run=3 pure-sig non-local seam renders.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-04_snapshot-seam-sig-depth-gate (a7a6396)

Latest build — install this exact version

npm install -g billion-context@0.0.8075-pr.5639.4458dd1

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
a7a6396 billion-context@0.0.8075-pr.5639.4458dd1 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5639.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: reject signature-only non-local snapshot-render seams that truncate recent history (#5632) [PR] fix: reject signature-only non-local snapshot-render seams that truncate recent history (#5632) Nov 4, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。这是 #5632(分析 #5576 时发现)的修复 PR,给 snapshot-render D 车道补第三道 seam 门。与既有 #3812(单匹配拒绝)、#4052(covered 行绑定排除)同属一个门族但机制互补、不重叠:#3812 只拦 run<2、#4052 只排除 covered 绑定,二者都不覆盖「run≥2 的纯签名深位双重复」——本 PR 正是补这个缺口,不是重做已有工作。

标签: bug / scope/kernel / p2(保留原 pr)。理由:出站前缀渲染是 src 侧折叠感知渲染/压缩决策面→kernel;缺陷类;瞬时错误视图可自愈、非数据丢失/非缓存泄露→p2。

我拉了分支 2026-11-04_snapshot-seam-sig-depth-gate(head a7a6396)对 master 逐行核了 diff(仅 src/server/snapshot-render.ts +30/-1、tests/snapshot-render-chain.test.ts +71),并手工把 4 个新用例对着 buildView 回溯链逐格推演过,产物与断言完全一致;另 grep 确认 v6/fastpath 车道独立。本地未跑测试(工作区无 node_modules),执行以远程 CI 为准。

八问

  1. 是什么问题:D 车道出站前缀渲染的 seam 对齐用 MIN_SEAM_RUN=2 作门槛,但回溯链的 run++ 对 byId 快路径和 identity-signature 回退两类命中都计数。两条相邻 uncovered 旧行的字节级孪生体落在客户端尾边界(宿主重铸 id→byId miss→bySig hit)且处深位时,恰好凑满 run=2,join 被钉在深位,join 之上的所有更新行被静默丢弃——模型在 wire 上看到「远古前缀+重复旧消息」,丢失全部真正最近的历史。

  2. 什么原因导致:seam 门只校验了 run 长度(≥2),没校验命中证据的质量与深度——纯签名 run(无 exact-id 佐证)在非局部位置(丢弃的行数 > 验证的行数)被当成和 id 锚定/局部 run 同等可信。签名不带 id,两条相邻 uncovered 行的字节孪生体就能假链到深位旧行上。根因 = 门把「匹配了 2 格」误当「验证了一个合法 join」。

  3. 影响范围与严重程度:触发面窄——需宿主重铸 msgid 且两条相邻 uncovered 旧行的字节孪生体恰好落在尾边界的深位,是特定瞬时时形,非每轮每会话。p2:受影响轮次的出站视图静默丢近期历史(模型基于截断上下文可能困惑/重复动作),但存储/transcript 完好、下一轮客户端重发即自愈;非持久数据丢失、非缓存泄露、非完全不可用。

  4. 怎么修复:加一道按命中质量区分的深度门。回溯时记 idAnchor(run 内是否有任何一格来自 exact-id 快路径)。纯签名 seam(无 idAnchor)不得钉非局部 join(gapAbove > run),除非 run 达到 MIN_NONLOCAL_SIG_SEAM_RUN=3。等价表述:签名-only seam 要丢历史须满足其一——带 ≥1 exact-id 佐证 / join 局部(gapAbove<=run)/ run≥3。局部 seam 行为不变。失败方向安全:误判只会降级 legacy 直传(完整客户端视图逐字透传,无截断风险),绝不放大截断。净效应很窄:只有 run==2 的纯签名非局部 seam 被新降级(run≤1 已被 Snapshot rendering identity signature does not include message ID: duplicate short messages silently truncate history (m | 快照渲染身份签名不含消息 id:重复短消息会静默截断历史(开灰度前必须修) #3812 拦、run≥3 放行)。

  5. 回归审查(逐项过既有行为):

  6. 是否破坏缓存:否。降级方向走 legacy 直传完整客户端视图,正是前缀缓存稳定的 legacy 路径所为——不改写 cache ref、无 stale 渗漏、无只增不减。被降级的轮次只是暂时放弃 snapshot-render 的前缀缓存收益(性能代价,非缓存正确性破坏),下一轮自愈。

  7. 是否改设计方向:否。仅在既有 seam 对齐判定内多加一道保守门,沿用既定「degrade instead of guess」教义(Snapshot rendering identity signature does not include message ID: duplicate short messages silently truncate history (m | 快照渲染身份签名不含消息 id:重复短消息会静默截断历史(开灰度前必须修) #3812/Snapshot rendering: When the text of a new message is identical to that of an already-compressed message, the entire mes | 快照渲染:新消息与已压缩消息文本相同时被整条丢弃(模型看不见这条最新消息) #4052/MESSAGE-IDENTITY.md),架构/边界/数据流无转向。

  8. 是否引入新配置:否。仅模块常量 MIN_NONLOCAL_SIG_SEAM_RUN=3,无 env/config/CLI 字段。

测试有效性:4 个新例构成新门的完整真值表(#3617 正反成对)。手工推演确认:例 1 复现原 bug、pre-fix 会红(渲染截断而非降级)有牙;例 2/3/4 分别钉住 id 锚点任意深度可信 / locality carve-out / 阈值提到 3 的边界,防未来过紧或误删条件。

CI 状态(head a7a6396):static-gates(win+ubuntu)、mysql-contract 绿;全量 test 分片矩阵仍在跑(当前 0 失败)。diff 干净(每行都服务于本 PR 目的)。结论:代码审核通过,待 test 分片全绿即可合——分片落地后我再回一条终态确认。

@ranxianglei ranxianglei added bug Something isn't working p2 scope/kernel labels Nov 4, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

APPROVE — 修到根因、失败方向安全、测试有牙、行为变更已披露。逐行读完 diff、手推四个新用例的判决表、grep 验证范围声明、本地定向验证(三个 render 测试文件 27/27 通过、typecheck 干净)后,无阻塞项。

结构化八问

  1. 是什么问题:快照渲染车道里,客户端重发历史时服务端靠「从尾部向前逐格匹配」定位接合点。原规则只看「连续匹配 ≥2 格」,不分匹配质量——若两行相邻的旧行恰好在客户端历史尾部有字节相同的孪生消息(且宿主重新铸过 id,id 对不上只能靠内容签名命中),接合点会被钉到深处,它上面所有真正新的行被静默裁掉,模型看到的是「远古前缀 + 重复旧消息」。
  2. 什么原因导致的:连续计数 run 把精确 id 命中与内容签名命中同等累计;Snapshot rendering identity signature does not include message ID: duplicate short messages silently truncate history (m | 快照渲染身份签名不含消息 id:重复短消息会静默截断历史(开灰度前必须修) #3812 只拦 run<2,Snapshot rendering: When the text of a new message is identical to that of an already-compressed message, the entire mes | 快照渲染:新消息与已压缩消息文本相同时被整条丢弃(模型看不见这条最新消息) #4052 只排除对已覆盖行的绑定,两者都不覆盖「纯签名 + 深位置」这个组合。根因是接缝资格判定把可误配的签名匹配与无歧义的 id 匹配(kernel 契约:id 永不复用)当成了同等强度的证据。
  3. 影响范围与严重程度:仅快照渲染车道的代理模式会话,且需窄条件同时成立(字节相同重复对 + 未覆盖行 + 非局部接缝 + 宿主重铸 id);正常流量以 id 命中为主,新门完全惰性。触发后果是最近上下文被静默截断——p2 级数据质量缺陷,不崩溃、不丢客户端数据。
  4. 怎么修复的:链式行走加 idAnchor 标志(run 中任一格来自精确 id 命中即置位);新增深度门:纯签名(!idAnchor)且非局部(接合点上方被丢的行数 > 匹配数)且 run<3 → 降级走 legacy 全量透传,reason=seam-unverified-depth。等价表述:纯签名接缝需满足三选一——至少一个精确 id 佐证 / 局部性(接合点贴近转录末尾)/ 连续 ≥3 格。局部接缝行为不变。
  5. 是否有回归问题:逐项清点既有行为——Snapshot rendering identity signature does not include message ID: duplicate short messages silently truncate history (m | 快照渲染身份签名不含消息 id:重复短消息会静默截断历史(开灰度前必须修) #3812 的 seam-too-short 检查仍在先且语义不变;Snapshot rendering: When the text of a new message is identical to that of an already-compressed message, the entire mes | 快照渲染:新消息与已压缩消息文本相同时被整条丢弃(模型看不见这条最新消息) #4052 的覆盖行排除逻辑逐字未动;局部接缝行为字节不变(用例 3 钉住);有 id 佐证的接缝不变(用例 2 钉住);run≥3 纯签名不变(用例 4 钉住);链未启动路径不受影响;buildAnchoredView(WS delta 车道)不走此链式行走,未触碰;plugin 模式在 buildView 之前提前返回,未触碰;新降级 reason 字符串纯增量(消费方只有观测/shadow/测试断言,没有分支逻辑依赖 reason 取值)。无回归。持久降级角落情形(宿主既重铸 id 又回退超过匹配深度)退化为 legacy 客户端全量视图 = Snapshot rendering: proxy-lane outbound is now rendered authoritatively server-side; existing sessions are immune to ker | 快照渲染:proxy 车道出站从服务端正史渲染,存量会话对内核升级免疫(#3752 根治) #3756 之前的行为,符合「宁降级不猜」,稳态下自愈。
  6. 是否破坏缓存:否。命中轮出站字节不变;降级轮发客户端视图原文(与其他任何降级 reason 同路径),前缀缓存策略未动。
  7. 是否改了设计方向:否。buildView 内单门增加,架构/边界/数据流无转向。
  8. 是否引入了新的配置:不涉及。无 env/config/默认值变化。

行为变更披露(旧→新):run=2 纯签名深接缝这一形状——旧:渲染被截断的视图(即 bug 本身);新:降级为 legacy 客户端全量视图,reason=seam-unverified-depth,下一轮自愈。其余所有形状出站字节不变。

范围声明验证:grep 确认 fastpath.ts/fastpath-scan.ts 无任何 run/连续/回溯链/接缝门——#5576 v6 水位车道用的是独立机制(元素计数 + 账本宽度 + 头部校验),缺陷只在快照渲染车道的 buildView,单文件单点修复即全覆盖,声明属实。

非阻塞观察(非本 PR 引入,未动代码):tests/verif-snapshot-render.test.ts 的符号化 SMT 测试在装有求解器的环境会失败——翻译层在 buildView 入口的 if ("reason" in base) 一行降级(子语言不支持 in 运算符)。用 origin/master 版的该文件复跑同样失败(@319 vs 本 PR @332,同一行),属存量缺口:该 J3 judge 目前在任何地方都不产生有效证明(CI 无求解器整测跳过)。修法是扩翻译器或调整守卫登记,属 verif 子系统工作,超出本 PR 范围,此处仅留痕。

判定:可合并(APPROVE)。

【协调】review-worker-r1 完成:PR #5639 审阅完毕,APPROVE,无阻塞项,无需决策路由。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 终态确认(head a7a6396):全绿。{total:30, failed:0, pending:0} = 13 success + 17 skipped(skipped 均为默认门控的 e2e 车道)。完整 test 分片矩阵(ubuntu/windows × node 22/24)、static-gates(win+ubuntu)、mysql-contract 及各 guard job 全部通过。

补充澄清:中途一度看到的 2 个 cancelled 是被取代的重新派发 run 的残留作业,不是测试失败——最终态干净无失败。分支基线即当前 master(23a826d37),单 commit 叠加,无冲突漂移。

收工判定:代码审核通过(八问见上条)+ 测试有牙(4 例真值表,手工逐格推演一致)+ CI 全绿 → 可合。合并仍按规矩由人操作,我不代合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收工确认(详细八问见本线程前两条回复):PR #5639 验证完成,可合。

合并仍按规矩由人操作,我不代合。

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 p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapshot-render seam: signature-only deep-duplicate pair passes the seam gate and silently truncates recent history

1 participant