From 2d3250709bf412076f8324c9d0c0568c89fbbfde Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 21 Nov 2026 10:55:18 -0700 Subject: [PATCH 1/2] build: pin bookspec at 5127b5b, law 47 (a write is one transaction, exactly once) Moves the checker, the runner and the Lean package together from 79cb439 so the pin test holds. Co-Authored-By: Claude Fable 5.2 --- Cargo.lock | 4 ++-- crates/ledger-core/Cargo.toml | 4 ++-- crates/ledger-package/Cargo.toml | 2 +- verify/lean/lake-manifest.json | 4 ++-- verify/lean/lakefile.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c43b6ed..de6d3aec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -822,7 +822,7 @@ dependencies = [ [[package]] name = "bookspec-checker" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=79cb439a3798053f71bae2cf8d4b9e882958365c#79cb439a3798053f71bae2cf8d4b9e882958365c" +source = "git+https://git.swaits.com/swaits/bookspec?rev=5127b5b9b110a8d459a5f33a78e6986344df651e#5127b5b9b110a8d459a5f33a78e6986344df651e" dependencies = [ "chrono", "include_dir", @@ -835,7 +835,7 @@ dependencies = [ [[package]] name = "bookspec-runner" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=79cb439a3798053f71bae2cf8d4b9e882958365c#79cb439a3798053f71bae2cf8d4b9e882958365c" +source = "git+https://git.swaits.com/swaits/bookspec?rev=5127b5b9b110a8d459a5f33a78e6986344df651e#5127b5b9b110a8d459a5f33a78e6986344df651e" dependencies = [ "bookspec-checker", "serde_json", diff --git a/crates/ledger-core/Cargo.toml b/crates/ledger-core/Cargo.toml index 8c7fb57d..947cb630 100644 --- a/crates/ledger-core/Cargo.toml +++ b/crates/ledger-core/Cargo.toml @@ -34,8 +34,8 @@ num-rational = "0.4" toml = "1" # The specification lives in its own repository (P13 step 6, D-34, D-65), # pinned to a commit. -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "79cb439a3798053f71bae2cf8d4b9e882958365c" } -bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "79cb439a3798053f71bae2cf8d4b9e882958365c" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "5127b5b9b110a8d459a5f33a78e6986344df651e" } +bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "5127b5b9b110a8d459a5f33a78e6986344df651e" } ledger-package = { path = "../ledger-package" } ledger-import = { path = "../ledger-import" } ledger-store = { path = "../ledger-store" } diff --git a/crates/ledger-package/Cargo.toml b/crates/ledger-package/Cargo.toml index 05b5c7da..983de7b6 100644 --- a/crates/ledger-package/Cargo.toml +++ b/crates/ledger-package/Cargo.toml @@ -22,7 +22,7 @@ zip = "9.0.1" workspace = true [dev-dependencies] -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "79cb439a3798053f71bae2cf8d4b9e882958365c" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "5127b5b9b110a8d459a5f33a78e6986344df651e" } proptest = "1" tempfile = "3" toml = "1" diff --git a/verify/lean/lake-manifest.json b/verify/lean/lake-manifest.json index d3d715c3..db64175c 100644 --- a/verify/lean/lake-manifest.json +++ b/verify/lean/lake-manifest.json @@ -5,10 +5,10 @@ "type": "git", "subDir": "lean", "scope": "", - "rev": "79cb439a3798053f71bae2cf8d4b9e882958365c", + "rev": "5127b5b9b110a8d459a5f33a78e6986344df651e", "name": "bookspec", "manifestFile": "lake-manifest.json", - "inputRev": "79cb439a3798053f71bae2cf8d4b9e882958365c", + "inputRev": "5127b5b9b110a8d459a5f33a78e6986344df651e", "inherited": false, "configFile": "lakefile.toml"}], "name": "wanderbooks", diff --git a/verify/lean/lakefile.toml b/verify/lean/lakefile.toml index 85472df6..dfed13f8 100644 --- a/verify/lean/lakefile.toml +++ b/verify/lean/lakefile.toml @@ -9,7 +9,7 @@ packagesDir = ".lake/packages" [[require]] name = "bookspec" git = "https://git.swaits.com/swaits/bookspec" -rev = "79cb439a3798053f71bae2cf8d4b9e882958365c" +rev = "5127b5b9b110a8d459a5f33a78e6986344df651e" subDir = "lean" [[lean_lib]] From d66cc98ee5a4f297cbe15c267cffc7bcc40cb8b5 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 21 Nov 2026 10:59:55 -0700 Subject: [PATCH 2/2] docs(verification): law 47, a write is one transaction, exactly once (P15 T1, D-88) Ties WB-format-8 to 10, the calls.rs spec block, the command-steps map and plan 2a to bookspec law 47 (Calls.lean): a call is a Steps run, no new Step. Co-Authored-By: Claude Fable 5.2 --- crates/ledger-store/src/calls.rs | 1 + docs/command-steps.md | 5 ++++ docs/spec/claims/format.md | 3 +++ docs/verification.md | 43 ++++++++++++++++++++++++++++++++ plan/p15-app-and-relay.md | 3 +++ 5 files changed, 55 insertions(+) diff --git a/crates/ledger-store/src/calls.rs b/crates/ledger-store/src/calls.rs index 207f45f2..9649b7b8 100644 --- a/crates/ledger-store/src/calls.rs +++ b/crates/ledger-store/src/calls.rs @@ -35,6 +35,7 @@ //! on the record, and a repeated request key answers what the first //! call answered and writes nothing. //! SOURCE: WB-format-8, WB-format-9, WB-format-10, WB-format-11, WB-format-12; +//! bookspec law 47 (lean/Bookspec/Calls.lean: invariants 1, 2 and 5); //! plan/p15-app-and-relay.md 2a (D-88, D-89). //! INVARIANTS: //! 1. Replay applies a call's lines only at its `ok` closing line, in diff --git a/docs/command-steps.md b/docs/command-steps.md index 23bfedbc..fdc3e73b 100644 --- a/docs/command-steps.md +++ b/docs/command-steps.md @@ -51,6 +51,11 @@ and the documents (tagged lines, control accounts, sends). keeps, so every law about balances, statements and periods holds across them with nothing to prove. Some keep a register with rules of its own (the note says which); see "Registers" below. +- **A tool call is a `Steps` run, not a step.** A call that writes is a + run of legal steps (a `Steps` run), so no `Step` constructor was added + for it: bookspec's law 47 (`Calls.call_preserves_inv`, `Calls.replay_inv`) + proves a replay of the counted steps of the journal's frames is + reachable and keeps the invariant. See `docs/verification.md` law 47. - **Several steps in one command** run inside `Ledger::atomically`: all of them happen or none does. diff --git a/docs/spec/claims/format.md b/docs/spec/claims/format.md index 23405935..0f652e04 100644 --- a/docs/spec/claims/format.md +++ b/docs/spec/claims/format.md @@ -256,6 +256,7 @@ line types (`call_transactions`, WB-format-2) and nothing else. Calls take turns: the server runs one write call at a time, so a call's lines are one run in the journal. `books.import_bank_csv` is one transaction like every other write (plan P15 6a). +*Proved:* Lean `Calls.prefix_law`, `Calls.replay_drop_frame`, `Calls.replay_ok_frame`, `Calls.call_preserves_inv` (bookspec law 47, `docs/verification.md` law 47): the lines of a call count only when it closed ok, a replay of a prefix inside a call is the replay before its begin, and a call is a run of legal steps. **Every reader of the journal applies the frame rule, because ids are reused after a failed call.** A failed call's entry, account, party and document ids @@ -320,6 +321,7 @@ transaction; an error text that holds one is kept masked (BS-partner-2: no journal line holds one). *Enforced:* ledger-mcp `calls::is_write_call`, `calls::key_problem`, `calls::begin`, `calls::close`, `calls::add_key_to_schema`, `Store::recorded_call`, `Keys`, `Replay`, `args_mac`, `Store::args_mac`, `hmac_sha256_hex`, `ANSWER_CAP`, `SESSION_KEYS_MAX`. *Checked:* `ledger-cli` `tests/call_transactions.rs` (`a_repeat_of_a_key_returns_the_first_answer_and_writes_nothing`, `the_same_key_for_another_request_is_refused_in_words`, `a_write_without_a_usable_key_is_not_run`, `every_tool_that_can_write_asks_for_a_key_and_no_other_does`, `the_same_key_under_two_tokens_is_two_calls`, `a_repeat_arriving_while_its_original_runs_gets_its_answer_and_changes_nothing`, `a_repeat_of_a_call_whose_answer_was_too_long_is_told_it_was_done`, `a_call_that_wrote_nothing_leaves_no_line_and_is_answered_again_only_within_the_session`, `a_key_reused_for_another_tax_id_is_refused_not_repeated`); `ledger-store` `tests/calls.rs` (`a_call_is_framed_and_its_answer_kept_by_key`, `the_sessions_key_table_is_bounded_in_count_and_in_bytes`, `a_long_answer_is_kept_as_its_hash_and_a_repeat_is_told_in_words_what_was_done`) and the unit tests `hmac_sha256_matches_rfc_4231` and `args_mac_tells_tax_ids_apart_and_holds_none` in `calls.rs`. +*Proved:* Lean `Calls.exactly_once`, `Calls.submit_repeat`, `Calls.replay_submit_repeat` (bookspec law 47, `docs/verification.md` law 47): a repeat of a key whose call committed adds nothing to the journal, changes no replay, and no call commits twice. **WB-format-10 A failed write is on the record, and builds nothing.** A call that answers with an error, is stopped by a close, or fails any other way @@ -344,6 +346,7 @@ the store heals from the journal where it can, and where it cannot says so it again), stops taking writes, and is rebuilt at the next open. *Enforced:* `Store::close_call`, `StoreError::CallCommitted`, ledger-mcp `calls::answered_ok`, `calls::close`, `calls::recover_vault`, `calls::put_tin`, `calls::purge_records`, `calls::settle_vault`, `ledger_vault::stage_tin`, `ledger_vault::stage_w9`, `ledger_vault::stage_purge`, `ledger_vault::settle`, `ledger_vault::pending_tags`. *Checked:* `ledger-store` `tests/calls.rs` (`a_failed_call_is_on_the_record_and_builds_nothing`, `a_call_that_wrote_nothing_leaves_no_line_and_is_remembered_for_the_session`, `a_closing_line_on_disk_but_sqlite_failing_is_a_call_that_counts`); `ledger-vault` `tests/vault.rs` (`a_staged_record_is_read_by_no_one_until_its_call_commits`, `a_call_that_did_not_commit_leaves_the_old_record_whole`, `a_purge_is_final_only_when_its_call_commits`); `ledger-cli` `tests/call_transactions.rs` (`a_failed_write_leaves_the_books_and_its_key_as_they_were`, `a_call_that_wrote_lines_and_then_failed_leaves_the_books_and_its_key_as_they_were`, `a_crash_with_the_ok_close_on_disk_but_sqlite_not_committed_leaves_the_call_done_once`, `a_set_tin_that_fails_leaves_the_vault_as_it_was`, `a_crash_between_the_commit_and_the_vault_settling_is_finished_at_the_next_start`). +*Proved:* Lean `Calls.replay_drop_frame`, `Calls.keyTable_failed_absent`, `Calls.keyTable_submit_failed` (bookspec law 47, `docs/verification.md` law 47): a failed call counts for nothing and leaves its key out of the table. **WB-format-11 Books that have not declared `call_transactions` take no write.** (The owner, 2026-11-20, D-89.) This replaces WB-format-3's "everything diff --git a/docs/verification.md b/docs/verification.md index 74e8051a..11df76ce 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -935,6 +935,49 @@ rule. both rules, a pre-feature schedule's replay after the upgrade, an unknown rounding is newer, and a daily schedule carrying no flag. +### A write is one transaction, exactly once (P15 T1, D-88, D-89) + +A tool call that writes is framed in the journal by `call.begun` and a +`call.closed` line (`crates/ledger-store/src/calls.rs`); only a frame closed +`ok` counts. The law is written once, in bookspec's `lean/Bookspec/Calls.lean` +(law 47 in `spec/laws.md`, pinned at 5127b5b); wanderbooks' product rules +WB-format-8, WB-format-9 and WB-format-10 are what it proves, since bookspec +has no rule of its own for the journal. + +47. **A write is one transaction, exactly once.** The steps that count are + those outside any frame and those of a frame closed `ok`, in order; a + frame closed `failed` or `unfinished`, and a frame with no close, count + for nothing. So a journal with such a frame replays as the journal + without it, and a replay of any prefix that ends inside a frame equals + the replay of the prefix before its begin. A frame closed `ok` is its + steps run in order from where the lines before it left the books. If + every counted step is legal where it is applied, the replayed books are + reachable and the invariant holds; a call is a run of legal steps + (`Steps`), so it needs no step of its own. The key table, from (token, + key) to the call that committed, is built from the journal alone: a + repeat of a key in it adds nothing to the journal and changes no + replay, a failed or unfinished call leaves its key out of the table, and + no call commits twice. + - Lean `Calls.prefix_law` (and `prefix_law_lines`, on the flat lines of a + file), `Calls.replay_drop_frame`, `Calls.replay_ok_frame`, + `Calls.replay_reachable`, `Calls.replay_inv`, `Calls.call_is_a_move`, + `Calls.call_preserves_inv`, `Calls.exactly_once`, + `Calls.submit_repeat`, `Calls.replay_submit_repeat`, + `Calls.keyTable_failed_absent`, `Calls.keyTable_submit_failed`; the + line reader `Calls.parse` is proved the inverse of `flatten` + (`parse_flatten`, `flatten_parse`), so a law about frames is a law + about lines + - *Modelled:* a call's identity (token, key), its steps, its outcome, and + `CallGate`'s state machine as `Calls.parse`. + - *Not modelled:* the close line's `first_seq` and `last_seq`, its tool, + its argument digest and its answer (on-disk consistency checks and + what a repeat is answered with; none changes which steps count), and + the session-memory table for calls that wrote no line (a call with no + line leaves no frame, and a repeat of it runs again and writes + nothing, so nothing is done twice). + - tests `crates/ledger-store/tests/calls.rs` (the frames, the replay of + every prefix, the key table after a restart) + ## What the proofs found The engine already had 190+ tests, property tests, mutation testing, diff --git a/plan/p15-app-and-relay.md b/plan/p15-app-and-relay.md index 6f5b9953..929d787a 100644 --- a/plan/p15-app-and-relay.md +++ b/plan/p15-app-and-relay.md @@ -77,6 +77,9 @@ What the code does today (read 2026-11-20 by a worker; file and line in (balances before and after, today's outstanding, next steps), so the original answer must be kept, not recomputed. +Landed 2026-11-21: the law is bookspec law 47 (`lean/Bookspec/Calls.lean`), +pinned at bookspec rev 5127b5b9b110a8d459a5f33a78e6986344df651e. + The rule: 1. **A call's lines commit together or not at all.** A call's events are