Skip to content

Gate P2 — Durability and recovery

Status: Gate PASSED (2026-10-20) on commit 21da1f7: - Linux/macOS CI: run 39497969575. - Nightly exhaustive, four-shard mutation and durability gates: run 39498455621. - Independent review: the first pass found 1 blocker, 5 major and 6 minor findings; the closure check found 1 major and 5 minor more (N1–N6). All are fixed with regression tests and confirmed closed by the reviewer. See P2-report.md, durable-log ADR 0006 and incremental structural commits ADR 0007.

0. Scope

  • SPEC §5 P2, §6.1 (read modes, input contract 1), §6.2 batch-level checks, §7 (op_log fields).
  • Involved SDs: SD7 (inputs), SD8 (statuses, history), I5 (durable prefix).
  • contextdb-store:
  • op_log as an own append-only segment log (the source of truth) behind the Durability trait;
  • content-addressed blobs;
  • snapshots and replay;
  • SQLite projections (diff_log, head_history, base_history) with a watermark;
  • HISTORICAL / SNAPSHOT / DIFF over persisted data;
  • format version 1 and the migration framework;
  • the crash-injection harness.
  • ctx replay | doctor [--rebuild | --truncate-before E [--yes]] | snapshot | migrate | export.
  • Core: incremental structural commits (ADR 0007), so cold-start replay meets G5.
  • Explicitly deferred:
  • the daemon/MCP and certificates (P3);
  • erasure and shredding (P9; P2 never deletes a blob);
  • a signed head (P9 threat model, ADR 0006 §2).

1. Gate matrix

Layer Requirement Result Evidence
G0 Spec ADR for canonical encoding, durable order, idempotency storage, missing-blob semantics; SDs unchanged; no §3.5 prohibited mechanism Pass ADR 0006 rev 3 (three review rounds) + §12 implementation notes; ADR 0007; SPEC v1.4.3
G1 Build & lint fmt, Clippy -D warnings, tests, cargo-deny, dependency graph (core allowlist unchanged; store's reviewed externals rusqlite, blake3, nix recorded in config/dependency-policy.toml) Pass (CI 39497969575, Linux + macOS) bash scripts/check.sh
G2 Golden T07b, T13, T18, T18b, T33, T34, T35, T68 Pass §2
G3 Oracle PROP10 10,000 seeds; P0/P1 properties carried forward Pass §3
G4 Robustness ≥ 1,000 runs per injection point; I5(c); no partial transaction; derived == oracle; in-flight id Committed/NotCommitted; retry at most once; poisoned store serves nothing; harness self-test Pass §3
G5 Performance commit p99 fullfsync on ≤ 25 ms, off ≤ 10 ms; cold replay 100K ≤ 5 s, with snapshot ≤ 1 s; also in the production configuration (file projections) Pass §4
G6 Scenario none for P2 beyond the T07b/T13 decision history N/A
G7 Regression P0/P1 G2/G3 (both modes, 10,000 paranoid seeds, depth 6/8), P1 G5 incl. memory Pass report
G8 Docs durability semantics (ack point, fullfsync), no erasure before P9 Pass README "Durability", ADR 0006
Independent review non-implementing reviewer (SPEC §4.2) Pass: 12/12 and N1–N6 closed, verified by the reviewer report, Independent review

2. Golden tests

T-ID What Test
T07b a superseded revision stays readable (Historical) store/tests/recovery.rs::historical_reads_survive_restart_t07b_t13, testkit/tests/p2_rebuild.rs::read_modes_reproduce_past_states_1000_seeds
T13 Historical/Snapshot bytes identical across repeated reads and restarts same two tests
T18 reopen replays to the identical state recovery.rs::reopen_replays_to_identical_state_t18
T18b idempotent retry returns the original result; txn_status; TxnIdReuse recovery.rs::idempotent_retry_and_txn_status_t18b
T33 corrupt earlier frame (or a final segment header with frames behind it) fails closed; doctor --truncate-before lists every dropped readable epoch/id, holds the lock, re-plans recovery.rs::corrupt_earlier_frame_fails_closed_t33, doctor_truncate_before_repairs_broken_chain_t33, review1_*, review2_*, review4_*, cli/tests/cli.rs
T34 corrupt final frame truncated and reported; --strict-tail fails closed recovery.rs::corrupt_final_frame_truncates_and_reports_t34
T35 blobs idempotent, verified, required (MissingBlob at the per-Op slot) recovery.rs::blobs_are_idempotent_verified_and_required_t35, testkit/tests/p2_blobs.rs
T68 format-0 log migrates; identical state; acked results preserved; corrupt legacy aborts untouched; an interrupted swap is refused at open and resumed store/tests/migration.rs, recovery.rs::review3_*

3. Properties and robustness

Check Runs Result
PROP10 (store): reopen from op_log, half of seeds with a snapshot, digest + DIFF for every epoch 10,000 seeds Pass
PROP10 (core): Db::from_inputs == incremental; identical later CommitResults/errors; DIFF; oracle 10,000 seeds Pass
Read modes reproduce past states (core) 1,000 seeds Pass
G4 pre-WAL / post-WAL-pre-sync / post-sync-pre-publish (hooked) 1,000 effective injections each, four tail fates, half with 512-byte segments Pass
G4 mid-snapshot (write, sync, rename, sync_dir) 1,004 Pass
G4 blob put (write, sync, rename, sync_dir) 1,004 Pass
G4 projection write (SQLite transaction fails before commit) 1,000 Pass
Harness self-test: no-op sync must be detected 200 seeds Pass (detected)
Review regressions: final-segment header, plan completeness, interrupted migration, lock, poison, semantic tail fault, unbuildable snapshot, per-store poison, no-create 10 tests Pass
Projections roll forward, foreign projection rebuilt, all read sources agree — Pass

Mutation audit (kernel files, including the new stage.rs): see the report.

4. Performance

See P2-report.md §G5 and docs/gates/p2-env.json.