Skip to content

[PR] fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849) - #7851

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-27_egress-diff-occurrence
Nov 27, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-11-27_egress-diff-occurrence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up on #7849 (the msgid→rid egress addressing migration). #7849 moved the egress PERSISTENCE layer to self-dispatched rids, but left the DIFF engine (diffEgressView) still matching on msgid (first-wins). This PR completes the migration on the diff side.

The gap

When the host mints a collision pair (two rows, same msgid, distinct rids) and a fold/delete removes one of the pair, the diff cannot express the deletion — the spine Set<msgid> marks BOTH rows "spine", so:

  • deleting the second row → ops=[] (no -D), the deleted row stays live (a ghost);
  • deleting the first row → U{rid=first, bytes=second}, writing the survivor's bytes onto the first row's rid (content mismatch + ghost).

The diff's contract "replay reproduces next exactly" is violated, with no runtime invariant to catch it.

The fix

The spine now matches each next row to a specific prev occurrence instead of a msgid: prefer the occurrence whose bytes agree (the survivor keeps its own rid — a pure -D, no spurious U), else the first occurrence after the pointer (msgid-only, so a content edit still emits a U). No-collision views have one occurrence per msgid, so the match is identical to the old first-wins key there — no behavior change for the common case.

Tests

Three regression tests in tests/egress-state.test.ts: the two repro cases (delete-first / delete-second of a collision pair) plus a survivor-content-edit case, each asserting the exact ops and the replay identity. The existing pinned diff cases (tail / nudge / fold / content-edit / num-lifecycle / move / 300-iter property) all still pass unchanged.

Scope

Single-module fix (src/storage/egress-state.ts), fix: only, regression tests added. Stacked on #7849 (the egress state table only exists on that branch). Severity p2 — the egress plane is default-off/unreleased and the collision requires the host to mint a wrong id; this closes the gap before GA.

@ranxianglei ranxianglei added bug Something isn't working p2 scope/storage labels Nov 27, 2026
@ranxianglei ranxianglei changed the title fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849) [PR] fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849) Nov 27, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 — this thread's PR (#7851 upstream) is the only PR targeting the egress-diff gap; the related open row #7850 (upstream #7849) is the stacked BASE PR (egress row addressing msgid→rid), a different thread, not a parallel fix for the same defect. No other open [PR] row touches src/storage/egress-state.ts.

标签: bug + scope/storage + p2 (egress plane is default-off/unreleased; the collision requires the host to mint a wrong id — matches the PR body's own p2 assessment; kept the existing pr label).

Live status (verified just now): PR #7851 is open, head 2026-11-27_egress-diff-occurrence, base 2026-11-27_drow-logseq (stacked on #7849's branch), mergeable: true, mergeable_state: unstable — the previous check run was cancelled and a new run is currently queued (CI in flight, no results yet).

Reviewing the diff now; full review conclusion (8-question form) to follow.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #7851 审核结论(8 问)

1. 是什么问题
#7849 把 egress 持久层寻址从 msgid 改成了自派发 rid,但 diff 引擎(diffEgressView)的 spine 仍按 msgid 匹配(first-wins)。当宿主铸出碰撞对(两行同 msgid、不同 rid)且 fold/删除删掉其中一行时,diff 无法表达这次删除——spine 是 Set<msgid>,把两行都标成 "spine":删第二行 → 不发 -D(幽灵行残留);删第一行 → U{rid=第一行, bytes=第二行}(内容错写到第一行的 rid 上 + 幽灵)。diff 的契约「replay 精确复现 next」被破坏,且运行时没有不变量能抓住它。

2. 什么原因导致的
根因是 #7849 的 msgid→rid 迁移在 diff 侧没做完:spine 用 Set<msgid>(first-wins)做身份,碰撞对的两行在 msgid 维度上不可区分。这是「寻址键从 msgid 换成 rid」这一机制迁移的遗漏面,不是表面现象——diff 是 egress op log 的唯一生产者,它按错键匹配就会产出错误的 I/D/U 序列。

3. 影响范围与严重程度
仅影响 egress-on 会话(egressPlane 默认 0,KDD #24,opt-in/未发布)且宿主铸出碰撞对(msgid 复用,本身是宿主 bug)时才触发。属于 opt-in 未发布特性里的潜在正确性缺口,需宿主 bug 配合才显现。p2(与 PR 自评一致)。

4. 怎么修复的
spine 改为逐 occurrence 匹配而非按 msgid:每个 next 行优先匹配字节相同的那个 prev occurrence(幸存者保留自己的 rid → 纯 -D,无多余 U),否则匹配指针后第一个 occurrence(仅 msgid,内容编辑仍发 U)。无碰撞视图每个 msgid 只有一个 occurrence,匹配结果与旧 first-wins 逐字节相同——常见路径零行为变化。

5. 是否有回归问题
无。我逐一核对了 diff 承担的既有行为:tail append / nudge appear+vanish / fold replace / content edit / num 生命周期(引用得失)/ move=D+I / 空视图 / 300-iter property / fork——全部保持。无碰撞路径经分析证明 ops 逐字节不变,且 17 个既有钉死测试 + 300-iter property 全部原样通过。高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。

6. 是否破坏缓存
不涉及。egress op log 是存储层记录,不是 prompt cache;未触碰缓存/重试/增量游标/去重键任何失效策略。

7. 是否改了设计方向
不涉及。是完成 #7849 既定的 msgid→rid 迁移方向(diff 侧收尾),没有新架构/边界/数据流转向。

8. 是否引入了新的配置
不涉及。无新 env/config/默认值。


代码与测试核查(本地实测)

  • 拉取 head 2026-11-27_egress-diff-occurrence,src/storage/egress-state.ts +62−23、tests/egress-state.test.ts +59,diff 干净(两文件均与本 PR 目的相关,无跑题/空行/lockfile 噪音)。
  • 手工推演 3 个复现 case + 边界(同字节重复、三 occurrence、乱序 swap)全部成立:匹配单调(指针 p 只前进)、D-run 在 prev 中连续、I 锚点在 replay 时必存在。
  • 定向测试 node --import tsx --test tests/egress-state.test.ts:20/20 通过(3 个新碰撞 case + 17 个既有钉死/property)。npm run typecheck 干净。
  • 测试有效性:3 个新测试是真测试——断言精确 ops(deepEqual)+ replay 恒等(norm)+ 具体 rid/bytes,bug 回归时能抓住。
  • 代码整洁:命名达意(prevOcc/spinePrev/matchedPrev)、旧 prevIdx/prevByMsg/spine 已删无死代码、注释讲为什么([PR] fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849) #7851 缘由)、风格与文件一致、无新依赖。

CI 状态(live 核查)
head 的 check runs:8 success / 10 skipped / 27 cancelled,0 个 failure。大量 cancelled 是叠在未合并的 base PR #7849(当前 blocked)上的 re-run 抖动,不是代码失败。

收工判定
代码正确、测试到位、无回归、diff 干净——代码层面可合。合并被两个外部条件门控:① base PR #7849 先合(stacked PR,egress state 表只在该分支上);② 最终 stacked head 上跑一次干净的 CI。无阻塞本 PR 自身代码的问题,无需返工。

(一个非阻塞观察,不立项:300-iter property 测试用随机 msgid,碰撞概率≈0,实际不覆盖碰撞路径——碰撞路径由 3 个定向 case 覆盖,足够;若日后想把 property 也扩到碰撞场景可再议。)

… longer ghosts or mismatches (follow-up on #7849)

diffEgressView keyed its spine on msgid (first-wins). When the host minted a
collision pair (two rows, same msgid, distinct rids) and a fold/delete removed
one, the spine Set marked BOTH rows "spine", so the D-run never fired (the
deleted row stayed live — a ghost) and the U wrote the survivor's bytes onto
the first row's rid (content mismatch). The diff's contract "replay
reproduces next exactly" was violated with no runtime invariant to catch it.

The spine now matches each next row to a SPECIFIC prev occurrence: prefer the
occurrence whose bytes agree (the survivor keeps its own rid — a pure -D),
else the first occurrence after the pointer (msgid-only, so a content edit
still emits a U). No-collision views have one occurrence per msgid, so the
match is identical to the old first-wins key there (no behavior change).

Regression tests: the two repro cases (delete-first / delete-second of a
collision pair) plus a survivor-content-edit case, each asserting the exact
ops and the replay identity.
@ranxianglei
ranxianglei force-pushed the 2026-11-27_egress-diff-occurrence branch from 1dbce58 to 7904d44 Compare November 27, 2026 12:46
@ranxianglei
ranxianglei changed the base branch from 2026-11-27_drow-logseq to master November 27, 2026 12:46
@ranxianglei
ranxianglei merged commit af8ed2a into master Nov 27, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1334-master.af8ed2a (rolling master tag).

npm install -g billion-context@0.0.1334-master.af8ed2a  # 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 added a commit that referenced this pull request Nov 28, 2026
…end default

From the #7738 egress-plane review — four storage/session bugs plus the
pluginDeltaResend default. Each is self-contained; B2 is the main one.

B2 (pin deadlock): tryIncrementalPin anchored the client's id list by
POSITION (ledgerEl[T-L+j]). After a fold, pi resends the FULL id list (L)
which is longer than the folded server view (T), so the pin failed ("incremental
list longer than the view"), degraded the new rows to h_ content ids, and — a
host id can never equal an h_ id — deadlocked forever on "reanchor next turn".
Replaced the egress path with an ID-anchored pin (tryEgressPin) that anchors by
element identity (list index vs ledger element rank, offset d = j - p), absorbs
the fold's rank shift, and classifies every turn shape in one pass:
  - full (d=0) / incremental / tail (d<0): restamp the aligned prefix with the
    ledger's canonical host ids, take the new increment from the tail;
  - zero overlap (REANCHOR_NOW): every declared id is a fresh increment — no 400,
    no h_ (the #7851 occurrence-aware diff rebuilds the ledger next turn);
  - fold-summary ranks stay content-derived (the client can never echo them).
It NEVER returns null in egress mode (no h_ degradation). The legacy (non-egress)
positional path is unchanged — issue5874 pins its null-degrade contract.

B3 (title lag): the egress identity row was upserted before deriveTitle ran, so
a session's first-turn title was never written (NULL for single-turn sessions,
one-turn lag otherwise). Re-upsert the identity row after the title is derived
(buildEgressIdentityInput).

B4/B5 (7-table session list empty): webSummaryRows ran `WITH bl AS (SELECT ...
FROM blocks)`, but a 7-table (egress) instance does NOT create the legacy
`blocks` table → the query threw "no such table: blocks" → the whole list
crashed to the disk walk, where egress sessions (no JSON files) are missing →
the panel showed 0 sessions. Guard on legacyTablesPresent: query the sessions
table alone and count egress_state rows so a single-turn egress session isn't
filtered as an empty stub (isEmptyStub checks hasEgress).

pluginDeltaResend default OFF -> ON (owner ruling 2026-11-28): the server must
be ready to handle the delta arm (direct-append) alongside the full /
incremental / tail / non-intersecting shapes. Inert until a shim claims delta
(x-bili-pf-delta: 1); roll back with BILI_ROLLOUT_PLUGIN_DELTA_RESEND=0.

Tests: c6 Test D updated for the never-null pin + Path A element-granular
ledger, Test E (post-fold full-list resend anchors) added; crosslane-wire-pin
stale Path A assertions fixed; new tests/egress-7table-session-list.test.ts (B4
repro). tsc clean; egress/pin/web suites green (c6 5/5, egress-record 9/9,
issue5874 43/43, crosslane 1/1, egress-7table 1/1, egress-authority-ladder 7/7,
egress-fork-host-e2e 11/11, egress-invariants-7773 1/1).

Scoped out (follow-up, see PR description): B1 — record the model answer at
end-of-turn so the FINAL turn's answer isn't lost if the conversation ends
before pi resends it. It needs a response-stream tee in relay.ts + a
recordEgressTurn append; kept out of this PR to leave the hot serve path
untouched.
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/storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant