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:
1 parent
d4c0036599
commit
98cbabde8e
22 files changed
+1516
-169
No files matched your search
@@ -612,6 +612,19 @@ pub fn committed(lines: &[JournalLine]) -> Result<Vec<JournalLine>, StoreError>
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// A call's tag: 16 lowercase hex digits naming it in file names outside
|
||||
/// the journal (a staged vault record), derived from its token and key,
|
||||
/// so a later open can ask the journal whether that call committed
|
||||
/// ([`Store::call_committed`]).
|
||||
pub fn call_tag(token: &str, key: &str) -> String {
|
||||
let mut h = Sha256::new();
|
||||
h.update(b"wanderbooks-call\0");
|
||||
h.update(token.as_bytes());
|
||||
h.update(b"\0");
|
||||
h.update(key.as_bytes());
|
||||
hex::encode(&h.finalize()[..8])
|
||||
}
|
||||
|
||||
/// HMAC-SHA256 (RFC 2104) of `msg` under `key`, hex.
|
||||
pub(crate) fn hmac_sha256_hex(key: &[u8], msg: &[u8]) -> String {
|
||||
const BLOCK: usize = 64;
|
||||
@@ -773,6 +786,15 @@ impl Store {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Whether the call with this tag ([`call_tag`]) committed with lines
|
||||
/// on the journal: its closing line says `ok`.
|
||||
pub fn call_committed(&self, tag: &str) -> bool {
|
||||
self.keys
|
||||
.by
|
||||
.keys()
|
||||
.any(|(token, key)| call_tag(token, key) == tag)
|
||||
}
|
||||
|
||||
/// The table's sizes: calls with lines, and the session's calls that
|
||||
/// wrote none with the bytes of their answers.
|
||||
pub fn call_table(&self) -> (usize, (usize, usize)) {
|
||||
@@ -834,10 +856,14 @@ impl Store {
|
||||
return Ok(());
|
||||
}
|
||||
let line = self.journal.append(BEGUN, begun_payload(&call.id))?;
|
||||
apply_line_to_sqlite(&self.conn, &line)?;
|
||||
// The frame is open from the moment its line is on disk, whatever
|
||||
// the projection says next: a call that fails here must close it
|
||||
// (`failed`), or the next call would begin inside it (a corrupt
|
||||
// journal).
|
||||
if let Some(call) = &mut self.call {
|
||||
call.begun = Some(line.seq);
|
||||
}
|
||||
apply_line_to_sqlite(&self.conn, &line)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user