feat(store): a tool call is one journal transaction (P15 T1, D-88)
Accounting reasoning: a write that is retried after a lost answer must happen once, and a call that dies between its journal lines must never be replayed as if whole. The journal feature `call_transactions` frames a call's lines with `call.begun` and `call.closed`; the lines between count only when the closing line says `ok`. Every replay (open, the viewer, verify, rebuild, the projection's catch-up) goes through one gate (`CallGate`), so no state is built from half a call and a replay of any prefix ending inside a call equals the replay of the prefix before it. A call that never closed is closed `unfinished` at the next open; a call that fails after writing lines is closed `failed`, its SQLite changes (one transaction per call) rolled back and the live ledger rebuilt without them. The closing line keeps the answer given, so a repeat of a request key returns it; the key table is rebuilt from the journal alone. The envelope is untouched. Lines outside a frame apply as ever, so every journal written before the feature replays as it was. Books get a unique id (`books_id`) at creation, and older books at the format upgrade, in the `journal.format_set` that declares the feature. The frame lines never move the audit's figure head. The upgrade's declaration now also carries the id, so the three tests that pinned its exact payload compare it without the id. No figure and no golden moved. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
7058fbd2b9
commit
2633109d55
15 files changed
+1375
-29
No files matched your search
@@ -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,98 @@ 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
|
||||
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`).
|
||||
|
||||
**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`;
|
||||
86 of the 140) 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 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
|
||||
that holds a full TIN is kept masked, so its repeat returns it 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`).
|
||||
|
||||
**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. 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`).
|
||||
|
||||
**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