docs,test: claims WB-format-8 to 10, the interface, the handbook and the tests follow the review

WB-format-8 now says every reader applies the frame rule because ids are
reused after a failed call, and names the committed accessor and the labels;
WB-format-9 the keyed argument digest, the bounded answer, the in-memory
table for calls that wrote nothing and what a repeat of a long answer is
told; WB-format-10 the vault staged inside the transaction and the honest
words when the closing line is on disk. docs/mcp-interface.md, the receipt
store's frame paragraph and the handbook (contract, tracing figures) say the
same.

Tests follow the new shapes: a call that wrote nothing leaves no line, the
head a write answers is where its own lines end and its closing line follows,
the idempotency table compares events, and the checks that a refusal or a
preview wrote nothing compare the raw journal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 10:40:00 -07:00
1 parent 4c23fade7a
commit b592aaf416
13 files changed
+175 -68

No files matched your search

+98 -44
View File
@@ -222,39 +222,62 @@ others are there; none is deleted for being stale.
**WB-format-8 Every write a tool makes is one transaction in the journal.**
(The owner, 2026-11-20, D-88: "Writes have to be TRANSACTIONAL ALWAYS! You
can record a failed transaction.") A tool call that writes frames its journal
lines: `call.begun { tool, token, key, args }` just before its first line, and
`call.closed { tool, token, key, args, outcome, first_seq, last_seq, answer |
error }` when it is over, `outcome` being `ok` (the answer given is `answer`,
kept as text so a repeat returns it byte for byte), `failed`, or `unfinished`.
A call that wrote no line is only its closing line. The lines between a begin
and its close count only when the close says `ok`: that is how a reader tells
a complete call from an incomplete one. Every replay (opening the books, the
viewer, verify, rebuild, the projection a restart catches up) goes through
one rule (`CallGate`): a line outside a frame applies at once (every line
before the books declared `call_transactions`, and the owner's own acts: the
format declaration, a repaired tail); a line inside a frame waits, and is
can record a failed transaction.") A tool call that writes journal lines
frames them: `call.begun { tool, token, key, args }` just before its first
line, and `call.closed { tool, token, key, args, outcome, first_seq,
last_seq, answer | answer_sha256 + answer_bytes | error }` when it is over,
`outcome` being `ok` (the answer given is `answer`, kept as text so a repeat
returns it byte for byte, when it is at most 4096 bytes; above that the line
keeps `answer_sha256`, the SHA-256 of the answer, and `answer_bytes`, its
length, so every closing line is bounded), `failed` (`error` says how), or
`unfinished` (written by the next open of books whose last call never
closed). `args` is a keyed digest of the call's arguments (WB-format-9). A
call that wrote no journal line has no frame and no closing line: there is
nothing to frame, and nothing it did can be half done. The lines between a
begin and its close count only when the close says `ok`: that is how a reader
tells a complete call from an incomplete one. Every replay (opening the
books, the viewer, verify, rebuild, the projection a restart catches up) goes
through one rule (`CallGate`): a line outside a frame applies at once (every
line before the books declared `call_transactions`, and the owner's own acts:
the format declaration, a repaired tail); a line inside a frame waits, and is
applied with its closing line when that says `ok`, and never when it says
`failed` or `unfinished` or when no closing line follows. So no state is built
from half a call, and a replay of any prefix that ends inside a call equals the
replay of the prefix before it. A close must name the frame it ends (its
`first_seq` is the begin line's, its `last_seq` the line before it); a frame
that begins inside another, a close with no frame, or a close that does not
match is a corrupt journal. The projection keeps a call's changes in one
SQLite transaction, released only after the `ok` closing line is on disk. When
the books are opened and the journal's last call never closed, its lines are
not applied, it is closed `unfinished` before anything else is written, and a
projection that holds its lines is rebuilt. The envelope `{seq, ts, type,
payload, prev}` is untouched: the feature adds two 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). The reader's view: a viewer reads a call's lines only once its
closing line is read; a reader of the memory sees a call's lines for the
moment between its tool finishing and its closing line (never after a
restart).
*Enforced:* `ledger_store::calls` (`CallGate`, `gate_all`, `closed_of`, `begun_of`, `Store::begin_call`, `Store::close_call`), `Store::open`, `Store::verify`, `Store::rebuild`, `Snapshot::refresh`, `format::CALL_TRANSACTIONS`, ledger-mcp `SharedStore::write_turn`.
*Checked:* `ledger-store` `tests/calls.rs` (`a_call_is_framed_and_its_answer_kept_by_key`, `a_call_that_wrote_nothing_is_only_a_closing_line`, `a_crash_at_each_point_of_a_call_leaves_the_whole_call_or_none_of_it`, `a_replay_of_any_prefix_inside_a_call_is_the_replay_of_the_prefix_before_it`, `a_viewer_applies_a_call_only_when_it_closes`, `a_frame_that_does_not_close_what_it_follows_is_corrupt`, `a_call_cannot_begin_inside_another_or_after_a_failed_close`), the unit test `call_transactions_is_its_own_feature` in `format.rs`, `tests/format.rs` (`every_event_the_store_replays_passes_the_gate`); `ledger-cli` `tests/call_transactions.rs` (`a_call_is_one_frame_in_the_journal_closed_with_its_answer`, `the_import_is_one_transaction`).
`failed` or `unfinished` or when no closing line follows. So no state is
built from half a call, and a replay of any prefix that ends inside a call
equals the replay of the prefix before it. A close must name the frame it
ends (its `first_seq` is the begin line's, its `last_seq` the line before
it); a frame that begins inside another, a close with no frame, or a close
that does not match is a corrupt journal. The projection keeps a call's
changes in one SQLite transaction, released only after the `ok` closing line
is on disk. When the books are opened and the journal's last call never
closed, its lines are not applied, it is closed `unfinished` before anything
else is written, and a projection that holds its lines is rebuilt. The
envelope `{seq, ts, type, payload, prev}` is untouched: the feature adds two
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).
**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
were never taken (nothing it wrote counted), so the next call hands them out
again; a reader that took the raw lines would pin the dead lines of a failed
call on whatever took the id next (a failed `books.create_bill` for entry 42,
then a manual entry 42, would read as a "Bill"). So a reader that derives a
fact (an entry's origin and events, an asset's trail, a party's events, an
attention item, a package, what adopting books would keep) reads the
committed journal (`committed`: the lines outside any call and those of calls
that closed `ok`, the frame lines left out) and never the raw one; a reader
that shows history (the viewer's journal page, `books.journal_history`)
shows every line and says in words of each line of a call that failed, never
finished or is still running that it did not count (`Standing`, `standings`).
Backups and restores copy the journal's bytes whole and read none of its
facts. The reader's view of a running call: a viewer reads a call's lines only
once its closing line is read; a request on the server that arrives between a
call's tool finishing and its closing line, when the call has written a line,
waits for the close, so no read shows what a call did before the call
committed.
*Enforced:* `ledger_store::calls` (`CallGate`, `gate_all`, `standings`, `committed`, `Standing`, `closed_of`, `begun_of`, `ANSWER_CAP`, `Store::begin_call`, `Store::close_call`), `Store::open`, `Store::verify`, `Store::rebuild`, `Snapshot::refresh`, `Snapshot::committed_journal`, `Snapshot::journal_standings`, `Store::journal_history`, `history_standing`, ledger-package `PackageBooks`, ledger-gui `Books::build`, `adopt`, `format::CALL_TRANSACTIONS`, ledger-mcp `SharedStore::write_turn`, `BooksServer::lock`.
*Checked:* `ledger-store` `tests/calls.rs` (`a_call_is_framed_and_its_answer_kept_by_key`, `a_call_that_wrote_nothing_leaves_no_line_and_is_remembered_for_the_session`, `a_long_answer_is_kept_as_its_hash_and_a_repeat_is_told_in_words_what_was_done`, `the_committed_journal_leaves_out_the_lines_of_a_call_that_failed`, `a_crash_at_each_point_of_a_call_leaves_the_whole_call_or_none_of_it`, `a_replay_of_any_prefix_inside_a_call_is_the_replay_of_the_prefix_before_it`, `a_viewer_applies_a_call_only_when_it_closes`, `a_frame_that_does_not_close_what_it_follows_is_corrupt`, `a_call_cannot_begin_inside_another_or_after_a_failed_close`, `a_call_whose_begin_line_the_projection_refuses_still_closes_its_frame`, `books_the_version_before_call_transactions_wrote_open_and_report_the_same_figures`), `tests/store.rs` (`books_written_under_older_rules_still_open`, `books_an_earlier_version_wrote_open_to_its_figures`), the unit test `call_transactions_is_its_own_feature` in `format.rs`, `tests/format.rs` (`every_event_the_store_replays_passes_the_gate`); `ledger-gui` `tests/view_model.rs` (`a_failed_calls_lines_are_not_facts_when_its_ids_are_used_again`: the viewer's books, the feed attention reads, and the history after a failed call and an id handed out again); `ledger-cli` `tests/call_transactions.rs` (`a_call_is_one_frame_in_the_journal_closed_with_its_answer`, `the_import_is_one_transaction`, `a_call_that_wrote_lines_and_then_failed_leaves_the_books_and_its_key_as_they_were`).
**WB-format-9 Every write call carries a request key, and a repeat of it
writes nothing.** Every tool that can change the books (no `readOnlyHint`;
@@ -269,14 +292,34 @@ call committed, with the same tool and arguments, returns that call's answer
as it was given, writes nothing, and is recorded in the access log as
`repeat`; with other arguments or another tool it is refused in words as a
misuse of the key, and nothing is changed. A key is the token's own: two
tokens with one key are two keys. The key table is rebuilt at every open from
the `ok` closing lines alone. A repeat that arrives while its original is
still running waits for it (calls take turns) and gets its answer. An answer
is kept as given: no tool answer holds a full TIN, and the three tools that
can are no 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`.
*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`); `ledger-store` `tests/calls.rs` (`a_call_is_framed_and_its_answer_kept_by_key`).
tokens with one key are two keys. "The same arguments" is a keyed digest
(`args_mac`): HMAC-SHA256 over the arguments' canonical JSON, unmasked, under
a secret of the books' own (`keys/calls.key`, 32 random bytes, made on first
need, mode 0600, never journaled, logged or answered), so two requests that
differ only in a tax id are two requests, and nothing journaled lets anyone
recover or test a guess of a tax id (a plain hash of nine digits would be
guessable). The key file is part of the books' keys folder and travels with
its backups; books restored without it refuse a repeat of an older key as a
misuse of the key (nothing is changed), never as a repeat. The key table is
rebuilt at every open from the `ok` closing lines alone and holds one small
entry per committed call, no answers: a repeat reads its answer from the
closing line. A call that answered `ok` but wrote no journal line leaves no
line, so its key and answer are kept in memory for the life of the server
only, in a table bounded at 512 calls and 2 MiB of answers, oldest first out
(an answer above 4096 bytes is not kept); a repeat within the session gets
the same answer, and after a restart a repeat simply runs again, which is
harmless because it wrote nothing (`books.back_up_now` and `books.begin_upload`
are such calls: a second backup or a second empty upload slot is no harm).
A call that wrote lines and whose answer was above 4096 bytes is repeated in
words: it says the call was done, with its journal lines, the answer's
length and SHA-256, that the answer was too long to keep, and writes
nothing. A repeat that arrives while its original is still running waits for
it (calls take turns) and gets its answer. An answer is kept as given: no
tool answer holds a full TIN, and the three tools that can are no
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`.
**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
@@ -285,11 +328,22 @@ its lines are never applied, the projection's changes are rolled back and the
live ledger is rebuilt from the journal without them; if it had written none,
the access log has it (as every call has) and the journal has nothing. A
failed call leaves its key unused: nothing happened under it, so the corrected
call may use it. A call whose closing line cannot be written has not
call may use it. Nothing a call writes outside the journal is final before
the call commits: the tax-id vault's writes (`books.set_tin`, `books.set_w9`,
`books.purge_tin`) are staged under names no reader opens and made final when
the call's closing line is written, or dropped (and a purge put back) when
the call fails; a crash between the closing line and that settling is
finished at the next start by what the journal says of the call, so a failed
or cut call never replaces or destroys a record (`ledger_vault::settle`,
`pending_tags`). A call whose closing line cannot be written has not
committed; the store takes no further write, and the books server stops, as
it does when an access record cannot be written.
*Enforced:* `Store::close_call`, ledger-mcp `calls::answered_ok`, `calls::close`.
*Checked:* `ledger-store` `tests/calls.rs` (`a_failed_call_is_on_the_record_and_builds_nothing`, `a_call_that_wrote_nothing_is_only_a_closing_line`); `ledger-cli` `tests/call_transactions.rs` (`a_failed_write_leaves_the_books_and_its_key_as_they_were`).
it does when an access record cannot be written. A call whose closing line
*is* on disk but whose projection cannot be brought up to it has committed:
the store heals from the journal where it can, and where it cannot says so
(`StoreError::CallCommitted`: the call was completed and counts, do not do
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`).
**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