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

+7
View File
@@ -6565,6 +6565,13 @@ impl Store {
crate::cancel::check()?;
replay_line_into_ledger(&mut self.ledger, &lines[i], self.base_currency)?;
}
// A call open now (the verification that heals is itself a call)
// keeps its projection transaction, on the new connection
// (calls.rs). It has written no line a rebuild would lose: it
// reads and rebuilds, nothing more.
if self.call.is_some() {
self.conn.execute_batch("SAVEPOINT call_tx")?;
}
Ok(())
}
+19 -1
View File
@@ -154,8 +154,10 @@ fn a_failed_call_is_on_the_record_and_builds_nothing() {
s.verify().unwrap();
}
type Step = Box<dyn Fn(&mut Store)>;
/// A call of every kind of step, by how far it got.
fn steps() -> Vec<Box<dyn Fn(&mut Store)>> {
fn steps() -> Vec<Step> {
vec![
Box::new(|s| {
s.create_entry(d(2026, 1, 5), "One").unwrap();
@@ -414,3 +416,19 @@ fn a_call_cannot_begin_inside_another_or_after_a_failed_close() {
Err(StoreError::CallRefused(_))
));
}
#[test]
fn a_call_that_rebuilds_the_projection_still_commits() {
// books.verify heals a drifted projection by rebuilding it, and is a
// call like any other: its transaction moves to the new database.
let tmp = tempfile::tempdir().unwrap();
let mut s = books(tmp.path());
s.begin_call(id("key-heal-0001")).unwrap();
s.rebuild().unwrap();
s.close_call(CallEnd::Done("{}")).unwrap();
s.verify().unwrap();
assert!(s.recorded_call("token-1", "key-heal-0001").is_some());
drop(s);
let s = Store::open(tmp.path()).unwrap();
s.verify().unwrap();
}