Repository navigation
feat(compat): semantic differential against beancount 3.2.3, gated in CI - #3071
Merged
Merged
Conversation
The parse-error harness compares syntax errors; this compares what rledger and beancount.loader.load_file make of a well-formed ledger after a FULL load: booking under every method, interpolation, prices, tolerances and rounding, pads and balance assertions, options and includes, plugins. - crates/rustledger-loader/examples/semantic_snapshot.rs: rledger side of pta-standards ptadiff semantic protocol (ptadiff-snapshot/1). Loads through Loader::load and process as rledger check does, every field read from the function that owns it. - rustledger_booking::account_balances (+ RealizeError): the realization the balance reports print, moved out of the CLI so the snapshot reads the same one; the CLI wrapper calls it. - scripts/compat-semantic-parity.py + tests/baselines/semantic-parity.manifest: pinned 10k generated ledgers + the compat corpus; per-category and per-deviation counts and every mismatching ledger pinned; --check fails on regressions, --update ratchets. - scripts/semantic_parity_hooks.py: rledger deliberate differences as data, each pointing at docs/reference/compatibility.md (two new sections: plugins in included files, currency_accounts posting order; #5 extended for custom amounts). - compat.yml: Semantic parity job. 97.7% of judged ledgers match; the rest is clustered into 16 categories. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 27, 2026
Merged
…e, as CI runs it A third-party plugin the oracle cannot import leaves a ledger unjudged; the first pin came from a venv that had some installed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
…dards#77) The tooling/differential tree is identical to the feature-branch commit it replaces, so no count changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
Nov 27, 2026
… from beancount Beancount booking regroups a transaction postings by the currency each weighs in. rledger keeps the written order: compatibility.md #22, and the semantic gate counts such a ledger as the currency-group-posting-order deviation (only when regrouping reproduces beancount order exactly). Maintainer decision on question 4 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 27, 2026
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
…s beancount does auto_accounts (and the auto plugin) ran in the pre-booking synth pass, ahead of every other plugin whatever the declared order, and over transactions booking then refused. It opened the accounts of a refused transaction and of an elided posting booking drops, where bean-check opens neither, and a plugin declared before it saw its opens. It is now a regular plugin, run at its declared place. Early validation still judges posting accounts against the opens it will insert, through rustledger_loader::early_validation_view: a copy of the stream with them, computed by the plugin itself, that nothing downstream sees. The LSP reads the same view. check --auto runs it after the file plugins, as bean-check --auto does. Document discovery stays in the synth pass (beancount runs it first; its documents carry no amounts). WASM cache v157. Maintainer decision on question 1 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
…uct rounds
booked_cost_number decided whether a sale takes the lot exact total with
Decimal checked_mul, which rounds a product past 28 digits and returns it
anyway. A whole sale of 19.25 VTI {94.94 # 3.83 USD} looked exact, was
weighed at the exact product of the rounded per-unit cost, and a residual
of exactly -0.005 against a 0.005 tolerance became a spurious E3001. The
comparison is exact now.
Exact total-cost weights are kept (compatibility #18 now covers costs);
the one-cent difference an elided gain on an exact half-cent tie can show
is documented and registered as the total-cost-half-cent deviation in the
semantic gate, whose manifest is ratcheted.
WASM cache v158. Maintainer decision on question 2 of #3071.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… from beancount Beancount booking regroups a transaction postings by the currency each weighs in. rledger keeps the written order: compatibility.md #22, and the semantic gate counts such a ledger as the currency-group-posting-order deviation (only when regrouping reproduces beancount order exactly). Maintainer decision on question 4 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… date The Python plugin dates the opens of the accounts it moves matched postings to at entries[0].date (usually an open or commodity); rledger dated them at the first transaction, later. Verified black-box against beancount_reds_plugins under bean-check 3.2.3. WASM cache v159. Maintainer decision on question 6 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… lot matches, as beancount does Inventory::is_booking_reduction counted only lots held at cost (#875), so holding 10 BTC bought without a cost, -1 BTC {98.52 USD} opened a short lot beside the long, and a purchase at a cost after a sale without a cost spec was an augmentation. bean-check 3.2.3 refuses both (No position matches); the gate now considers every opposite-sign position. BREAKING CHANGE: such postings are booking failures now. WASM cache v160. Maintainer decision on question 3 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
…s beancount does (#3075) * fix(loader): run auto_accounts where it is declared, after booking, as beancount does auto_accounts (and the auto plugin) ran in the pre-booking synth pass, ahead of every other plugin whatever the declared order, and over transactions booking then refused. It opened the accounts of a refused transaction and of an elided posting booking drops, where bean-check opens neither, and a plugin declared before it saw its opens. It is now a regular plugin, run at its declared place. Early validation still judges posting accounts against the opens it will insert, through rustledger_loader::early_validation_view: a copy of the stream with them, computed by the plugin itself, that nothing downstream sees. The LSP reads the same view. check --auto runs it after the file plugins, as bean-check --auto does. Document discovery stays in the synth pass (beancount runs it first; its documents carry no amounts). WASM cache v157. Maintainer decision on question 1 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(compat): ratchet the semantic parity manifest With close_tree (#3073) on main, auto_accounts at its declared place clears both entries|extra-in-impl|open (8) and entries|extra-in-impl|close (12): 99.50% -> 99.74% of judged ledgers match, no regression. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
A plugin reference was matched to a native plugin by its last dotted segment, so beancount.plugin.unrealized (which beancount fails to import) or anything.zerosum silently ran the native plugin. A native plugin is now named by its bare name, by beancount.plugins.<name>, or by the exact path of the third-party module it replaces (THIRD_PARTY_MODULES); anything else resolves as any other module reference. native_plugin_name is the rule. BREAKING CHANGE: a misspelled or otherwise inexact plugin path no longer runs a native plugin. Surface parity: the LSP E8006 note for the two lima fixtures that use the misspelled path is allowlisted with the existing plugin entries. Semantic gate ratcheted (two compat files now match). WASM cache v161. Maintainer decision on question 5 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… from beancount Beancount booking regroups a transaction postings by the currency each weighs in. rledger keeps the written order: compatibility.md #22, and the semantic gate counts such a ledger as the currency-group-posting-order deviation (only when regrouping reproduces beancount order exactly). Maintainer decision on question 4 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… date The Python plugin dates the opens of the accounts it moves matched postings to at entries[0].date (usually an open or commodity); rledger dated them at the first transaction, later. Verified black-box against beancount_reds_plugins under bean-check 3.2.3. WASM cache v159. Maintainer decision on question 6 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… lot matches, as beancount does Inventory::is_booking_reduction counted only lots held at cost (#875), so holding 10 BTC bought without a cost, -1 BTC {98.52 USD} opened a short lot beside the long, and a purchase at a cost after a sale without a cost spec was an augmentation. bean-check 3.2.3 refuses both (No position matches); the gate now considers every opposite-sign position. BREAKING CHANGE: such postings are booking failures now. WASM cache v160. Maintainer decision on question 3 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
A plugin reference was matched to a native plugin by its last dotted segment, so beancount.plugin.unrealized (which beancount fails to import) or anything.zerosum silently ran the native plugin. A native plugin is now named by its bare name, by beancount.plugins.<name>, or by the exact path of the third-party module it replaces (THIRD_PARTY_MODULES); anything else resolves as any other module reference. native_plugin_name is the rule. BREAKING CHANGE: a misspelled or otherwise inexact plugin path no longer runs a native plugin. Surface parity: the LSP E8006 note for the two lima fixtures that use the misspelled path is allowlisted with the existing plugin entries. Semantic gate ratcheted (two compat files now match). WASM cache v161. Maintainer decision on question 5 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
…uct rounds
booked_cost_number decided whether a sale takes the lot exact total with
Decimal checked_mul, which rounds a product past 28 digits and returns it
anyway. A whole sale of 19.25 VTI {94.94 # 3.83 USD} looked exact, was
weighed at the exact product of the rounded per-unit cost, and a residual
of exactly -0.005 against a 0.005 tolerance became a spurious E3001. The
comparison is exact now.
Exact total-cost weights are kept (compatibility #18 now covers costs);
the one-cent difference an elided gain on an exact half-cent tie can show
is documented and registered as the total-cost-half-cent deviation in the
semantic gate, whose manifest is ratcheted.
WASM cache v158. Maintainer decision on question 2 of #3071.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… from beancount Beancount booking regroups a transaction postings by the currency each weighs in. rledger keeps the written order: compatibility.md #22, and the semantic gate counts such a ledger as the currency-group-posting-order deviation (only when regrouping reproduces beancount order exactly). Maintainer decision on question 4 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… date The Python plugin dates the opens of the accounts it moves matched postings to at entries[0].date (usually an open or commodity); rledger dated them at the first transaction, later. Verified black-box against beancount_reds_plugins under bean-check 3.2.3. WASM cache v159. Maintainer decision on question 6 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
… lot matches, as beancount does Inventory::is_booking_reduction counted only lots held at cost (#875), so holding 10 BTC bought without a cost, -1 BTC {98.52 USD} opened a short lot beside the long, and a purchase at a cost after a sale without a cost spec was an augmentation. bean-check 3.2.3 refuses both (No position matches); the gate now considers every opposite-sign position. BREAKING CHANGE: such postings are booking failures now. WASM cache v160. Maintainer decision on question 3 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 28, 2026
A plugin reference was matched to a native plugin by its last dotted segment, so beancount.plugin.unrealized (which beancount fails to import) or anything.zerosum silently ran the native plugin. A native plugin is now named by its bare name, by beancount.plugins.<name>, or by the exact path of the third-party module it replaces (THIRD_PARTY_MODULES); anything else resolves as any other module reference. native_plugin_name is the rule. BREAKING CHANGE: a misspelled or otherwise inexact plugin path no longer runs a native plugin. Surface parity: the LSP E8006 note for the two lima fixtures that use the misspelled path is allowlisted with the existing plugin entries. Semantic gate ratcheted (two compat files now match). WASM cache v161. Maintainer decision on question 5 of #3071. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What
A full-pipeline semantic differential against beancount 3.2.3, the counterpart of the parse-error parity harness for everything after the parser: booking under every method, interpolation, prices, tolerances and rounding, pads and balance assertions, options and includes, plugins.
Both sides describe each ledger with a snapshot in pta-standards' format-generic
ptadiff-snapshot/1schema (errors; booked entries with interpolated, padding and plugin-made entries, each posting's units, resolved cost, price and flag, each transaction's inferred tolerances; final balances lot by lot; effective options). ptadiff (rustledger/pta-standards#77) canonicalizes, normalizes, compares, keys (field|path|kind|booking|features), minimizes and clusters.crates/rustledger-loader/examples/semantic_snapshot.rs: rledger's side, ptadiff's JSON-lines protocol in semantic mode (multi-file inputs). Loads throughLoader::load+processwithcheck's options, and reads every field from its owner:parse_errors_to_ledger_errors,option_warnings_to_errors,merge_with_padding_spanned,CostSpec::resolve,transaction_tolerances(onpre_booking_directives),DisplayContext, and the realization below. No re-derivation.rustledger_booking::account_balances(new, withRealizeError): the realizationbalances/balsheet/incomeprint, moved out of the CLI (report_cmd::account_balancesnow calls it), so the snapshot cannot drift from the reports.scripts/compat-semantic-parity.py+tests/baselines/semantic-parity.manifest: a pinned 10,000-ledger sample of ptadiff's seeded generators (lots and booking, pads/balances/tolerances, multi-file with options and plugins, built-in plugins) plus the compat corpus. Pins every category's and deviation's count and every mismatching ledger;--checkfails on a regression or a moved pin,--updateratchets,--self-testruns first in CI.scripts/semantic_parity_hooks.py: rledger's deliberate differences as data, each pointing atdocs/reference/compatibility.md, counted apart from the mismatches: AVERAGE booking (feat(loader): add path traversal protection #20), plugins in included files (new chore(ci): increase Claude code review max turns #21),currency_accountsposting order (new, Plugin Differences), cross-file booking order (fix: replace unwrap calls with defensive pattern matching #7),customamounts and display precision (test: add comprehensive integration tests for loader crate #5, extended); representation-only ones normalized (one E3001 per currency, ci: add merge_group trigger for GitHub Merge Queue #1; unpopped push, missing include and document root located nowhere, refactor: extract evaluate_function into category-based helpers #3;effective_datelink suffix).compat.yml: aSemantic parityjob beside the parse-error one.Results
10,730 ledgers (10,000 generated, 730 compat): 97.7% of the judged ledgers match (9,363 match, 217 mismatch, 1,106 deliberate deviations, 44 unjudged: third-party plugins beancount cannot import where CI runs it). 15 categories; the largest, minimized:
options|display_precision{150 # 5 USD}sampled as one0; a balance~tolerance sampled (fixed in a separate PR)entries|extra-in-impl|closeplugin close_tree+plugin auto_accounts+close Expenses:Rent(never opened)entries|extra-in-impl|openplugin auto+ a transaction booking refuses: rledger auto-opens its accountsentries|postings.order|...|reduceentries|postings.order|...multi-currency(compat)Fixes, one PR per root cause: #3072 (display precision sampling), #3073 (
close_treeand a never-opened parent), #3074 (STRICT total-match posting order). With all three applied, the same inputs match at 99.5% (46 mismatches, 13 categories, no regression); each ratchets this manifest once it lands after this PR.Open questions (not decided here)
plugin "beancount.plugins.auto"+ a transaction booking refuses: rledger auto-opens its accounts (andnounusedthen reports them), beancount'sauto_accountsruns after booking over the surviving entries.plugin close_treedeclared beforeplugin auto_accounts: beancount drops the never-opened close before anything opens it, rledger opens it first. Options: declare a deviation (the split pass is documented architecture); letauto_accountsskip transactions booking refuses; honour declaration order when a regular plugin precedes a synth one.17.125 ACME {286.04 # 2.75 USD}with gains elided: beancount books 3527.25 (its rounded per-unit makes the tie .245000...001), rledger 3527.24 (exact .245, half-even). And a STRICT total sale of4 VTI {125.51 USD, "lot1"}+19.25 VTI {94.94 # 3.83 USD}@ 163.92 with cash 3811.14: rledger reports E3001 (residual -0.00500000000000000000000002, from the rounded per-unit times the units), beancount none (its product rounds back to the exact total; the exact residual is -0.005, within tolerance). Options: extend feat(core): implement string interning for performance #18 (weigh totals as written) to costs and carry the lot's exact total through a whole-lot reduction; round each weight to 28 significant digits in the precise residual, as Python's context does; or document.10 BTCwithout cost,-1 BTC {98.52 USD}: beancountNo position matches; rledger books a short lot at cost beside the long (ReductionScope::CostBearingOnly, pinned as deliberate in core). Options: follow beancount (a reduction against every position when the posting has a cost spec), or document as a deviation.28600.65 USD,50 RHT, elidedEquity:Opening-Balancesbooks as USD, -USD, RHT, -RHT); rledger keeps the written order. Cosmetic. Options: mimic, or document.beancount.plugin.unrealized) runs rledger's native plugin by its last segment, where beancount fails to import it. Options: requirebeancount.plugins.for that namespace, or document.zerosum: beancount's opens the matched account (Assets:ZeroSum-Matched:...), rledger's does not.open include "x"still includesx): the open parser PRs (fix(validate): a transaction beancount's grammar discards moves no inventory #3066) cover the first; the second belongs to the parse-error harness.How to test
pip install beancount==3.2.3 "ptadiff @ git+https://github.com/rustledger/pta-standards@$(sed -n 's/^#@ptadiff-rev //p' tests/baselines/semantic-parity.manifest)#subdirectory=tooling/differential" cargo build --release -p rustledger-loader --example semantic_snapshot python -I scripts/compat-semantic-parity.py --self-test python -I scripts/compat-semantic-parity.py --rledger target/release/examples/semantic_snapshot \ --compat-dir tests/compatibility/files --check --minimize 10 --report report.md#@ptadiff-revpins rustledger/pta-standards#77's head; merge that first (the pinned commit is fetchable from its branch meanwhile).🤖 Generated with Claude Code