---
title: "SRBC Theory Validation Program — Round 09：Failure Recovery / Crash Consistency / Snapshot Lineage"
author: "Neo.K with Aletheia (GPT-5.6 Sol)"
institution: "EveMissLab / 一言諾科技有限公司"
version: "v0.1"
date: "2026-09-23"
language: "zh-TW"
document_type: "Persistent QRSRC Crash-Recovery Validation Report"
status: "Round 09 completed"
---

# SRBC Theory Validation Program — Round 09

## Failure Recovery / Crash Consistency / Snapshot Lineage

**作者：** Neo.K with Aletheia (GPT-5.6 Sol)  
**機構：** EveMissLab / 一言諾科技有限公司  
**日期：** 2026-09-23  
**版本：** v0.1  

---

## Canonical Source Note

本報告以 UTF-8 Markdown 保存；數學 source 僅使用 ` $...$ ` 與 `$$...$$`。

本輪不再只測 in-memory correctness，而是建立第一代 persistent QRSRC transaction simulator：

```text
WAL
→ immutable staged snapshot
→ durable COMMIT
→ atomic HEAD
→ checkpoint
→ lineage
```

並在 transaction 的各 durable cut 主動 crash / restart。

完整可執行 simulator：

```text
round09_crash_runtime.py
```

已放入 package，能直接重新執行本輪 crash matrix；這修正了 Round 08 downloadable replay artifact 只做既有 hash comparison、沒有真正重跑 engine 的 reproducibility gap。

---

# 0. 本輪問題

Round 08 已經能保證正常執行時：

$$
S_{t+1}^{\mathrm{inc}}
=
S_{t+1}^{\mathrm{full}}.
$$

但真正 long-horizon runtime 還有更危險的問題：

> 如果在 recompute / commit 的中間 crash 呢？

要求不是「重啟後程式能跑」。

真正要求：

$$
\boxed{
\operatorname{Recover}
(
\operatorname{Crash}_k(T)
)
\in
\{
S_t,
S_{t+1}
\}.
}
$$

只能看到完整舊 epoch 或完整新 epoch。

---

# 1. Durable transaction protocol

本輪採：

```text
BEGIN
↓
EVENT
↓
PREPARE
↓
IMMUTABLE CHILD SNAPSHOT
↓
COMMIT
↓
HEAD ADVANCE
↓
CHECKPOINT
```

其中關鍵 durable barrier：

$$
\boxed{
\text{child snapshot}
\prec
\text{COMMIT}
\prec
\text{HEAD}
\prec
\text{WAL truncation}.
}
$$

---

# 2. Crash matrix

建立：

$$
\boxed{
1000
}
$$

個連續 transactions。

每個 transaction 在：

$$
\boxed{
8
}
$$

個 crash cuts 重啟。

總 crash scenarios：

$$
\boxed{
8000
}
$$

結果：

$$
\boxed{
8000/8000
}
$$

符合預期 recovery epoch。

| crash cut | scenarios | pass | legal recovered epoch |
|---:|---:|---:|---|
| 0 | 1000 | 1000 | parent |
| 1 | 1000 | 1000 | parent |
| 2 | 1000 | 1000 | parent |
| 3 | 1000 | 1000 | parent |
| 4 | 1000 | 1000 | parent |
| 5 | 1000 | 1000 | child |
| 6 | 1000 | 1000 | child |
| 7 | 1000 | 1000 | child |

在 COMMIT 前：

$$
\boxed{
\text{rollback parent}.
}
$$

COMMIT durable 後：

$$
\boxed{
\text{roll-forward / remain child}.
}
$$

沒有一次 mixed closure 被接受為 HEAD。

---

# 3. Staged snapshot 在 COMMIT 前不是 closure

cut 4 時 child snapshot blob 已經 durable。

但尚未有：

```text
COMMIT
```

recovery 仍必須回：

$$
S_t.
$$

child blob 只是：

$$
\boxed{
\text{orphan staged artifact}.
}
$$

可以在 recovery 後 GC。

因此：

$$
\boxed{
\text{snapshot exists}
\not\Rightarrow
\text{snapshot committed}.
}
$$

---

# 4. COMMIT 後、HEAD 前

這是最關鍵 crash window。

COMMIT 已 durable：

$$
C(T)=1.
$$

但 HEAD 仍指 parent。

crash 後 recovery 必須：

$$
\boxed{
\operatorname{RollForwardHead}(S_{t+1}).
}
$$

本輪：

$$
\boxed{
1000/1000
}
$$

此 cut 正確 roll-forward。

---

# 5. Idempotent replay

每個 committed transaction 又測：

- duplicate WAL 再加 1 份；
- duplicate WAL 再加 5 份。

共：

$$
\boxed{
2000
}
$$

duplicate replay tests。

failure：

$$
\boxed{
0.
}
$$

也就是：

$$
\boxed{
\operatorname{Replay}(T)^n
=
\operatorname{Replay}(T)
}
$$

在本地 closure-state recovery 中成立。

這不代表所有外部 side effect 都 exactly-once；如果未來 transaction 會發 email、呼叫 API、寫遠端 DB，仍需要外部 idempotency key / outbox。

---

# 6. Snapshot lineage

完整 canonical chain：

$$
\boxed{
1001
}
$$

epochs：

- genesis；
- 1000 committed child epochs。

lineage validation：

$$
\boxed{
\text{PASS}.
}
$$

每個 manifest 綁定：

$$
(
E_t,
E_{t-1},
H_{t-1},
\mathrm{txid}_t,
h(\mu_t),
h(S_t),
h(\mathcal C_t)
).
$$

---

# 7. Lineage tamper tests

四種 tamper：

1. parent manifest hash；
2. state content；
3. certificate snapshot；
4. duplicate txid。

結果：

$$
\boxed{
4/4\ \text{detected}.
}
$$

因此 current lineage 不只是一串 epoch numbers，而是 content-addressed chain。

---

# 8. Negative control：HEAD before COMMIT

故意使用錯誤 protocol：

1. BEGIN；
2. EVENT；
3. child snapshot；
4. **HEAD := child**；
5. 尚未 COMMIT。

結果：

$$
\boxed{
\text{未提交 child 在 crash 前已可見}.
}
$$

crash recovery 最後雖然能 rollback parent，

但：

$$
\boxed{
\text{recoverable}
\neq
\text{atomic visibility}.
}
$$

所以 HEAD 不得先於 COMMIT。

---

# 9. Negative control：過早截斷 WAL

故意：

1. child snapshot durable；
2. COMMIT durable；
3. HEAD 尚未 advance；
4. WAL 先被清掉；
5. crash。

結果：

$$
\boxed{
\text{committed transaction lost}.
}
$$

也就是 durability 被破壞。

因此：

$$
\boxed{
\text{WAL compaction}
\succ
\text{durable HEAD / checkpoint}.
}
$$

WAL truncation 不是 housekeeping 細節，而是 closure lineage protocol 的一部分。

---

# 10. Redo from WAL

另一個 failure：

- COMMIT 存在；
- child snapshot blob 遺失；
- BEGIN / EVENT 還在。

recovery 直接從：

$$
S_t+\mu_t
$$

重算 child，

再驗：

$$
H_c^{\mathrm{redo}}
=
H_c^{\mathrm{COMMIT}}.
$$

本輪：

$$
\boxed{
\text{REDO succeeds}.
}
$$

所以 durable event log 可以作第二條 recovery route。

---

# 11. Commit 存在但沒有 blob，也沒有 event

故意留下：

- BEGIN；
- COMMIT；

但拿掉：

- child snapshot；
- EVENT。

recovery：

$$
\boxed{
\operatorname{UNRECOVERABLE}.
}
$$

沒有猜測、沒有靜默回退、沒有假裝 transaction 沒 commit。

這是正確失敗。

---

# 12. Round 08 replay artifact gap

Round 08 notebook 內部確實做：

$$
\text{genesis}
\rightarrow
5000\text{ transactions}
\rightarrow
\text{same final hash}.
$$

但 package 裡的 `round08_replay.py` 只重新驗證：

- existing transaction log；
- existing final snapshot hashes。

沒有完整 engine 去重跑 mutation。

Round 09 因此正式區分：

$$
\boxed{
\text{artifact-consistency replay}
}
$$

與：

$$
\boxed{
\text{executable state reconstruction}.
}
$$

本輪的：

```text
round09_crash_runtime.py
```

是後者。

---

# 13. Recovery correctness

本輪第一代 crash criterion：

$$
\boxed{
\forall T,\forall k:
\operatorname{Recover}
(
\operatorname{Crash}_k(T)
)
\in
\{
S_t,S_{t+1}
\}.
}
$$

並要求：

$$
\boxed{
\operatorname{Integrity}
=
1.
}
$$

8000/8000 crash scenarios 滿足。

---

# 14. Persistent QRSRC

現在 QRSRC 已從純語義狀態一路進入持久化 runtime：

$$
\boxed{
\operatorname{PQRSRC}
=
(
G_C,
\mathcal C,
R,
W,
H,
L
).
}
$$

其中：

- $G_C$：dependency graph；
- $\mathcal C$：certificate snapshot；
- $R$：roots / semantic runtime state；
- $W$：write-ahead log；
- $H$：committed HEAD；
- $L$：snapshot lineage。

---

# 15. v0.9 的 transaction visibility rule

reader 不讀 staging snapshot。

reader 只做：

$$
\boxed{
\operatorname{ReadClosure}()
=
\operatorname{Snapshot}
(
\operatorname{HEAD}
).
}
$$

HEAD 是 closure visibility 的唯一入口。

這避免：

$$
\boxed{
\text{mixed epoch}.
}
$$

---

# 16. Checkpoint

正式 production checkpoint 還應保存：

- epoch；
- HEAD manifest hash；
- committed tx watermark；
- root-registry digest；
- certificate-registry digest；
- runtime version；
- evaluator digest。

Round 09 simulator 尚未加入 runtime-version migration attack；v0.9 已將它列為下一層必要欄位。

---

# 17. Round 09 的直接結果

## Crash safety

$$
\boxed{
8000/8000.
}
$$

## Duplicate replay

$$
\boxed{
2000/2000.
}
$$

## Lineage

$$
\boxed{
1001\text{ epochs valid}.
}
$$

## Tamper detection

$$
\boxed{
4/4.
}
$$

## Bad ordering controls

- HEAD-before-COMMIT：確實有 atomic visibility violation；
- WAL truncate before durable HEAD：確實會失去 committed tx；
- COMMIT + missing blob + event present：可 redo；
- COMMIT + no blob + no event：正確標 unrecoverable。

---

# 18. 本輪沒有證明什麼？

這仍然是 single-process persistence simulator。

沒有證明：

1. 真實檔案系統 fsync ordering；
2. sector tearing；
3. power-loss hardware semantics；
4. multi-process concurrent writer；
5. distributed consensus；
6. network partition；
7. cloud object-store consistency；
8. external side-effect exactly-once。

所以這輪證據是：

$$
\boxed{
\text{transaction protocol / recovery semantics validation},
}
$$

不是 storage hardware certification。

---

# 19. 下一輪

Round 10 最自然的是：

$$
\boxed{
\text{Concurrency / MVCC / Multi-Writer Conflict}.
}
$$

測：

- reader 在長 transaction 中看到哪個 epoch；
- 兩個 writer 同時從同一 parent 修改不同 roots；
- disjoint mutation 能不能 merge；
- overlapping mutation 如何 conflict；
- compare-and-swap HEAD；
- lost update；
- serializability；
- snapshot isolation；
- certificate graph merge。

到了這裡，SRBC 已經從：

> 自然語言到底有沒有說完？

一路推到：

> 多個 agent / writer 同時修改一個可驗證語義 closure 時，如何保持真實的 epistemic state consistency？

---

# 附錄 A：Crash Matrix

| cut | scenarios | pass | expected recovery |
|---:|---:|---:|---|
| 0 | 1000 | 1000 | parent |
| 1 | 1000 | 1000 | parent |
| 2 | 1000 | 1000 | parent |
| 3 | 1000 | 1000 | parent |
| 4 | 1000 | 1000 | parent |
| 5 | 1000 | 1000 | child |
| 6 | 1000 | 1000 | child |
| 7 | 1000 | 1000 | child |

---

# 附錄 B：Machine Results

```json
{
  "round": "SRBC Theory Validation Round 09",
  "transactions": 1000,
  "crash_cuts_per_transaction": 8,
  "crash_scenarios": 8000,
  "crash_pass": 8000,
  "crash_fail": 0,
  "cut_stats": {
    "0": {
      "n": 1000,
      "pass": 1000
    },
    "1": {
      "n": 1000,
      "pass": 1000
    },
    "2": {
      "n": 1000,
      "pass": 1000
    },
    "3": {
      "n": 1000,
      "pass": 1000
    },
    "4": {
      "n": 1000,
      "pass": 1000
    },
    "5": {
      "n": 1000,
      "pass": 1000
    },
    "6": {
      "n": 1000,
      "pass": 1000
    },
    "7": {
      "n": 1000,
      "pass": 1000
    }
  },
  "idempotency": {
    "duplicate_replay_tests": 2000,
    "failures": 0
  },
  "lineage": {
    "epochs": 1001,
    "valid": true,
    "reason": "ok",
    "tamper_tests": {
      "parent_hash_tamper_detected": true,
      "state_tamper_detected": true,
      "certificate_tamper_detected": true,
      "duplicate_tx_detected": true
    }
  },
  "negative_controls": {
    "head_before_commit": {
      "uncommitted_child_became_visible_before_crash": true,
      "recovery_rolled_back_to_parent": true
    },
    "wal_truncate_before_head": {
      "committed_transaction_lost": true
    },
    "redo_from_wal_without_snapshot_blob": {
      "success": true
    },
    "commit_without_snapshot_or_event": {
      "unrecoverable_detected": true
    }
  },
  "recovery_rule": {
    "cuts_0_to_4": "rollback to parent epoch",
    "cuts_5_to_7": "roll forward / remain at fully committed child epoch"
  }
}
```

---

# 附錄 C：Artifacts

- `SRBC_Theory_Validation_Round09_Report_v0.1_2026-09-23.md`
- `SRBC_Core_Patch_v0.9_2026-09-23.md`
- `pqrsrc_wal_protocol_v09.yaml`
- `round09_crash_runtime.py`
- `results_round09.json`
- `crash_matrix_round09.csv`
- `lineage_manifest_round09.json`
- `genesis_blob_round09.json`
- `final_blob_round09.json`
- `crash_examples_round09.json`
- `input_certificates_v07/*.json`
- `validation.json`
