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:
1 parent
4c23fade7a
commit
b592aaf416
13 files changed
+175
-68
No files matched your search
@@ -471,11 +471,18 @@ fn a_mutating_call_answers_with_the_head_and_a_refusal_names_its_remedy() {
|
||||
.unwrap();
|
||||
let head = added["head"]["seq"].as_u64().unwrap();
|
||||
let start = answer_of(&w.call("books.start", json!({}))).unwrap();
|
||||
// The head a write call answers is where its own lines end; its closing
|
||||
// line (which holds this very answer) follows at once, and is the
|
||||
// journal's head from then on (WB-format-8).
|
||||
assert_eq!(
|
||||
start["head"]["seq"],
|
||||
json!(head),
|
||||
"the head the call answered is the journal's"
|
||||
json!(head + 1),
|
||||
"the journal ends one line past the head the call answered: its closing line"
|
||||
);
|
||||
let journal = String::from_utf8(books.journal_raw()).unwrap();
|
||||
let last: serde_json::Value = serde_json::from_str(journal.lines().last().unwrap()).unwrap();
|
||||
assert_eq!(last["type"], "call.closed");
|
||||
assert_eq!(last["payload"]["last_seq"], json!(head));
|
||||
assert!(!added["next_steps"].as_array().unwrap().is_empty());
|
||||
// A confirm with no preview is refused as stale_preview, naming the
|
||||
// tool that previews.
|
||||
|
||||
@@ -156,7 +156,7 @@ fn an_invoice_from_issue_to_paid() {
|
||||
assert!(draft.starts_with(b"%PDF"), "a PDF, not bytes inline");
|
||||
assert!(draft.len() > 1_000, "the DRAFT copy is a page: {preview}");
|
||||
assert_eq!(books.journal_raw(), before, "a preview journals nothing");
|
||||
assert!(books.journal().len() == before.len());
|
||||
assert!(books.journal_raw().len() == before.len());
|
||||
|
||||
// The confirm: the same number, the issued copy filed with the invoice.
|
||||
let mut confirmed = issue.clone();
|
||||
|
||||
@@ -349,13 +349,13 @@ fn a_package_the_build_refuses_journals_no_decision_even_with_a_reason() {
|
||||
draft(&mut w, "2026-03-10", "Open", "40.00");
|
||||
let mut args = json!({"as_of": "2026-03-31", "cash_accounts": ["1000"]});
|
||||
args["allow_open_drafts"] = json!({"reason": "the CPA wants it before the receipt comes"});
|
||||
let before = books.journal().len();
|
||||
let before = books.journal_raw().len();
|
||||
for _ in 0..2 {
|
||||
let why = answer_of(&w.call("books.export_cpa_package", args.clone()))
|
||||
.expect_err("the build refuses an unknown capital account");
|
||||
assert!(why.contains("unknown capital account 3999"), "{why}");
|
||||
assert_eq!(
|
||||
books.journal().len(),
|
||||
books.journal_raw().len(),
|
||||
before,
|
||||
"a decision was journaled for a package that was refused"
|
||||
);
|
||||
|
||||
@@ -997,11 +997,11 @@ fn books_p2_served_cut_over_whole() {
|
||||
}
|
||||
let verified = a.call("books.verify", json!({})).unwrap();
|
||||
assert_eq!(verified["status"], "ok", "{verified}");
|
||||
// It counts the lines there were when it ran: the call's own closing
|
||||
// line comes after its answer.
|
||||
// It counts the lines there were when it ran, all of them: a call that
|
||||
// wrote nothing leaves no closing line of its own.
|
||||
let events = verified["events"].as_u64().unwrap();
|
||||
let on_disk = journal(&dir).iter().filter(|b| **b == b'\n').count() as u64;
|
||||
assert!(events > 470 && events < on_disk, "{events} of {on_disk}");
|
||||
assert!(events > 470 && events == on_disk, "{events} of {on_disk}");
|
||||
assert_eq!(verified["database"], ledger_store::db_file());
|
||||
assert_eq!(verified["other_databases"], json!(["wanderbooks.db"]));
|
||||
assert_eq!(
|
||||
|
||||
@@ -224,11 +224,6 @@ impl Mcp {
|
||||
mcp
|
||||
}
|
||||
|
||||
/// The journal, without the frames of tool calls (D-88): the events.
|
||||
fn journal(&self) -> Vec<u8> {
|
||||
common::without_call_lines(&self.journal_raw())
|
||||
}
|
||||
|
||||
/// The journal, byte for byte: what a check that a refusal or a
|
||||
/// preview "journaled nothing" compares, so a stray frame line is seen.
|
||||
fn journal_raw(&self) -> Vec<u8> {
|
||||
|
||||
@@ -2104,7 +2104,9 @@ fn idempotent_tools_change_nothing_when_repeated() {
|
||||
m.ok(name, args.clone());
|
||||
let (journal, vault) = (m.journal(), vault_bytes(&m));
|
||||
m.ok(name, args.clone());
|
||||
let changed = m.journal_raw() != journal || vault_bytes(&m) != vault;
|
||||
// The events, not the frames: a repeat with a new key is a call of
|
||||
// its own, and its frame is no change of the books.
|
||||
let changed = m.journal() != journal || vault_bytes(&m) != vault;
|
||||
*repeats_change.entry(name).or_default() |= changed;
|
||||
}
|
||||
let wrong: Vec<String> = repeats_change
|
||||
|
||||
@@ -11,6 +11,7 @@ You are the bookkeeping agent for these books. The engine enforces the accountin
|
||||
- Never invent accounts. If the account you need does not exist, add it with books.add_account first.
|
||||
- Posted entries are immutable; there is no edit. Corrections go through books.reverse_entry.
|
||||
- {evidence_rule}
|
||||
- Every tool that changes the books takes a request_key you make up (8 to 128 characters, a UUID is fine), new for each different action. If an answer is lost, send the same call again with the same key and the same arguments: the books do not do it twice, and answer what they answered (for a very long answer, they say the call was done and name its journal lines). The same key with other arguments is refused. A call that fails changes nothing and leaves its key free; fix it and send it again with the same key. Books waiting for the owner's format upgrade take no write at all (the format-upgrade section).
|
||||
- Show the numbers: after every change, show the human the affected balances.
|
||||
- After posting, check books.digest and offer it to the human (the review of what changed), so they can review it too.
|
||||
- A full TIN goes only into the vault (books.set_tin, books.set_w9); never repeat one anywhere (the parties-and-tins section).
|
||||
@@ -3,6 +3,7 @@
|
||||
- Reports are pure functions of the posted entries. When the human questions a figure, trace it to its entries with the tools: the report (books.trial_balance, books.profit_and_loss, books.balance_sheet, books.cash_flow), then books.search_entries and books.get_entry for the entries behind it, and books.show to put them on the human's screen.
|
||||
- A report without dates covers the fiscal year to date, everywhere (the report tools, the export, books.show and the viewer); one with only an end date covers that date's fiscal year to it. {period_rule} The IIF is never a period: every posted entry from the first through its as_of. Every result names the dates it covers: say them when you quote a figure, and pass dates whenever the human means another period.
|
||||
- A cash flow line names its entry (books.cash_flow: each line's entry, kind and accounts). An expense a member paid personally (or equipment a lender paid for) is cash borrowed and spent on its date: a financing line and an operating (or investing) line, each with on_behalf, the part no bank account moved; the reimbursement is a repayment. A noncash disclosure is an entry that moved no cash at all (property contributed, debt converted to capital). A warning names an entry whose later payment or collection the books can't classify, with the fix. A role refusal names the setting to change.
|
||||
- books.journal_history shows every line of the journal. A line it says did not count belongs to a call that failed, never finished or is still running: nothing it wrote is in the books, and the ids it took were handed out again, so never trace a figure to such a line.
|
||||
- Never guess, and never look for the books' files: the tools are the evidence.
|
||||
- books.verify checks the books end to end when a number looks wrong or a human asks whether the books are intact.
|
||||
- A member's odd cent: closes, the statement of members' equity, the K-1 worksheet and the viewer split earnings among the members one running way. Each close gives a member their share of everything closed to the same members and shares so far, to the cent (odd cents by largest remainder, ties to the member listed first when that count began), less what earlier closes gave them, so no member is ever a cent from their exact share. Earnings not yet closed are split the way their close will split them, so a member's capital on a day never changes when its month is closed. books.close_period's members shows each member's part, running total and exact share; the first close that posts may carry a one-time correction of the rounding left by closes made under an earlier rule (a cent or so per member; each member's this_close shows it) (books.list_periods' close_rule names each close's rule). A change of members or shares starts a new count.
|
||||
|
||||
@@ -90,7 +90,7 @@ impl BooksServer {
|
||||
#[tool(
|
||||
name = "books.journal_history",
|
||||
title = "Journal history",
|
||||
description = "The journal in words, in order: each line's seq, time, type and a sentence saying what it did, to what, and the entry it belongs to. Filter by after_seq, types (an exact type like entry.posted, or a group like entry.) and subject (entry:12, invoice:3, bill:3, account:10, party:5, asset:2). The way to trace a figure back to what produced it, and the only way to see what the journal holds. Read-only; at most 200 lines a call.",
|
||||
description = "The journal in words, in order: each line's seq, time, type and a sentence saying what it did, to what, and the entry it belongs to. Filter by after_seq, types (an exact type like entry.posted, or a group like entry.) and subject (entry:12, invoice:3, bill:3, account:10, party:5, asset:2). The way to trace a figure back to what produced it, and the only way to see what the journal holds. A line of a call that failed or never finished is listed and says it did not count. Read-only; at most 200 lines a call.",
|
||||
annotations(read_only_hint = true, open_world_hint = false)
|
||||
)]
|
||||
pub(super) async fn journal_history(
|
||||
|
||||
@@ -773,7 +773,9 @@ fn books_the_version_before_call_transactions_wrote_open_and_report_the_same_fig
|
||||
assert_eq!(after, expected["snapshot"]["Ok"]);
|
||||
s.begin_call(id("key-old-books-2")).unwrap();
|
||||
// January is closed in these books: the first framed call is a March one.
|
||||
let e = s.create_entry(d(2026, 3, 1), "A first framed call").unwrap();
|
||||
let e = s
|
||||
.create_entry(d(2026, 3, 1), "A first framed call")
|
||||
.unwrap();
|
||||
let bank = s.ledger().chart().find_by_code("1000").unwrap().id;
|
||||
let capital = s.ledger().chart().find_by_code("3000").unwrap().id;
|
||||
s.add_line(e, bank, Side::Debit, money(10)).unwrap();
|
||||
|
||||
@@ -634,6 +634,41 @@ count. Every write call is one transaction: its lines commit together with
|
||||
its closing line or not at all, and after a crash a call without its closing
|
||||
line is not treated as done (WB-format-8 to WB-format-10).
|
||||
|
||||
What the books keep of a call, and what a repeat is told:
|
||||
|
||||
- A call that wrote journal lines is framed by `call.begun` and
|
||||
`call.closed`; its closing line keeps the answer (at most 4096 bytes). A
|
||||
repeat of it returns that answer byte for byte. If the answer was longer,
|
||||
the closing line keeps its SHA-256 and length instead, and a repeat is
|
||||
told in words that the call was done, with the journal lines it wrote
|
||||
(`books.journal_history` with `after_seq` lists them), and nothing is
|
||||
done again.
|
||||
- A call that wrote no journal line leaves no line at all. Its key and
|
||||
answer are kept in memory for the life of the server: 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`,
|
||||
`books.begin_upload`).
|
||||
- "The same arguments" is a keyed digest of them, tax ids included, under a
|
||||
secret of the books' own that is never journaled: two requests that differ
|
||||
only in a tax id are two requests, and the same key with the other tax id
|
||||
is refused.
|
||||
- A write that fails after it wrote lines is on the record
|
||||
(`books.journal_history` lists its lines and says of each that it did not
|
||||
count); ids it took are handed out again to the next call, so a reader
|
||||
that takes the journal raw would pin its dead lines on whatever takes the
|
||||
id next: every reader applies the frame rule, and the journal in words
|
||||
(`books.journal_history`) and the viewer's journal page show every line and
|
||||
say of the ones that did not count that they did not.
|
||||
- A write to the tax-id vault is part of the call: it is final only when the
|
||||
call commits, so a failed or cut call never replaces or destroys a tax id.
|
||||
- A request that arrives while a call that has written a line is still
|
||||
open waits for its closing line: no read shows what a call did before the
|
||||
call committed.
|
||||
- If a call's closing line is saved but the books' working copy cannot be
|
||||
brought up to it, the call is told so in words: it was completed and
|
||||
counts, the books server stopped to protect the books, and sending the call
|
||||
again with the same key answers what it answered and changes nothing.
|
||||
|
||||
Books an older version wrote take no write at all until the owner gives the
|
||||
format upgrade its go-ahead (D-89, WB-format-11): every write is refused,
|
||||
before it runs, with `format_upgrade_pending` and the words "nothing can be
|
||||
|
||||
+18
-8
@@ -199,14 +199,24 @@ a backup is then proven where it lands, by a drill (docs/mcp-interface.md,
|
||||
- **A tool call is a frame, not a record** (plan P15 2a, D-88, feature
|
||||
`call_transactions`): a call that writes lines is framed by
|
||||
`call.begun {tool, token, key, args}` before its first line and
|
||||
`call.closed {tool, token, key, args, outcome, first_seq?, last_seq?,
|
||||
answer?, error?}` after its last. The lines between count only when
|
||||
`outcome` is `ok` (then `answer` is the text of the answer given, kept
|
||||
so a repeat of `key` returns it); `failed` and `unfinished` (written by
|
||||
the open that finds a call that never closed) say the lines in the frame
|
||||
never count, in any replay. A call that wrote no line is a closing line
|
||||
alone. A line outside a frame applies as ever, so every journal written
|
||||
before the feature replays as it was. `store.created` carries
|
||||
`call.closed {tool, token, key, args, outcome, first_seq, last_seq,
|
||||
answer | answer_sha256 + answer_bytes | error}` after its last. `args`
|
||||
is an HMAC-SHA256 of the call's arguments under the books' own secret
|
||||
(`keys/calls.key`), never a plain hash (a tax id would be guessable). The
|
||||
lines between count only when `outcome` is `ok` (then `answer` is the
|
||||
text of the answer given, kept so a repeat of `key` returns it, when at
|
||||
most 4096 bytes; above that `answer_sha256` and `answer_bytes` stand in
|
||||
its place); `failed` and `unfinished` (written by the open that finds a
|
||||
call that never closed) say the lines in the frame never count, in any
|
||||
replay. A call that wrote no line has no frame and no closing line (its
|
||||
key and answer are kept in memory for the life of the server only). A
|
||||
line outside a frame applies as ever, so every journal written before
|
||||
the feature replays as it was. **Every reader that derives a fact reads
|
||||
the committed journal** (`calls::committed`: the lines outside a frame and
|
||||
those of `ok` frames), because ids are handed out again after a failed
|
||||
call and a raw reader would pin the dead lines on whatever takes the id
|
||||
next; a reader that shows history shows every line and says of the dead
|
||||
ones that they did not count (`calls::standings`). `store.created` carries
|
||||
`books_id` (the books' own unique id) in books made since the feature;
|
||||
older books are given one in the `journal.format_set` of their upgrade.
|
||||
Neither frame line moves the audit's figure head.
|
||||
|
||||
+98
-44
@@ -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
|
||||
|
||||
Reference in new issue
Block a user