Commit Graph
214 Commits
Author SHA1 Message Date
swaitsandClaude Fable 5.2 5d5f94e8dc fix(store): a drill and a preview keep the stored files the store reads when it verifies the books
The store's own verification reads the text an extraction recorded as a stored
file, so a verification that left the stored files out would not prove books
with extracted text. Every proof now builds the books with their stored files,
as a restore does, and a test holds it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 17:49:22 -07:00
swaitsandClaude Fable 5.2 a6cd89d2a6 refactor: the server, restore and the window's seams on the plain-folder backup; git removed from the store
Restore reads a destination folder, a set's folder, or a backup file with an
optional passphrase; the server cuts the books under the store's lock and
writes the folder outside it; the format upgrade proves a local backup in the
book's folder (the same form) before it moves the format. The old backup
(git processes, their locks, the output drain) and every test of it are gone;
what each test protected is held by the new form's tests (table in the
report). Old settings and an old history in a book's folder are said in the
status and left alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 17:42:05 -07:00
swaitsandClaude Fable 5.2 9f4529b078 feat(store): backups in plain folders, written once (P15 section 9, D-91, D-92)
A backup is a folder holding one folder per set of books, made only of
files that are written once: the journal and the access log as immutable
segments, an index of stored files and the stored files under their hash,
the vault and keys by content hash, and a manifest, written last, that
makes a backup complete. It is built beside the git form for now.

Accounting reasoning: the journal is append-only and a stored file never
changes, so what the store's lock must fix is one look (its length, that
its last line is the head, the vault and keys); the rest is read after it.
A destination is written only when its newest whole manifest is a point on
the live journal (byte-identical prefix); otherwise nothing is written.
Two writers cannot corrupt it: pieces are named by what is in them, the
manifest number is taken by exclusive create, the loser looks again.

A passphrase (D-92) seals every piece with XChaCha20-Poly1305 in 1 MiB
chunks, the key derived by Argon2id at the owner passphrase's own cost
(64 MiB, 3 passes, 1 lane); names are made from the key and say nothing;
the derived key is kept in the book's local/ folder, owner-only.
"Save a backup..." is a zip of the same form (.wbbackup).

New dependencies: none new to the tree. chacha20poly1305, zeroize and zip
(deflate only) were already used by ledger-vault, the viewer and the
packages; ledger-store now names them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 17:19:12 -07:00
swaitsandClaude Fable 5.2 813042a7a6 Merge branch 't3/p15-c1-desktop-packages': packages for Windows, macOS and Linux, and the Claude desktop extension (P15 C1)
The two Connect page baselines are re-blessed on the merged code: the
page gained the extension row here and the stopped test clock on main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:57:46 -07:00
swaitsandClaude Fable 5.2 26311f8b52 test(store): where each system keeps the books, and that no install folder holds them (P15 C1)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:42:45 -07:00
swaitsandClaude Fable 5.2 479d3a5c5e feat(store): a missing git says how to get it, for this system; a Mac's git stub is not a git (P15 C1)
Backups run the system's git, which the program does not carry (it is a
separate GPL program: bundling it is the owner's decision). The error a
backup reports with no git now says so in plain words and how to get one
on Windows (Git for Windows, winget), macOS (the command line tools, or
Homebrew) and Linux (the package manager); backups stay off until then
and nothing else changes. On a Mac without the developer tools,
/usr/bin/git is a stub that opens Apple's installer and fails: it no
longer counts as found. Git for Windows' per-user folder is searched too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:19:35 -07:00
swaitsandClaude Fable 5.2 657766ae5a docs: two doc links name a private item, so rustdoc -D warnings refuses them; plain code text now
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 14:41:39 -07:00
swaitsandClaude Fable 5.2 fd779a6f1a Merge branch 't3/fix-windows-close-macos-lock-tests': git's output is read when git has ended; the lock test removes every lock named
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 14:37:03 -07:00
swaitsandClaude Fable 5.2 17624bfd40 fix(store): a git's output is taken when git has ended and the pipes hold nothing, not after a fixed wait on a pipe that has no end
run_with waited up to 10 s for each of stdout and stderr to reach end-of-file
after git exited. On Windows a pipe has no end while any process holds a copy
of its write end: std makes the child's end of each pipe inheritable when it
makes the pipe and starts every child with all inheritable handles, so a
process started at the same moment (a `taskkill` that stops another git while
a close's own last backup begins) keeps the pipe open until it ends. Each
command then cost up to 20 s, and the close's last backup passed its 60 s
bound (the open/close hammer on Windows: 106 s).

The reader now takes what git wrote as soon as git has ended and the pipe
holds nothing (PeekNamedPipe on Windows, poll(2) on Unix, the reader seen
blocked in its read for 100 ms), and never loses a byte already in the pipe;
the 10 s wait stays only as the last resort. `taskkill` goes through
lock::spawn, and on Windows spawns are exclusive, so no child takes a copy of
another's pipe ends. WANDERBOOKS_GIT_TIMINGS=<file> appends one line per git
command (ran, spawn, pipes, how each pipe ended) for runs nobody can watch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:44:36 -07:00
swaitsandClaude Fable 5.2 610e41d1d1 Merge branch 't3/wanderbooks-app-hosted-bridge': nothing on the desktop starts a detached host (P15 A5)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:32:59 -07:00
swaitsandClaude Fable 5.2 bf977b1bc7 Merge branch 't3/mcp-refusals-write-nothing': a refused call writes nothing; four tools checked before writing
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:30:50 -07:00
swaitsandClaude Fable 5.2 38612ab553 fix(mcp,store,core): four refusals are decided before the call's first line (P15 T1, D-88)
A refusal is decided before anything is written; a failed call on the
record is for a call that failed part way. Four tools wrote a line and then
refused, so under T1 each left a begun line, its lines and a failed closing
line in the journal for a plain "no":

- books.attach_receipt and books.file_document: bytes already filed are one
  file, so filing them again links the existing attachment; a link it
  already holds was refused after the earlier links were written. The store
  now asks first (Store::check_filing_links).
- books.draft_entry and books.draft_from_template: a no_party_reason that
  names a full tax id was refused by the mark, after the draft was made.
  Ledger::check_no_party_reason is asked first.
- books.dispose_asset: a receipt named twice was refused at its second
  link, after the disposal was posted. The ids are checked for repeats
  first.

Each has a test that the journal is byte for byte as it was. No journal
format or frame shape changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:30:25 -07:00
swaitsandClaude Fable 5.2 2275c34e86 fix(store,host): books list with nothing running says which books wait for a format upgrade
Plan P15 unit A5, fix round. With nothing running, `books list` reads the folder
and takes no lock (nothing is opened), so it stopped showing which companies wait
for a format upgrade, which a server showed. It now reads what each journal
declares (`ledger_store::declared_format`: no lock, nothing written, the hash
chain not verified, so it says what the books declare and no more) and adds
"; waiting for a format upgrade (`wanderbooks books upgrade ID`)"; a journal that
cannot be read says why on its line. The listing no longer fails when a company's
folder vanishes while it is made (a book put aside meanwhile): a vanished entry is
skipped, not an error (`list_books_inner` used `entry?`).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:19:58 -07:00
swaitsandClaude Fable 5.2 5a98e417a1 Merge branch 't3/remote-mcp-oauth-signin': the remote door and sign-in for web assistants (P15 B1, D-83, D-86, D-90)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 12:16:48 -07:00
swaitsandClaude Fable 5.2 e00e52f2f3 feat(mcp): the remote door and the sign-in behind it (P15 B1, D-83, D-86)
A second HTTP listener in the books server, on 127.0.0.1 only, off until the
app's admin request (RemoteStart) names the one public address. Every
connection begins with the relay's PROXY v2 header, whose address is the
caller's (never an HTTP header); the door speaks stateless plain-JSON MCP for
one company per path, and is its own OAuth 2.1 server: metadata at every
place products look, client ID metadata documents, dynamic registration and
a typed client id and secret, PKCE S256, exact redirects, single-use short
codes, rotated refresh tokens (a reused one ends its family), short access
tokens, the issuer pinned. /authorize never approves: it parks the request
and only the owner-only admin socket turns it into a code. An approval is one
principals token (so A4's list and revoke see it) plus a record naming the
product, which survives the product registering again. Read and draft by
default; posting raised per approval. Every table is bounded and expires;
secrets are kept as SHA-256 only. A stranger's unsigned request is a 401 with
the metadata pointer and is counted, never written to the books' record.

The access record gains an optional 'from' (the caller's address), kept as an
IP when it is one (the TIN masking would turn it to dots).

The tools a model reaches for first now carry the company's name and 'call
books.start first' in their own descriptions (plan 3.4), local and remote.

Dependencies: none new to the tree. reqwest (client documents, as ledger-host
already uses it), subtle, getrandom and hyper-util (already pulled in by
ledger-store and axum) are now declared by ledger-mcp; cargo deny and the
notices check pass unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 11:15:26 -07:00
swaitsandClaude Fable 5.2 d66cc98ee5 docs(verification): law 47, a write is one transaction, exactly once (P15 T1, D-88)
Ties WB-format-8 to 10, the calls.rs spec block, the command-steps map and
plan 2a to bookspec law 47 (Calls.lean): a call is a Steps run, no new Step.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 10:59:55 -07:00
swaitsandClaude Fable 5.2 38647e2143 Merge branch 't3/transactional-mcp-writes': every write through the tools is one transaction, exactly once (P15 T1, D-88, D-89)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 10:40:34 -07:00
swaitsandClaude Fable 5.2 b592aaf416 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>
2026-11-21 10:40:00 -07:00
swaitsandClaude Fable 5.2 4c23fade7a test(store): the call frames and an old-books fixture written before call transactions (P15 T1, 8.0.6 items 1 and 2)
books_written_under_older_rules_still_open gains hand-written call frames
through JournalWriter (an ok call, a failed call whose party id is handed
out again, a call that never finished, a call with an answer too long to
keep): only the lines of calls that closed ok are the books'.

old-books/p15_t1_before was written by main 7058fbd2, the version before
this unit (no frames, no request keys), through the old-books-writer
pattern, with that version's expected.json: this version opens it, every
line counts, the figures are the same, it takes no call until the owner's
upgrade and keeps every figure after it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 10:23:47 -07:00
swaitsandClaude Fable 5.2 98cbabde8e 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>
2026-11-21 10:19:26 -07:00
swaitsandClaude Fable 5.2 d4c0036599 fix(store,gui,package): every reader that derives facts reads the committed journal (P15 T1 review)
A failed call's ids are handed out again (nothing it wrote counted), so a
reader of the raw journal pins dead lines on whatever takes the id next: a
failed books.create_bill for entry 42 then a manual entry 42 showed as a
Bill. One accessor, calls::committed (lines outside a call and of calls
that closed ok, the frame left out), now feeds the viewer's books (entry
events and origin, asset trails, party events), the package feed attention
reads, and the adopt preview's settings check. The journal page and
journal_history keep every line and say in words of each line of a call
that failed, never finished or is still running that it did not count.

A call's closing line is now bounded (ANSWER_CAP 4 KiB: above it, the
answer's SHA-256 and length), a call that wrote no line leaves no line (its
key and answer live in a bounded in-memory table), and the journaled
argument digest is an HMAC under the books' own call key, so two requests
that differ only in a tax id are two requests and nothing journaled lets a
guess of one be tested.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 10:09:17 -07:00
swaitsandClaude Fable 5.2 e542319e63 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>
2026-11-21 09:43:52 -07:00
swaitsandClaude Fable 5.2 2633109d55 feat(store): a tool call is one journal transaction (P15 T1, D-88)
Accounting reasoning: a write that is retried after a lost answer must
happen once, and a call that dies between its journal lines must never be
replayed as if whole. The journal feature `call_transactions` frames a
call's lines with `call.begun` and `call.closed`; the lines between count
only when the closing line says `ok`. Every replay (open, the viewer,
verify, rebuild, the projection's catch-up) goes through one gate
(`CallGate`), so no state is built from half a call and a replay of any
prefix ending inside a call equals the replay of the prefix before it. A
call that never closed is closed `unfinished` at the next open; a call that
fails after writing lines is closed `failed`, its SQLite changes (one
transaction per call) rolled back and the live ledger rebuilt without them.
The closing line keeps the answer given, so a repeat of a request key
returns it; the key table is rebuilt from the journal alone.

The envelope is untouched. Lines outside a frame apply as ever, so every
journal written before the feature replays as it was. Books get a unique id
(`books_id`) at creation, and older books at the format upgrade, in the
`journal.format_set` that declares the feature. The frame lines never move
the audit's figure head. The upgrade's declaration now also carries the id,
so the three tests that pinned its exact payload compare it without the id.
No figure and no golden moved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 09:16:03 -07:00
swaitsandClaude Fable 5.2 e9dc03a44a test(store): a git that cannot end on SIGTERM is deaf to it, not stopped
On macOS a SIGTERM sent to a SIGSTOPped git ended it inside the grace and it
removed its own locks, so the three tests that need a git the kill must end
failed there (the grace was not waited, no lock was left). A blocked signal
stays pending on every system, and the mask is inherited through exec and
through git's own children: the test shim blocks SIGTERM for a git when a
deaf flag file exists. The program's stop (SIGTERM, grace, SIGKILL) is
unchanged. Checked here with the stop turned off: the tests still pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 08:27:50 -07:00
swaits 40d818fb5e Merge branch 't3/fix-linux-ci-failures' 2026-11-20 22:43:10 -07:00
swaits 7801455336 fix(store): a store's writer lock is free when it is dropped, even with a child forked from another thread
Cause: a book's writer lock is a flock, which lasts as long as any copy of
its open file description does. A child forked by another thread of the
server (git, for another book's backup, on a timer) holds a copy of every
descriptor from its fork until its exec, so a close of book B, answered
after its Store was dropped, could be followed by an open of B that found
the lock still held: "another program has these books open". The open's
failed attempt left B failed, and the next close found it not open. This
broke the unit's rule that a close answers only once the lock is released,
and that closing book A never refuses a job on book B (the hammer's maker
thread saw it on GitHub's slower runner; with a 40 ms fork-to-exec delay in
the backup's git it fails on every cycle).

Fix: every child the crate starts goes through lock::spawn, which holds a
process-wide gate while it runs (it returns once the child has exec'd);
dropping the Store's WriterLock closes the file, waits for the gate to
empty of spawns begun before, then takes the lock afresh and lets it go
(the kernel lets go of a closed file's last copy a moment after the exec),
for 500 ms at most. A test with a child held between fork and exec fails
without it.
2026-11-20 21:36:57 -07:00
swaitsandClaude Sonnet 5.5 c072e68fda docs(store): the doc link to take_lock_notes is a method link
rustdoc -D warnings refused [`take_lock_notes`]: a method is linked as Self::take_lock_notes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 21:23:44 -07:00
swaitsandClaude Sonnet 5.5 49ae7c0d13 fix(store): a stopped heal leaves no copy and no rebuild, and the bound names the heal
verify_and_heal copied the database aside before looking at the stop, so a
verification or an open that was stopped right after finding a drift left a
.mismatch copy behind. The look now comes first (heal_drift), before anything
is done: a stopped heal leaves the database and the folder exactly as they
were. The rebuild and its verification stay unstoppable once begun, since
stopped half way the live ledger would be part replayed.

INVARIANT 10's close bound said that heal was one pass over the journal and
named no term for it. It is about six (three in the rebuild, three in the
verification) plus the copy and one hash of each stored file, so it is now the
fourth named exception to the bound, with that cost, and 'an open stops
anywhere' says where it cannot.

Test: a stop before the heal leaves no copy and no rebuild; the same drift
heals when not stopped. It fails with the look moved back after the copy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 20:20:24 -07:00
swaitsandClaude Sonnet 5.5 6d7044c284 fix(store): an adoption that does not finish leaves no lock file in the source; a queued job leaves its turn when stopped
An adoption copies books in from a folder the owner names and promises the
original is left as it was. Taking the source's writer lock creates the lock
file when the source never had one, and a close that stopped the adoption (or
a refusal, or a panic) left that file behind. The lock is now a guard
(SourceLock): a lock file the adoption made is removed again on every way out
but success, exactly that file (on Unix, only while the path still names the
very file the guard holds), and one the source already had is never removed.
A success still leaves the one it made and reports it (source_lock_created),
as before; a restore's and a put-aside's locks are the root's own and are kept.

Books are made, adopted and restored one at a time across processes
(run/books.lock). A job queued for that turn blocked in flock with no look at
its stop, so a close that stopped it could not make it leave; the wait now
tries the lock every few milliseconds and gives up with Stopped when asked.

Tests: stopped at each of the seven phases, refused after the lock, panicking,
a lock swapped in by someone else, a source that had its lock, and a success;
a queued create stops when asked and otherwise waits its turn. Each was
mutation-checked (no removal; a blocking wait).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 19:57:16 -07:00
swaitsandClaude Sonnet 5.5 aa64df9a25 fix(mcp,store): a close stops every call and job that can run long, and says so; an unrecorded refusal never ran
A close waited, unbounded, for a running books.back_up_now (git only Backups::shut
could cancel), for a restore, create or adopt (they hold the one lifecycle lock,
and at the server's close admin_jobs.wait() waited for them before anything was
released), and, through the store lock, for a verification or a package reading
every stored file. The bound's T_calls term was not finite.

Now a close calls hurry at its start, and the stoppable work looks at it:
books.back_up_now and timer-asked backups (git stopped, a stopped run records
'stopped' and no result of its own), books.verify (per journal line and file; a
heal of a drifted database is begun only if no stop came before it: stopped half
way it would leave the live ledger part replayed), books.export_cpa_package (per
stored file). Such a call answers that it was stopped because the books are
closing, and its access record says refused: stopped_by_close. On the admin
socket restore, adopt, create and open take a JobStop: asked at each phase and
file copied, they remove what they wrote and leave the root byte for byte as it
was; the renames that put the books in place are the point of no return, after
which they finish (two renames and two syncs). A close of any book, and the
server's own, raises the flag before it waits for the lifecycle lock.

A close whose last backup had to be killed in the owner's folder now says which
file was left, and the target's backup is marked failed by shut when the run's
future was dropped at its bound. INVARIANT 10 is rewritten so each term of the
bound is enforced by code, and lists the calls that can run long (and the one
known exception, books.import_bank_csv); INVARIANTS 8 and 9 say exactly which
refusals are recorded and why an unrecorded one never ran; the format upgrade's
wording says a stop is honoured up to its final look.

Tests: the close is held to the bound while a backup call, a verification, a
package and each admin job is running and would never end; the stopped job leaves
the root byte for byte as it was; a lock left in a backup folder is reported and
never removed. Sleeps that stood for 'the other side got there' now wait on the
condition (Expect: 100-continue for a half-sent body, a writable named pipe for a
fetch that is reading).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 17:15:36 -07:00
swaitsandClaude Sonnet 5.5 6f174f3f87 fix(store): git is told to end before it is killed, and nothing in the owner's backup folder is ever deleted
A stopped git was killed outright and the program then removed lock files:
in the archive every lock found, in a folder target any lock new since the
push whose mtime held still for 1.5 s. Git does not touch a lock it is
holding, so an unchanged mtime does not prove a lock stale: another git (the
owner's, another machine's on a shared disk, a sync client's) stalled in a
hook or an fsync loses its lock to that rule, and two ref updates race. The
removal also re-resolved the repository and refs paths, so a folder swapped
for a link redirected it.

Now: SIGTERM goes to the git's process group first (git removes its own
locks on SIGTERM, a push's receiving end its quarantine), TERM_GRACE (3 s)
is waited for the group to end, and only then SIGKILL. A folder target is
never written to or deleted from except by git: a lock our kill left there
is left, noted with its whole path, and the push fails with LockLeft, which
tells the owner which file to remove and that it is only safe once nothing
else uses the folder. The archive keeps only two removals: the locks our own
stopped git made (not there when the command began), and at open and at the
start of a backup a lock older than ten minutes. Removals go through a
directory handle opened once, never follow links, and take only regular
files named as git names its locks (git_locks.rs).

Tests use real git: SIGTERM mid-commit, mid-add and mid-push leaves no lock
and no cleanup; a frozen group (SIGSTOP, so SIGTERM stays pending) is killed
after the grace and the archive's locks go while the target's stay and are
named; a git that traps SIGTERM is killed after the grace; fsck --strict on
both repositories right after a stop during a 48 MiB pack's receipt; the
archive's age rule; a swapped refs folder or archive path touches nothing
outside.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 16:31:58 -07:00
swaitsandClaude Sonnet 5.5 7e5b698c1c test(mcp): say what the running-call test proves; name the phase watcher's type
The running-call test passes even with a cut that marks every request inside
(mutation check): the call runs in the session's task, past the handler's own
check for a cut, so what it proves is that the close waits for the call and
does not kill it. The line of the cut (a body read to its end is never cut) is
proved at its seat by local::tests::a_body_read_to_its_end_is_never_cut_and_one_not_yet_is,
which fails when a later poll can cut a whole body. Also a type alias for
clippy's type_complexity.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 15:51:12 -07:00
swaitsandClaude Sonnet 5.5 10790d8794 fix(store): a killed git leaves no lock for anyone to remove, and a verification can be told to stop
A git killed (cancelled by a close, or silent for GIT_TIMEOUT) leaves the
lock files it held, and nothing removed them for 300 s (the archive) or ever
(a folder target): an immediate reopen's backup failed on index.lock and
waited 15 minutes, and a receive-pack killed holding a ref lock could stop
every later push. This process knows when it killed its own git, so once
the command is reaped AND everything it started is gone (the process group
is waited for: a killed process can still take a lock in its last
instructions) the locks it could have left are dealt with at once, each
noted for the caller's record.
 - the book's own archive: every lock is removed (this process holds the
   book's store lock, so no other wanderbooks process runs git on it); the
   same at open (clear_archive_locks), where a lock is a dead git's.
 - a target on this computer: D-30 makes the folder the owner's (an external
   disk, a synced folder), and nothing enforces that no other computer, data
   root with a book of the same id, or hand pushes to it (the only guard is
   the fast-forward rule). So a lock there is removed only if it was NOT
   there when the push began (one that was is left and noted) and it has
   stood unchanged for LOCK_SETTLE after the kill (a live writer holds a ref
   lock for the milliseconds of a ref update). Said in INVARIANT 5, with the
   one case this cannot see (a second writer stalled holding the lock past
   LOCK_SETTLE). A far repository is never touched.
 - a git killed inside `init` (found by the test with real git: the first
   backup of a book made HEAD.lock in a repository that isn't one yet, which
   stopped every later init) is covered the same way.
 - no git of ours starts another to go on after it (gc.auto=0,
   maintenance.auto=false), so 'everything it started is gone' is true.

Also: a drill or proof can be told to stop (the cancel flag), looked at
between phases, once per journal line replayed or applied, once per stored
file hashed or listed and once per 64 KiB chunk compared (cancel.rs, a
thread-scoped flag so nothing else can be stopped by it), and leaves nothing
(its scratch clone is removed). Tests use REAL git, made slow by a
reference-transaction hook that waits: killed mid-commit, mid-add (a huge
sparse file), mid-push; the next backup succeeds and git fsck passes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 13:10:26 -07:00
swaitsandClaude Sonnet 5.5 ca6f5aa982 fix(store,mcp): a type claims only what it does alone, and a restore never says 'no such books'
ledger-store: a file coming in (Uploads::receive) now writes each chunk under
the lock a close takes and stops at the first chunk after a close, removing
its part; an export fetch (Exports::get) reads under that lock, so a close
waits for it. The INVARIANTS say exactly this: after close() returns no byte
is written or kept and none is read for a caller; the one thing a request
begun before the close does after it is remove the part file only it made;
a request still waiting for its next bytes is not woken by the type (the
books server's gate waits for it and cuts one that never finishes).

ledger-mcp: a restore over an open book took the book out of the list
before it shut the door, so every call while the restore waited for what was
inside got 404 'no such books' for a book that exists. The door is shut
first and the book listed closed: such a call gets the closed refusal (503,
the words), as in a close. The drain test now requires 503 throughout.
(A refusal at a shut door is not written to the access log, as in a close:
INVARIANT 11.)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 12:22:19 -07:00
swaitsandClaude Sonnet 5.5 181859d801 fix(store): logs, uploads, exports and git can be closed, so a handle from before a close can never write after it
A book closed while the server runs stays a book of the root: another
process may open it, or this one may open it again, and a new access log
is then opened against the file's own head. Any holder of the old handle
that appends (an access record written late), sweeps (a timer) or
renames (an upload part, a claim dropped) reaches the new book's files and
breaks its chain. Each of these now has a closed state, set under the
very lock every change to its files goes in under, so a change whose
work began before the close is whole and one after it is refused,
unwritten. git also takes a cancel flag: a command running is stopped
with all it started, and none starts, so a close can end a backup that
is still going instead of leaving it to run against books reported closed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 10:08:42 -07:00
swaitsandClaude 1c28760d87 refactor(store,config): their Decimal arithmetic goes through the kernel (K-U12)
Ten places, now zero, and both crates join kernel_only_crates so the lint
part of `just check` holds them there.

ledger-store (8): a disposal's preview adds the asset's posted runs and
takes book value and gain or loss by subtraction; an attested receipt is
compared with the entry's debits; an older settlement's remainder is the
document's total less what was recorded. Each called rust_decimal's own
checked_add or checked_sub, which rounds where the exact answer needs
more than 96 bits and says nothing. They call the kernel's now
(kernel::total_of, Amount::checked_add and checked_sub): exact, or the
refusal each of these places already had (too_large, or no figure to
compare). Two unary minuses go through money::neg. Posted lines are
bounded (BS-entry-3, BS-entry-4), so no figure in real books changes.

ledger-config (2): a member's "50%" is divided by a hundred through
Amount::checked_div (the raw `/` computed the same quotient), and the
members' shares are added by kernel::total_of. Shares that cannot be
added exactly are refused with a sentence saying to write them with
fewer places, where the raw sum would have rounded them and then
compared the rounded figure with one. ledger-core's own check of the
same setting already did this.

Checked: the detector reads 0 for both; both crates' suites pass (682
tests); clippy with -D warnings.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-10 00:27:14 -07:00
swaitsandClaude 1726c8b6dd build(deny): a supply-chain gate: advisories, licences, sources (cargo-deny)
Nothing checked what the program is built from. `just deny` now does, in
the lint part of `just check` and weekly in scheduled.yml (an advisory
is published when it is, not when we push), from one file, deny.toml:

- advisories: no crate in the lock file with a known vulnerability
  (RustSec), none yanked; an unmaintained crate is refused when it is
  one of our own direct dependencies. Two advisories are lived with,
  each with its reason and date: the quick-xml 0.38 that typst's
  citation reader brings, which no XML from outside reaches.
- licences: the permissive ones, plus MPL-2.0 for one unchanged crate
  (option-ext) and CDLA-Permissive-2.0 for Mozilla's root certificates.
  No font licence is allowed, so a crate that carries fonts is refused
  and every font we ship is a file here beside its licence. A crate
  offering only a copyleft licence is refused.
- sources: crates.io and the bookspec repository, nothing else.
- bans: no dependency by wildcard version.

The crates are marked `publish = false` (one line in the workspace,
inherited by all eleven): they are parts of one program, not libraries
for crates.io, and with that cargo-deny accepts their path dependencies
on each other.

cargo-deny 0.20.2 is a build tool pinned in mise.toml, not a dependency
of the program.

Shown: `just deny` prints advisories ok, bans ok, licenses ok, sources
ok on this tree.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 20:03:51 -07:00
swaitsandClaude 9ad6f89816 fix(deps): 23 known vulnerabilities closed; the XLSX reader keeps & in a cell
The first run of cargo-deny on the lock file (2026-11-09) listed 23
RustSec advisories, one unsound crate and two yanked ones. This closes
all but two by upgrading; the two are a second copy of quick-xml that
typst brings and that reads nothing from outside (the gate's file,
next commit, says so with its reason and date).

A wrong answer found on the way. quick-xml 0.42 reports a character or
entity reference (`&amp;`, `&#38;`) as an event of its own, where 0.38
handed it over inside the text. The reader's first build on 0.42 took
only the text events, so a cell holding `AT&amp;T` read as `ATT`: a
payee's name, changed without a word, on its way into an import. The
reader now turns each reference into its character (the five XML names,
decimal and hexadecimal numbers) in shared strings and in inline cell
text, and refuses a file whose reference names no character rather than
dropping it. Two new tests: a reference in a cell is its character; a
reference to no character is refused.

What moved, and the advisory each closes:
- quick-xml 0.38 -> 0.42 in ledger-reader, the copy that parses files
  from outside (RUSTSEC-2026-0194, -0195: a slow or memory-hungry parse
  of hostile XML).
- rusqlite 0.32 -> 0.41, with `fallible_uint` so a u64 past i64::MAX
  is an error and never a wrapped number (libsqlite3-sys,
  RUSTSEC-2026-0459). One test's use of `column_names` follows the new
  signature.
- rust_xlsxwriter 0.90 -> 0.102, which drops the old zip 4
  (RUSTSEC-2026-0367, -0368, -0369, -0429).
- In the lock file only: rustls (-0346 to -0349), rustls-webpki
  (-0382), webpki-root-certs (-0383), ctutils (-0385), tokio (-0386),
  zstd, zstd-safe and zstd-sys (-0391, -0398, -0403, -0410),
  pulldown-cmark (-0433), rmcp 3.5 -> 3.9 (-0457, -0461, -0462), and the
  yanked async-executor and clipboard-win.
- fuzz/Cargo.lock in step, so the fuzz targets build what ships.

No new dependency of ours: rsqlite-vfs and sqlite-wasm-rs enter the
lock file as rusqlite's own, for a target (wasm) we do not build.

Shown: `cargo check --workspace --all-targets` clean; `cargo test` of
ledger-reader (4 passed), ledger-import (145 passed, 2 ignored) and
ledger-store (579 passed, 2 ignored, exit 0). The store run kept its
scratch files in memory (TMPDIR on tmpfs): on the loaded disk a synced
write took 30 ms and the refusal law alone ran past half an hour.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 20:03:28 -07:00
swaitsandClaude Sonnet 5.5 46dccd5d76 fix(core): payroll_remit_plan refuses past exact arithmetic instead of panicking
The remittance plan totalled the payables with a raw `total +=`, which
panics on Decimal overflow, on a pub fn returning a bare plan. Its
callers refused first through sum_exact_of, but that was an unenforced
precondition (BS-entry-4: every derived figure is checked arithmetic).
It now returns Result<_, LedgerError>, totalling through
kernel::total_of and refusing TooLargeToCompute; Ledger and the store
propagate it and keep their pre-checks. A test shows payables past the
range, up and down, are refused, not a panic.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:50:54 -07:00
swaitsandDeepSeek V4.1 Flash b72ba2514a docs: SOURCE lines cite what states the rule now, not a retired record
Unit S-E4: 37 SOURCE clauses across ledger-core, ledger-gui, ledger-mcp
and ledger-store still cited records bookspec retired on 2026-11-08
(D-71). A retired id names what a rule was, not what governs now, so
each clause cites its successor: BS-ledger-13 is WB-ledger-16 (the
audit), BS-ledger-12 is WB-ledger-15 (evidence read from the bytes),
and BS-format-1, whose retirement names no successor, becomes the
WB-format rule that states each clause's fact: WB-format-1 (the format
gate), WB-format-2 (a journal feature declared before its first line),
WB-format-3 (the owner's format upgrade) or WB-format-4 (each projection
schema in a file of its own). No clause's fact was left without a live
rule, so no claim was added.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:00:48 -07:00
swaitsandClaude Opus 5.5 045e70bb0d merge: tests where coverage was thinnest, the audit's strict close bound, WB-ledger-17 (V-D2; reviewed, fixes applied)
Ninety-six tests, each encoding the rule it covers, reach what the core
and store suites left untouched: the evidence requirement (34% to 100% of
its lines), the store's reconcilable accounts (0% to 100%), the command
steps' refusals, conventions, settings and the audit's branches. ledger-
core's line coverage rises from 89.79% to 95.49%, and the floor with it.

Found: the digest listed cash accounts found by name in hash order, so
the same books could list them differently; they come in ascending
account id now. The audit now holds a close's member split to under one
unit (BS-partner-1 statement 5) once the count has been trued up, a
close records its rule, and only drift beyond one unit before; the
reconciliations rule is written down as WB-ledger-17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 07:33:54 -07:00
swaitsandClaude Sonnet 5.5 ae32a83407 docs(spec): WB-ledger-17, the reconciliations rule, and the order the tests pin
Which accounts the monthly close reconciles, and when each is due, was a
module's own spec block with no id. It is now WB-ledger-17 (product-only, a
CONVENTION sourced to docs/parties-and-attachments.md "Reconciliations"),
checked against the code: the cash accounts (configured ones in the order
given, else by name in ascending account id), the card accounts (ascending
id), then the other liabilities with a statement in the order the statements
are given (period end, then file; not ascending id), each once; and an account
is due through last month's end when it has a posted line on or before it and
no reconciliation not voided is dated on or after it. The module and the test
file cite it.

The order within the cash group is the account id's, as `card_accounts` sorts,
not the chart code's (`ChartOfAccounts::all` is unordered). The test is renamed
to say so and its codes are out of creation order, so a sort by code fails it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 06:15:39 -07:00
swaits 5fd382450b Merge branch 'main' into t3/coverage-gap-tests-v-d2 2026-11-09 05:07:33 -07:00
swaits 5e4950697e Merge main into the K-U5 branch: X-H1b, K-U3, S-E2, S-E3, X-H1c 2026-11-09 04:35:21 -07:00
swaitsandClaude Sonnet 5.5 74fc553272 docs: the sub-references the review found land on the part that states the claim
A review of S-E3 against the pinned bc92cf3 records found citations one
part off, and old vocabulary the test could not see. Each is checked
against the record's own text:

- BS-statement-5: the partition of the P&L is statement 3 (not 2, and
  not BS-statement-3, the cash-flow statement); the ASC 340-40-25-7/-8
  trail (a cost traceable to one job is that job's, several only by a
  stated allocation) is statement 4, not 6.
- BS-asset-1: "one figure everywhere" is statement 31 (28 is the two
  figures, schedule and books); "disposed only for a disposal dated by
  then" is statement 30 (and 7 where the schedule stops).
- BS-arap-6: one receivable line per invoice, each tagged, is statements
  1-2 and invariant 4 (one application per document).
- BS-asset-1 statements 8 and 9 for the true-up and the credit back.
- BS-arap-2: "nothing unattached, no command adds a hand line" is
  invariants 2 and 3, beside 1, 6 and 9.
- BS-format-2: a class name written differently and reported adds 32.
- BS-arap-5: the cash-basis refusal is statement 6, everywhere.
- BS-partner-3: statement 3's cases are lettered (a)-(e), not numbered.
- BS-asset-1 "rules 23-24 / 25-26" in the claims, "BS-arap-3 SCENARIOS:"
  and "WB-ledger-15 INVARIANT 3" are in the new vocabulary.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 04:01:09 -07:00
swaitsandClaude Sonnet 5.5 09308d5528 feat(core): new schedules round to the currency's minor unit (D-72)
The owner's decision D-72: a new monthly-even schedule rounds each month
to its currency's minor unit (yen whole, dinar to the thousandth), where
the cent rule gave two places to every currency; a schedule written
earlier replays under the cent rule, so nothing journaled moves
(BS-prepaid-4, BS-entry-8).

The rule is the schedule's own flag, journaled on its schedule.registered
line ("rounding": "minor_unit", absent for the cent rule), not the
sequence position of the journal feature: a flag survives a snapshot, a
copy and a replay that starts mid-journal. The new feature
schedule_minor_unit gates it (KNOWN_FEATURES, ensure_feature in
Store::register_schedule): books that haven't declared it keep the cent
rule and write nothing new, and an older reader stops at the declaration
as newer books (BS-format-1); an unknown rounding is newer, never
corrupt. A dollar schedule plans the same under both rules.

Tests: a dinar schedule written before the feature replays to the same
plan and the same posted line after the owner's upgrade, while one written
after plans 0.333, 0.333, 0.334. WB-prepaid-2 becomes yes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 03:33:15 -07:00
swaitsandClaude Sonnet 5.5 e41cc3a161 docs: sub-references name bookspec's statements, invariants and scenarios
Unit S-E rewrote each `B-n` citation to its bookspec id but kept the
sub-reference after it ("item 7", "rule 11", "INVARIANT 2"). Those
numbers counted parts of the retired rules.md text, so `BS-statement-5
item 7` pointed at finished and abandoned projects, not at the snapshot
it meant. Bookspec numbers a record's parts from 1 as `statement`,
`invariant` and `scenario`; every sub-reference now says so.

The map was built by content, not by position: each old item,
INVARIANT or SCENARIO was read in `git show ca8d676d5^:docs/spec/rules.md`
(the last full rule text), found in the pinned records
(bookspec bc92cf3) and in docs/spec/claims/, and each reference was
read in its context before it was mapped. Where the old numbering still
survives as the "Rule n" labels inside bookspec's statements (the cash
flow, party totals) the new number is that statement's position; where
a record carries the whole rule differently (the asset depreciation, the
IIF file, the arap invariants) the reference follows the content. Where
bookspec keeps no counterpart, the product rule that states it is cited
instead: WB-statement-5 (a project's facts and names), -7 (the snapshot),
WB-arap-4 (the document_standing feature), -8 (the issued PDF), -15 (a
payment event names its line), WB-ledger-15 (BS-ledger-12 is retired).
A reference that had pointed at the wrong part is corrected, for example
the discount-reason references that said BS-arap-6 INVARIANT 2 (a
bound) now say invariant 6 (the discount cap and date).

Only the reference tokens and their sentence change; no paragraph is
reflowed. A reference wrapped across a comment prefix keeps its wrap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 03:30:06 -07:00
swaitsandClaude Sonnet 5.5 11314db1f7 fix(store): cash accounts found by name come in chart order
FINDING from V-D2's reconcilable tests: cash_accounts returned the asset
accounts whose names say cash in the order ChartOfAccounts::all yields
them (a HashMap: "order unspecified"), so books.digest's
unreconciled_accounts could list the same books' accounts in a different
order from one run to the next. card_accounts, the rule beside it,
already sorts by account id. The name-matched path now sorts the same
way; configured codes keep the order they were configured in. No figure,
membership or due date changes, only the order of the list.

The earlier ignored test (cash_accounts_come_in_chart_order) now runs.
This is a small fix kept in its own commit so it can be dropped without
touching the tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 03:08:03 -07:00
swaitsandClaude Sonnet 5.5 32514662d1 test(store): reconcilable lines, by rule
The module that decides which accounts the monthly close reconciles, and
when one is due, ran 0% from the store's own suite (the server and the
viewer are its readers). These tests build real books in a Store, record
real statements, complete and void real reconciliations, and ask the
module, with expected values worked by hand from its two invariants:

- INVARIANT 1: the reconcilable accounts are the cash accounts, then the
  card accounts, then every other liability with a statement, each once;
  an asset with a statement but no cash name never joins.
- INVARIANT 2: an account is due, through last month's end, iff it has a
  posted line on or before it and no standing reconciliation reaches it;
  a voided one reaches nothing; a draft counts for nothing; activity
  only this month is not due.
- cash accounts by name (case-insensitive, no placeholders, no
  expenses/liabilities) or by configured code; card accounts by the
  recorded business-card method, else by name (not "gift").

SOURCE: docs/parties-and-attachments.md "Reconciliations" and the
module's own CONVENTION; no BS- or WB- id covers the module yet.

FINDING (ignored test cash_accounts_come_in_chart_order): cash_accounts
yields name-matched accounts in HashMap order, so books.digest's
unreconciled_accounts can list them in a different order between runs.
card_accounts sorts by account id; cash_accounts does not.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 02:33:23 -07:00
swaitsandDeepSeek V4.1 Flash 797c418184 fix: the last rule citations in program output name bookspec ids
The engine's last program-output citations were the retired wanderbooks
numbers. Each moves to the bookspec id that states the rule:

- B-43 -> BS-entry-5, in the eight evidence-source strings of
  `Ledger::origin_exemption` and the two golden lines that record them.
- B-23 -> BS-ledger-8, in the CPA package README's aging tie-out.
- B-38 -> BS-arap-2, in `books.bills_due`'s description.
- B-37 -> BS-statement-5, in the project page's contribution note. The
  old "item 7" was the snapshot presentation in the retired numbering;
  in BS-statement-5 the figures are item 2 (a project's figures are
  exactly its tagged lines, net revenue less expenses) and item 4 (no
  cost is allocated), so the note cites those.

None of the strings is stored. The evidence source is computed on every
call by `evidence::requirement` from the ledger (`origin_exemption`);
the journal records only a draft state's note and a discard's reason
(`entry.draft_state_set`, `entry.draft_discarded`), never the gate's
source. The CPA README is built on request into the package's bytes and
exported for a token; it is never read back. Tool descriptions are
compiled into the router. The GUI note is a `const`. So an old book
replays unchanged and reports the new text; no compatibility layer is
needed.

Golden verification: `draft_states_and_evidence_gate.json` changes in
exactly two strings, the reversal's and the closing entry's evidence
sources. Both are recomputed from the same ledger by the test and
compared whole; after the change the test passes against the file, and
`git diff` shows no other line moved. The figures, decisions, journal
lines and trial balances are untouched, as the hand worksheet
`plan/golden-worksheets/draft-states-and-evidence-gate.md` derives.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 01:36:40 -07:00