Merge branch 't3/transactional-mcp-writes': every write through the tools is one transaction, exactly once (P15 T1, D-88, D-89)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
38647e2143
61 files changed
+5801
-339
No files matched your search
+153
-3
@@ -171,9 +171,10 @@ in their second line, so they wait for nothing. Books an older version wrote
|
||||
declare less (format 1, written before the gate, declares nothing): they *wait
|
||||
for a format upgrade*, which is a fact of their journal alone
|
||||
(`JournalFormat::upgrade`). They open and replay as they are, byte for byte;
|
||||
everything that needs nothing new is written as ever; a write that would need
|
||||
the newer format or a feature they haven't declared is refused before anything
|
||||
is journaled (`StoreError::FormatUpgradePending`, guard
|
||||
everything that needs nothing new is written as ever, except that since D-88
|
||||
and D-89 they take no tool write at all (WB-format-11); a write that would
|
||||
need the newer format or a feature they haven't declared is refused before
|
||||
anything is journaled (`StoreError::FormatUpgradePending`, guard
|
||||
`format_upgrade_pending`), never declared on the way. Every setting key and
|
||||
tax category an earlier version didn't read needs a feature
|
||||
(`format::setting_feature`, `format::tax_category_feature`: the P3 data-safety
|
||||
@@ -219,6 +220,155 @@ 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 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).
|
||||
|
||||
**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`;
|
||||
83 of the 140: the three that only read what is sealed, `books.vendor_1099`,
|
||||
`books.get_w9` and `books.export_cpa_package`, write nothing and may answer with
|
||||
a full TIN, so they are reads) takes a required `request_key`, 8 to 128 characters of plain
|
||||
text, which the agent makes up, new for each action. A write without a usable
|
||||
key is refused in words before it runs; a preview (a confirmed tool called
|
||||
without `confirmed: true`) writes nothing and needs none. The key is taken out
|
||||
of the arguments before the tool sees them. A repeat of a (token, key) whose
|
||||
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 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
|
||||
rolls back: if it had written lines, its closing line says `failed` with how,
|
||||
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. 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. 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
|
||||
that needs nothing new is written as ever" for writes: from the release that
|
||||
carries the feature, books an older version wrote are opened and read as
|
||||
ever, and every write call is refused, before it runs, with the upgrade remedy
|
||||
and the words "nothing can be written", until the owner's go-ahead (the format
|
||||
upgrade, WB-format-3). So there is one way a write can happen, the one that is
|
||||
proved. The Store's own commands, which the owner's acts and the tests call
|
||||
directly outside a call, are unchanged; `Store::begin_call` refuses.
|
||||
*Enforced:* `Store::ensure_takes_calls`, `Store::begin_call`, `StoreError::FormatUpgradePending`, ledger-mcp `calls::begin`.
|
||||
*Checked:* `ledger-store` `tests/calls.rs` (`books_that_have_not_declared_the_feature_take_no_call_and_still_read`), the unit test `call_transactions_is_its_own_feature` in `format.rs`; `ledger-cli` `tests/format_upgrade.rs` (`books_p2_served_cut_over_whole`, `format_upgrade_waits_for_consent`, `documents_v2_refused_until_consent`).
|
||||
|
||||
**WB-format-12 Every set of books has a unique id.** (Plan P15 6a: the hash of
|
||||
the journal's first line, which carries a currency and a time to the second,
|
||||
told two sets of books apart badly.) Books made since `call_transactions` are
|
||||
born with `books_id`, 128 random bits in hex, in their `store.created` line.
|
||||
Older books get one with the format upgrade: the `journal.format_set` that
|
||||
declares `call_transactions` carries `books_id` when the books have none. The
|
||||
id is read from the journal alone (`books_id_of`), so it is the same after a
|
||||
restart and for the viewer, and a restored backup keeps it. Books that have
|
||||
had neither yet have no id (`Store::books_id` is None).
|
||||
*Enforced:* `Store::create`, `Store::declare_journal_format`, `Store::books_id`, `Snapshot::books_id`, `books_id_of`.
|
||||
*Checked:* `ledger-store` `tests/calls.rs` (`new_books_are_born_with_an_id_and_no_two_share_one`, `books_that_have_not_declared_the_feature_take_no_call_and_still_read`), `tests/format.rs` and `tests/format_upgrade.rs` (the upgrade's declaration holds the id).
|
||||
|
||||
## B-34 The QuickBooks Desktop file (IIF): plain ASCII, every entry through as_of, closes left out, classes carried
|
||||
|
||||
**bookspec:** `BS-format-2`
|
||||
|
||||
Reference in new issue
Block a user