mirror of
https://github.com/ranxianglei/billion-context.git
synced 2026-12-02 19:26:20 +08:00
The review-grade walkthrough (en/zh) still described the pre-round-2 architecture — egress_snapshot tables, messages as the canonical id truth, no lazy projection, no perf gate. Add the round-2 chapter (ruling 7439-2/5: op-log canonical numbering, window re-anchor, sole-canonical + lazy projection, pin-from-flow, envelope freeze, hard-fail, measured 10w matrix, resident bench) and mark the superseded sections inline instead of deleting them. Supporting sync: - storage.md (en/zh): egress tables + canonical-authority semantics - msgid-infrastructure.md (en/zh): KDD #22 carve-out on the 'messages.msg_id is the single id truth' statement - configuration.md (en/zh): egressPlane knob gains the round-2 lazy-projection semantics - index.md (en/zh): pr-6785 doc row - reference/testing.md: ACP_TEST_EG_BENCH bench lane No code changes. Docs-only.
This commit is contained in:
@@ -26,9 +26,11 @@ Everything that must survive a process restart lands in ONE SQLite file: session
|
||||
|
||||
**Consistency.** Checkpoint frame signatures + S4 per-row checksums; verdicts trust the chain, never content similarity. Optional at-rest encoding: AES-256-GCM (#708) + zstd (#1080). The mysql dialect under `src/storage/mysql.ts` is a TEST MIRROR only (the mysql-contract CI lane) — SQLite remains the production store.
|
||||
|
||||
**Egress plane (KDD #22, #7398/#7439 — the outbound conversation op log).** `egress_state`/`egress_flow` (SQLite lane only, gate `rollout.features.egressPlane`) hold the sparse I/D/U op log of each session's outbound view; rows are self-contained (bytes ride the row, no content CAS). Both tables key on `(session_id, op_seq)` (append-only row cursor, recovery/truncation key) and I rows additionally carry `log_seq` — the canonical, never-reissued message number. For egress-on sessions the op log is the SOLE canonical message authority: outbound bytes are served from it, the pin channel resolves its I rows instead of the messages ledger, the per-turn unified ingest stops (messages demoted to a LAZY projection, rebuilt one-time on rollback/web-read/restore) and the session JSON envelope freezes at bootstrap. Recovery = `recoverEgressBase` (bounded state replay); no healthy point ⇒ the turn hard-fails (ruling 7439-5), never degrades to client bytes. Full walkthrough: [PR #6785 doc §6](../pr-6785-unified-storage-and-flows.md#6-round-2).
|
||||
|
||||
## Hard invariants (see AGENTS.md before touching this)
|
||||
|
||||
- Message ids are never reused (kernel contract); `messages.msgId` is the canonical id.
|
||||
- Message ids are never reused (kernel contract); `messages.msgId` is the canonical id — with the KDD #22 carve-out: for egress-on sessions the op log's I rows (`egress_flow.msgid` + `log_seq`) are the canonical message authority and the messages rows are a lazy projection.
|
||||
- Row order = identity carrier; fold = inactive mark, never physical delete.
|
||||
- Upgrades are purely additive; rollback drill before any breaking change.
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
|
||||
**一致性。** 检查点帧签名 + S4 逐行校验和;判决只信链、不信内容相似。可选静态加密:AES-256-GCM(#708)+ zstd(#1080)。`src/storage/mysql.ts` 的 mysql 方言只是**测试镜像**(mysql-contract CI 车道)——生产存储永远是 SQLite。
|
||||
|
||||
**egress 平面(KDD #22,#7398/#7439——出站会话 op log)。** `egress_state`/`egress_flow`(仅 SQLite 车道,gate `rollout.features.egressPlane`)存每个会话出站视图的稀疏 I/D/U op log;行自包含(字节随行走,不经内容 CAS)。两表均以 `(session_id, op_seq)` 为主键(append-only 行游标,恢复/截断键),I 行另带 `log_seq`——正史消息编号,永不重发。对 egress-on 会话,op log 是**唯一**正史消息权威:出站字节从它 serve,pin 通道解析它的 I 行而非 messages 账本,逐轮统一 ingest 停止(messages 降级为**惰性投影**,回滚/web 读/恢复时一次性重建),会话 JSON 信封在 bootstrap 冻结。恢复 = `recoverEgressBase`(有界 state 重放);无健康点 ⇒ 整轮硬失败(裁定 7439-5),绝不降级到客户端字节。完整梳理:[PR #6785 文档 §6](../pr-6785-unified-storage-and-flows.zh-CN.md)。
|
||||
|
||||
## 硬不变量(动手前先读 AGENTS.md)
|
||||
|
||||
- 消息 id 永不复用(内核契约);`messages.msgId` 是规范 id。
|
||||
- 消息 id 永不复用(内核契约);`messages.msgId` 是规范 id——KDD #22 例外:egress-on 会话的正史消息权威是 op log 的 I 行(`egress_flow.msgid` + `log_seq`),messages 行是惰性投影。
|
||||
- 行序 = 身份载体;折叠 = inactive 标记,不是物理删除。
|
||||
- 升级纯加性;破坏性变化前先回滚演练。
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
|
||||
| `rollout.features.identityChannelHarvest` | boolean \| number | 0 (off) | BILI_ROLLOUT_IDENTITY_CHANNEL_HARVEST | Identity-channel harvest cohort gate (#5825): allows the loopback-only transcript/sqlite harvest (src/identity-harvest.ts: claude-code / codebuddy / mcode / goose / qwen lanes) without any per-install env switch, when neither the per-install switch (BILI_IDENTITY_HARVEST) nor this key is set nothing ever reads client storage. Owner ruling 2026-11-07: this cohort key is deliberately separate from rollout.features.pluginLaneServerHistory (which governs row PINNING of admitted ids) — either enabler may activate harvesting. Default 0%; raise after small-cohort observation of the degrade warn-once rate. See identity-channels.md. |
|
||||
| `rollout.features.pluginLaneServerHistory` | boolean \| number | 100 (on, GA) | BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY | Plugin-lane server-owned history (#4491): for enabled installs, (a) plugin-lane requests may carry an internal `biliMsgIds` array parallel to `messages` that pins message identity to client-supplied ids (always stripped before upstream forwarding; malformed arrays are ignored with a warning, id-poisoning shapes hard-fail on the incremental lane); (b) the loopback-only `POST /__bili/plugin/render` endpoint serves the outbound prefix rendered from the unified transcript (folded regions collapse to summary anchors; any desync degrades to a non-2xx so the shim falls back to its local history); (c) the incremental-lane probe advertises `serverHistory`. Default 100% (GA, owner ruling 2026-11-13); set 0 to roll an install back to the pre-GA state. |
|
||||
| `rollout.features.pluginMsgIdIncremental` | boolean \| number | 100 (on, GA) | BILI_ROLLOUT_PLUGIN_MSG_ID_INCREMENTAL | Incremental msgid pin channel (#7064 §8, owner rulings 2026-11-18/19): steady plugin-lane turns declare their message ids in TAIL FORM — the bounded `x-bili-pf-tail-ids` header (anchor + new ids, ≤ 2048 ids, `?` placeholder slots) or a short body id array — instead of the FULL list; the server re-stamps the prefix ids from its own ledger live rows (ingest is INSERT OR IGNORE on (session_id,seq) — a position's msg_id is written once, never overwritten). Acceptance (2026-11-19 form): the declared tail [T-L, T-1] must match the ledger overlap segment row-by-row (any drift degrades to `full`, never 400); ultra-long sessions (> 2048 ids) pin a truncated tail the same way — the longer overlap proves MORE. Only snapshot rounds (empty ledger / post-fold re-anchor) send the full form; full form always wins when both arrive. The response carries `x-bili-msgid-mode: incremental\|full` (cleared on any 4xx; one learning point next to x-bili-pf-seq). Any mismatch self-heals within one round. Default 100%; set 0 to roll back to full-list pinning (byte-identical to pre-feature). Requires pluginLaneServerHistory. See docs/session-identity-resolution.md. |
|
||||
| `rollout.features.egressPlane` | boolean \| number | 0 (off) | BILI_ROLLOUT_EGRESS_PLANE | The egress plane — ONE switch for the whole new path (#7398/#7439; replaces the retired egressOpLog/egressServeLog pair). ON: every wire lane (OpenAI/Anthropic/Responses/Google) records its outbound conversation view as sparse ops (I/D/U) into the egress_state/egress_flow dual tables — rows are SELF-CONTAINED (message bytes ride the row; no content CAS, ruling 7439-1) — and serves the outbound core-message portion back from the op log, byte-identical by construction (the row bytes are the pipeline's own final core JSON); pinned plugin lanes additionally take server authority — the kernel input is replayed from the flow (rulings 7439-3/5). A bounded backward ladder recovers to the newest healthy log point; ANY unrebuildable row (missing/empty bytes, unknown role), corrupt log, or probe failure degrades that turn to the legacy chain — never a partial swap, never client-as-authority. The system block stays live-built in both paths (prefix-cache anchor discipline). SQLite lane only; title-gen/compaction side requests excluded. Default 0 = off: legacy chain, zero rows, byte-identical to pre-feature. |
|
||||
| `rollout.features.egressPlane` | boolean \| number | 0 (off) | BILI_ROLLOUT_EGRESS_PLANE | The egress plane — ONE switch for the whole new path (#7398/#7439; replaces the retired egressOpLog/egressServeLog pair). ON: every wire lane (OpenAI/Anthropic/Responses/Google) records its outbound conversation view as sparse ops (I/D/U) into the egress_state/egress_flow dual tables — rows are SELF-CONTAINED (message bytes ride the row; no content CAS, ruling 7439-1) — and serves the outbound core-message portion back from the op log, byte-identical by construction (the row bytes are the pipeline's own final core JSON); pinned plugin lanes additionally take server authority — the kernel input is replayed from the flow (rulings 7439-3/5). A bounded backward ladder recovers to the newest healthy log point; ANY unrebuildable row (missing/empty bytes, unknown role), corrupt log, or probe failure degrades that turn to the legacy chain — never a partial swap, never client-as-authority. The system block stays live-built in both paths (prefix-cache anchor discipline). SQLite lane only; title-gen/compaction side requests excluded. Default 0 = off: legacy chain, zero rows, byte-identical to pre-feature. Round 2 (KDD #22): for egress-on sessions the `messages` table is a LAZY projection — no per-turn ingest, the pin channel resolves the op log's I rows, and the session JSON envelope freezes at bootstrap — so per-turn cost stays O(live-window) at any ledger size (10w cumulative measured 638 ms p50; resident guard: `tests/egress-bench.test.ts`, PR #6785 doc §6). |
|
||||
| `rollout.features.pluginDeltaResend` | boolean \| number | 0 (off) | BILI_ROLLOUT_PLUGIN_DELTA_RESEND | Delta resend — the tail-slice form of the full-resend watermark lane: steady plugin-lane turns send x-bili-pf-delta: 1 + body.messages = ONLY the new elements (L = T − stampT, no prefix); the server rebuilds the view from the stashed prefix cores plus the parsed tail (same hit provenance as the full lane). ANY unsatisfiable claim (count/body/tail-ids width mismatch, anchor-chain break after a known list, rollout off) returns 400 pf_delta_reanchor + x-bili-msgid-mode: full and the client resends that turn in full form — one-round convergence, never a silent misparse. OFF by default: delta bodies are unprocessable by servers that do not ship this arm, so the key stays 0 until client send-sides exist. See technical-notes.md “Delta resend”. |
|
||||
| `rollout.features.pluginFullResendWatermark` | boolean \| number | 5 (experimental grey) | BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK | Full-resend watermark fastpath (#5403/#5418): plugin-lane chat-completions turns whose previous response carried an x-bili-pf-seq stamp assert the resent prefix via the echoed count (structural scan, no full parse); on a hit the pipeline consumes stashed canonical prefix cores plus only the new tail window (byte-identical outbound provenance; ANY doubt falls back to the untouched full-parse path per turn and re-stamps, five credited misses hold the lane for one hour). Requires the client to echo the stamp back as x-bili-pf-count (dsh/pi/opencode/omp do; unadapted lanes never hit). EXPERIMENTAL grey rollout — ON by default for roughly 5% of installs (owner ruling 2026-11-02: small cohort before GA; one-time intro notice in the web UI for every install, tri-state switch in quick config). Force it with `true`, turn off with `false` (or a percent) / env = 0. See technical-notes.md “Full-resend watermark fastpath”. |
|
||||
| `rollout.features.passDshExtensions` | boolean \| number | 0 (off = intercept) | BILI_ROLLOUT_PASS_DSH_EXTENSIONS | DSH client-extension intercept (#7168/#7439): DSH (deepseek-harness) rides top-level `dsh_*` fields on every request — `dsh_session_log` (the 8 MiB lossless session-log upload for the official DeepSeek API; the model never reads it) plus the sibling `dsh_plugin_packages`; forked/seeded sessions resend the whole log each turn until the watermark catches up. Default 0% = INTERCEPT: bili strips every TOP-LEVEL `dsh_*` key from the inbound body (src/server/handle.ts) before any protocol path builds the outbound, so the 8 MiB is never forwarded upstream — no bandwidth waste, no unknown-field risk on a non-DeepSeek upstream. DSH is unaffected: its upload watermark only advances on a 2xx, which bili still returns, so the resends self-heal. The window meter is separately exempt via the #7168 dsh_* skip (src/preflight.ts). RELEASE by flipping to 100% (or removing the strip) once the server-authoritative egress work (#6785 / discussion #7439) ships the client-extension sideband; force pass-through now with `true` / env = 1. |
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
| `rollout.features.identityChannelHarvest` | boolean \| number | 0(关) | BILI_ROLLOUT_IDENTITY_CHANNEL_HARVEST | 身份信道采集的灰度门(#5825):当安装级开关(BILI_IDENTITY_HARVEST)未设置时,允许仅由本灰度键激活回环专属的转录/SQLite 采集(claude-code / codebuddy / mcode / goose / qwen 车道);两者都不设则永不读客户端存储。owner 裁定 2026-11-07:本灰度键与 rollout.features.pluginLaneServerHistory(它管已接纳 id 的行钉住)刻意分离——任一使能方可激活采集。默认 0%,小流量观察退化率后再抬。见 identity-channels.zh-CN.md。 |
|
||||
| `rollout.features.pluginLaneServerHistory` | boolean \| number | 100(开,已 GA) | BILI_ROLLOUT_PLUGIN_LANE_SERVER_HISTORY | 插件车道服务端正史(#4491):对已放量的安装,(a) 插件车道请求可携带与 `messages` 平行的内部字段 `biliMsgIds`,把消息身份钉在客户端提供的 id 上(转发上游前一律剥掉;格式错误的数组告警后忽略,身份投毒形态在增量车道直接硬失败);(b) 仅回环可达的 `POST /__bili/plugin/render` 端点从统一存储渲染出站前缀(折叠区收敛为摘要锚点;任何失步都返回非 2xx,shim 退回本地历史);(c) 增量车道探测响应通告 `serverHistory`。默认 100%(GA,owner 裁定 2026-11-13);设 0 可把安装回滚到 GA 前状态。 |
|
||||
| `rollout.features.pluginMsgIdIncremental` | boolean \| number | 100(开,已 GA) | BILI_ROLLOUT_PLUGIN_MSG_ID_INCREMENTAL | 增量 msgid pin 通道(#7064 §8,owner 裁定 2026-11-18/19):稳态插件轮用**尾形态**申报消息 id——有界的 `x-bili-pf-tail-ids` 头(锚点+新增,≤ 2048 个,`?` 占位槽)或短 body id 数组——替代全量清单;服务端从自己账本的 live 行重盖前缀 id(ingest 是 INSERT OR IGNORE on (session_id,seq)——位置上的 msg_id 只写一次,永不改写)。接受规则(2026-11-19 定型):声明的尾段 [T-L, T-1] 与账本重叠段逐行相等(任一行漂移⇒降级 full,永不 400);超长会话(>2048)截断的尾清单同样可 pin——重叠段更长、证明更强。只有快照轮(账本空/折叠后重锚)发全量形态;全量优先于尾形态同时到达。响应携带 `x-bili-msgid-mode: incremental\|full`(4xx 即清,与 x-bili-pf-seq 同一学习点)。任何失配一轮内自愈。默认 100%;设 0 回滚到全量清单 pin(与特性前字节一致)。需先开 pluginLaneServerHistory。见 session-identity-resolution.zh-CN.md。 |
|
||||
| `rollout.features.egressPlane` | boolean \| number | 0(关) | BILI_ROLLOUT_EGRESS_PLANE | egress 平面——整条新链路的**唯一开关**(#7398/#7439;取代已退役的 egressOpLog/egressServeLog 双键)。开:四条 wire 车道(OpenAI/Anthropic/Responses/Google)每轮把出站会话视图记为稀疏 op(I/D/U)写入 egress_state/egress_flow 双表——行**自包含**(消息字节随行走,不经内容 CAS,裁定 7439-1)——并从 op 日志回放重建出站核心消息段,按构造字节一致(行内字节就是管线自己的最终 core JSON);pinned 插件车道另获服务端权威——内核输入从流水回放(裁定 7439-3/5)。有界回溯阶梯恢复到最近健康日志点;任何不可重建行(缺/空字节、未知 role)、日志损坏或探针失败,整轮降级 legacy 链路——绝不部分替换、绝不客户端为准。system 块两条路径都保持 live 构建(前缀缓存锚点纪律)。仅 SQLite 车道;标题生成/压缩侧路请求排除。默认 0 = 关:legacy 链路,零行,与特性前字节一致。 |
|
||||
| `rollout.features.egressPlane` | boolean \| number | 0(关) | BILI_ROLLOUT_EGRESS_PLANE | egress 平面——整条新链路的**唯一开关**(#7398/#7439;取代已退役的 egressOpLog/egressServeLog 双键)。开:四条 wire 车道(OpenAI/Anthropic/Responses/Google)每轮把出站会话视图记为稀疏 op(I/D/U)写入 egress_state/egress_flow 双表——行**自包含**(消息字节随行走,不经内容 CAS,裁定 7439-1)——并从 op 日志回放重建出站核心消息段,按构造字节一致(行内字节就是管线自己的最终 core JSON);pinned 插件车道另获服务端权威——内核输入从流水回放(裁定 7439-3/5)。有界回溯阶梯恢复到最近健康日志点;任何不可重建行(缺/空字节、未知 role)、日志损坏或探针失败,整轮降级 legacy 链路——绝不部分替换、绝不客户端为准。system 块两条路径都保持 live 构建(前缀缓存锚点纪律)。仅 SQLite 车道;标题生成/压缩侧路请求排除。默认 0 = 关:legacy 链路,零行,与特性前字节一致。第 2 轮(KDD #22):egress-on 会话的 `messages` 表是**惰性投影**——不逐轮 ingest,pin 通道解析 op log 的 I 行,会话 JSON 信封 bootstrap 冻结——单轮成本恒为 O(存活窗口),与账本规模无关(10w 累计实测 638ms p50;常驻守卫:`tests/egress-bench.test.ts`,PR #6785 文档 §6)。 |
|
||||
| `rollout.features.pluginDeltaResend` | boolean \| number | 0(关) | BILI_ROLLOUT_PLUGIN_DELTA_RESEND | Delta 重发——全量重发水位快路径的尾切片形态:稳态轮发 x-bili-pf-delta: 1 + body.messages = **只有**新元素(L = T − stampT,无前置);服务端用钉存前缀核 + 解析出的尾部重建视图(与全量车道同源的命中可证)。任何不成立的声明(count/body/tail-ids 宽度不符、已知清单后锚链断裂、灰度关)返回 400 pf_delta_reanchor + x-bili-msgid-mode: full,客户端当轮改发全量形态——一轮收敛,绝不静默错解。默认**关**:delta body 对未上车的服务端不可处理,故保持 0 直到客户端发送端就位。见 technical-notes.zh-CN.md「Delta 重发」。 |
|
||||
| `rollout.features.pluginFullResendWatermark` | boolean \| number | 5(实验性灰度) | BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK | 全量重发水位快路径(#5403/#5418):插件车道 chat-completions 回合若上一轮响应盖有 x-bili-pf-seq,则用回声计数声明重发前缀(结构扫描,不做全量解析);命中时管线只消费钉存的前缀核 + 新增尾巴窗口(出站字节同源可证;任何疑点当轮回退未动过的全量解析路径并重新盖戳,连续五次计名失配将车道按住一小时)。需客户端把戳回声为 x-bili-pf-count(适配的车道回带;其余车道不会命中)。**实验性灰度**——默认仅约 5% 的安装开启(owner 裁定 2026-11-02:先小流量再 GA;web 面板对全部安装显示一次性公告、快速配置提供三态开关);`true` 强制开、`false`(或百分比)/ env = 0 关。见 technical-notes.zh-CN.md「全量重发水位快路径」。 |
|
||||
| `rollout.features.passDshExtensions` | boolean \| number | 0(关 = 拦截) | BILI_ROLLOUT_PASS_DSH_EXTENSIONS | DSH 客户端扩展拦截(#7168/#7439):DSH(deepseek-harness)每个请求都带顶层 `dsh_*` 字段——`dsh_session_log`(给官方 DeepSeek API 的 8 MiB 增量无损会话日志,模型根本不读)加孪生字段 `dsh_plugin_packages`;fork/seed 会话在水位追上前每轮从头整段重传。默认 0% = 拦截:bili 在入站 body 解析后、任何协议路径构建出站前,删掉所有**顶层** `dsh_*` 键(src/server/handle.ts),8 MiB 永不转发上游——不浪费带宽,非 DeepSeek 上游也不见陌生大字段。DSH 不受影响:其上传水位只在 2xx 时推进,bili 照常回 2xx,重传自愈。窗口计量另由 #7168 的 dsh_* 豁免(src/preflight.ts)兜底。等服务端权威 egress 工作(#6785 / 讨论 #7439)把客户端扩展旁路带做好后,翻到 100%(或移除裁切)即放开;现在想临时放行用 `true` / env = 1。 |
|
||||
|
||||
+1
-1
@@ -35,4 +35,4 @@
|
||||
| [lifecycle](lifecycle.md) | Transition-switch ledger / retirement inventory / hygiene record (CI-enforced `BILI_*` coverage) |
|
||||
| [auto-merge-guardrails](auto-merge-guardrails.md) | Evidence appendix behind §7 of `AGENTS.md` (AI auto-dev review history) |
|
||||
| [unified-loop-spec](unified-loop-spec.md) | Historical design: unified compress-loop spec (implemented; code is the source of truth) |
|
||||
| [PR #6785 in depth](pr-6785-unified-storage-and-flows.md) / [中文](pr-6785-unified-storage-and-flows.zh-CN.md) | Review-grade walkthrough of PR #6785: unified-storage tables (schema v12) / implementation logic / per-turn data flow / full switch ledger + measured validation (#5874/#7064/#7398/#4491) |
|
||||
| [PR #6785 in depth](pr-6785-unified-storage-and-flows.md) / [中文](pr-6785-unified-storage-and-flows.zh-CN.md) | Review-grade walkthrough of PR #6785: unified-storage tables (schema v12) / implementation logic / per-turn data flow / full switch ledger + measured validation (#5874/#7064/#7398/#4491) + round 2: op-log canonical numbering, lazy projection, window re-anchor, resident perf gate (KDD #22) |
|
||||
|
||||
+1
-1
@@ -35,4 +35,4 @@
|
||||
| [lifecycle](lifecycle.md) | 过渡开关台账 / 退役模块盘点 / 卫生记录(CI 强制 `BILI_*` 覆盖) |
|
||||
| [auto-merge-guardrails](auto-merge-guardrails.md) | `AGENTS.md` §7 背后的证据附录(AI 自动开发评审史) |
|
||||
| [unified-loop-spec](unified-loop-spec.md) | 历史设计:统一压缩循环规格(已落地,以代码为准) |
|
||||
| [PR #6785 详尽梳理](pr-6785-unified-storage-and-flows.zh-CN.md) / [EN](pr-6785-unified-storage-and-flows.md) | PR #6785 审查级梳理:统一存储表结构(schema v12)/ 实现逻辑 / 逐轮数据流转 / 开关总账 + 实测验证(#5874/#7064/#7398/#4491) |
|
||||
| [PR #6785 详尽梳理](pr-6785-unified-storage-and-flows.zh-CN.md) / [EN](pr-6785-unified-storage-and-flows.md) | PR #6785 审查级梳理:统一存储表结构(schema v12)/ 实现逻辑 / 逐轮数据流转 / 开关总账 + 实测验证(#5874/#7064/#7398/#4491)+ 第 2 轮:op log 正史编号、惰性投影、窗口 re-anchor、常驻性能门(KDD #22) |
|
||||
|
||||
@@ -46,13 +46,13 @@ One-off closure from the review: `parseTailIds` alone lacked the reserved-prefix
|
||||
|
||||
## 5. Persistence single source of truth
|
||||
|
||||
The unified-store `messages.msg_id` column is the ONLY id truth: ingestion pins validated ids into rows (T5 ruling: no parallel ledger; skeleton rows carry no ids). Ledger primary key `(session_id, msg_id, content_hash)`; canonical rows key on **MSGID, not content hash** (#4491); fork clones preserve numbers (#4316 L3 PR3/3 `cloneSessionRows`).
|
||||
The unified-store `messages.msg_id` column is the ONLY id truth: ingestion pins validated ids into rows (T5 ruling: no parallel ledger; skeleton rows carry no ids). Ledger primary key `(session_id, msg_id, content_hash)`; canonical rows key on **MSGID, not content hash** (#4491); fork clones preserve numbers (#4316 L3 PR3/3 `cloneSessionRows`). **KDD #22 carve-out (egress-on sessions only):** the op log is the canonical message authority (`egress_flow.msgid` + `log_seq`); the messages rows become a LAZY projection rebuilt one-time on plane rollback / web read / restore, and the pin channel (KDD #20/#21) resolves the op log's I rows instead of this ledger for those sessions — all other consumers unchanged.
|
||||
|
||||
## 6. Consumers (six; what question each one asks of the ids)
|
||||
|
||||
| Consumer | Location | Question answered | Id-usage boundary |
|
||||
|---|---|---|---|
|
||||
| ① storage-column identity | unified store `messages.msg_id` | join key for every settle/reconcile path | the single identity-space entry point; the other four's id evidence ultimately folds in here |
|
||||
| ① storage-column identity | unified store `messages.msg_id` (egress-on: op-log I rows, KDD #22) | join key for every settle/reconcile path | the single identity-space entry point; the other four's id evidence ultimately folds in here |
|
||||
| ② session-resolve last-resort rung #5719 | tryMsgIdRescue (src/session-resolve.ts ~:324; fork-exit call sites ~:432/:481/:501) | after bytes/tag evidence was destroyed (compaction deleted cells, system rewrite deleted fragments), is this request the SAME session? | ANY id overlap under the same raw key ⇒ same session; NOTE: no LANE attribution (§7 boundary B) |
|
||||
| ③ settlement membership probe #4805 | probeRequestMembership (src/request-membership.ts; call sites src/server/prepare-openai.ts:597, prepare-anthropic.ts:640; consumed cache-ledger.ts:1866) | was this id admitted by this session's ledger? needle = latest admitted id | **pure evidence — never enters the identity space**, never re-keys/forks; worst case one unsettled cycle, self-heals |
|
||||
| ④ incremental-lane canonical rows #4491/#4834 | src/incremental-lane.ts (validateMsgIds :623, claim-reuse 400 :628, cache-control rekey :631-635; dsh-side burned-claim pre-screen ~:2584) | which canonical rows did this delta turn append? | claim semantics: re-sent claimed id = retry-storm signal, turn 400s |
|
||||
|
||||
@@ -47,13 +47,13 @@
|
||||
|
||||
## 5. 持久化单一事实源
|
||||
|
||||
统一存储 `messages.msg_id` 列是唯一 id 事实源:ingest 时把校验过的 id 钉进行(T5 裁定:无双平行 ledger、skeleton 行不携 id)。账本主键 `(session_id, msg_id, content_hash)`;canonical 行按 **MSGID 而非内容 hash** 键控(#4491);fork 克隆保号(#4316 L3 PR3/3 `cloneSessionRows`)。
|
||||
统一存储 `messages.msg_id` 列是唯一 id 事实源:ingest 时把校验过的 id 钉进行(T5 裁定:无双平行 ledger、skeleton 行不携 id)。账本主键 `(session_id, msg_id, content_hash)`;canonical 行按 **MSGID 而非内容 hash** 键控(#4491);fork 克隆保号(#4316 L3 PR3/3 `cloneSessionRows`)。**KDD #22 例外(仅 egress-on 会话):op log 是正史消息权威**(`egress_flow.msgid` + `log_seq`);messages 行降级为**惰性投影**(平面回滚 / web 读 / 恢复时一次性重建),pin 通道(KDD #20/#21)对这些会话改解析 op log 的 I 行而非本账本——其余消费者不变。
|
||||
|
||||
## 6. 消费方(五个,id 各自回答什么问题)
|
||||
|
||||
| 消费方 | 位置 | 回答的问题 | id 使用边界 |
|
||||
|---|---|---|---|
|
||||
| ① 存储列身份 | unified store `messages.msg_id` | settle/reconcile 一切 join 的主键 | 唯一身份空间入口,其余四方的 id 证据最终都折到这里 |
|
||||
| ① 存储列身份 | unified store `messages.msg_id`(egress-on:op-log I 行,KDD #22) | settle/reconcile 一切 join 的主键 | 唯一身份空间入口,其余四方的 id 证据最终都折到这里 |
|
||||
| ② session-resolve 最后一档 #5719 | tryMsgIdRescue(src/session-resolve.ts ~:324;fork-exit 调用点 ~:432/:481/:501) | 字节/标签证据被压缩或 system 重写摧毁后,这条请求还是不是既有会话? | 同一 raw key 下**任意 id 重叠 ⇒ 认定同会话**;注意它不做 lane 归属判定(§7 边界 B) |
|
||||
| ③ 结算 membership 探针 #4805 | probeRequestMembership(src/request-membership.ts;调用点 src/server/prepare-openai.ts:597、prepare-anthropic.ts:640;消费 cache-ledger.ts:1866) | 这个 id 是否已被本会话账本准入?needle = 最近准入 id | **纯证据,永不进身份空间**、永不 re-key/fork;误伤仅致一轮结算未决,自癒 |
|
||||
| ④ 增量车道 canonical 行 #4491/#4834 | src/incremental-lane.ts(validateMsgIds :623、认领复用 400 :628、cache-control rekey :631-635;dsh 侧 burned-claim 预筛 ~:2584) | 本轮增量追加了哪些正史行? | 认领语义:已认领 id 再上行=重试风暴信号,整回合 400 |
|
||||
|
||||
@@ -338,3 +338,46 @@ Construction = the user scenario's plugin shape: client history grows from 1 mes
|
||||
- A valid delta-arm rerun in the growing scenario (with `pluginDeltaResend:true`).
|
||||
- The compact B row ≈8MB @ 100k rows vs the "few-KB per turn" red line: a design-declared exception (#7398 §5); to hold the red line strictly, the B row could become a "range reference + anti-forgery fingerprint" (the #7064 l1_world demotion idea), at the cost of losing the state table's self-contained replay closure — needs an owner ruling.
|
||||
- After an archive restore the egress op-log restarts empty (the next turn re-appends the full +I view — correct, but one full batch).
|
||||
|
||||
## 6. Round 2 — ruling 7439-2 (KDD #22): the op log as sole canonical, lazy projection, window re-anchor (2026-11-22)
|
||||
|
||||
> Round-2 work landed on the same branch after the §1–§5 snapshot. Where this section and earlier sections conflict, THIS section wins.
|
||||
|
||||
### 6.1 R-A: canonical message numbering (op_seq / log_seq)
|
||||
|
||||
- Both egress tables carry TWO keys: `op_seq` (PK, per-table append-only row cursor — the recovery/truncation key) and `log_seq` (canonical message number, **I rows only**; D/U/B rows are NULL). `log_seq` is session-scoped and **never re-issued** (kernel id contract); every I row's `log_seq` = the canonical index of that turn's new row in the live view, stamped at record time — numbering no longer derives from position or from the messages table.
|
||||
- `recoverEgressBase` is bounded (the state table is physically compacted); a row-less session bootstraps via a fresh B op; a pinned session with rows but **no healthy point hard-fails the turn** (ruling 7439-5: 500 + `x-bili-egress: unreadable` + `{type:'egress_flow_unreadable'}` via `EgressAuthorityRejectError` — the lane catch no longer swallows it; the session never truncates its own corrupt rows and never re-bootstraps from client bytes).
|
||||
- R-B: fork = `egressFork` whole-table op-log copy (self-fork throws; empty parent no-ops).
|
||||
|
||||
### 6.2 B: in-txn window re-anchor delta (#7474 — the 2s-floor root cause)
|
||||
|
||||
Root cause of the pre-fix growing-session latency (ep3 ON 5697 ms/turn @ 100k): the pf-watermark lane persists ONLY the ~56-element tail window every HIT turn (`lastMessagesFolded`), while `planIngestDelta` was built for strict-append turns — its equal-len/shrink/boundary-id gates structurally rejected a sliding window, so nearly EVERY turn fell to the full path: `remapPlanToAbsolute` = SELECT **all** ~100k session rows + identity→seq map rebuild + per-row byte repair. Writes were never the cost; the READ was O(total ledger).
|
||||
|
||||
Fix: `planIngestReanchor` + the `ingestSession` re-anchor txn branch. Per window row, ONE indexed `(session_id, msg_id, identity)` probe: existing rows **keep their seq** (identity-stability invariant; byte-hash + retired_at checks), new rows land at `MAX(seq)+1`, #6947 ref backfill; `anchored === 0` or a stored-`tail_json` mismatch → the branch declines and the full path runs UNCHANGED. O(window) point lookups ≈ ms; the full path remains the universal fallback.
|
||||
|
||||
### 6.3 P2b/P2b-ext: the egress-on session's messages projection goes LAZY (KDD #22)
|
||||
|
||||
For sessions with `metadata.egressAuthority === true` (and `egressPlane` on):
|
||||
|
||||
- **No per-turn unified ingest**: `ingestRowsNow` and the debounced unified legs early-return — the `messages` table is demoted to a **lazy projection** for these sessions (rebuilt one-time O(n) on plane rollback / web read / replica restore). Boot after restart still comes from the op log (`recoverEgressBase`), not from the projection.
|
||||
- **Pin channel reads the op log**: the KDD #20/#21 pin ledger (tail-overlap / live-id re-stamp) for egress-on sessions resolves from `egress_flow` I rows (msgid + log_seq) instead of the messages ledger (`snapPinLiveIds` shim). Wire unchanged.
|
||||
- **Envelope frozen at bootstrap** (`d28d9ff3a`): no per-turn read+rewrite of the 15.5MB growing session JSON (kernel refs are never pruned — messageRefs 10MB + tsStamps 5.5MB at 100k); the frozen route must keep the resident fields unthinned (`9183ea817`, #4788 D2) or the pinned turn 502s.
|
||||
- **Verification**: the egress probe (flow vs client sample) is the SOLE drift verifier for egress-on sessions — `BatchedViewVerification` is off for them (`13b9baae2`): the client-vs-canonical leg would only measure the known server-wins divergence (ruling 7439-5) and re-latch drift forever.
|
||||
- Flow-corruption semantics: HARD FAIL, no projection fallback for outbound — flow and messages die together anyway (flow independence, ruling 7439-2 §2).
|
||||
|
||||
### 6.4 Post-fix measured (100k cumulative, folded shape view ~1800–2100, 8-turn steady, same box/dist per pair)
|
||||
|
||||
| run | arm | build | steady p50 / max | total |
|
||||
|---|---|---|---|---|
|
||||
| ep3 | ON pre-fix | a33d02184 | 5697 / 6298 ms | 3273 s |
|
||||
| ep5f | OFF pre-fix | a33d02184 | 2301 / 2946 ms | 1124 s |
|
||||
| ep8d | OFF post-B | fb88bc2af | 1954 / 2735 ms | 1067 s |
|
||||
| ep10 | ON post-fix | fb88bc2af | 1327 / 1374 ms | 676 s |
|
||||
| ep18 / ep20 | ON merged | dbf4b140b | 730 / 761 · **638 / 655 ms** | 462 / 456 s |
|
||||
| ep22 | OFF merged | dbf4b140b | 2016 / 2957 ms | 1070 s |
|
||||
|
||||
**Acceptance `<1s` @ 10w cumulative met by the ON arm (638 ms p50, 9× faster than pre-fix); ON is now faster than the same-build OFF arm.** ep20 DB: no JSON envelope, messages table 0 rows for the egress-on session, egress_flow 1 row/turn, state 25 rows bounded, WAL capped at 8 MiB (journal_size_limit). The OFF-arm floor (~2s) is the pre-PR #5744 family (per-turn full read+rewrite of the growing JSON envelope + 244MB DB fsync) — out of scope per the single-switch ruling. The ep14c-era 2.2GB WAL anomaly was a pre-WAL-cap build; post-cap builds hold 8 MiB.
|
||||
|
||||
### 6.5 Resident perf gate (ruling: e2e bench ×3, ≤+20% over baseline)
|
||||
|
||||
`tests/egress-bench.test.ts` (gate `ACP_TEST_EG_BENCH=1`; dedicated CI lane `.github/workflows/ci-e2e-egbench.yml` on master): hermetic in-process proxy (port 0, temp XDG), 30k-row growing pinned session with host-side folds + the pf watermark channel, median-of-3 steady p50/max within +20% of `tests/e2e/bench/egress-bench.baseline.json` (calibration 201/300 ms; missing baseline prints CALIBRATION and passes). Pins per-turn cost to O(live-window): a regression back to a full-table path goes red. The 100k growing-run matrix above stays as the deep-dive reference; the bench is the resident guard.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
> 范围:`2026-11-15_msgid-snapshot-unified` @ `39941c816`(base `origin/master` `b10c1a0d4`)。
|
||||
> 134 文件 +13740/−367。本文是本 PR 的**审查级**完整梳理:四部分(表结构 / 实现逻辑 / 数据流转 / 开关)+ 实测验证 + 本轮发现与修复。行号均指 head 处源码。
|
||||
> **第 2 轮(owner 裁定 7439-2,KDD #22,2026-11-22)已落在同一分支、晚于本快照**——op log 正史编号、窗口 re-anchor delta、messages 惰性投影与常驻性能门。见 **§6**(与本文件 §1.2 egress DDL 草图、§5.4 遗留项冲突处以 §6 为准)。
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -338,3 +340,46 @@ fold tx:blocks 插/更 + 覆盖行 retire(同事务)+ fold_journal 一行
|
||||
- delta 臂在增长场景的有效重跑(带 `pluginDeltaResend:true`)。
|
||||
- 压实 B 行 ≈8MB @10w 行 vs "每轮新增存储几 K" 红线:设计自认的例外(7398 §5);若要彻底守住红线,可把 B 行改成"区间引用+防伪指纹"(#7064 对 l1_world 的降级思路),代价是失去"状态表独立可重放"的封闭性——需 owner 裁定。
|
||||
- 归档恢复后 egress op-log 从空重启(下一轮全量 +I 重建,正确但有一次全批)。
|
||||
|
||||
## 6. 第 2 轮——裁定 7439-2(KDD #22):op log 唯一正史、惰性投影、窗口 re-anchor(2026-11-22)
|
||||
|
||||
> 第 2 轮工作落在同一分支、晚于 §1–§5 快照。本节与前面章节冲突时,以本节为准。
|
||||
|
||||
### 6.1 R-A:正史消息编号(op_seq / log_seq)
|
||||
|
||||
- 两张 egress 表各带两个键:`op_seq`(PK,每表 append-only 行游标——恢复/截断键)与 `log_seq`(正史消息编号,**仅 I 行**;D/U/B 行为 NULL)。`log_seq` 会话内作用域、**永不重发**(kernel id 契约);每条 I 行的 `log_seq` = 该轮新增行在存活视图里的正史下标,记账时戳定——编号不再依赖位置、也不再依赖 messages 表。
|
||||
- `recoverEgressBase` 有界(state 表被 compaction 物理裁剪);无行会话经新 B op 引导;有行但**无健康点**的 pinned 会话整轮**硬失败**(裁定 7439-5:500 + `x-bili-egress: unreadable` + `{type:'egress_flow_unreadable'}`,经 `EgressAuthorityRejectError`——车道 catch 不再吞掉;会话永不截断自己的坏行、永不从客户端字节重引导)。
|
||||
- R-B:fork = `egressFork` 整表 op log 拷贝(self-fork 抛错;空父 no-op)。
|
||||
|
||||
### 6.2 B:事务内窗口 re-anchor delta(#7474——2s 地板的根因)
|
||||
|
||||
修复前增长会话延迟(10w 时 ON 臂 ep3 5697ms/轮)的根因:pf 水位车道每个 HIT 轮只持久化 ~56 元素尾窗(`lastMessagesFolded`),而 `planIngestDelta` 为严格追加轮设计——其等长/缩短/边界 id 门结构性拒绝滑动窗口 ⇒ 几乎**每轮**落入全量路径:`remapPlanToAbsolute` = SELECT **全部** ~10w 会话行 + identity→seq 映射重建 + 逐行字节修复。写从来不是成本;读是 O(总账本)。
|
||||
|
||||
修复:`planIngestReanchor` + `ingestSession` re-anchor 事务分支。每窗口行一次索引点查 `(session_id, msg_id, identity)`:已存在行**保持原 seq**(身份稳定性不变量;字节 hash + retired_at 校验),新行落在 `MAX(seq)+1`,#6947 ref 回填;`anchored === 0` 或存储 `tail_json` 不符 ⇒ 分支让位,全量路径原样执行。O(窗口) 点查 ≈ 毫秒;全量路径仍是通用兜底。
|
||||
|
||||
### 6.3 P2b/P2b-ext:egress-on 会话的 messages 投影惰性化(KDD #22)
|
||||
|
||||
对 `metadata.egressAuthority === true`(且 `egressPlane` 开)的会话:
|
||||
|
||||
- **不再逐轮统一 ingest**:`ingestRowsNow` 与防抖统一腿早退——这些会话的 `messages` 表降级为**惰性投影**(平面回滚 / web 读 / 副本恢复时一次性 O(n) 重建)。重启后的引导仍走 op log(`recoverEgressBase`),不走投影。
|
||||
- **pin 通道读 op log**:KDD #20/#21 pin 账本(尾重叠 / 活 id 重盖)在 egress-on 会话上改从 `egress_flow` I 行(msgid + log_seq)解析,不经 messages 账本(`snapPinLiveIds` shim)。wire 不变。
|
||||
- **信封在 bootstrap 冻结**(`d28d9ff3a`):不再逐轮读+写 15.5MB 的会话 JSON(kernel refs 永不裁剪——10w 时 messageRefs 10MB + tsStamps 5.5MB);冻结路由必须保持常驻字段不被裁剪(`9183ea817`,#4788 D2),否则 pinned 轮 502。
|
||||
- **校验**:egress 探针(flow vs 客户端抽样)是 egress-on 会话唯一的漂移校验器——`BatchedViewVerification` 对它们关闭(`13b9baae2`):客户端 vs 正史那条腿只会量到已知的服务端赢分歧(裁定 7439-5),并把 drift 永远锁死。
|
||||
- flow 损坏语义:硬失败,出站无投影兜底——flow 与 messages 同生共死(flow 独立性,裁定 7439-2 §2)。
|
||||
|
||||
### 6.4 修复后实测(10w 累计,折叠形态视图 ~1800–2100,稳态 8 轮,同机同 dist 成对)
|
||||
|
||||
| 跑 | 臂 | build | 稳态 p50 / max | 总时长 |
|
||||
|---|---|---|---|---|
|
||||
| ep3 | ON 修复前 | a33d02184 | 5697 / 6298 ms | 3273 s |
|
||||
| ep5f | OFF 修复前 | a33d02184 | 2301 / 2946 ms | 1124 s |
|
||||
| ep8d | OFF 修复后(B) | fb88bc2af | 1954 / 2735 ms | 1067 s |
|
||||
| ep10 | ON 修复后 | fb88bc2af | 1327 / 1374 ms | 676 s |
|
||||
| ep18 / ep20 | ON 合并后 | dbf4b140b | 730 / 761 · **638 / 655 ms** | 462 / 456 s |
|
||||
| ep22 | OFF 合并后 | dbf4b140b | 2016 / 2957 ms | 1070 s |
|
||||
|
||||
**验收线「10w 累计 <1s」由 ON 臂达成(638ms p50,比修复前快 9×);ON 臂现在比同 build 的 OFF 臂更快。** ep20 DB:无 JSON 信封,egress-on 会话 messages 表 0 行,egress_flow 每轮 1 行,state 25 行有界,WAL 上限 8MiB(journal_size_limit)。OFF 臂地板(~2s)属修复前 #5744 家族(逐轮全量读+写膨胀的 JSON 信封 + 244MB DB fsync)——按单开关裁定不在本 PR 范围。ep14c 时代 2.2GB WAL 异常是 WAL 上限前的 build;上限后的 build 稳在 8MiB。
|
||||
|
||||
### 6.5 常驻性能门(裁定:e2e bench ×3,不超基线 +20%)
|
||||
|
||||
`tests/egress-bench.test.ts`(gate `ACP_TEST_EG_BENCH=1`;专属 CI 车道 `.github/workflows/ci-e2e-egbench.yml`,master 触发):hermetic 进程内代理(port 0、临时 XDG),3w 行增长的 pinned 会话(宿主侧折叠 + pf 水位通道),3 次中位稳态 p50/max 不超 `tests/e2e/bench/egress-bench.baseline.json`(校准值 201/300 ms;基线缺失时打印 CALIBRATION 并放行)。把单轮成本钉在 O(存活窗口):任何退回全表路径的回归会红。上面的 10w 增长矩阵留作深查参照;bench 是常驻守卫。
|
||||
|
||||
@@ -264,3 +264,28 @@ Three additional phases harden the #1628 failure class:
|
||||
- **Cache-lane doctor** — lays out an opencode cache lane
|
||||
(`npm/billion-context@latest/<ts>/node_modules/billion-context`) and asserts
|
||||
`doctor --json` resolves the update target to the running copy, not a global root.
|
||||
|
||||
## E2E: Egress-Plane Perf Bench (`ACP_TEST_EG_BENCH`)
|
||||
|
||||
`tests/egress-bench.test.ts` (dedicated CI lane `.github/workflows/ci-e2e-egbench.yml`,
|
||||
master push + `workflow_dispatch`): a hermetic growing-session benchmark that pins the
|
||||
egress plane's per-turn cost to O(live-window) (KDD #22, #7474).
|
||||
|
||||
```bash
|
||||
ACP_TEST_EG_BENCH=1 node --import tsx --test tests/egress-bench.test.ts
|
||||
```
|
||||
|
||||
- Gated by `ACP_TEST_EG_BENCH=1`; skips by default; the `npm test` glob does not cover it.
|
||||
- Hermetic by construction: in-process proxy on port 0, temp XDG root, loopback upstream —
|
||||
no fixture registry, no port-range assumptions (#360), nothing shared with a running bili.
|
||||
- Shape: a pinned plugin conversation grown to ~30k ledger rows (100 msgs/turn, host-side
|
||||
folds every 300 refs, live tail ~1800) driving the pf watermark channel exactly as the
|
||||
production lanes do; steady = the second half of the run.
|
||||
- Verdict: median-of-3 steady p50/max within **+20%** of
|
||||
`tests/e2e/bench/egress-bench.baseline.json` (calibration: 201/300 ms on the perf box).
|
||||
A missing baseline prints the CALIBRATION numbers and passes — regenerate it only after
|
||||
a deliberate storage-path change, with justification in the PR (same discipline as the
|
||||
wire-contract goldens).
|
||||
- A regression back to a full-table ingest path (the pre-#7474 shape: O(total ledger) reads)
|
||||
goes red well before a real 100k session would. The deep-dive 100k growing matrix lives in
|
||||
the PR #6785 doc §6 (docs/pr-6785-unified-storage-and-flows.md).
|
||||
|
||||
Reference in New Issue
Block a user