Skip to content

[PR] Snapshot rendering: proxy lane outbound prefix rendered from server-side canonical history; existing sessions immune to | 快照渲染:proxy 车道出站前缀从服务端正史渲染,存量会话对内核升级免疫(#3756) - #3759

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-19_snapshot-render
Oct 19, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #3756. 根治 #3752/#3751 的 id-churn 家族:折叠覆盖不再锚定客户端重发字节,改锚服务端统一存储正史。

机制

src/server/snapshot-render.ts — maybeSnapshotView(session, clientMsgs):

  • 激活门:rollout feature snapshotRender(默认 0%,BILI_ROLLOUT_SNAPSHOT_RENDER=1 强制)+ 会话有活跃折叠块 + 统一存储可读;任一不满足 → 原样返回客户端视图,行为面与现状逐字节相同。
  • 出站视图 = 快照行前缀 + 客户端尾巴:
    • 前缀:统一存储 tail rows(tailSeqs 视图序,read-only 访问器)按分歧点截断;
    • 覆盖区:块的 seq/signature 覆盖集引擎自拥抑制(不信任 reconcile 的 re-key 产物——升级轮行保留 fold-time id,漏剥双渲),acp_summary_<blockId> 锚原位重渲真摘要(kernel prune 的 summaryIndexById 既有纪律);
    • 尾巴:分歧点之上客户端字节逐字(缓存稳定);rewind 掉的行在 join 之下,永不复活。
  • 链回溯:从尾倒走,id 快路径 + 内容签名兜底(role|contentType|toolName|text + 图片长度签名,与 [PR] protocol-stable core identity: same logical conversation, same ids in every dialect (#3642) #3658 canonical 种子同构)——升级后 id 全部重铸仍可按内容链接;活尾巴未开始前跳过,断链即整轮降级 legacy。
  • checkpoint 一轮采用滞后(有意):本轮视图=上轮 lastMessages,客户端头部替换下一轮才被采用;覆盖区靠锚+覆盖集永不复活。
  • 观测闩 metadata.snapshotRenderTurns;首轮 info 日志。

prepare 接线(openai/anthropic/responses 三车道同型)

renderMsgs = maybeSnapshotView(session, msgs) 后:effectiveTokenCount / planReasoningDrop / processTurn 吃 render 视图;reconcileFoldCoverage 仍观察客户端视图(观测与渲染分离)。

kernel-change: 测试缝

kernel/src/wire/identity.ts 加 __setMessageIdSaltForTests(模块级盐,插在 canonical 种子前;unset 时种子逐字节不变——金桩验证 5/5 不漂)。wire/index.ts re-export identity 模块。kernel 0.0.134。生产代码零调用。

测试(tests/snapshot-render.test.ts 7/7)

  1. steady:锚渲染一次、覆盖行抑制、轮轮前缀逐字节稳(openai run-merge 吸收的尾 assistant 已计入 tail 断言)。
  2. identity-seed upgrade(核心验收):__setMessageIdSaltForTests("upgrade-v2") 原地翻盐 → 出站前缀逐字节不变、块活、无 destroy 判决——正是 0.1.200 → 0.1.201 upgrade (#3658 identity change) mass-unfolds persisted sessions incl. Anthropic lane; downgrade re-churns #3752/Image message ids re-mint whenever an earlier image leaves the visible tail (membership-based ClusterCounter suffix) — prefix-cache breaks per fold, feeds #3748 storage growth #3751 的事故形状,当场钉死。
  3. checkpoint:dsh 式头部替换 → 服务端锚照渲、覆盖区不复活、一轮采用滞后注释、编辑后轮稳。
  4. rewind:裁掉的尾巴不回来。
  5. protocol switch:openai→anthropic 中途切换同会话,锚在新 wire 上渲染,不分叉。
  6. D-off 对照:不开开关时同场景确实 churn(钉住要修的 bug 本身)。
  7. storage-off:统一存储不可用 → 200 正常服务、无 D 闩,回退干净。

回归:golden-storage-render 5/5、storage-unified 14/14、rollout 25/25、fold-reconcile 66/66、tsc 0。

验收四场景对照(issue #3756)

  • 换身份函数存量会话出站逐字节不变 → 测试 2 ✅
  • 切协议一次 miss 后稳 → 测试 5 ✅(wire 格式切换的 miss 不可避免,身份/块零 churn)
  • 客户端任意删压 rewind 覆盖区出站不变 → 测试 3/4 ✅
  • 稳态 turn-over-turn 前缀字节稳定 → 测试 1 ✅

后续(不在本 PR)

…#3756)

- src/server/snapshot-render.ts: maybeSnapshotView(session, clientMsgs) builds
  the outbound view from unified-storage tail rows: covered rows suppressed by
  block seq/signature coverage, acp_summary_* anchors re-rendered in place,
  client tail joined at the divergence point (rewind-safe, id fast path +
  content-signature fallback chain). Degrades whole-turn to the legacy path on
  any mismatch; gated by rollout feature snapshotRender (default 0%).
- prepare-openai/anthropic/responses: tokenCount / reasoningDrop / processTurn
  consume the render view; reconcile still observes the client view.
- storage accessors: store.tailSeqs, shadow.tailViewRows, persist
  unifiedTailSeqs/unifiedTailViewRows (read-only).
- kernel seam: wire/identity __setMessageIdSaltForTests (test-only salt;
  production seeds unchanged byte-for-byte), kernel 0.0.134.
- tests/snapshot-render.test.ts 7/7: steady prefix stability, identity-seed
  upgrade immunity, client checkpoint absorption (one-turn adoption lag),
  rewind, mid-session protocol switch, D-off churn documentation, storage-off
  fallback. golden-storage-render 5/5, rollout 25/25, storage-unified 14/14,
  fold-reconcile 66/66.
@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Oct 19, 2026
@ranxianglei ranxianglei changed the title 快照渲染:proxy 车道出站前缀从服务端正史渲染,存量会话对内核升级免疫(#3756) [PR] Snapshot rendering: proxy lane outbound prefix rendered from server-side canonical history; existing sessions immune to | 快照渲染:proxy 车道出站前缀从服务端正史渲染,存量会话对内核升级免疫(#3756) Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-19_snapshot-render (7a4ae1d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4446-pr.3759.fc202f9

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

ework review

@ranxianglei

Copy link
Copy Markdown
Owner Author

ai: zhipuai-lb/glm-5.3

Review 结论:可合。设计对、验收真、默认面零风险。本地全复跑通过。

逐点核验(不是只看 body——diff 全文+本地实测)

  1. 默认路径零风险:snapshotRender: { percent: 0 },三张 prepare 只多一次 featureEnabled 检查,关闭时逐字节返回客户端视图。kernel 测试缝(__setMessageIdSaltForTests)生产零调用、null 时种子逐字节不变(金桩 5/5 复跑绿)。
  2. 回归类被当场钉死:测试 2 用内核盐原地翻盐模拟 0.1.200 → 0.1.201 upgrade (#3658 identity change) mass-unfolds persisted sessions incl. Anthropic lane; downgrade re-churns #3752/[PR] protocol-stable core identity: same logical conversation, same ids in every dialect (#3642) #3658 全量 id 重铸 → 出站前缀逐字节不变、块活、无 destroy 判决——正是事故形状。测试 6(D-off 对照)证明同场景在旧路径确实 churn,钉住了「要修的 bug」本身,不是自说自话。
  3. 降级纪律干净:store 不可用/无行/行不可解析/视图指针悬空/链不上 → 一律原样返回客户端视图,never guess(全在代码里逐条核对)。
  4. 双 id 空间处理正确:引擎自拥覆盖(seq+signature 覆盖集),不信任 reconcile 的 re-key 产物(升级轮行保留 fold-time id,reconcile 可能已把块改键到客户端新 id——漏剥=双渲,这个选择对);reconcile 继续观察客户端视图,渲染/观测分离。
  5. 本地复跑(7a4ae1d worktree):snapshot-render 7/7、golden-storage-render 5/5、storage-unified 14/14、fold-reconcile 66/66、tsc 干净。
  6. CI:head 上除 ci-gate-plugins.yml 空 run(CI 误红:Windows 测试偶发挂起 + 手动 gate-plugins 工作流被每次 push 空触发(均与代码变更无关) #3574-B 已知噪声,0 job,不在 release gate 必需集)外全绿;checks 表里那两条 hermetic 红 = 旧代被新 push 取消的残影(02:20:26 新代 success)。

非阻塞 notes(后续可收紧)

  • 性能(:146-167 覆盖集构建):每轮全量 getMessages + 每行 JSON.parse,覆盖集是 O(|effectiveMessageIds| × rows) 双重扫描/块。几千行的会话每轮多付十几毫秒——灰度期可接受,翻转默认前建议把 rows 按 id 建一次索引(byId 链回溯已有,覆盖集可复用)。
  • google 车道未接(v1 非目标已声明):切到 google 仍走旧路径,记得后续跟进。
  • blockSeqs 为空(块的历史早于统一存储)时锚落在 index 0(摘要置顶)——语义可用,建议补一行注释说明这是有意回退。
  • body 写 "kernel 0.0.134",实际 bump 是 0.0.135——纯文案 nit。

与 #3757 的关系

#3757(fork 前缀门降 advisory)止住的是「churn 之后的 409 卡死」;本 PR 止住的是 proxy 车道上 churn 本身。两件互补,都进 0.1.202 的话,升级换代对存量会话的三层伤害(失锚→重铸→卡死)就全拆完了。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.586-master.b4e5b11 (rolling master tag).

npm install -g billion-context@0.0.586-master.b4e5b11  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Oct 19, 2026
prepareGoogle now consumes maybeSnapshotView for effectiveTokenCount and
core.processTurn (reconcileFoldCoverage keeps observing the client view),
mirroring the openai/anthropic/responses lanes landed in #3759. Reasoning-drop
is deliberately absent on this wire (#651: Gemini validates thoughtSignature),
so only two consumers switch, not three.

Adds google variants to tests/snapshot-render.test.ts driven over the native
Gemini wire: steady-state prefix byte-stable, seed-upgrade prefix byte-identical
across the #3752 identity re-mint (via __setMessageIdSaltForTests), and the
D-off control showing the legacy path still churns. Rollout-gated behind
BILI_ROLLOUT_SNAPSHOT_RENDER and default-off, so no behavior change until enabled.
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
ranxianglei added a commit to yanhuojiyusheng/billion-context that referenced this pull request Oct 19, 2026
…t 0.0.133)

The 0.0.134→0.0.136 bumps (ranxianglei#3759/ranxianglei#3767) updated kernel/package.json and the
root lock's workspace entry but never regenerated kernel/package-lock.json —
the same dual-lock drift ranxianglei#3658 hit. npm ci inside kernel/ would refuse
(lock does not satisfy package.json). Regenerated with
npm install --package-lock-only; no source changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR 发版

Projects

None yet

1 participant