Skip to content

test(compat): fuzz prices on reductions, and correct a wrong premise - #2125

Merged
robcohen merged 7 commits into
mainfrom
chore/fuzzer-price-axis
Aug 24, 2026
Merged

robcohen merged 7 commits into
mainfrom
chore/fuzzer-price-axis

Conversation

@robcohen

Copy link
Copy Markdown
Member

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:

  • seed 117 — rledger rejects, beancount books. rledger takes [email protected] + [email protected], leaving 6 @10.00, so a later -14 {10.00} fails Not enough units. beancount pools the 8.75 lots, leaves 17 @10.00, books it.
  • seed 394 — the reverse. Pooled 11.00 is fully consumed, so a later -3 {11.00} finds no lot; rledger keeps 7 @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

robcohen and others added 4 commits August 24, 2026 02:26
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
@robcohen
robcohen requested a review from a team as a code owner August 24, 2026 03:41
@robcohen

Copy link
Copy Markdown
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 --seed <n>", so that had better be deterministic and had better reproduce what the sweep saw.

Three runs of --seed 117 are byte-identical, and the single-seed run reproduces the sweep's finding exactly — same header, same classification:

seed=117 method=FIFO tie=date price=yes
rledger rejected the ledger; beancount booked it
...
0/1 agreed
0 expected divergence(s) (#2118 lot pooling)
1 unexplained divergence(s)

So the instruction the gate prints actually works.

robcohen and others added 2 commits August 24, 2026 03:53
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
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant