feat(mcp): every write call is one transaction with a request key (P15 T1, D-88, D-89)

Accounting reasoning: these are financial books reached over the internet,
where a request is retried. A write whose answer is lost and then sent again
must not post twice, a call half done must not be left looking done, and a
failed write must be on the record.

Every tool that can change the books (83 of the 140: three that only read
what is sealed and may answer with a TIN are reads) takes a required
`request_key`, added to its schema in tools/list and taken out of the
arguments before the tool runs, so no tool, preview digest or check changes.
A write without a usable key is refused in words. Write calls take turns,
and each runs as one transaction of the store: opened (or answered from the
books if its key committed: the same tool and arguments return the first
answer and write nothing; other arguments are refused as a misuse of the
key; the access log says `repeat`), then closed with its answer if it
answered ok, or rolled back and closed `failed` if it errored, failed or was
stopped by a close. Books an older version wrote take no write at all until
the owner's go-ahead (D-89): every write is refused with the upgrade remedy;
reads work as ever. `books.import_bank_csv` is one transaction like the rest.

The handbook, docs/mcp-interface.md, the claims (WB-format-8 to 12, and
WB-format-3 amended for D-89) and docs/parity.md say so. Tests that wrote to
old books through the tools now assert the refusal and write after the
upgrade; the shared wire helpers add a fresh key to every tool call (the
journal helpers leave the call frames out, as they left out nothing before),
so no other test changed. The store-level `_waits_for_<feature>` tests still
check each feature's own gate. No figure and no golden moved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 09:43:52 -07:00
1 parent 2633109d55
commit e542319e63
25 files changed
+1084 -186

No files matched your search

+28
View File
@@ -611,6 +611,34 @@ with generated URIs, checks after each call that the server still
serves, restarts it after them to check the books reopen, and drives
every tool over every book in ledger-store's `tests/fixtures/old-books`.
## Writes: one transaction, one request key (plan P15 2a, D-88)
Every tool that can change the books (no `readOnlyHint`; 83 of the 140: the
three that read what is sealed and put it in a file, `books.vendor_1099`,
`books.get_w9` and `books.export_cpa_package`, are annotated so but write
nothing and may answer with a full TIN, so they are read like any read)
takes one more argument than its own, `request_key`, and its schema says it
is required: 8 to 128 characters of plain text the agent makes up, new for
each different action and never reused for another. The agent sends the same
call again with the same key when its answer is lost; the books do not do it
twice, and answer what they answered the first time (a repeat is recorded in
the access log as `repeat`, and writes nothing, even after the books were
closed and opened). The same key with other arguments, or another tool, is
refused in words and changes nothing. A key is the token's own. A write
without a usable key is refused in words before it runs. A preview (a tool
with `confirmed`, called without `confirmed: true`) writes nothing and needs
no key. A failed write changes nothing and leaves its key free: the corrected
call may use it; where the call got as far as writing journal lines, the
journal says it failed (`call.closed`, outcome `failed`) and none of them
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).
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
written"; every read works as ever. No tool can give the go-ahead.
## Tool design principles
- **Narrow tools, explicit arguments.** No "do what I mean" tools. The agent
+8
View File
@@ -256,3 +256,11 @@ Three new rows, none above changed status, and the floor stands.
| Books home: a visible folder per book, `<Documents>/Wanderbooks/<id>`, holding `AGENTS.md`, `CLAUDE.md`, `.mcp.json` and `.claude/settings.json` and nothing of the books | A QBO/Xero company has no counterpart; the point is the agent's workplace (D-27) | partial | `books_home_holds_no_books_data`, `a_books_home_made_again_keeps_what_a_person_kept` (`crates/ledger-host/tests/books_home.rs`); `partial` until the macOS home is tried |
| Agent dock: Claude Code or Codex in a terminal along the bottom of the viewer, started in the books home; never required | QBO's assistant panel is a cross-check only | partial | `dock_runs_the_chosen_agent`, `agent_missing_offers_the_installer` (`crates/ledger-gui/tests/dock.rs`); Linux checked; macOS by the CI run; Windows not offered (ConPTY unchecked) |
| First run with no terminal: the viewer sets up the private folder, the owner passphrase, the first books and an agent | QBO's "set up your company" flow | partial | `first_run_onboards_with_no_terminal` (`crates/ledger-gui/tests/welcome.rs`); the AppImage's whole path is the EM's to try on a clean machine |
## P15 T1: every write is one transaction, exactly once (2026-11-21, D-88, D-89)
| Area | Counterpart (a cross-check, not the spec) | Status | Notes |
|---|---|---|---|
| A tool call's lines commit together with a closing line or not at all; a call that never closed, or failed, builds nothing in any replay; a failed call is on the record | A database transaction; QBO and Xero make a write all or nothing and say so on failure | partial | WB-format-8, WB-format-10; `ledger-store` `tests/calls.rs` (`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_failed_call_is_on_the_record_and_builds_nothing`); partial until the Lean law is in bookspec and a `done` needs a golden |
| Every write carries a request key; a repeat returns the first answer and writes nothing, across a restart; the same key for another request is refused | An idempotency key (a payments API's `Idempotency-Key`); QBO's `requestid` | partial | WB-format-9; `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`, `every_tool_that_can_write_asks_for_a_key_and_no_other_does`); `books.import_bank_csv` is one transaction (`the_import_is_one_transaction`) |
| Books that haven't declared the feature take no write and still read; every set of books has a unique id | No counterpart; the owner's rule (D-89) | partial | WB-format-11, WB-format-12; `ledger-store` `tests/calls.rs` (`books_that_have_not_declared_the_feature_take_no_call_and_still_read`, `new_books_are_born_with_an_id_and_no_two_share_one`); `ledger-cli` `tests/format_upgrade.rs` (`books_p2_served_cut_over_whole`) |
+5 -2
View File
@@ -258,7 +258,9 @@ restart).
**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
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
@@ -270,7 +272,8 @@ 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
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`).