Repository navigation
test(compat): classify the lot-pooling divergence and gate CI on the booking fuzzer (#2118) - #2120
Conversation
beancount's `Inventory` is keyed by `(currency, cost)`, so acquisitions
sharing `(cost, date, label)` pool into one position while rustledger keeps
a slot per acquisition. The two then consume in different orders. We decided
to keep rustledger's behavior -- it respects acquisition order and
beancount's cannot -- so the fuzzer has to stop reporting it as a failure or
the run is permanently red, and a permanently red run is one nobody reads.
`pooling_shape` matches only a NON-CONTIGUOUS repeat of one lot identity
within a single date. `[a, b, a]` pools `a`'s later units ahead of `b` and
diverges; `[a, a, b]` pools into the order it already had, a repeat across
different dates cannot pool at all, and a label makes the repeat a different
identity. It is deliberately narrow: every case it matches is a case this
harness stops guarding.
Divergences are still compared and still printed in full -- only the verdict
changes -- and the three counts print unconditionally, including a zero. A
count that appears only when non-zero reads as "nothing was waived" when the
line is simply absent. The exit code tracks unexplained divergences alone.
An acceptance divergence is never waived whatever shape the lots take.
Pooling redistributes units between lots; it cannot make one engine reject a
ledger the other books.
Evidence it still says no, which is the only thing that makes a waiver safe:
- Five `pooling_shape` cases in `--self-test`, four of them near-misses it
must reject. Mutating the function to `return True` fails four of them.
- Against a PRE-FIX rledger the sweep is exit=1 with 11 unexplained -- all
8 LIFO/label and 3 of the LIFO/date divergences, the whole of #2115 --
and waives only the 5 pooling ones. The classifier does not swallow the
bug it would be most tempting to swallow.
- Against a fixed rledger: 195/200 agreed, 5 expected, 0 unexplained.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
There was a problem hiding this comment.
Pull request overview
Updates the differential booking fuzzer harness to treat the known, intentionally-accepted beancount-vs-rustledger lot-pooling divergence (#2118) as an expected divergence, keeping the fuzz run signal-focused on new regressions while still printing full divergence reports.
Changes:
- Adds a narrowly-scoped
pooling_shape()classifier to identify the specific non-contiguous same-date lot-repeat shape that triggers beancount pooling reordering. - Extends
gen_ledger()/check_one()to produce an explicit verdict (agree/expected/real) and tags expected cases in output. - Updates the CLI summary and exit code to count and fail only on unexplained divergences; adds
--self-testcases for the classifier’s near-misses.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Self-review of #2120. The pooling shape is computed from the GENERATOR, not from the divergence, so a ledger could take that shape and diverge for an unrelated reason and still be waived. One guard covered part of it -- an acceptance divergence is never pooling -- but a wrong-units bug in a pooling-shaped ledger would have been waived silently. Pooling moves units BETWEEN lot identities of one holding; it cannot create or destroy them. `same_totals` requires the per-(account, currency) units to match before a divergence can be waived. Cost-less positions are excluded, and finding out why is the reason this took two passes: consuming a different lot changes the COST BASIS, so the cash and income legs legitimately differ -- that difference is precisely what #2118 is about. Guarding every account rejected all five known cases. Restricting to lot-bearing holdings keeps the guard on the one quantity pooling must leave alone. Also corrects `Booked`'s annotation, which said a 5-tuple while the keys have six elements, and names the fields. Evidence, unchanged in shape from the parent commit: - `--self-test` gains four `same_totals` cases, including both sides of the cost-less boundary. Mutating it to `return True` fails two. - Fixed rledger: 195/200 agreed, 5 expected, 0 unexplained, exit 0. - Pre-fix rledger: 184/200, 5 expected, 11 unexplained, exit 1 -- the whole of #2115 still caught, not waived. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
|
Self-review notes. This PR is what makes CI integration possible, and that follow-up is worth taking.
It could not have been wired in before now: with five permanent divergences it would have been red on every run. Separating "expected" from "unexplained" and moving the exit code onto the latter is exactly the precondition. I have not done it here to keep this PR to one change. Filing it as a follow-up unless a reviewer would rather it landed together. Two things verified rather than assumed while reviewing:
Known limitation, stated deliberately. The shape is computed from the generator, not from the divergence, so a false NEGATIVE is possible: a pooling divergence the matcher misses is reported as a real failure. That is the safe direction. The dangerous direction — waiving a genuine bug — is what the acceptance guard, the units-total guard, and the pre-fix-binary check cover. |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
`compat-booking-fuzz.py` was referenced by no workflow, while its siblings `compat-budget-fuzz.py`, `compat-bql-test.py` and `compat-values.py` all run in `compat.yml`. A booking fuzzer that only runs when someone remembers to run it is not a regression gate. It could not have been wired in before the previous two commits: with five permanent #2118 divergences it would have been red on every run. Now the exit code tracks UNEXPLAINED divergences alone, so a red X means something new, which is the only kind of alarm anyone keeps reading. Follows the budget fuzz exactly -- `--self-test` first so a harness that cannot detect a bug fails loudly rather than passing vacuously, then the sweep, `continue-on-error` with the verdict in a step output, and a separate gate that turns it into an error with a reproduce command. It runs in the same place for the same reason: the orphan branch checked out later has no `scripts/` and no `target/`. `--start-seed` is new. Seeds were always `range(runs)`, so every run re-covered identical ground; CI fixes the start for PR and push so a red X does not move when an unrelated commit lands, and uses the run id nightly so the campaign reaches seeds the fixed window never does. Same policy as the budget fuzzer and the synthetic corpus. 250 seeds on PR and 2000 nightly: a case is about 0.1s, so 250 costs ~25s. actionlint reports the same three findings here as on main -- lines 124, 737 and 1163, none of them in these steps. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
|
Wired it in after all — 239d036. The PR is now classify + gate rather than classify alone, which reads better as one change: the classification exists so that CI can run this, and separating them would have left the enabling commit with no visible effect.
250 seeds on PR, 2000 nightly. A case is ~0.1s, so the PR cost is ~25s. actionlint reports the same three findings on this branch as on |
|
"Run compatibility tests" is red here, and it is the new gate working correctly — not a defect in it. This branch is cut from Reproduced locally against a pre-fix binary over the same seed window, and the numbers match CI exactly: Against a binary with #2119 applied, the same window is So the gate is doing precisely what it was written to do: waive the six known pooling cases, and fail on fourteen unexplained ones that are a genuine bug on this branch. Consequence: this PR has to merge after #2119. I branched it off |
Found by merging all six open PRs together locally and running the gate the way CI runs it on a PR (250 seeds from 0). The result was RED: seed 211 is #2118 surfacing as an acceptance difference, and this classifier refused to waive it. A gate that cannot be green on main is the exact thing this classifier exists to prevent, and no single PR's CI would have shown it -- only the merged tree does. The refusal rested on a claim already known to be false: that pooling "can never" make one engine reject a ledger the other accepts. Pooling changes which lots SURVIVE a reduction, so a later reduction naming an explicit cost finds its lot drained on one engine and present on the other. Seeds 117 and 394 show both directions; 211 lands in the PR window. So they are waived -- but they are the more serious face of #2118, a ledger that fails to LOAD rather than one that reports different figures, so they get their own line rather than being folded into the total: 7 expected divergence(s) (#2118 lot pooling) of which 1 are ACCEPTANCE differences 0 unexplained divergence(s) Waived, never silent: they still print in full like any other divergence. Both properties verified against real binaries: - with #2119 applied: exit 0, 0 unexplained -- the gate is green post-merge - without it: exit 1, 12 unexplained -- the gate still catches #2115, so the wider waiver did not swallow the bug it was written to find Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
|
Found a defect that no individual PR's CI could show: merged together, this gate would have been RED on I merged all six open PRs locally and ran the gate the way CI runs it on a PR — 250 seeds from 0. Result: one unexplained divergence, seed 211. It is #2118 surfacing as an acceptance difference, and this classifier was refusing to waive it. That refusal rested on a claim I had already found to be false and only half-corrected. Pooling changes which lots survive a reduction, so a later reduction naming an explicit cost finds its lot drained on one engine and present on the other. Seeds 117 and 394 show both directions; 211 lands inside the PR window. Since #2118 provably produces these, refusing to waive them means the gate can never be green — which is precisely what this PR exists to prevent. Fixed in fef1b8b. Acceptance divergences with the pooling shape are now waived, but they are the more serious face of #2118 — a ledger that fails to LOAD rather than one that reports different figures — so they get their own line instead of disappearing into the total: Waived, never silent: they still print in full like any other divergence. Both properties verified against real binaries, not argued:
This reverses a position I argued for in this PR, and the reversal is worth naming: I said an acceptance divergence was "too severe to wave through on a heuristic". The severity is real, and it is why these get their own line and why #2118 was escalated and #2121 now warns about it. But severity is an argument for documenting and for revisiting #2118 — not for a permanently red gate that everyone learns to ignore, which masks far more than it protects. Also confirmed while checking: all six PRs merge into |
…-pooling-divergence
…2125) * test(compat): classify the lot-pooling divergence as expected (#2118) beancount's `Inventory` is keyed by `(currency, cost)`, so acquisitions sharing `(cost, date, label)` pool into one position while rustledger keeps a slot per acquisition. The two then consume in different orders. We decided to keep rustledger's behavior -- it respects acquisition order and beancount's cannot -- so the fuzzer has to stop reporting it as a failure or the run is permanently red, and a permanently red run is one nobody reads. `pooling_shape` matches only a NON-CONTIGUOUS repeat of one lot identity within a single date. `[a, b, a]` pools `a`'s later units ahead of `b` and diverges; `[a, a, b]` pools into the order it already had, a repeat across different dates cannot pool at all, and a label makes the repeat a different identity. It is deliberately narrow: every case it matches is a case this harness stops guarding. Divergences are still compared and still printed in full -- only the verdict changes -- and the three counts print unconditionally, including a zero. A count that appears only when non-zero reads as "nothing was waived" when the line is simply absent. The exit code tracks unexplained divergences alone. An acceptance divergence is never waived whatever shape the lots take. Pooling redistributes units between lots; it cannot make one engine reject a ledger the other books. Evidence it still says no, which is the only thing that makes a waiver safe: - Five `pooling_shape` cases in `--self-test`, four of them near-misses it must reject. Mutating the function to `return True` fails four of them. - Against a PRE-FIX rledger the sweep is exit=1 with 11 unexplained -- all 8 LIFO/label and 3 of the LIFO/date divergences, the whole of #2115 -- and waives only the 5 pooling ones. The classifier does not swallow the bug it would be most tempting to swallow. - Against a fixed rledger: 195/200 agreed, 5 expected, 0 unexplained. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * test(compat): narrow the #2118 waiver with a units-total guard Self-review of #2120. The pooling shape is computed from the GENERATOR, not from the divergence, so a ledger could take that shape and diverge for an unrelated reason and still be waived. One guard covered part of it -- an acceptance divergence is never pooling -- but a wrong-units bug in a pooling-shaped ledger would have been waived silently. Pooling moves units BETWEEN lot identities of one holding; it cannot create or destroy them. `same_totals` requires the per-(account, currency) units to match before a divergence can be waived. Cost-less positions are excluded, and finding out why is the reason this took two passes: consuming a different lot changes the COST BASIS, so the cash and income legs legitimately differ -- that difference is precisely what #2118 is about. Guarding every account rejected all five known cases. Restricting to lot-bearing holdings keeps the guard on the one quantity pooling must leave alone. Also corrects `Booked`'s annotation, which said a 5-tuple while the keys have six elements, and names the fields. Evidence, unchanged in shape from the parent commit: - `--self-test` gains four `same_totals` cases, including both sides of the cost-less boundary. Mutating it to `return True` fails two. - Fixed rledger: 195/200 agreed, 5 expected, 0 unexplained, exit 0. - Pre-fix rledger: 184/200, 5 expected, 11 unexplained, exit 1 -- the whole of #2115 still caught, not waived. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * ci(compat): run the booking fuzzer, gated on unexplained divergences `compat-booking-fuzz.py` was referenced by no workflow, while its siblings `compat-budget-fuzz.py`, `compat-bql-test.py` and `compat-values.py` all run in `compat.yml`. A booking fuzzer that only runs when someone remembers to run it is not a regression gate. It could not have been wired in before the previous two commits: with five permanent #2118 divergences it would have been red on every run. Now the exit code tracks UNEXPLAINED divergences alone, so a red X means something new, which is the only kind of alarm anyone keeps reading. Follows the budget fuzz exactly -- `--self-test` first so a harness that cannot detect a bug fails loudly rather than passing vacuously, then the sweep, `continue-on-error` with the verdict in a step output, and a separate gate that turns it into an error with a reproduce command. It runs in the same place for the same reason: the orphan branch checked out later has no `scripts/` and no `target/`. `--start-seed` is new. Seeds were always `range(runs)`, so every run re-covered identical ground; CI fixes the start for PR and push so a red X does not move when an unrelated commit lands, and uses the run id nightly so the campaign reaches seeds the fixed window never does. Same policy as the budget fuzzer and the synthetic corpus. 250 seeds on PR and 2000 nightly: a case is about 0.1s, so 250 costs ~25s. actionlint reports the same three findings here as on main -- lines 124, 737 and 1163, none of them in these steps. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * test(compat): fuzz prices on reductions, and correct a wrong premise The generator excluded prices on reductions as "a separate surface from lot selection". This adds them: a quarter of reductions take `@ <price>`, a tenth `@@ <total>`, and the price is deliberately NOT pinned to the rate the cash leg implies. A posting carrying a cost takes its weight from the COST, so a disagreeing price is still balanced -- checked against both engines first, since if it were not, every generated ledger would be unbalanced and the comparison would reject it for the wrong reason. Stating the negative result plainly: over 500 seeds the axis found no price-specific divergence. Every divergence in the run traces to #2118 lot pooling. Prices reach the booked postings intact on both engines. What it did surface, by perturbing the stream, is that #2118 is worse than recorded -- it causes ACCEPTANCE divergences, in both directions: seed 117 rledger rejects, beancount books. FIFO drains [email protected] + [email protected] leaving 6 @10.00, so a later `-14 {10.00}` fails; beancount pools the two 8.75 lots, leaves 17 @10.00, and books it. seed 394 beancount rejects, rledger books. Pooled 11.00 is fully consumed, so a later `-3 {11.00}` finds no lot; rledger keeps 7 @11.00. That disproves the premise the acceptance guard was written on, which said pooling "can never" make one engine reject what the other accepts. The guard KEEPS its behavior -- a ledger one engine refuses to load is too severe to wave through on a heuristic -- but the comment now says the true reason rather than a claim the fuzzer refutes. The units-total guard rests on a claim that does hold: pooling moves units between lot identities and cannot create or destroy them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * test(compat): waive #2118's acceptance divergences, tallied separately Found by merging all six open PRs together locally and running the gate the way CI runs it on a PR (250 seeds from 0). The result was RED: seed 211 is #2118 surfacing as an acceptance difference, and this classifier refused to waive it. A gate that cannot be green on main is the exact thing this classifier exists to prevent, and no single PR's CI would have shown it -- only the merged tree does. The refusal rested on a claim already known to be false: that pooling "can never" make one engine reject a ledger the other accepts. Pooling changes which lots SURVIVE a reduction, so a later reduction naming an explicit cost finds its lot drained on one engine and present on the other. Seeds 117 and 394 show both directions; 211 lands in the PR window. So they are waived -- but they are the more serious face of #2118, a ledger that fails to LOAD rather than one that reports different figures, so they get their own line rather than being folded into the total: 7 expected divergence(s) (#2118 lot pooling) of which 1 are ACCEPTANCE differences 0 unexplained divergence(s) Waived, never silent: they still print in full like any other divergence. Both properties verified against real binaries: - with #2119 applied: exit 0, 0 unexplained -- the gate is green post-merge - without it: exit 1, 12 unexplained -- the gate still catches #2115, so the wider waiver did not swallow the bug it was written to find Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr --------- Co-authored-by: Claude Opus 5 <[email protected]>
Follow-up to #2118, which we decided not to fix: beancount pools acquisitions sharing
(cost, date, label)into one inventory position while rustledger keeps a slot per acquisition, so the two consume in different orders. rustledger's answer respects acquisition order and beancount's cannot, so we keep ours.That leaves the fuzzer reporting 5 permanent failures per 200 seeds, and a permanently red run is one nobody reads. This teaches it the difference between "known and accepted" and "new".
The classifier is deliberately narrow
pooling_shapematches only a non-contiguous repeat of one lot identity within a single date:[a, b, a]a's later units ahead ofb[a, a, b][a, b, a]on 3 dates[a("x"), b, a("y")]Every case it matches is a case this harness stops guarding, so "some identity repeats" would have been too broad.
What does not change
Divergences are still compared and still printed in full — only the verdict changes. Nothing is skipped.
An acceptance divergence (one engine rejecting a ledger the other books) is never waived whatever shape the lots take: pooling redistributes units between lots, it cannot change accept/reject.
All three counts print unconditionally, including a zero. A count that appears only when non-zero reads as "nothing was waived" when the line is simply absent — and waived cases are exactly the ones worth keeping in view.
The exit code now tracks unexplained divergences alone.
Evidence it can still say no
A waiver is only safe if you can show what it refuses to waive.
--self-testgained fivepooling_shapecases, four of them near-misses it must reject. Mutating the function toreturn Truefails four of the five.rledger(before fix(core): break LIFO ties by insertion order like FIFO and HIFO #2119 landed the LIFO tie-break fix) the sweep isexit=1with 11 unexplained — all 8 LIFO/label and 3 of the LIFO/date divergences, which is the whole of LIFO picks a different same-date lot than beancount #2115 — while waiving only the 5 pooling cases. The classifier does not swallow the bug it would be most tempting to swallow.rledger:195/200 agreed, 5 expected, 0 unexplained,exit=0.🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr