Commit Graph
187 Commits
Author SHA1 Message Date
swaitsandClaude Fable 5.2 e6d722372e Merge branch 't3/plain-folder-backups': a backup is a plain folder; git leaves the program (D-91, D-92)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 20:23:15 -07:00
swaitsandClaude Fable 5.2 573dcb0531 docs: claims WB-backup-12 to 21, backups for a person, the end of plan section 9 and the module invariants for the second pass
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 20:10:14 -07:00
swaitsandClaude Fable 5.2 344b3b4abe feat: the window and the server say each new state in words; a proof cut short is made again; the proof does not mistake the books' own recovery for a changed head
- books ahead of the folder (as after a restore from an older backup) offer a
  new backup set beside the old one, at the person's request: books.back_up_now
  new_set, back-up --new-set, a button in the Backups window
- a key file lost from a sealed destination stops backups and asks for the
  passphrase; plain is written only after an explicit removal, which the record
  keeps (a damaged record falls back to what the folder itself holds)
- a restore that is not of the newest backup says so first, in the warning
  colour, with both dates and how many backups it passes over
- a folder a sync service keeps (or may) is said in plain words at set-up and
  in the window: one computer only, kept offline, a second computer its own
- a drill that finds only an older whole backup fails in words
- a manifest whose proof was cut short is marked unproven and proven by the
  next backup, even one with nothing new; a saved backup file is proven whole
  before it is given its name
- the proof compares the journal its pieces make with the head the manifest
  records before the books open, and lets opening add only after it
- the restore tests are split from backups.rs to keep each under a minute; the
  clone-of-an-old-git-backup test builds the working tree without git

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 20:07:38 -07:00
swaitsandClaude Fable 5.2 9ac47a3f10 test(store): damaged pieces are repaired, a drill never passes on an older backup, books ahead and diverged, a disk with no links, headers, sync stand-ins, a destination of 3000 backups
Each test fails without the change it covers: the reviewer's sequence (a
byte flipped in backup 2's segment, more backups, a drill, a restore), a
damaged stored file found by the rotating share, a drill that must fail
when only an older manifest is whole, ahead told from diverged with a new
set beside the old, the no-link path (and two writers racing on it), sealed
pieces in folders, header settings capped and authenticated, one key
derivation per setting, files not downloaded yet, vault scratch files, and
a destination of 3000 backups made cheaply (12 MB of manifests, 0.8 KB for
the newest, 32 ms to find and read it).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 19:21:34 -07:00
swaitsandClaude Fable 5.2 6a8dc6c88b fix(store): a backup is proven after it is written and repaired when a piece is damaged; a drill passes only on the newest backup
A backup that restores old or wrong books while reporting good is the worst
defect the product can have. A piece already in the destination was taken as
the piece (its name is its hash), the manifest built on the newest backup
whose pieces were the right length, no proof ran after a backup, and the
drill fell back to older manifests and recorded ok with the older head.

- the manifest just written is read back and proven before the backup is
  recorded good: every journal and access segment re-hashed, the chain
  replayed to its head, vault and keys present, the index, and the stored
  files this backup added plus a rotating sixteenth of the others (every
  stored file is re-read within 16 manifest numbers; the drill re-hashes all)
- a piece found damaged is written again under a generation suffix beside
  the damaged file (never touched), a new manifest names it, and the reader
  accepts any generation of a piece whose contents hash right
- the drill passes only on the newest manifest, and only when it reaches the
  head of the last backup recorded good; an older whole backup is a failure
  that says so with its date
- no consolidation: a manifest names the one before it and only what is new
  (a chain of 64, each link proven by the hash its successor holds)
- restore and drill read newest first and stop at the first that proves
- live books that are the beginning of the destination's longer history are
  ahead; any other mismatch is diverged or other books
- a new set can begin beside the old (.2), never touching it; set folders
  carry a fixed prefix so no book id is a reserved name on Windows
- no hard link is never a reason to replace: only errors that mean the disk
  makes no links fall back, to a move that refuses to replace
- sealed pieces are sharded by two digits; header settings are capped at 4x
  and bound into the sealed check; find derives one key per distinct setting
- vault scratch files are never backed up as records
- files a sync service has not downloaded read as not downloaded yet

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 19:10:34 -07:00
swaitsandClaude Fable 5.2 fd78612dd4 chore: clippy, developer docs without git, the free-text clause count
The count of free-text source clauses falls from 56 to 54: the git form's spec
blocks are gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 18:34:47 -07:00
swaitsandClaude Fable 5.2 f6bc047e5a test(store): what the removed tests of the old form protected, held by the new form
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 18:00:38 -07:00
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 e7d5e4b8cd Merge branch 't3/refuse-tax-ids-in-free-text': free text refuses a tax id's shapes; references take nine digits; bank files mask (WB-partner-15)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:56:02 -07:00
swaitsandClaude Fable 5.2 049cf2a6b5 fix(store): text composed from stored text is masked, never refused; the audit reads each field as its class
An asset an earlier version took may hold a number that reads as a tax id in
its description. Depreciation, the final depreciation and the disposal
compose their entry descriptions from it and went through the checked
constructor, so such an asset could no longer be depreciated or disposed
of. The composed text now holds the number masked to its last four. A
template's default description and an issued invoice's file name, also
composed from stored text, are masked the same way. A write-off's file name
and description are checked before its entry is journaled, as the rest of
its evidence is. The read-back of the projection reads an old tag or serial
number as history (replay), so verify never refuses books that hold one. The
audit's tax_id_in_journal gives each journal key a class: a bare nine digits
in a tag, serial, reference, file name, code or label is a number, in
free words a finding.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:13:06 -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 657daf43da test(cli,store): through the server a refusal writes nothing, a bank file is masked, a chart file refused; the store's own texts meet the check
The store's attestation notes and model names, attachment and document
texts and the unlink, withdraw and void reasons are checked before
anything is journaled, like the engine's. Two end-to-end tests changed
their words (not their data): spec_projects expects "tax id" where it
expected "TIN", documents expects "tax id" where it expected
"taxpayer", for the refusal the new check now gives first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:38:14 -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 98b1adb754 feat(import,store): bank files mask, chart files refuse, the audit finds an old line
A bank file's description cell is not typed by a person and often carries
a nine-digit reference, so books.import_bank_csv no longer meets a refusal
for one: a number that reads as a tax id is kept masked to its last four
digits (•••-••-1234) and the answer says how many values and on which
lines (masked_count, masked, masked_note). A chart file is typed by a
person: a cell that looks like a tax id refuses the file, naming its row
and column, never the number. The store's own attachment, unlink, withdraw
and void texts meet the same check. books.audit gains tax_id_in_journal: a
journal line an earlier version took whose text field looks like a tax id
is named by line and field, never the number; the books open and replay
as they are and the journal is never rewritten (BS-entry-4).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:05:19 -07:00
swaitsandClaude Fable 5.2 548901ce7d feat(core): the engine refuses free text that looks like a tax id
Entry and reversal descriptions, write-off and void reasons, document
memos, references, duplicate reasons and line descriptions, asset
descriptions, serials and tags, period names, account codes, schedule and
recurring descriptions and payroll employee names now meet the one
free-text detector in the Ledger command itself (FreeTextHoldsTin), so a
caller other than the MCP layer cannot journal a tax id (BS-partner-2).
Replay never refuses (BS-entry-4). Draft notes, discard reasons, no-party
reasons and send references and notes move from the strict nine-digit
reading to the shapes (parties::check_note), as the owner chose on
2026-11-21; party fields, names and recipients keep the strict reading.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 14:51:47 -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 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 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