Skip to content

fix(plugin)!: native validation plugins report as beancount's do - #2594

Merged
robcohen merged 3 commits into
mainfrom
fix/plugin-native-python-alignment
Oct 11, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/plugin-native-python-alignment

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

The issue asked to list every plugin that exists both natively and in Python, diff their output, and align them on beancount's text and severity.

The pairs. There are two python: built-ins: check_commodity and leafonly. Beancount 3's own plugin modules that run unchanged under the compat layer are check_commodity, close_tree, coherent_cost, commodity_attr, onecommodity and unique_prices, plus leafonly and noduplicates once #2592 lands. I checked each against bean-check, the native plugin and the Python versions on the same fixtures. Every native one differed except close_tree (same inserted closes, no diagnostics).

Plugin Native before Now (= bean-check)
check_commodity warning commodity 'USD' used but not declared; no open/price-annotation currencies, no config error Missing Commodity directive for 'USD' in 'Assets:Bank', beancount's occurrence rules and {account-re: currency-re} config
leafonly one error per posting, Posting to non-leaf account ... - has child accounts, unlocated one per account at its open, Non-leaf account '...' has postings on it, tree order; a pad counts
coherent_cost flagged only price-without-cost: missed 1 HOOL beside 1 HOOL {5 USD} Currency 'HOOL' is used both with and without cost, at the first without-cost txn
onecommodity an error per extra posting; ignored config regex, onecommodity: FALSE, multi-currency open, costs, balances one per account (More than one currency in account 'X': EUR,USD, and the cost-currency variant), at beancount's entry, all of those honored
unique_prices flagged identical repeated prices only disagreeing ones: Disagreeing price entries, located as beancount does
commodity_attr ignored a tuple/set of allowed values (beancount's own example form), own messages Missing attribute ... / Invalid value ... valid options: ..., located; None or null
noduplicates Duplicate transaction: ..., unlocated Duplicate entry: <date> "<narration>" at the later copy

The python:check_commodity built-in now reads the config, and python:leafonly counts pads and uses tree order, so both agree with the native plugins.

Severity change → ### Breaking: check_commodity is now an error, so rledger check exits 1 on an undeclared commodity, as bean-check does. The old test pinning it as a warning came from a coverage matrix (#1038), not from a recorded decision.

Deliberate divergences (commented at both implementations, in the docs and in the CHANGELOG):

  1. Beancount's leafonly also reports a parent account named only by a note, document, close or custom (its realization counts them), which I confirmed with bean-check. None of those posts anything, so rledger does not report them. This is the one place where correctness and beancount's text pull apart; flagging those would be a one-line change if you prefer compat.
  2. noduplicates: beancount prints both entries' Python repr, so rledger keeps the Duplicate entry: prefix and names the duplicate instead. It also still compares transactions only, where beancount compares every directive type; that is a possible follow-up.
  3. Beancount joins sets (onecommodity's currencies, commodity_attr's options) in an order that changes between runs. rledger sorts the currencies and keeps the options in config order.

How tested (fail without the fix)

  • plugin_conformance::native_and_python_implementations_agree: check_commodity (also with a config) and leafonly (also with a pad), native vs python: built-in, compared line for line and against bean-check's text and location; the five other pairs held to bean-check's exact text and line. Every expected line was taken from bean-check on the same ledger. Without the fix it fails with warning[PLUGIN]: commodity 'USD' used but not declared.
  • native_plugins_test: 7 new alignment tests (config, occurrence rules, locations, opt-outs, tuples, agreeing duplicates) plus 4 updated ones. 12 fail without the fix.
  • The existing conformance and pedantic cases now assert the aligned messages; the Python cases are told apart by the runtime banner.
  • Full suites pass with RLEDGER_REQUIRE_*: rustledger-plugin, -ops, -loader, -lsp, -wasm and rustledger. clippy (workspace, all features), fmt and cargo doc -D warnings are clean. Release-config clippy has only the wasm_plugins_dir dead-code error, which main already has and fix(cli): name the build with plugin runtimes when one is missing; plugin conformance on macOS and Windows #2593 fixes.

Plugins with both implementations whose beancount module does not run under the compat layer yet (it needs inventory, account_types, number or loader): auto_accounts, check_average_cost, check_closing, check_drained, currency_accounts, implicit_prices, nounused, pedantic, sellgains. These are not compared here; a possible follow-up.

Closes #2539

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

The plugins rledger has both natively and in Python reported the same
ledger differently depending on which ran. The native check_commodity,
leafonly, coherent_cost, onecommodity, unique_prices, commodity_attr and
noduplicates now match beancount 3: its messages, as errors, at the
entries beancount names. check_commodity is an error, not a warning, and
reads the config ignore map; leafonly reports each parent once at its
open; coherent_cost catches a currency held with and without cost;
onecommodity reads its config, opt-out, costs and balances; unique_prices
allows agreeing repeats; commodity_attr reads tuples. The python:
built-ins match too. A conformance case holds each pair to bean-check's
output.

Deliberate divergences, documented: leafonly ignores a note, document,
close or custom on a parent; noduplicates names the duplicate instead of
printing Python reprs; set-joined lists are in a stable order.

Closes #2539

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner October 10, 2026 22:33
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 28.6ms ± 1.2ms 410.2ms ± 9.6ms 14.4x 51.2 MB / 49.9 MB
investment 44.8ms ± 0.3ms 1561.8ms ± 18.8ms 34.9x 57.3 MB / 58.1 MB
fifo 45.5ms ± 0.3ms 8283.5ms ± 8.5ms 182.1x 57.4 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 29.0ms ± 0.7ms 28.6ms ± 1.2ms -1.5% ✅ within noise 51.4 MB → 51.2 MB (-0.4%)
investment 44.8ms ± 0.4ms 44.8ms ± 0.3ms -0.1% ✅ within noise 57.4 MB → 57.3 MB (-0.2%)
fifo 45.2ms ± 0.4ms 45.5ms ± 0.3ms +0.8% ✅ within noise 57.2 MB → 57.4 MB (+0.3%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.6ms, investment 0.2ms, fifo 0.2ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 819
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

@robcohen

robcohen commented Oct 11, 2026 •

Copy link
Copy Markdown
Member Author

Review loop

Round Scope Finding Fix
1 Each native port checked against beancount 3's source: occurrence rules, iteration and report order, which entry an error is located at, config parsing, falsy metadata. The python: built-ins checked against the native ports none n/a
2 Oracle sweep: 150 corpus files (tests/**) × leafonly, coherent_cost, onecommodity, unique_prices and check_commodity, bean-check vs native, plus example.beancount × 6 plugins No plugin divergence. What remains: 3 onecommodity set-order cases, a documented divergence. 14 cases (13 check_commodity, 1 coherent_cost) where rledger's booking rejects a transaction and drops it before the regular plugins run; that is the pipeline, not this PR n/a
3 After merging main (#2587 stdin inputs, #2588 note tags and links with ABI 2, #2592 realization/compare). Conflicts were the conformance doc table, where I kept both rows, and CHANGELOG (main's file plus this PR's entry). Checked that all four PRs' behavior survived the merge: stdin _entries_in, the aligned python: built-ins, NoteData tags and ABI 2, the shim modules This PR's leafonly test built NoteData without the new tags/links fields 7001360: fields added. On the merged tree: workspace and release-config clippy clean; rustledger-plugin, -ops and rustledger suites pass; the conformance matrix passes (44, native_and_python_implementations_agree included). Fail-without-fix re-run on the merged tree: agreement case fails (warning[PLUGIN]: commodity 'USD' used but not declared), 12 native tests fail

The loop converged. The required checks are green on 7001360.

@robcohen

Copy link
Copy Markdown
Member Author

Decisions (robcohen):

  1. check_commodity reports an error, not a warning (as implemented). bean-check exits 1 on the same ledger, and the plugin is opt-in: enabling it means undeclared commodities should fail check. Keep the CHANGELOG Breaking entry.
  2. leafonly divergence kept: only real postings (and pads) on a non-leaf account are flagged, never a parent carrying only a note, document, close or custom. Beancount's "has postings on it" is false in those cases, and notes/documents on parent accounts are legitimate. Keep it documented at both implementations, in the CHANGELOG and in the compat notes.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

robcohen and others added 2 commits October 11, 2026 09:07
…hon-alignment

# Conflicts:
#	CHANGELOG.md
#	crates/rustledger/tests/plugin_conformance.rs
@robcohen
robcohen merged commit 938c3ef into main Oct 11, 2026
53 of 55 checks passed
@robcohen
robcohen deleted the fix/plugin-native-python-alignment branch October 11, 2026 10:13
robcohen added a commit that referenced this pull request Oct 11, 2026
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.

plugin: align native and Python implementations' messages and severities

1 participant