fix(mcp,vault,store): the tax-id vault is inside the transaction; a read never sees an open call; the commit outcome is told truthfully (P15 T1 review)

The vault wrote a tax id before its journal line, so a call that failed or
was cut left the new tax id (and lost the old) with no line to say so. A
vault write made for a call is now staged under a name no reader opens
(.staged-TAG, .purging-TAG) and is made final, or dropped, only when the
call closes: a purge is set aside and put back if the call fails. A crash
between the closing line and the settle is finished at the next start by
what the journal says of the call. The readers that check a vault record
against the party's committed vault_record hash (the 1099 and CPA package
paths) therefore only ever see committed records; the filing scan reads
every final record on purpose (more tax ids scanned is safer).

close_call(Done) told the caller none of a call counted when its closing
line was on disk and only SQLite failed. It counted: the store now heals
from the journal where it can, and otherwise says the call counts, stops
taking writes and rebuilds at the next open.

A call whose begin line the projection refused left its frame open, so the
next call began inside it (a corrupt journal): the frame is now closed
failed.

A read arriving between a call's return and its closing line waits for the
close (a call that has written no line leaves reads free), so no read shows
what a call did before it committed.

Tests added through the tools: a call that writes lines and fails, a repeat
arriving while its original runs, the same key under two tokens, a crash
with the ok close on disk and SQLite behind, the vault under a failed and a
crashed call, a key reused for another tax id. The helpers that drop frame
lines no longer back the checks that a refusal or a preview wrote nothing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 10:19:26 -07:00
1 parent d4c0036599
commit 98cbabde8e
22 files changed
+1516 -169

No files matched your search

+8 -4
View File
@@ -921,11 +921,15 @@ impl BooksServer {
self.wrote_tins(&store, &w.bytes)?;
}
let tin_hash = match &tin {
Some(t) => Some(vault.put_tin(id, t).map_err(|e| e.to_string())?),
Some(t) => {
Some(super::calls::put_tin(&vault, id, t).map_err(|e| e.to_string())?)
}
None => None,
};
let w9_hash = match &w9_file {
Some(w) => Some(vault.put_w9(id, w).map_err(|e| e.to_string())?),
Some(w) => {
Some(super::calls::put_w9(&vault, id, w).map_err(|e| e.to_string())?)
}
None => None,
};
// The W-9 is in the vault: its upload is used up.
@@ -1047,7 +1051,7 @@ impl BooksServer {
.map_err(|e| e.to_string())?;
}
let vault = self.open_vault(&store, true)?;
let hash = vault.put_tin(id, &tin).map_err(|e| e.to_string())?;
let hash = super::calls::put_tin(&vault, id, &tin).map_err(|e| e.to_string())?;
store
.set_party_tin(
id,
@@ -1238,7 +1242,7 @@ impl BooksServer {
if !p.confirmed.unwrap_or(false) {
return Ok(Json(out));
}
ledger_vault::purge_records(&vault_dir, id).map_err(|e| e.to_string())?;
super::calls::purge_records(&vault_dir, id).map_err(|e| e.to_string())?;
if let Some(f) = new_facts {
store.set_party_w9(id, Some(f)).map_err(|e| e.to_string())?;
out.journaled = true;