Skip to content

[PR] fix: egress row addressing changed from msgid to self-dispatched rid (follow-up ruling on #7773) | fix: egress 行寻址从 msgid 改为自派发 rid(#7773 后续裁定) - #7849

Merged
ranxianglei merged 3 commits into
masterfrom
2026-11-27_drow-logseq
Nov 27, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zai/glm-5.2)

PR body draft — egress row addressing moves to self-issued rids (#7773 follow-up)

这是啥

D 行(删除)payload 之前用 msgid 做端点:{"start":"h_07c9...","end":"b6ab41..."}。owner 实测裁定(2026-11-27,#7773 后续):msgid 不是可靠的持久地址——

  1. proxy 侧很多 msgid 本来就是内容 hash(宿主 id 不可用时降级),看着像「我们造的」;
  2. 客户端 msgid 可能冲突(两个不同消息同一个 id,kernel 契约挡不住宿主铸错);
  3. 折叠/re-home 之后同一个 msgid 在历史里出现多次,payload 里的字符串分不清指哪一次。

改为:所有 egress 表的行寻址一律用我们自派发的 rid——稠密(每会话 MAX(rid)+1)、append-only flow 里永不删除、永不重发。

改了什么

  • egress_state PK (session_id, msgid) → (session_id, rid);新增 idx_egress_state_msgid (session_id, msgid) 保 serving 查找。
  • egress_flow 新增 rid INTEGER 列(I/U 行带目标 rid,D 行 NULL);payload 寻址全部 rid 化:
    • I: {after: rid|null}(原来 after: msgid|null)
    • D: {start: rid, end: rid}(原来 start/end: msgid)
    • U: payload 加 rid(目标行的 msgid 保留为交叉校验)
  • 不变量 ⑤(tests/egress-invariants-7773.test.ts + 每次写入断言):日志寻址是 rid,不是 msgid。
  • 内核身份缝不动:prev↔next 视图 diff 仍按 msgid 匹配(那是 kernel 身份,KDD 契约)——只有持久层(表主键 + op payload 锚点)去 msgid 化。测试含「同 msgid 冲突两行」用例:新行拿新 rid,MAX(rid)+1 永不歧义。
  • 前沿/高水位:egressRowHighWater = SELECT COALESCE(MAX(rid),0) FROM egress_flow(U 行带 rid、D 行 NULL → 全表 MAX 即 I 行 MAX)。log_seq 不能当行 id(retired-slot re-homing 允许旧 log_seq 被再引用)。
  • fork(to-now 整拷 / point 前缀):四表 INSERT 列表带 rid 逐字复制;usage 流拷贝不变。
  • 探针:migrateSchema 旧形状判定加「缺 rid 列」→ 首开 drop 重建(从未发布规则;开发库按 egress-plane.md §7 毁库重建)。
  • 测试:9 个文件全量转换 + 新用例(msgid 冲突行、moved row 消耗 rid);文档:egress-plane en/zh(表结构/不变量/裁定账本/交接手册)、architecture/storage 三语、deprecations en/zh 登记。

边界

  • 块平面(egress_block_* 的 startMsgid/endMsgid)不动——那是折叠时刻的一次性对齐坐标,不是日志寻址。
  • pin 通道/web 读仍按 msgid 走新索引,wire 不变。
  • 配置面:无变化。

这是啥

D 行(删除)payload 之前用 msgid 做端点:{"start":"h_07c9...","end":"b6ab41..."}。owner 实测裁定(2026-11-27,#7773 后续):msgid 不是可靠的持久地址——

  1. proxy 侧很多 msgid 本来就是内容 hash(宿主 id 不可用时降级),看着像「我们造的」;
  2. 客户端 msgid 可能冲突(两个不同消息同一个 id,kernel 契约挡不住宿主铸错);
  3. 折叠/re-home 之后同一个 msgid 在历史里出现多次,payload 里的字符串分不清指哪一次。

改为:所有 egress 表的行寻址一律用我们自派发的 rid——稠密(每会话 MAX(rid)+1)、append-only flow 里永不删除、永不重发。

改了什么

  • egress_state PK (session_id, msgid) → (session_id, rid);新增 idx_egress_state_msgid (session_id, msgid) 保 serving 查找。
  • egress_flow 新增 rid INTEGER 列(I/U 行带目标 rid,D 行 NULL);payload 寻址全部 rid 化:
    • I: {after: rid|null}(原来 after: msgid|null)
    • D: {start: rid, end: rid}(原来 start/end: msgid)
    • U: payload 加 rid(目标行的 msgid 保留为交叉校验)
  • 不变量 ⑤(tests/egress-invariants-7773.test.ts + 每次写入断言):日志寻址是 rid,不是 msgid。
  • 内核身份缝不动:prev↔next 视图 diff 仍按 msgid 匹配(那是 kernel 身份,KDD 契约)——只有持久层(表主键 + op payload 锚点)去 msgid 化。测试含「同 msgid 冲突两行」用例:新行拿新 rid,MAX(rid)+1 永不歧义。
  • 前沿/高水位:egressRowHighWater = SELECT COALESCE(MAX(rid),0) FROM egress_flow(U 行带 rid、D 行 NULL → 全表 MAX 即 I 行 MAX)。log_seq 不能当行 id(retired-slot re-homing 允许旧 log_seq 被再引用)。
  • fork(to-now 整拷 / point 前缀):四表 INSERT 列表带 rid 逐字复制;usage 流拷贝不变。
  • 探针:migrateSchema 旧形状判定加「缺 rid 列」→ 首开 drop 重建(从未发布规则;开发库按 egress-plane.md §7 毁库重建)。
  • 测试:9 个文件全量转换 + 新用例(msgid 冲突行、moved row 消耗 rid);文档:egress-plane en/zh(表结构/不变量/裁定账本/交接手册)、architecture/storage 三语、deprecations en/zh 登记。

边界

  • 块平面(egress_block_* 的 startMsgid/endMsgid)不动——那是折叠时刻的一次性对齐坐标,不是日志寻址。
  • pin 通道/web 读仍按 msgid 走新索引,wire 不变。
  • 配置面:无变化。

…follow-up, owner ruling 2026-11-27)

D-row payloads carried msgid endpoints ({"start":"h_...","end":"b6ab..."}):
content-hash ids when the host id was unavailable, potentially-colliding
client ids, and ambiguous after fold re-homing (one msgid can occupy a
slot twice in history). The persistent log must address rows by an id we
issue ourselves: dense per session (MAX(rid)+1), append-only flow never
deletes, so a retired rid can never be re-issued.

- egress_state PK (session_id, msgid) -> (session_id, rid) + msgid index
- egress_flow gains a rid column (I/U rows carry it, D rows NULL);
  payload addressing: I {after: rid|null}, D {start: rid, end: rid},
  U +rid (the target msgid stays as a cross-check)
- invariant 5 (invariants suite + per-write assert): log addressing is
  rid, never msgid; the state<->flow twin check joins on (rid, log_seq)
- the diff (prev<->next view match) still keys on msgid: that is the
  kernel identity seam (KDD contract) and only the persistent layer
  de-msgid-ifies. New case: a colliding msgid gets a fresh rid and
  MAX(rid)+1 stays unambiguous
- frontier/high-water = egressRowHighWater = MAX(rid) over the flow
  (U rows carry a rid, D rows NULL). log_seq cannot serve as the row id:
  retired-slot re-homing legitimately re-cites an old log_seq
- fork (to-now full copy / point-in-time prefix) copies rid verbatim;
  the migrate probe adds the rid-less shape (never shipped: first-open
  rebuild, docs/egress-plane.md section 7)
- docs: egress-plane en/zh (tables, invariants, ruling ledger, handover
  manual), architecture/storage en/zh/ja, deprecations en/zh register
  the change with the rebuild handoff
@ranxianglei ranxianglei changed the title fix: egress 行寻址从 msgid 改为自派发 rid(#7773 后续裁定) [PR] fix: egress row addressing changed from msgid to self-dispatched rid (follow-up ruling on #7773) | fix: egress 行寻址从 msgid 改为自派发 rid(#7773 后续裁定) Nov 27, 2026
…d_rid/after_rid)

The docs wrote the D/I payload keys as start_rid/end_rid/after_rid, but the
actual JSON payload keys are start/end/after (holding rid values). Also
clarify that the U row's rid is a column, not a payload key.

Drive-by fix from PR #7849 review (mirror 7850).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: zai/glm-5.2)

查重

不重复。本 PR 是 owner 2026-11-27 裁定的直接落地(#7773 后续),无其他在途 PR 做同一件事。

审核结论

审了什么:完整 diff(23 文件 +402/-258)+ 9 个测试文件 + 4 个文档文件(en/zh)。本地跑了 PR 自己的 egress 测试套件(18/18 绿)。CI 在新 head(1282f83f2f3)上运行中。

核心交付(持久层 rid 寻址)—— 正确:

  • egress_state PK (session_id, msgid) → (session_id, rid),新增 idx_egress_state_msgid 保 serving 查找 ✓
  • egress_flow 新增 rid 列,payload 寻址全部 rid 化(I: after=rid, D: start/end=rid, U: rid 列 + msgid 交叉校验)✓
  • egressRowHighWater = SELECT COALESCE(MAX(rid),0) ✓
  • fork 四表 INSERT 带 rid 逐字复制 ✓
  • migrateSchema 探针加「缺 rid 列」→ drop 重建 ✓
  • 不变量 ⑤(日志寻址是 rid 不是 msgid)+ 每次写入断言 ✓
  • 内核身份缝不动(prev↔next diff 仍按 msgid 匹配)✓
  • 测试含 msgid 冲突行(append 场景)+ dup-rid 硬错 + moved row 消耗 rid ✓

发现一个缺口(已立 drive-by issue):

diffEgressView(src/storage/egress-state.ts:448)仍按 msgid 键控(spine 扫描 + prevByMsg first-wins)。当宿主铸出两条同 msgid 的消息(冲突对)后,删掉其中一条时,diff 无法表达这个删除:

  • prev=[A(X),B(X)] next=[A(X)] → ops=[](没发 D),replay 后 B 仍 live(幽灵行)
  • prev=[A(X),B(X)] next=[B(X)] → ops=[U rid=1 bytes=B](U 写到 A 的 rid 带 B 的字节,内容错配)

diff 的契约「replay 精确复现 next」被违反,无运行时不变量能抓住。旧代码在冲突时 fail-fast(duplicate msgid 硬错),新代码静默分叉——这是碰撞场景下的 fail-fast → silent 回归。

严重度:p2——egress 平面默认关(opt-in,未发布),冲突需宿主铸错(宿主 bug),只在删冲突对一行时触发。但 egress 平面 GA 前应修。

已立 drive-by issue 跟踪:mirror #7851(含复现、根因、修法、决策选项)。

顺手修(已 push 到 PR 分支):

  • commit 1282f83:文档 payload 键名修正——start_rid/end_rid/after_rid → start/end/after(实际 JSON 键名),4 个文件(egress-plane en/zh + deprecations en/zh)。

八问

  1. 是什么问题:egress 表行寻址之前用 msgid,但 msgid 不是可靠的持久地址(可能是内容 hash、宿主间可能冲突、折叠后分不清指哪一次)。owner 裁定改用自派发 rid。
  2. 什么原因导致的:msgid 是内核身份,proxy 可能从内容 hash 映射而来、宿主间可能冲突、折叠/re-home 之后分不清指哪一次——不能当持久地址。
  3. 影响范围与严重程度:egress 平面默认关(opt-in,未发布),当前无用户影响。但这是核心存储变更,egress 平面 GA 后影响所有 egress-on 会话。p2。
  4. 怎么修复的:所有 egress 表行寻址改用自派发 rid(稠密、每会话、append-only、永不重发)。持久层(表主键 + op payload 锚点)去 msgid 化;内核身份缝(prev↔next diff)不动。
  5. 是否有回归问题:diff 仍按 msgid 键控,冲突对删一行时静默分叉(幽灵行/内容错配)——旧代码 fail-fast,新代码 silent。已立 drive-by issue [PR] fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849) #7851 跟踪。egress 平面默认关,当前无用户影响。
  6. 是否破坏缓存:不涉及。egress 平面默认关,无缓存影响。
  7. 是否改了设计方向:是。行寻址方案从 msgid 改为 rid(owner 裁定)。内核身份缝不动(仍按 msgid 匹配)。
  8. 是否引入了新的配置:不涉及。无新配置键。

合并判定

可合——核心交付(持久层 rid 寻址)正确且测试覆盖充分(含冲突 append 场景)。diff 缺口(冲突 delete)已立 drive-by issue #7851 跟踪,不阻塞本 PR(egress 平面默认关,当前无用户影响)。

标签:mirror 标签端点未实现(ework shim 限制),无法打标签。GitHub PR 侧建议标签:refactor + p2(egress 平面默认关,当前无用户影响;核心存储变更)。

ranxianglei pushed a commit that referenced this pull request Nov 27, 2026
… 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.
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-27_drow-logseq (af89c93)

Latest build — install this exact version

npm install -g billion-context@0.0.12241-pr.7849.7ee4344

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
af89c93 billion-context@0.0.12241-pr.7849.7ee4344 build
1282f83 billion-context@0.0.12234-pr.7849.e162493 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zai/glm-5.2)

CI 全绿:36 success / 12 skipped / 0 failure(含主 CI 全部 test 分片、e2e 全套、Theorem 无关)。可合入;合并后线上实例按 docs/egress-plane.md §7 毁库重建(rid 形状,从未发布过的中间形态)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: zai/glm-5.2)

收到。CI 全绿确认(36 success / 12 skipped / 0 failure)。

合并是 human-only(系统规则禁止 agent 合并 PR),请自行合并:
#7849

合并后按 docs/egress-plane.md §7 毁库重建(rid 形状,从未发布过的中间形态)——收到。

… + fork = zero id conversion

The five numbers across the five egress tables answer five different
questions; this section puts them side by side (which one is the write
counter, which the kernel citation, which the row identity, which the
view offset) and states the fork consequence explicitly: every key is
(session_id, rid), so fork copies rows verbatim with NO id conversion —
the child keeps its forked rids as lineage identity and continues from
its own MAX(rid)+1; the usage stream carries no rids at all, so its
fork copy is a plain row copy (whole to-now / at<=W prefix point).

en+zh (docs/egress-plane.md §3). Closes the doc gap flagged in the
#7849 review thread.
@ranxianglei
ranxianglei merged commit 4c99c39 into master Nov 27, 2026
48 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1333-master.4c99c39 (rolling master tag).

npm install -g billion-context@0.0.1333-master.4c99c39  # 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 Nov 27, 2026
… 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 added a commit that referenced this pull request Nov 27, 2026
…rrence

[PR] fix: egress diff occurrence-aware — collision-pair deletion no longer ghosts or mismatches (follow-up on #7849)
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant