Skip to content

fix(loader): run auto_accounts where it is declared, after booking, as beancount does - #3075

Merged
robcohen merged 2 commits into
mainfrom
fix/auto-accounts-declared-order
Nov 28, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/auto-accounts-declared-order

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

auto_accounts (and the auto plugin's two parts) is now a regular plugin, run at its declared place in the post-booking pass, as beancount runs it. Maintainer decision on open question 1 of #3071.

  • AutoAccountsPlugin implements RegularPlugin (it implemented SynthPlugin); the synth pass now runs document discovery alone. beancount runs that first (PLUGINS_PRE), and its documents carry no amounts, so its pre-booking place is unobservable.
  • Early validation keeps what it needed the synth opens for: rustledger_loader::early_validation_view (new) returns a copy of the stream with the opens the plugin itself would insert (run through the same dispatch, only = auto_accounts), which Early judges posting accounts against and nothing downstream sees. Without it Early would hold "never opened" for every posting to an auto-opened account; Late drops those for the transactions it checks but reports them for a refused one. Costs one stream copy, only for a ledger that runs the plugin. pre_booking_directives is that view, so WASM validateSource holds the same judgments.
  • The LSP's run_ledger_validation runs Early on the same view.
  • check --auto runs the plugin after the file's plugins (beancount's PLUGINS_AUTO).
  • Docs: PluginPass, the process pipeline comment, Phase in rustledger-validate, the plugin crate's pass notes, and AGENTS.md's pipeline pointer.

Why

Running it pre-booking, ahead of every plugin, was visible in the output:

  • It opened accounts named only by a transaction booking then refuses. With Assets:Broker named only by an oversold sale, bean-check opens Assets:Cash and Assets:Stock and reports the booking error alone; nounused then also reported the extra open.
  • It opened an account named only by an elided posting that books to zero and is dropped (Income:Gains beside a purchase). bean-check runs the plugin on the booked entry and opens nothing for it.
  • A plugin declared before it saw its opens. close_tree declared before auto_accounts drops the close of a never-opened account in beancount; together with fix(plugin): close_tree closes a tree by a parent that was never opened, as beancount does #3073 this now matches.

Semantic gate

The entries|extra-in-impl|open category (8 ledgers) is gone: 97.73% → 97.82%, no regression, manifest ratcheted. With #3073 applied too, entries|extra-in-impl|close (15) goes as well. I measured both together locally; nothing new appears.

Tests

  • test_auto_accounts_opens_nothing_for_a_transaction_booking_refuses (new; verified against bean-check 3.2.3).
  • auto_plugin_test's two existing tests expected 3 opens for a ledger whose third account is an elided zero posting. bean-check 3.2.3 opens 2, and they now say so.
  • Tests that looked the plugin up with find_synth use find_regular.
  • Passing: clippy (-D warnings, all features/targets); plugin, loader, validate, LSP, CLI (incl. upstream_checks_test), WASM, FFI (wasi, component, component-tests) and surface-parity suites; parse-error parity --check (no regressions); semantic gate --check after --update.

WASM cache v157 (open PRs hold v151–v156; renumber at merge if needed): a Ledger archives its processed directives. Loader cache unchanged (parsed directives).

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 17:04
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 42.9ms ± 2.5ms 598.4ms ± 6.0ms 14.0x 45.0 MB / 51.1 MB
investment 64.2ms ± 1.2ms 2170.4ms ± 10.3ms 33.8x 47.2 MB / 59.1 MB
fifo 64.1ms ± 0.7ms 12461.0ms ± 665.2ms 194.3x 49.0 MB / 58.7 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 41.9ms ± 0.3ms 42.9ms ± 2.5ms +2.4% ✅ within noise 45.1 MB → 45.0 MB (-0.2%)
investment 65.6ms ± 1.2ms 64.2ms ± 1.2ms -2.1% ✅ within noise 47.1 MB → 47.2 MB (+0.3%)
fifo 64.6ms ± 0.5ms 64.1ms ± 0.7ms -0.8% ✅ within noise 49.2 MB → 49.0 MB (-0.2%)

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

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.88889% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-loader/src/process.rs 98.71% 1 Missing ⚠️

📢 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%, 179 masked)
Full AST Match 100%
Total Files 828
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 and others added 2 commits November 27, 2026 18:53
…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]>
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]>
@robcohen
robcohen force-pushed the fix/auto-accounts-declared-order branch from 7ade281 to 98b6f33 Compare November 28, 2026 01:00
robcohen added a commit that referenced this pull request Nov 28, 2026
Restacked on #3075 (v157).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 28, 2026
Restacked on #3075: the STRICT total-match posting-order mismatches now match, no regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit e706ec1 into main Nov 28, 2026
70 of 71 checks passed
@robcohen
robcohen deleted the fix/auto-accounts-declared-order branch November 28, 2026 02:04
robcohen added a commit that referenced this pull request Nov 28, 2026
Restacked on #3075 (v157).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 28, 2026
Restacked on #3075: the STRICT total-match posting-order mismatches now match, no regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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