Repository navigation
fix(compat): compare balances as money, not as raw Decimals - #1916
Merged
Merged
Conversation
Re-lands the correction from #1910, which was pushed after that PR had already auto-merged and so never reached main. The comparison used raw Decimal equality, which reported two divergences that were representation differences rather than value disagreements. The two tools quantize at different layers: beancount rounds when it books, rledger books what the arithmetic implies and rounds when it displays. `0.035 SPY @ 137.142857143 USD` against an explicit `4.80` leaves 5e-12. beancount books 0.00 and loses it; rledger books 0.000000000005, keeps the postings summing to exactly zero, and renders 0.03 on every surface that knows the currency. Only `sum(number)` - a deliberately currency-less projection, which is what this harness asks for - shows the residue, and there the exact sum is the correct answer. #1909 was closed as working-as-intended on that basis: rledger preserving the value is the better behavior, since beancount silently discards a tenth of a cent someone deliberately typed. Each side is now quantized to beancount's own exponent before comparing: beancount has already rounded to the currency's precision at booking, so its exponent IS the precision at which these figures are money. Stated cost: a genuine divergence smaller than one display unit is invisible, which is by definition a difference no user could observe in a balance. Verified against seven cases that this silences only what it should - both #1909 representation cases go quiet, while a one-cent error, a sign flip, a missing posting and a magnitude blowup all still report. Corpus, with #1913 also applied: 4 divergences -> 1, the survivor being issue-520.beancount, a tracked regression fixture.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the booked-value compatibility harness to treat compared balances as monetary quantities (quantized to beancount’s booked precision) rather than comparing raw Decimal representations, reducing false-positive divergences when the two tools retain different internal precision.
Changes:
- Quantize rledger totals to beancount’s exponent before comparing, and treat un-quantizable cases as true divergences (
scripts/compat-values.py). - Update the compat workflow step comment to reflect the current single known divergence (
.github/workflows/compat.yml).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| scripts/compat-values.py | Quantizes rledger values to beancount’s booked precision prior to comparison; expands rationale in docstring. |
| .github/workflows/compat.yml | Comment-only update: refreshes the “known divergences” note for the value comparison step. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 93% |
| Full AST Match | 100% |
| Total Files | 812 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
This was referenced Aug 1, 2026
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.
Re-lands the correction from #1910. That PR auto-merged at 15:18 yesterday with head
8b2342e82; I pushed this commit afterwards, so it was stranded on the branch and never reached main. Same content, plus a comment correction.What
The value oracle compared raw
Decimals, which is the one question guaranteed to expose a representation difference rather than a value disagreement. Each side is now quantized to beancount's own exponent before comparing.The two tools legitimately carry different precision for the same balance because they quantize at different layers: beancount rounds when it books; rledger books what the arithmetic implies and rounds when it displays.
0.035 SPY @ 137.142857143 USDagainst an explicit4.80leaves 5e-12. beancount books0.00and loses it. rledger books0.000000000005, keeps the postings summing to exactly zero, and renders0.03on every surface that knows the currency. Onlysum(number)— a deliberately currency-less projection, which is what this harness asks for — shows the residue, and there the exact sum is the correct answer.That is why #1909 was closed as working-as-intended: rledger preserving the value is the better behavior, since beancount silently discards a tenth of a cent someone deliberately typed.
Quantizing to beancount's exponent is principled rather than a fudge: beancount has already rounded to the currency's precision at booking, so its exponent is the precision at which these figures are money.
Stated cost
A genuine divergence smaller than one display unit is now invisible. That is the deliberate trade, and it is written into the docstring — it is also, by definition, a difference no user could observe in a balance.
Verification
The harness was shown able to report dirty, not just clean:
0.03vs0.0300000000050.00vs-0.0003183Corpus, with #1913 also applied: 4 divergences to 1, the survivor being
issue-520.beancount, a tracked regression fixture.Also
The workflow comment listed #1911 as a known divergence. #1913 fixes it, so the comment now names only
issue-520.