Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/architecture/storage.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

**整合性。** チェックポイントフレーム署名 + S4 行ごとのチェックサム; 判定はチェーンを信頼し、コンテンツの類似性を決して信頼しない。任意の静止時エンコーディング: AES-256-GCM (#708) + zstd (#1080)。`src/storage/mysql.ts` 配下の mysql ダイアレクトはテストミラーのみである(mysql-contract CI レーン) — SQLite が本番ストレージであり続ける。

**egress プレーン(KDD #23/#24、#7439/#7577/#7591/#7773 — 出向会話 op log)。** `egress_flow`(SQLite レーンのみ、ゲート `rollout.features.egressPlane`)は各セッションの出向ビューの **append-only** I/D/U op log を保持し、行は自己完結(バイトは行に乗る、content CAS 不要)。flow のキーは `(session_id, op_seq)`(稠密な行カーソル、復旧/切り詰め鍵)、I 行はさらに `log_seq`(正規メッセージ番号、再発行なし)を持つ;フロンティアは flow 上の `MAX(log_seq)`(退役した `B` ベース行の `highWater` payload は消滅、#7773)。**`egress_state` は物化ライブビュー**(#7773):PK `(session_id, msgid)`、`pos` 順;各 append は同一トランザクション内で op を行に適用(I 挿入+シフト、U その場更新、D 物理削除+シフト)、サービスコピーは構造上ライブビューの大きさに有界 — ベース行も圧縮も op ミラーもない。egress-on セッションでは op log が**唯一の**正規メッセージ権威:出向バイトはそこから配信、pin チャネルは messages レジャーではなく物化 state を読む、ターンごとの統一 ingest は停止(messages は**遅延射影**に格下げ、ロールバック/web 読み取り/復元時に一括再構築)、セッション JSON エンベロープは bootstrap で凍結。復旧:state コピーが損傷したら**全履歴リプレイで再構築**しそのまま配信(flow が権威);flow 自体がリプレイ不能なら `recoverEgressBase` が全履歴 walk を 1 度だけ実行(`egressFlowWalkBack`)— 最新健全プレフィックスまで尾を切り詰め;健全な点が皆無 ⇒ ターンはハード失敗(裁定 7439-5)で、クライアントバイトに劣化することはない。裁定 7439-2 は読み書き側を blocks テーブル本体に置く:`summary_bytes` がブロック要約をインライン化(読取り側はこれを優先、content CAS は legacy フォールバックのみ)、`start_msgid`/`end_msgid` は折りたたみ時にフローの msgid 座標へ一度だけ整列 — フロー記録セッションのみ、他は NULL。**#7581 がブロックライフサイクルログ**(`egress_block_flow`/`egress_block_state`)**を二重クロックで追加** — ブロックテーブルは自分自身を番号付けし、各行は `flow_op_seq` でフロークロックを指す;reap はそのブロックの最終スナップショットを携えた `D` 行で、state 行は物理削除(#7773);フロークローク W の定点 fork:フロー行 `op_seq <= W`・ブロック行 `flow_op_seq <= W` をコピーし、**両 state テーブルを W までリプレイして物化**(任意のポイント可 — 「最新ベース未満」ゲートは廃止);egress-on の checkpoint はこの定点 fork に退役。**#7617 は ID を統合**:egress-on の stage-0 は状態なし(`MAX(op_seq)`/flow の `MAX(log_seq)` からの境界、l1 カーソルも resync もない)、R3 故障 latch は `sessions.r3_latched_at`(legacy l1 列との二重キャリアで読替/クリア)、egress-on セッションは年齢 GC から除外され手動 archive は拒否(アーカイブ形式が op log を載せるまで)。**番号付け(2026-11-25、[egress-plane.md](../egress-plane.md) §10)**:`log_seq` がカーネル引用番号そのもの(`mNNNNN` = m + log_seq、system 行 = 0);arm 時の一括 backfill で op log が完全履歴になり、`refs` 書き込み経路は egress-on で退役、kstate overlay の refs 再構築が正当経路に。**構造不変条件(#7773 §6、毎回の書き込み後にアサート、両プレーン)**:flow 行数は減少しない・state 行数 == ライブビュー長さ・最大 value == 歴史上の最大単一行・行文字列はちょうど I/D/U(メッセージ)/ I/U/D(ブロック)— スイート `tests/egress-invariants-7773.test.ts`。全体:[PR #6785 ドキュメント §6](../pr-6785-unified-storage-and-flows.md#6-round-2) ・ブロック:[egress-block-flow.md](../egress-block-flow.md) ・一箇所:[egress-plane.md](../egress-plane.md)。
**egress プレーン(KDD #23/#24、#7439/#7577/#7591/#7773 — 出向会話 op log)。** `egress_flow`(SQLite レーンのみ、ゲート `rollout.features.egressPlane`)は各セッションの出向ビューの **append-only** I/D/U op log を保持し、行は自己完結(バイトは行に乗る、content CAS 不要)。flow のキーは `(session_id, op_seq)`(稠密な行カーソル、復旧/切り詰め鍵)、I 行はさらに `log_seq`(正規メッセージ番号、再発行なし)を持つ;フロンティアは flow 上の `MAX(log_seq)`(退役した `B` ベース行の `highWater` payload は消滅、#7773)。**`egress_state` は物化ライブビュー**(#7773):PK `(session_id, rid)`、`pos` 順;各 append は同一トランザクション内で op を行に適用(I 挿入+シフト、U その場更新、D 物理削除+シフト)、サービスコピーは構造上ライブビューの大きさに有界 — ベース行も圧縮も op ミラーもない。ログと state キーの行アドレスは再発行されない稠密な `rid` で、msgid ではない(owner 裁定 2026-11-27、#7773 続行:msgid はカーネル同一性 — content-hash 代理・衝突可能・折りたたみ後にどの発生を指すか曖昧 — 、rid は自発行。D 端点 / U 目標 / I アンカーは全て rid を参照し、`idx_egress_state_msgid` が msgid 検索に供される)。egress-on セッションでは op log が**唯一の**正規メッセージ権威:出向バイトはそこから配信、pin チャネルは messages レジャーではなく物化 state を読む、ターンごとの統一 ingest は停止(messages は**遅延射影**に格下げ、ロールバック/web 読み取り/復元時に一括再構築)、セッション JSON エンベロープは bootstrap で凍結。復旧:state コピーが損傷したら**全履歴リプレイで再構築**しそのまま配信(flow が権威);flow 自体がリプレイ不能なら `recoverEgressBase` が全履歴 walk を 1 度だけ実行(`egressFlowWalkBack`)— 最新健全プレフィックスまで尾を切り詰め;健全な点が皆無 ⇒ ターンはハード失敗(裁定 7439-5)で、クライアントバイトに劣化することはない。裁定 7439-2 は読み書き側を blocks テーブル本体に置く:`summary_bytes` がブロック要約をインライン化(読取り側はこれを優先、content CAS は legacy フォールバックのみ)、`start_msgid`/`end_msgid` は折りたたみ時にフローの msgid 座標へ一度だけ整列 — フロー記録セッションのみ、他は NULL。**#7581 がブロックライフサイクルログ**(`egress_block_flow`/`egress_block_state`)**を二重クロックで追加** — ブロックテーブルは自分自身を番号付けし、各行は `flow_op_seq` でフロークロックを指す;reap はそのブロックの最終スナップショットを携えた `D` 行で、state 行は物理削除(#7773);フロークローク W の定点 fork:フロー行 `op_seq <= W`・ブロック行 `flow_op_seq <= W` をコピーし、**両 state テーブルを W までリプレイして物化**(任意のポイント可 — 「最新ベース未満」ゲートは廃止);egress-on の checkpoint はこの定点 fork に退役。**#7617 は ID を統合**:egress-on の stage-0 は状態なし(`MAX(op_seq)`/flow の `MAX(log_seq)` からの境界、l1 カーソルも resync もない)、R3 故障 latch は `sessions.r3_latched_at`(legacy l1 列との二重キャリアで読替/クリア)、egress-on セッションは年齢 GC から除外され手動 archive は拒否(アーカイブ形式が op log を載せるまで)。**番号付け(2026-11-25、[egress-plane.md](../egress-plane.md) §10)**:`log_seq` がカーネル引用番号そのもの(`mNNNNN` = m + log_seq、system 行 = 0);arm 時の一括 backfill で op log が完全履歴になり、`refs` 書き込み経路は egress-on で退役、kstate overlay の refs 再構築が正当経路に。**構造不変条件(#7773 §6、毎回の書き込み後にアサート、両プレーン)**:flow 行数は減少しない・state 行数 == ライブビュー長さ・最大 value == 歴史上の最大単一行・行文字列はちょうど I/D/U(メッセージ)/ I/U/D(ブロック)— スイート `tests/egress-invariants-7773.test.ts`。全体:[PR #6785 ドキュメント §6](../pr-6785-unified-storage-and-flows.md#6-round-2) ・ブロック:[egress-block-flow.md](../egress-block-flow.md) ・一箇所:[egress-plane.md](../egress-plane.md)。

## 厳格な不変条件(これに触れる前に AGENTS.md を参照すること)

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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 #23/#24, discussions #7439/#7577/#7591/#7773 — the outbound conversation op log).** `egress_flow` (SQLite lane only, gate `rollout.features.egressPlane`) holds the **append-only** I/D/U op log of each session's outbound view; rows are self-contained (bytes ride the row, no content CAS). The flow keys on `(session_id, op_seq)` (dense row cursor, recovery/truncation key) and I rows additionally carry `log_seq` — the canonical, never-reissued message number; the frontier is `MAX(log_seq)` on the flow (the retired `B` base row's `highWater` payload is gone, #7773). **`egress_state` is the MATERIALIZED live view** (#7773): PK `(session_id, msgid)`, `pos`-ordered; every append applies its ops to the rows in the same transaction (I inserts + shifts, U in-place, D physically deletes + shifts), so the serving copy is bounded by the live view's size by construction — there is no base row, no compaction, no op mirror. For egress-on sessions the op log is the SOLE canonical message authority: outbound bytes are served from it, the pin channel reads the materialized state 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: a damaged state copy is **rebuilt by full-history replay** and served as-is (the flow is the authority); if the flow itself does not replay, `recoverEgressBase` does ONE full-history walk (`egressFlowWalkBack`) — the newest healthy prefix truncates the tail; no healthy point ⇒ the turn hard-fails (ruling 7439-5), never degrades to client bytes. Ruling 7439-2 lands the read/write side on the blocks table itself: `summary_bytes` inlines the block summary (readers prefer it, the content CAS keeps its role only as the legacy fallback), and `start_msgid`/`end_msgid` align the block to the flow's msgid coordinates once at fold time — for flow-recorded sessions, NULL otherwise. **#7581 added the block lifecycle log** (`egress_block_flow`/`egress_block_state`) on **dual clocks** — the block tables number themselves, each row pointing at the flow clock via `flow_op_seq`; reap is a `D` row carrying the block's full terminal snapshot with the state row physically deleted (#7773); a point fork at flow watermark W copies flow rows `op_seq <= W` and block rows `flow_op_seq <= W`, then **materializes both state tables by replay to W** (any point — the "below the newest base" gate is gone); checkpoints for egress-on retired in favor of this point-fork. **#7617 consolidated identity**: egress-on stage-0 is stateless (frontiers from `MAX(op_seq)` / the flow's `MAX(log_seq)`, no l1 cursor, no resync), the R3 fault latch lives in `sessions.r3_latched_at` (dual-carrier read/clear with the legacy l1 column), and egress-on sessions are excluded from age GC and refused on manual archive until the archive format carries the op log. **Renumber (2026-11-25, [egress-plane.md](../egress-plane.md) §10):** `log_seq` IS the kernel citation number (`mNNNNN` = m + log_seq, system row = 0); the arm-time one-shot backfill makes the op log the complete history, so the `refs` write path retires for egress-on and the kstate overlay's ref rebuild is the legitimate path. **Structural invariants after every write, both planes (#7773 §6):** flow row count never shrinks · state row count == live view length · largest value == historical max SINGLE row · row alphabet exactly I/D/U (message) / I/U/D (block) — suite `tests/egress-invariants-7773.test.ts`. **Usage stream (owner ruling 2026-11-27):** `egress_usage` (5th egress table, own clock) records the in-memory cache ledger's mutations as an append-only M/S/F event stream so an egress-on session rebuilds its ledger by replay after a restart (detail: [egress-plane.md](../egress-plane.md) §12). Full walkthrough: [PR #6785 doc §6](../pr-6785-unified-storage-and-flows.md#6-round-2) · blocks: [egress-block-flow.md](../egress-block-flow.md) · one-stop: [egress-plane.md](../egress-plane.md).
**Egress plane (KDD #23/#24, discussions #7439/#7577/#7591/#7773 — the outbound conversation op log).** `egress_flow` (SQLite lane only, gate `rollout.features.egressPlane`) holds the **append-only** I/D/U op log of each session's outbound view; rows are self-contained (bytes ride the row, no content CAS). The flow keys on `(session_id, op_seq)` (dense row cursor, recovery/truncation key) and I rows additionally carry `log_seq` — the canonical, never-reissued message number; the frontier is `MAX(log_seq)` on the flow (the retired `B` base row's `highWater` payload is gone, #7773). **`egress_state` is the MATERIALIZED live view** (#7773): PK `(session_id, rid)`, `pos`-ordered; every append applies its ops to the rows in the same transaction (I inserts + shifts, U in-place, D physically deletes + shifts), so the serving copy is bounded by the live view's size by construction — there is no base row, no compaction, no op mirror. Row addressing in the log and the state key is the dense, never-reissued `rid`, never a msgid (owner ruling 2026-11-27, #7773 follow-up: msgids are kernel identities — content-hash-proxied, collision-prone, occurrence-ambiguous after folds — while rids are ours; D endpoints / U targets / I anchors all reference rids, `idx_egress_state_msgid` serves the msgid lookups). For egress-on sessions the op log is the SOLE canonical message authority: outbound bytes are served from it, the pin channel reads the materialized state 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: a damaged state copy is **rebuilt by full-history replay** and served as-is (the flow is the authority); if the flow itself does not replay, `recoverEgressBase` does ONE full-history walk (`egressFlowWalkBack`) — the newest healthy prefix truncates the tail; no healthy point ⇒ the turn hard-fails (ruling 7439-5), never degrades to client bytes. Ruling 7439-2 lands the read/write side on the blocks table itself: `summary_bytes` inlines the block summary (readers prefer it, the content CAS keeps its role only as the legacy fallback), and `start_msgid`/`end_msgid` align the block to the flow's msgid coordinates once at fold time — for flow-recorded sessions, NULL otherwise. **#7581 added the block lifecycle log** (`egress_block_flow`/`egress_block_state`) on **dual clocks** — the block tables number themselves, each row pointing at the flow clock via `flow_op_seq`; reap is a `D` row carrying the block's full terminal snapshot with the state row physically deleted (#7773); a point fork at flow watermark W copies flow rows `op_seq <= W` and block rows `flow_op_seq <= W`, then **materializes both state tables by replay to W** (any point — the "below the newest base" gate is gone); checkpoints for egress-on retired in favor of this point-fork. **#7617 consolidated identity**: egress-on stage-0 is stateless (frontiers from `MAX(op_seq)` / the flow's `MAX(log_seq)`, no l1 cursor, no resync), the R3 fault latch lives in `sessions.r3_latched_at` (dual-carrier read/clear with the legacy l1 column), and egress-on sessions are excluded from age GC and refused on manual archive until the archive format carries the op log. **Renumber (2026-11-25, [egress-plane.md](../egress-plane.md) §10):** `log_seq` IS the kernel citation number (`mNNNNN` = m + log_seq, system row = 0); the arm-time one-shot backfill makes the op log the complete history, so the `refs` write path retires for egress-on and the kstate overlay's ref rebuild is the legitimate path. **Structural invariants after every write, both planes (#7773 §6):** flow row count never shrinks · state row count == live view length · largest value == historical max SINGLE row · row alphabet exactly I/D/U (message) / I/U/D (block) — suite `tests/egress-invariants-7773.test.ts`. **Usage stream (owner ruling 2026-11-27):** `egress_usage` (5th egress table, own clock) records the in-memory cache ledger's mutations as an append-only M/S/F event stream so an egress-on session rebuilds its ledger by replay after a restart (detail: [egress-plane.md](../egress-plane.md) §12). Full walkthrough: [PR #6785 doc §6](../pr-6785-unified-storage-and-flows.md#6-round-2) · blocks: [egress-block-flow.md](../egress-block-flow.md) · one-stop: [egress-plane.md](../egress-plane.md).

## Hard invariants (see AGENTS.md before touching this)

Expand Down
Loading
Loading