Repository navigation
test(compat): fuzz prices on reductions, and correct a wrong premise - #2125
Merged
Merged
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
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
`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
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
Member
Author
|
Self-review: verified a property this work has been relying on without ever testing it. The CI gate added in #2120 tells the reader to "Reproduce one with Three runs of So the instruction the gate prints actually works. |
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
…vergence' into chore/fuzzer-price-axis # Conflicts: # scripts/compat-booking-fuzz.py
Base automatically changed from
chore/fuzzer-expected-pooling-divergence
to
main
August 24, 2026 04:32
# Conflicts: # scripts/compat-booking-fuzz.py
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2120 — base it there, not
main. Merge after it.The generator deliberately 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 not pinned to the rate the cash leg implies.Checked before generating anything: a posting carrying a cost takes its weight from the COST, so a price that disagrees with the proceeds is still a balanced transaction on both engines. Had that not held, every generated ledger would have been unbalanced and the harness would have rejected them for a reason that has nothing to do with booking.
The negative result, stated plainly
Over 500 seeds the price axis found no price-specific divergence. Prices reach the booked postings intact on both engines; every divergence in the run traces to #2118. Recording that so the next person does not re-run the same experiment expecting a different answer.
What it did surface, and a correction
Perturbing the seed stream exposed three acceptance divergences, all caused by pooling, and they show #2118 is worse than that issue recorded — it can make a ledger fail to load, in both directions:
[email protected] + [email protected], leaving6 @10.00, so a later-14 {10.00}failsNot enough units. beancount pools the 8.75 lots, leaves17 @10.00, books it.11.00is fully consumed, so a later-3 {11.00}finds no lot; rledger keeps7 @11.00.That disproves a premise I wrote in #2120, which justified never waiving an acceptance divergence by claiming pooling "can never" cause one. The conclusion was right and the reason was wrong. The guard keeps its behavior — a ledger one engine refuses to load is too severe to wave through on a heuristic — and the comment now says that instead of a claim this harness refutes.
The units-total guard rests on a claim that does hold: pooling moves units between lot identities and cannot create or destroy them.
Escalated on #2118, and #2121 now warns that a ledger may fail to load rather than only that figures may differ.
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr