build(check): every crate is held at zero Decimal arithmetic outside the kernel (K-U12)
The viewer was the last crate with arithmetic of its own on amounts. With it at zero, `just kernel-only` runs the detector over all eleven crates, and it now fails when a folder under crates/ is not in its list, so a new crate cannot do money arithmetic of its own from the day it is added. Why it matters for the books: the proofs (Kani, Lean) are about the kernel. A sum or a product computed anywhere else is one they say nothing about, and rust_decimal's own operators either panic or round without saying so. Bar item 1 of AGENTS.md is now a property the compiler checks for the whole workspace, not a rule to remember. Checked on main after the merge: the detector reads 0 places and 0 waivers for ledger-gui, the crate's whole test suite passes in one run (300 passed, 0 failed, 1 ignored), clippy with warnings denied and fmt are clean. docs/proofs/k-u12.md is the account: the 183 places by crate, the rule each kind followed, and the decision for every site that was not a plain sum or sign. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e444a41071
commit
ef86f7820a
7 files changed
+129
-16
No files matched your search
@@ -13,3 +13,4 @@ Columns: date | type (scout, run/verify, implement, refactor, debug, review) | p
|
||||
2026-11-09 | review | muse / muse-wonder-full-1.0 / reasoningEffort high | large (the K-U10a diff) | 1h05m | | six findings, all reproduced: one refusal the docs did not state (a step of 27 or 28 places), four gaps in what the properties covered, stale sentences; no wrong figure in 400,000 sampled pairs | me, ~1 h: the properties now also prove nothing representable is refused; the refusal stated and pinned | worth its cost: the completeness gap is the kind the author's own tests cannot see; it ran no cargo, Kani or Lean itself
|
||||
2026-11-09 | debug/hard implement | claudeAgent / claude-sonnet-5-5 / effort high | medium (7 files) | 4h (machine shared) | | accepted after rework | me, ~1.5 h: its ranking used the exact product, which K-U10a makes a refusal for weights of 27 places (now the rounding product, with a test); it ran no Kani, and Kani then failed the unit: a cover in `split_by_weights_within_one_step` could no longer be reached, since the exact ranking makes the bound strict on i64 (harness tightened) | K-U10b, ties by the exact remainder; its measurement of what moves (`ties.rs`) was what the owner's decision needed; worked from a stale base again
|
||||
2026-11-10 | refactor | claudeAgent / claude-sonnet-5-5 / effort high | medium (18 files, +94/-69; 50 sites in three crates) | ~1h (machine shared with a second worker and my own runs) | | accepted as sent | none | K-U12, ledger-mcp + ledger-package + ledger-import through the kernel; the brief gave a rule table and a decision for every site that was not a plain sign or sum, and the diff matched it line for line; one sound deviation (a usize count as `count()`, since clippy refuses the fold); it reported what it had and had not re-run
|
||||
2026-11-10 | refactor | claudeAgent / claude-sonnet-5-5 / effort high | large (16 files, +244/-151; 123 sites in one crate) | ~1h20m (machine shared with a second worker) | | accepted as sent | none | K-U12, ledger-gui through the kernel; the brief gave the rule table and a decision for each of the 30 sites that were not a plain sign or sum, and the diff matched it line by line. Its saved site list missed one `.sum()`, which its own detector re-run caught. A 30-minute cap cut its test run, so it ran the suite in two pieces and did not re-run all of it after its last change: my one whole run on main is the result (300 passed, 0 failed, 1 ignored). The rule table's "fold for a count" fails clippy's `unnecessary_fold` after a `.map`; say `fold(0_usize, |n, c| n + c.len())` next time
|
||||
@@ -121,14 +121,15 @@ over the rationals to state. What carries it instead:
|
||||
`just kernel-only` runs the detector over the crates named in the
|
||||
justfile's `kernel_only_crates`, and the lint part of `just check` runs
|
||||
it, so a new raw operator or rust_decimal method on a `Decimal` outside
|
||||
the kernel fails the build. The list is ledger-core and the four outer
|
||||
crates that were already at zero (ledger-cli, ledger-host, ledger-reader,
|
||||
ledger-vault); the other six join it as K-U12 brings each to zero, and a
|
||||
crate never leaves it. A waiver is an
|
||||
the kernel fails the build. With this unit the list was ledger-core and
|
||||
the four outer crates already at zero (ledger-cli, ledger-host,
|
||||
ledger-reader, ledger-vault); K-U12 (`k-u12.md`) brought the other six
|
||||
there, so it is every crate of the workspace, and a crate never leaves
|
||||
it. A waiver is an
|
||||
`#[allow(clippy::arithmetic_side_effects)]` or
|
||||
`#[allow(clippy::disallowed_methods)]` with a `reason`, and the detector
|
||||
counts them on its last line so one cannot slip in unseen. There are none
|
||||
in ledger-core.
|
||||
in any crate.
|
||||
|
||||
## What this does not show
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# K-U12: no Decimal arithmetic outside the kernel (every other crate)
|
||||
|
||||
K-U11 (`k-u11.md`) brought ledger-core to zero and put the detector in
|
||||
`just check`. This unit does the same for the crates around the core, so
|
||||
bar item 1 of `AGENTS.md` holds for the whole workspace and the compiler
|
||||
checks it.
|
||||
|
||||
## What was measured
|
||||
|
||||
`scripts/raw-decimal-arith.sh <package>`, after K-U9:
|
||||
|
||||
| Crate | Places |
|
||||
|---|---|
|
||||
| ledger-gui | 123 |
|
||||
| ledger-mcp | 19 |
|
||||
| ledger-import | 18 |
|
||||
| ledger-package | 13 |
|
||||
| ledger-store | 8 |
|
||||
| ledger-config | 2 |
|
||||
| ledger-cli, ledger-host, ledger-reader, ledger-vault | 0 |
|
||||
|
||||
183 places. Each was a raw operator on a `Decimal` (it panics when the
|
||||
result does not fit), one of rust_decimal's own `checked_*` methods (it
|
||||
rounds silently past 96 bits, K-U10) or an `Iterator::sum`.
|
||||
|
||||
## What was done
|
||||
|
||||
Every site calls the kernel, or `ledger_core::money`'s helpers over it
|
||||
(`neg`, `signed_amount`, `on_side`, `add_in_range`, `sub_in_range`, public
|
||||
since this unit so the outer crates have no copy of their own):
|
||||
|
||||
| Was | Now |
|
||||
|---|---|
|
||||
| unary minus | `neg` |
|
||||
| a line's sign by its side, written out as a `match` | `signed_amount`, `on_side` |
|
||||
| `+`, `-`, `+=`, `-=` on figures drawn from the books | `add_in_range`, `sub_in_range`: exact, since posted lines are bounded (BS-entry-3, BS-entry-4) |
|
||||
| `.sum()` of amounts | `kernel::total`, `total_of` |
|
||||
| rust_decimal's `checked_add`, `checked_sub` | `Amount::checked_add`, `checked_sub` by their full path, the same `None` handled the same way |
|
||||
| `/`, `checked_div` | `Amount::checked_div` |
|
||||
| `rescale` | `kernel::rescale_exact`, which cannot round |
|
||||
|
||||
No figure moves and no test, golden or snapshot was edited. What changes
|
||||
is the edge: a sum exact arithmetic cannot hold is a blank cell, a note or
|
||||
a refusal where a raw operator panicked or rust_decimal rounded.
|
||||
|
||||
The places that were not a plain sum or sign, each decided one by one
|
||||
before the rewrite and read again in the diff:
|
||||
|
||||
| Place | Decision |
|
||||
|---|---|
|
||||
| `ledger-config`, `parse_share` | a percent over 100 through `Amount::checked_div`; the shares are summed exactly, and a set too long to add exactly is refused with a sentence saying so |
|
||||
| `ledger-import`, `templates::equal_shares` | 100 / n through the kernel, rounded to two places by `round_places` (a half to even, as before), the last share the exact remainder; no owners gives no shares where `/` panicked |
|
||||
| `ledger-package`, `text.rs` | at least two places, padding only, by `rescale_exact` |
|
||||
| `ledger-store`, the disposal preview | its sums and differences through `Amount`, joining the `None` it already returned |
|
||||
| `ledger-gui`, a party's part of an entry (`books.rs`) | the fraction is a quotient, so its product with each line is a rounded figure by construction: `Amount::checked_mul_rounded`, then cut to the cent as before, the remainder to the first line exactly |
|
||||
| `ledger-gui`, a member's share as a percent (three pages) | `checked_mul_rounded` by 100: rust_decimal's product, which is the exact one here (a share of 28 places times 100 is the same digits at 26) |
|
||||
| `ledger-gui`, "running hot" (`profit.rs`) | the average is a third, a quotient; 1.25 times it is `checked_mul_rounded`, and a limit that cannot be computed flags nothing |
|
||||
| `ledger-gui`, `share_of_what_for` | `kernel::share_of`, the one copy of whole × weight / total (K-U3) |
|
||||
| `ledger-gui`, averages, runway, progress bars, `compact` | `Amount::checked_div`; each quotient is rounded for display or turned into a bar's length on the next line, and none is summed |
|
||||
| `ledger-gui`, the cash-flow table's rows by key | `total_of`; a sum that cannot be computed exactly blanks the cell where `.sum()` panicked |
|
||||
| `ledger-gui`, the demo books | amounts to a step of 25 or 50 by `Amount::checked_div`, `round_places` to a whole number (a half to even, which `Decimal::round` was) and an exact product |
|
||||
|
||||
Sums of `usize` and `f32` (counts, column widths) are folds, since the
|
||||
detector refuses `Iterator::sum` of any type: reading the source does not
|
||||
show what a `.sum()` adds.
|
||||
|
||||
## The gate
|
||||
|
||||
`just kernel-only`, in the lint part of `just check`, now runs the
|
||||
detector over every crate of the workspace, and fails when a folder under
|
||||
`crates/` is not in the justfile's `kernel_only_crates`: a new crate is
|
||||
held at zero from the day it is added. No crate has a waiver.
|
||||
|
||||
## How it was checked
|
||||
|
||||
- The detector on each crate: 0 places, 0 waived.
|
||||
- Each crate's whole test suite on main after its merge, clippy with
|
||||
warnings denied, and fmt.
|
||||
- Every diff read line by line against the decision made for its site
|
||||
before the rewrite. ledger-store and ledger-config (10 places) were
|
||||
done by hand; the other 173 by two workers from a rule table and a
|
||||
per-site list (`docs/delegation-log.md`).
|
||||
|
||||
## What this does not show
|
||||
|
||||
The same as K-U11's list. The detector shows arithmetic goes through the
|
||||
kernel, not that each site calls the right function; the tests and the
|
||||
reading above carry that. `add_in_range` and `sub_in_range` panic on a
|
||||
sum exact arithmetic cannot hold, as the raw operators did: they are for
|
||||
figures drawn from posted lines, which the line cap keeps in range, and
|
||||
this unit proves nothing new about that bound. The viewer and the exports
|
||||
have no Kani harness or Lean theorem of their own, and need none for
|
||||
this: they hold no arithmetic now.
|
||||
+1
-1
@@ -28,7 +28,7 @@ promise.
|
||||
| Fuzzing | crash, hang, broken books (4); for `fuzz_store_replay` (validly chained journals with fuzz-chosen events): books that open must verify, and the viewer must accept exactly what the writer does | `fuzz/fuzz_targets/`, corpora in `fuzz/corpus/` | `just fuzz <target> <secs>` | 10 min each | weekly |
|
||||
| Miri | undefined behavior in our use of dependencies (4) | the core's unit, bridge, invariant tests (the exhaustive calendar walk aside) | `just miri` | ~4 min | on demand |
|
||||
| Golden | `tests/golden/fixture_company.json` (5) | `invariants.rs` | `just check` | <1s | every change |
|
||||
| Kernel only | no `Decimal` arithmetic outside `src/kernel/`: no raw operator, none of rust_decimal's own arithmetic or rounding methods, no `Iterator::sum` (AGENTS.md, bar item 1; the proofs are about the kernel only) | `scripts/raw-decimal-arith.sh`, which asks clippy twice and compares; the crates held at zero are the justfile's `kernel_only_crates` (every crate that has reached zero; the rest join as K-U12 brings each there, and none leaves) | `just kernel-only` (in `just check`, the lint part) | ~1 min warm, a few minutes cold (two clippy runs of the crate) | every change. A waiver is an `#[allow]` with a `reason`; the last line counts them, and ledger-core has none |
|
||||
| Kernel only | no `Decimal` arithmetic outside `src/kernel/`: no raw operator, none of rust_decimal's own arithmetic or rounding methods, no `Iterator::sum` (AGENTS.md, bar item 1; the proofs are about the kernel only) | `scripts/raw-decimal-arith.sh`, which asks clippy twice and compares; every crate of the workspace is held at zero since K-U12 (the justfile's `kernel_only_crates`; the recipe fails when a folder under `crates/` is not in it) | `just kernel-only` (in `just check`, the lint part) | ~1 min warm, a few minutes cold (two clippy runs of the crate) | every change. A waiver is an `#[allow]` with a `reason`; the last line counts them, and no crate has one |
|
||||
| Dependencies | no crate in the lock file with a known vulnerability (RustSec) or yanked; none under a licence that does not fit MIT OR Apache-2.0; none from a source `deny.toml` does not name; none of our own unmaintained (4) | `deny.toml`, each exception with its reason and date | `just deny` (in `just check`, the lint part) | seconds, needs the network | every change, and weekly (`scheduled.yml`), since an advisory is published when it is, not when we push. First run, 2026-11-09: 23 advisories; closed by upgrades (quick-xml, rusqlite, rust_xlsxwriter, rmcp, rustls, tokio, zstd, pulldown-cmark) but two, lived with in `deny.toml` |
|
||||
| Notices | every crate the program links and every font it embeds, with the licence text each asks to travel with (1, the licence itself) | `THIRD-PARTY-NOTICES.txt`, written by cargo-about from `ledger-cli`'s manifest, by `scripts/notices-packaged.py` (the crates' own licence files, where cargo-about could only give a licence's standard text with a placeholder for the copyright line) and from the licence files beside the fonts | `just notices`; `just notices-check` (in `just check`, the lint part) | ~2 min (12 CPU-minutes: it reads every crate's files for licence text) | every change that touches a dependency or a font. `just notices` writes the file; `just notices-check` fails when a dependency changed and the file was not regenerated, and the fix is `just notices` and committing the result |
|
||||
| Benchmarks | a baseline (6) | `ledger-core/benches/books.rs`, `ledger-store/benches/store.rs` | `just bench` | ~2 min | none (no budget, by decision) |
|
||||
|
||||
@@ -1075,7 +1075,10 @@ kernel. What the proofs and their reviews found, beyond the tidying:
|
||||
of 28-digit shares (`checked_add_rounded`), which exact addition
|
||||
refused for every split by thirds. `kernel::rescale_exact` is the one
|
||||
place a figure's written places change, and it refuses to round.
|
||||
`docs/proofs/k-u11.md` has the account.
|
||||
`docs/proofs/k-u11.md` has the account. K-U12 did the same for the
|
||||
crates around the core (183 places, 123 of them in the viewer), so the
|
||||
gate covers every crate of the workspace and fails on a crate it does
|
||||
not list; `docs/proofs/k-u12.md`.
|
||||
- **The sweep changed no posted figure.** Every golden and existing test
|
||||
passed unchanged. `round_places` reproduces `round_dp_with_strategy` to
|
||||
the character except a negative-zero input (which no call site can
|
||||
|
||||
@@ -59,9 +59,11 @@ check-shard shard:
|
||||
;;
|
||||
esac
|
||||
|
||||
# The crates with no Decimal arithmetic outside the kernel. A crate joins
|
||||
# this list when its count reaches zero (K-U12) and never leaves it.
|
||||
kernel_only_crates := "ledger-core ledger-cli ledger-host ledger-reader ledger-vault ledger-store ledger-config ledger-import ledger-package ledger-mcp"
|
||||
# The crates with no Decimal arithmetic outside the kernel: every crate of
|
||||
# the workspace, since K-U12. None leaves the list, and `kernel-only`
|
||||
# fails when a folder under crates/ is not in it, so a new crate joins it
|
||||
# on the day it is added.
|
||||
kernel_only_crates := "ledger-core ledger-cli ledger-host ledger-reader ledger-vault ledger-store ledger-config ledger-import ledger-package ledger-mcp ledger-gui"
|
||||
|
||||
# Money arithmetic lives in the kernel and nowhere else (AGENTS.md, bar
|
||||
# item 1). The compiler is asked (scripts/raw-decimal-arith.sh): a raw
|
||||
@@ -72,6 +74,13 @@ kernel_only_crates := "ledger-core ledger-cli ledger-host ledger-reader ledger-v
|
||||
kernel-only:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
for dir in crates/*/; do
|
||||
crate=$(basename "$dir")
|
||||
case " {{kernel_only_crates}} " in
|
||||
*" $crate "*) ;;
|
||||
*) echo "kernel-only: $crate is not in kernel_only_crates (justfile): add it, and bring it to zero" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
for crate in {{kernel_only_crates}}; do
|
||||
scripts/raw-decimal-arith.sh "$crate"
|
||||
done
|
||||
|
||||
@@ -20,7 +20,7 @@ books. The gaps are in what the gates do not see.
|
||||
|
||||
## P1: a promise of the manual that is not kept, or a correctness risk
|
||||
|
||||
1. **The kernel rule is not met and nothing enforced it.** Bar item 1
|
||||
1. **The kernel rule was not met and nothing enforced it.** Done. Bar item 1
|
||||
says money arithmetic lives in `kernel/` and nowhere else.
|
||||
`scripts/raw-decimal-arith.sh` (95ae7717d) asks the compiler, and at
|
||||
8ad55e82a it lists **210 places in ledger-core** that add, subtract,
|
||||
@@ -43,10 +43,16 @@ books. The gaps are in what the gates do not see.
|
||||
names it (`checked_add_rounded`, `checked_sub_rounded`). Four places
|
||||
changed a figure's written places with `Decimal::rescale`, which can
|
||||
round; `kernel::rescale_exact` cannot. `docs/proofs/k-u11.md`.
|
||||
- K-U12, the outer crates. Worker or script, decided on the counts.
|
||||
- K-U12, the outer crates: done (merged 1c28760d8, a167766dd,
|
||||
e444a4107). All 183 places go through the kernel: ledger-store and
|
||||
ledger-config by hand, the other four crates by two workers from a
|
||||
rule table and a decision for every site that was not a plain sum
|
||||
or sign, each diff read against it. No figure moves; a sum exact
|
||||
arithmetic cannot hold is a blank or a refusal where it panicked or
|
||||
was rounded. `docs/proofs/k-u12.md`.
|
||||
- The script in `just check` at zero, so the count cannot rise again:
|
||||
done for five crates; each of the other six joins
|
||||
`kernel_only_crates` as K-U12 brings it to zero.
|
||||
done for every crate of the workspace, and `just kernel-only` fails
|
||||
on a crate that is not in its list.
|
||||
2. **Decimal sums and products rounded silently.** Done (K-U10a, merged
|
||||
e632855f1). `Decimal::checked_add` and `checked_mul` return a rounded
|
||||
answer when the exact one needs more than 28 digits; the kernel's
|
||||
@@ -190,8 +196,8 @@ signing (D-64); the re-audit (P10); Q-6 before P9b.
|
||||
## Order of work
|
||||
|
||||
1. Land what is in flight: V-D3, K-U9, K-U10a, K-U10b (all four done).
|
||||
2. K-U11a on top of them (done, and the detector is in `just check` for
|
||||
the crates at zero), then K-U12.
|
||||
2. K-U11a on top of them, then K-U12 (both done; the detector is in
|
||||
`just check` for every crate).
|
||||
3. `overflow-checks`, the CI split, `just prove`'s cap, `cargo-deny`
|
||||
(all four done).
|
||||
4. One gate at the end (`just check`, `just prove`), one push, four gates
|
||||
|
||||
Reference in new issue
Block a user