Skip to content

fix(validate): report held account errors only for refused transactions; forecast copies keep the template's location - #2706

Merged
robcohen merged 1 commit into
mainfrom
fix/plugin-location-held-errors
Oct 20, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/plugin-location-held-errors

Conversation

@robcohen

Copy link
Copy Markdown
Member

What changed

#2687, forecast copies keep the template's location. The native forecast plugin set filename/lineno to None on every copy of a # template, so an error on a copy printed as <unknown>:. Beancount 2.3.6's forecast makes each copy with entry._replace(date=...), which keeps the template's meta. The copies now keep its location as well.

I checked every other native plugin that creates directives against its beancount (or beancount_reds_plugins) source:

  • These already keep the source location, matching their reference: implicit_prices, check_drained (at the close), effective_date, generate_base_ccy_prices, box_accrual, capital_gains_classifier, valuation, currency_accounts.
  • These use a synthetic <plugin> name, as their reference does: the auto_accounts, zerosum, effective_date, long_short and split_expenses opens.
  • Beancount does not keep a source location for these either, so I left them alone:
    • check_closing uses <check_closing>:0.
    • close_tree uses <beancount.plugins.close_tree>:0.
    • Document discovery uses the main file at line 0.
    • rledger gives all three no location. That differs only in the synthetic name, so I've listed it as a follow-up.

#2686, held account errors are reported only for transactions booking refused. finalize used to report the early phase's held errors for every transaction the late phase never saw. Now booking hands the validator the transactions it refused, through the new ValidationSession::<EarlyDone>::note_refused_by_booking, and finalize reports held errors only for those.

  • The loader passes FailedBookings into late_validate. The LSP records its failed set the same way.
  • Transactions a plugin deleted or replaced are no longer reported. Beancount validates only what its plugins return.
  • The fix: zero-value posting pruning hides validation errors #877 elided-posting case is still reported, by late as before.
  • Interaction with forecast: generated transactions lose the template location, so their errors print as <unknown> #2687: forecast copies are now placed at the template's line with an empty span, so they don't match the template's held key. The template's held E1001 used to be printed as a third, duplicate error. It is now dropped, because the template is not a refused transaction. With this change, rledger check matches bean-check 2.3.6 on the issue's ledger: two E1001s, both at the template's line.
  • FFI, wasm and the standalone callers run Early and Late on the same list, so nothing is held at finalize there and their behavior is unchanged.

No CACHE_VERSION bump: the cache holds parse output, and both changes happen after parsing.

How tested

  • Oracle: bean-check (beancount 2.3.6, via uv) on the issue's ledger gives fc.beancount:3: Invalid reference to unknown account 'Expenses:Rent' twice. The new loader test pins the same result: 2 E1001s, at line 3.
  • New tests, each shown to FAIL with the fix reverted:
    • forecast::tests::test_forecast_copies_keep_the_template_location
    • loader_test::test_forecast_copies_report_at_the_template
    • validate::tests::held_errors_are_reported_only_for_transactions_booking_refused: deleted means no E1001, refused means one at the transaction, seen-by-late means one.
    • lsp::diagnostics::tests::a_refused_transaction_keeps_its_account_error
    • python_plugin_wasi::a_transaction_a_plugin_deletes_is_not_validated (Python-gated): a filter plugin deletes a transaction that uses an unopened account, and there is no E1001 for it, while a refused transaction keeps its E1001.
    • The existing test_refused_transaction_keeps_its_account_errors also fails if the loader stops recording refusals.
  • Test suites, cargo doc -D warnings, cargo clippy --workspace --all-features --all-targets -D warnings and cargo fmt all pass. The test suites were for -p rustledger-validate -p rustledger-loader -p rustledger-plugin -p rustledger-lsp --all-features: 1321 passed.

Closes #2687
Closes #2686

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

…ns; forecast copies keep the template's location

The native forecast plugin cleared the file and line of every copy of a
`#` template, so errors on a copy printed as `<unknown>:`. Beancount's
forecast keeps the template's meta; the copies now keep its location
(#2687).

The early phase's held posting-account errors were reported at finalize
for every transaction late never saw: those booking refused (deliberate)
but also those a plugin deleted or replaced. Booking now hands the
validator the refused transactions (`note_refused_by_booking`, called by
the loader and the LSP), and finalize reports only theirs (#2686).

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 20, 2026 14:11
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.9ms ± 0.5ms 828.7ms ± 5.4ms 18.0x 52.4 MB / 50.2 MB
investment 72.3ms ± 1.4ms 3048.0ms ± 14.5ms 42.2x 54.2 MB / 58.2 MB
fifo 69.9ms ± 0.9ms 15382.6ms ± 97.9ms 220.0x 55.6 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 45.8ms ± 0.4ms 45.9ms ± 0.5ms +0.3% ✅ within noise 52.4 MB → 52.4 MB (-0.1%)
investment 71.4ms ± 0.9ms 72.3ms ± 1.4ms +1.2% ✅ within noise 54.6 MB → 54.2 MB (-0.6%)
fifo 70.1ms ± 0.5ms 69.9ms ± 0.9ms -0.2% ✅ within noise 56.6 MB → 55.6 MB (-1.8%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.3ms, investment 0.8ms, fifo 0.5ms), 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

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen

Copy link
Copy Markdown
Member Author

Deep-review rounds (lane V6)

Round Scope Checks Findings
1 The whole diff, re-read adversarially: the forecast copy's span vs the held key, the order of note_refused_by_booking against run_late, the LSP failed set, the FFI/wasm/standalone callers of finalize Fail-without-fix for all 5 new tests and the existing refused test. Changed-crate suites: 1321 passed One existing validate test relied on the old behavior (it was not recording its refused transaction). Fixed before the first push
2 The other native plugins that create directives, compared with their beancount and reds sources; the CACHE_VERSION question bean-check 2.3.6 against rledger check on the issue's ledger: 2× E1001 at line 3 on both None

Converged after round 2. Follow-up: check_closing, close_tree and document discovery have no location in rledger, while beancount gives them a synthetic name (<check_closing>:0, <beancount.plugins.close_tree>:0, <main file>:0). That is not a lost source location, so it is not in this PR.

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

Labels

None yet

Projects

None yet

1 participant