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>
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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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 (`&`, `&`) 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&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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Pointers that said the rule text lives in docs/spec/rules.md now point at bookspec's rules and/or wanderbooks' claims in docs/spec/claims/: the dated-rule catalog doc, the kernel module header, a payout doc, the spec-derived and model and GnuCash tests (including its panic message), the MCP interface crate table and the spec README. Same treatment for the other stale mentions the grep found in attention, the P3 seams test and the store schema. AGENTS.md gains a Docs index row for docs/spec/claims/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retired-reference test now scans the whole text of every tracked file (git ls-files, skipping plan/, docs/spec/rules.md and docs/spec/claims/) for any word-boundary retired number from 1 to 45, wrapped references included, with an exact-count allow-list for the deliberately kept user-visible and golden strings; a count rising or falling fails. The SOURCE test now reads each whole clause with its continuations (crates/*/src, crates/*/tests and fuzz/), checks every bookspec and product-rule id in it, requires every path-like token to exist and every crate code reference to name a real item, counts clauses passing only through the free-text branch against a constant (56; 353 clauses checked), and keeps a floor on the total. The repo_root doc comment became the module header.
Lines the tightened check made fail, fixed in the lines not the test: relative sources/ and claims/ paths in form1099, instruments, kernel entries, money, kernel round and the 1099 tests now give full docs/spec paths; wrapped docs/spec/sources/ and docs/parties-and-attachments.md paths in ledger, store, reconciliation, tins and the GUI books module are joined; settings.rs names the real parser path instead of a runtime filename; the bounds tests name the real kernel and calendar files, and spec_bounds no longer cites rules.md for the line bound.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5.
Co-Authored-By: Muse Wonder 1.0
The K-U1 review: foreign 0.99999999999999999999999999 (26 places) x rate
0.005 into USD booked 0.01, though the exact product
0.00499999999999999999999999995 is under half a cent. Decimal::checked_mul
rounds a product finer than 28 places to 28 before fx_booked rounds it to
the cent: two roundings, one cent off. A ledger in one money books the
exact product rounded once (BS-ledger-1, BS-ledger-14).
Owner decision D-75 (2026-11-08): a new line's foreign amount and its rate
take at most MAX_LINE_SCALE (10) decimal places each, as a base amount does
(B-28), so their product has at most 20 places, under Decimal's 28.
Ledger::add_line_fx refuses past it with ValueOutOfRange ("foreign amount
..." / "FX rate ..."; the variant for an amount that is not a journal
line's), trailing zeros not counted, before computing, and never on replay
(is_replaying; replay_add_line_fx books a journal's older line verbatim).
Tests: 11-place foreign amount and rate refused; ten and ten accepted with
hand-checked books; the review's input refused, not mis-booked; trailing
zeros are not places; replay keeps a 26-place foreign line in core, and a
store journal holding one opens with its figures.
fx_booked's spec block states the precondition (scales within 10 each, and
the mantissas' product within Decimal's 96 bits) and that the result is
exact under it, and documents Decimal::checked_mul's behaviours outside it
(rounding past scale 28 and past 96 bits; 1e-28 x 1e-28 underflowing to
zero); invariant 1 now says None when T's checked_mul cannot hold the
product. The bridge covers every D-75 scale (0..=10 each, products to 20
places) against an independent exact reference, shows 26 places is where the
reference and Decimal part (and the engine refuses), and pins an open edge
this bridge found: ten places each still allow a 20-place product past
~7.9e8 that outgrows 96 bits (1050000010.0000000001 x 9.9999999999 books
10500000099.90, exact 10500000099.89). B-28 and B-3 claims record the
enforcement and checks.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claims/ledger.md conflicted with the reduced B-9 section: the D-73 pick,
Enforced and Checked lines sit above its product rules; the check's
place corrected (after the schedule double-post check, not ahead of it)
and the citation completed (BS-ledger-16, the Lean model since L-G1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
periods.rs conflicted with K-U2: the frozen replay rules delegate to
K-U4's checked twins, whose rounding now goes through K-U2's
round_places (so every rounding stays in the kernel); no figure changes.
The K-U4 note gains the review's list of bounded raw sums left, and the
caveat that the twin test checks delegation (the review's independent
20,000-case comparison found the twins identical).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A correction comes after what it corrects (Pacioli ch. 31; B-9). Until now
only document reversals and depreciation/schedule runs were held to it; a
plain posted entry could be reversed with an earlier date, leaving the
books carrying the opposite of an entry that doesn't exist yet at the
reversal's date. The owner's decision D-73 (2026-11-08) makes it one rule
for every kind of entry; bookspec BS-ledger-5 states it.
- Ledger::check_reversal refuses date < original.date() with one error,
ReversalBeforeOriginal (it replaces DocumentReversalBeforeOriginal,
which was the document-only wording). Same-day reversals are allowed.
- Not on replay (B-28): the check sits behind is_replaying(), so a journal
an earlier version wrote, holding a reversal dated before its original,
reopens with the same figures.
- The store's own date check for depreciation runs and schedule months
(InvalidSchedule / AssetEntryIrreversible wording) was the same rule
for a narrower case; it is removed so there is one variant for all.
Store::check_reverse_entry, books.reverse_entry (preview and post), and
the document voids all reach the refusal through check_reversal; the
only construction path for a reversal is reverse_entry_steps, which
calls it first.
Tests: store reversal_dates.rs (plain entry refused before it, nothing
journaled, same day and later taken; a journal with an earlier-dated
reversal written the old way opens with the same figures); ledger-cli
spec_mcp (preview, unconfirmed and confirmed post all refuse alike).
Existing tests changed: store assets.rs (three expectations move to the
new variant); core spec_asset_basis.rs (it backdated a reversal on
purpose to check the trial balance carries -100.00 between the dates; it
now replays one, as an old journal would); model.rs (the model oracle's
`reverse` requires the date, as the Lean/bookspec rule does); bookspec
common.rs (the pinned depreciation example words this refusal
"entry_irreversible"); spec_documents.rs (variant rename).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ledger-core/tests/exact_totals.rs: the engine's sum/add/sub helpers, arap's
document_total, audit::check_articulation (current_earnings + closed was a
raw + that panicked for a public caller's MAX figures) and the frozen
close splits' try_ twins refuse at Decimal::MAX with TooLargeToCompute,
and give the infallible rules' exact result for ordinary input.
ledger-store/tests/exact_totals.rs: an invoice or a bill of enormous
lines is refused and journals nothing. (A posted entry's lines are capped
when it posts, restored or new, so report sums over posted lines cannot
reach the edge; documents are the figures that can.)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Store::create_invoice / create_bill summed their lines with a raw .sum()
before arap::document_total (which is checked) ran; a document restored
from its journal is bounded only by what the version that wrote it
checked (rules.md B-28), so two lines near Decimal::MAX panicked the sum.
They now call document_total (itself now kernel::total_of). The
remittance and disposal-run sums go through money::sum_exact_of and
refuse with TooLargeToCompute. No figure changes for any ordinary input.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The laws are proved once in bookspec (D-69), so the documents that said
"put the new theorem in `verify/lean`" or cited
`verify/lean/Wanderbooks/<File>.lean` now say otherwise:
- AGENTS.md's formal-methods bar: a new law is written in bookspec's
`lean/Bookspec/`; wanderbooks requires it and moves its pin (the lakefile,
the manifest, and the crates' Cargo.toml together; the pin test fails if
they drift). `Audit.lean` lists every theorem.
- docs/verification.md: the model and every cited Lean file are
`bookspec/lean/Bookspec/<File>.lean`; "Running it" says the dependency is
fetched and that all 151 theorems are audited.
- docs/testing.md and docs/spec/rules.md: the same paths, and the apportion
row records where its law moved.
- README's repo map and the two test comments that named the Lean peer.
No accounting behavior changes; only where the proofs and their names live.
Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
One fixture serves both parity rows (draft states and discard; the one
evidence gate). A Store fixture, because the gate's receipt-on-file half
lives in the store. New fixture, built like books_for_drafts and extended.
Hand-computed in plan/golden-worksheets/draft-states-and-evidence-gate.md,
before serializing anything:
- Requirement (B-43 inv. 2, threshold strictly > 25.00): drafts of 40.00,
60.00 and 100.00 are Required; 12.50 is Exempt (policy); the reversal
(debits 100.00) is Exempt by origin (D-47, D-12); the closing entry
(52.50) is Exempt by origin. Receipt counts are pinned beside them: the
gate refuses the 40.00 and 60.00 drafts (no receipt) with the journal
head unchanged, then lets the rest post; the reversal has no receipt.
- Trial balance 2026-01-31 before and after the discard of the 60.00
draft: Cash 447.50 Dr, Equity 500.00 Cr, Software 52.50 Dr, totals
500.00; identical after the discard, next entry id 7 both times.
- The close is refused while the draft is open (B-12), accepted after the
discard: Dr Retained Earnings 52.50 / Cr Software 52.50 (a loss), id 7;
trial balance then 447.50 Dr, 500.00 Cr, 52.50 Dr.
Code and hand values agreed on the first run. Strength: four scratch edits
of the golden (a balance, a decision, a discard reason, the next id) each
fail the test.
Adds serde::Serialize to evidence::Requirement (tagged, snake_case) so the
gate's result can be pinned.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The host has staged a downloaded, signature-checked update since step 4,
but the only way to apply it was `wanderbooks update` at a terminal, and
nothing in the viewer or on an agent's first call said one waited. The
owner's accept is the name plan 8.0.3 allocated for it: the lease socket
gains `Intent::ApplyUpdate`, and the host installs the staged copy from a
thread and lets its existing watch for a replaced program (host.rs
INVARIANT 7) restart onto it once no call runs, so the books stay open and
every holder's session carries on. With no host running there is no call
to cut off, so the viewer applies it itself.
The viewer reads `<root>/updates/staged/meta.json` every few seconds and
shows a standing notice with "Update now"; Books gains "Check for updates"
(which looks at the feed at once, whatever the daily look last did) and
"Update to X". `books.start` gains the allocated `update_waiting` field
and a next step telling the agent to tell the human; no tool can accept.
`apply_staged` waits up to five seconds for the update lock: running the
new tests showed the host's own look can hold it for a moment after it
writes `meta.json`, and the owner's accept should wait that out rather
than answer "nothing waits".
Tests: `books_start_says_an_update_waits` and
`the_owner_accepts_a_staged_update_in_the_app` in
`crates/ledger-cli/tests/update.rs` (a bridge writes all through the
restart, each account in the chart exactly once);
`the_menu_checks_for_updates_and_a_waiting_update_shows_a_notice_that_accepts`
and `books_outside_a_data_root_have_no_update_notice` in
`crates/ledger-gui/tests/update_notice.rs`.
main's canonical default made Root::setup take std::fs::canonicalize(home),
which on Windows is \\?\C:\... with the long name. root.rs now uses
root::canonical (canonicalize, then the prefix off) at every site, so no
root, record or message keeps the prefix; Unix is unchanged (the identity),
and macOS still agrees on /tmp and /private/tmp. windows_root.rs compares
against default_root(canonical(home)), so TEMP's 8.3 short name is not in
the expectation, and asserts the root has no prefix.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
Run 13 failed at the same helper: the store holds LockFileEx locks on
wanderbooks.lock and books.lock, which are mandatory on Windows, so
reading them is refused. tree() skips any *.lock and the live SQLite
files at any depth. The other read_dir walkers in the store, cli and gui
tests either read only metadata or copy closed books; the cli harness's
book_files already tolerates a refused read.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
spec_store's tree() read every file under the root while a Store was
open; on Windows SQLite holds byte-range locks on its database, so the
read failed (os error 33) in two tests. The lock seam locks only
wanderbooks.lock, never data, so it is not the cause. tree() now leaves
out the live database and its -wal/-shm/-journal; the tests compare the
journal, blobs and kept-aside files.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
P11c run 11 on Windows: `bash` there is WSL's, with no distribution, and
the cap never bit. The simulation is Unix's; the books' full-disk
behavior is the same code everywhere.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
std's append(true) opens without FILE_WRITE_DATA, so SetEndOfFile on that
handle is refused (PermissionDenied) on Windows: the torn-line cut on open
(chain::tests::an_unfinished_last_line_is_cut_away_on_open) and the
roll-back of a failed append (chain and journal) could not truncate. Not a
rename/share-delete problem: std already opens with all three sharing
flags. chain::truncate cuts through a short-lived write handle on Windows
and the handle itself elsewhere; the journal's roll-back uses it too.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
std::fs::canonicalize on Windows returns \\?\C:\..., which git refuses
("not a git repository"): every argument handed to git now has the
extended-length prefix taken off (root::without_extended_prefix, with a
unit test that runs everywhere; \\?\UNC\ becomes \\). The access-record
test's fixture is a FIFO in the log's place, which Windows has no
counterpart for; the refusal path is the same code on every system, so
the test and its helper are Unix-only. main (8f0e5f08) merged in.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp