ledger: checkpoint reads only sequences and block hashes (#71 stage 1)
mergeddd0ef0eea77b208b #90 · opened 2026-11-06 20:51 UTC · closed 2026-11-06 21:19 UTC · merged 2026-11-06 21:19 UTC
Imported from GitHub aien-dev/spark-rsi-mv#90, by drakestapleton
Base 7e8bf7da7f2adc0bea7938cc042d8a7873619cc1 · Head a708ac977ea014558c1c536ef7b0a44507663f6c
Merged on GitHub as 505c75dedac8796f4fa16f5376db13e9bd0f7d84; reachable from main 2edaf6704304e089f6f50fcd3daedd71b2446840 (observed 2026-11-18T16:40:15Z)
drakestapleton wrote on 2026-11-06 20:51 UTC
Refs #71. Stage 1 only. Stage 2 (append-maintained Merkle frontier or cached internal nodes) is out of scope and not started.
What changed
ImprovementLedger::checkpoint called all_blocks(), which selects every column, materializes every payload and parses every blob list, though a checkpoint needs only the block hashes, their count and the last sequence. It now runs one SELECT sequence, block_hash FROM blocks ORDER BY sequence ASC (one SQLite statement, one read snapshot) through a private helper leaf_hashes, and holds the connection lock across that read and the checkpoint insert, so no append through this handle lands between them.
Unchanged: the Merkle format, root bytes, duplicate-last behavior, hex hash encoding, compute_merkle_root, the signature scheme, and the empty-ledger refusal (Cannot create checkpoint on empty ledger). verify_chain_integrity (the other all_blocks caller) keeps all_blocks: the audit needs every payload, link and blob list and stays authoritative. src/main.rsledger log also keeps it (it prints full blocks).
Behavior note: on main, a payload column holding non-text bytes made checkpoint fail as a side effect of materializing it. checkpoint never verified payload digests (a text payload edit was already checkpointed on main), so that refusal was incidental. The full audit still refuses such a ledger; the repro test asserts this.
Head
a708ac977ea014558c1c536ef7b0a44507663f6c on branch fix/issue-71-checkpoint-hash-query, base main7e8bf7da.
Command: cargo test --locked --test test_cryptographic_improvement_ledger checkpoint_
Run
Tree
rc
Last line
before
main src/ledger/db.rs + new tests
101
test result: FAILED. 3 passed; 1 failed — test_checkpoint_does_not_materialize_payloads panicked: checkpoint must not read payloads: "Invalid column type Blob at index: 4, name: payload_json"
after
this branch
0
test result: ok. 4 passed; 0 failed
negative control
this branch with checkpoint pointed back at all_blocks() (uncommitted)
101
test result: FAILED. 3 passed; 1 failed — same panic
test_checkpoint_does_not_materialize_payloads (repro): stores X'FF00FE' as the payload of block 2, asserts all_blocks() fails, then asserts checkpoint succeeds with the root, count, sequence and signature computed by the all_blocks path before the corruption, and that verify_chain_integrity still refuses.
test_checkpoint_matches_all_blocks_path_prefix_by_prefix (parity): at prefix sizes 0,1,2,3,4,5,7,8,9,16,17, checkpoint and the pre-change all_blocks construction give identical up_to_sequence, block_count, merkle_root and signature (p256 RFC 6979, deterministic); size 0 gives the same refusal and stores nothing; each stored checkpoint round-trips and the audit verifies it with the key. Passes before and after, as parity should.
Other host-local gates at the head:
Full suite, cargo test --locked -j1 --no-fail-fast -- --test-threads=1 (bwrap, core 6, CARGO_TARGET_DIR in /dev/shm with an in-tree target symlink to it so the judge unit tests find their fixture binary): rc 101, 339 passed, 3 failed, 1 ignored; test_cryptographic_improvement_ledger 12/12 ok. The 3 failures (test_codebase_observation_current_repo: assertion failed: telemetry.tests_passing; daemon_cycle_with_a_correct_fixture_reaches_the_later_gates: identity; daemon_cycle_with_a_wrong_answering_fixture_is_refused_and_rolled_back: quota decision) fail identically with main's src/ledger/db.rs on the same host (rc 101, same panics): pre-existing on this host, not regressions from this change. Two GPU tests reported NOT_RUN (opt-in).
cargo fmt --all -- --check: rc 0.
tests/gates/run.sh crumb-verify with crumb built from aien-architecture-mv @12ad0141 (the CI pin): rc 0, crumb verify: OK: 33 crumbs current at HEAD a708ac9.
tests/gates/run.sh zero-disk-secrets: rc 0.
Labels
Tier: IMPLEMENTED, EXERCISED (host).
Repro/parity/negative control: PASS (host-local).
GitHub CI on the head: NOT_RUN (desk gate; the workflow runs on pull_request only).
No measured speedup claimed: this removes payload materialization from the checkpoint path; it does not measure disk traffic or wall time. Host results are not hardware evidence.
Apply it
git checkout -b patch-dd0ef0eea77b208b7e8bf7da7f2adc0bea7938cc042d8a7873619cc1
curl -fsSL https://interplane.io/drakestapleton/spark-rsi-mv/patches/dd0ef0eea77b208b.patch | git am