From d66cc98ee5a4f297cbe15c267cffc7bcc40cb8b5 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 21 Nov 2026 10:59:55 -0700 Subject: [PATCH] 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