Skip to content

[PR] feat: snapshot-lane — pin proxy-lane historical ids server-side (#3756) - #3758

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-19_snapshot-lane-id-pinning
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-19_snapshot-lane-id-pinning

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

Closes #3756 — Fixes part of #3752 (R2 root cause).

In proxy mode (client resends its full history every turn), message ids were re-derived from client bytes each turn. When the kernel's identity function changed (#3658 seed swap → #3752 mass-unfold), every historical id was re-minted, block coverage was lost, and persisted sessions unfolded en masse (126K→998K tokens, cache hit 2%).

This adds an opt-in snapshot lane: the server-side snapshot becomes the authority for historical ids. The client resend is demoted to an observation that discovers the new tail; aligned prefix positions get stamped with the stored msg_id before the pipeline runs. Structurally, historical id re-minting no longer exists in this lane — a kernel upgrade or identity-function change can never touch existing sessions again. The incremental lane keeps serving independently; reconcile/anchor machinery is untouched for non-D lanes (it stays naturally dormant here).

How it works

Config surface

One new rollout feature entry; no new config fields, no new named env var:

Item Default Force-on
rollout.features.proxySnapshotLane percent: 0 (off) "proxySnapshotLane": true in config, or existing generic tier BILI_ROLLOUT_PROXY_SNAPSHOT_LANE=1 (documented at CONFIGURATION.md:99 / :1765)

Engages only when unified storage is available; legacy storage falls back to the current path with one info log per session.

Behavior-change flag

Default OFF ⇒ zero past-behavior change. When engaged, for proxy-lane sessions with unified storage: historical message ids come from the server snapshot instead of being re-derived from resent bytes each turn (the intended fix). Outbound content/order is byte-identical by construction (passthrough on any unaligned shape; asserted in tests). One visibility note: the Responses API carries bili-minted core ids as item ids on the wire (already the case pre-change for derived ids); steady state is byte-identical, and after an identity-function change the stable frozen ids are what stay on the wire — which is the point. No threshold/timing/output-format changes elsewhere.

Acceptance mapping (the issue's four zero-churn scenarios)

  1. Upgrade kernel / swap identity function → identity swap (acceptance 1+4) test: replays a [PR] protocol-stable core identity: same logical conversation, same ids in every dialect (#3642) #3658-style re-mint; the pinned resend keeps block coverage and its outbound deep-equals the steady-state rendering; the unpinned control drifts (proves the bug existed and the lane removes it).
  2. Switch protocol/dialect → alignment is content-fingerprint based (protocol-neutral): alignKeyOf unit test + dialect-stamped view construction cover it; zero snapshot migration, one upstream miss when the wire format itself changes (unavoidable), stable pure-function output afterwards.
  3. Client deletes/compresses/rewinds the covered region arbitrarily → TRUNCATE-cov + REPLACE tests: covered rows stay server-authoritative in view AND registry; dsh-style full checkpoint replacement absorbed, never forwarded.
  4. Steady-state cache → APPEND test stamps the prefix from verbatim client bytes; the identity-swap test asserts turn messages deep-equal across turns.

v1 scope & non-goals (per issue)

Lanes: anthropic/openai/responses v1. Non-goals: google lane (follow-up), legacy storage (info-once fallback), mid-history edits (bail passthrough), CCR storage of absorbed heads, #3771 image-fingerprint seeds. The R1 capacity cliff (MAX_ANCHORS) remains out of scope — non-D lanes still rely on the #3753 stopgap.

Verification

  • npm run typecheck clean; tests/snapshot-lane.test.ts 9/9 green locally.
  • Targeted adjacent suites green locally: rollout, fold-drift, incremental-lane, anthropic-cache-control, openai-pck-identity, responses-fold-cache-seam (63 pass / 0 fail). Full-suite verdict left to CI.
  • kernel/ untouched (host-side only); no version bump; plugin-mode path returns the same reference (no behavioral surface there).

Proxy-mode clients resend their full history every turn, so message ids were
re-derived from client bytes each turn. Any kernel identity-function change
re-minted every historical id and mass-unfolded persisted sessions (#3752;
the #3658 seed swap was the incident). This adds an opt-in snapshot lane
that pins historical ids server-side:

- src/snapshot-lane.ts: pinSnapshotIds() aligns the client resend against
  the unified-store snapshot (order-centric walk, dialect-neutral content
  fingerprints per #3642) and stamps stored msg_ids onto aligned prefix
  positions before the pipeline runs. Appends ride the existing rawTail
  ingest (#3007); registry state persists via session_ext (snap:reg /
  snap:head). Every unaligned shape bails to byte-identical passthrough —
  the lane can only change ids, never content or order.
- src/server/prepare-{anthropic,openai,responses}.ts: hook after XToCore;
  plugin mode returns the same reference untouched.
- src/rollout.ts: proxySnapshotLane feature entry (percent 0 = default off).
- tests/snapshot-lane.test.ts: 9 tests incl. the #3752 identity-swap replay
  (pinned resend keeps coverage and byte-stable outbound; unpinned control
  drifts), dsh-style checkpoint absorption (observed, never forwarded),
  rewind/truncate clamping, and gate/bail directions.
- reference/architecture.md: module map line.

Closes #3756
Fixes part of #3752 (R2 root cause; R1 capacity cliff stays out of scope —
non-D lanes still rely on the #3753 lite-anchor stopgap)
@ranxianglei ranxianglei changed the title feat: snapshot-lane — pin proxy-lane historical ids server-side (#3756) [PR] feat: snapshot-lane — pin proxy-lane historical ids server-side (#3756) Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-19_snapshot-lane-id-pinning (d781cb8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4441-pr.3758.1824430

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-pr3758.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)

查重: 不重复。 本条是 GitHub PR #3758 的镜像——#3756(快照渲染/D 车道设计)的实现 PR,不是另一项并行工作。相关条目:

标签: opencode + scope/kernel + p1 —— 两条真实车道(anthropic/responses)即 OpenCode 车道 + 最常见 openai 车道;失败域为上下文管理/渲染核心(scope/kernel);严重度继承 #3752 的 p1 性质(不根治则每次未来身份函数变更都会再触发一次 mass-unfold 成本爆炸)。

此 PR 为我早前在 #3756 线程完成的工作(floor 3 已汇报)。现按 PR review 规范做独立复审:拉分支核对代码、确认 CI 状态、既有行为回归清点、测试有效性审查。结论按八问体例随后回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

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

关闭说明:owner 已在 #3756 交付同一 issue 的实现 —— PR #3759(分支 2026-10-19_snapshot-render)。按「一个 issue 一个 PR」纪律,本 PR 与 #3759 是同一机制的两条并行实现,保留两个会让验收标准互相打架,故关闭本条;#3759 为唯一在途 PR。

本 PR 的测试套件(tests/snapshot-lane.test.ts,9 例,含身份函数翻盐后的出站逐字节不变对照)覆盖同样的四个验收场景、角度不同(id 盖章 + 快照注册表),审阅 #3759 时可作参照。如需保留本 PR,重新打开即可(分支 2026-10-19_snapshot-lane-id-pinning @ d781cb8 仍在)。

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

Labels

None yet

Projects

None yet

1 participant