Repository navigation
fix(loader): run a plugin declared in more than one file once, from its first file in breadth-first include order - #3042
Merged
Conversation
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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ts first file in breadth-first include order rledger runs the plugins of included files (bean-check 3.2.3 ignores them), so a plugin declared in the main file and again in an include ran once per declaration: a plugin that adds entries (implicit_prices) added them twice, and check_commodity reported each error twice. - New canonical `rustledger_loader::plugins_in_run_order`: the declarations in beancount's breadth-first file order (`SourceMap::parse_ranks`), each distinct (name as written, config) pair run from the first file that declares it only. A repeat within that one file still runs as written, as beancount runs a top-level file's repeat, so a single-file ledger runs what bean-check runs. Both deviations are documented there and at the dispatch site. - `run_plugins` applies it, so `rledger check`/`process`, the WASM `Ledger`, ffi-wasi/component and the LSP (which runs a view's declarations) all share it; the FFI's reported plugin list and the split/merge equivalence fingerprint use it too. `LoadResult::plugins` / `Ledger::plugins` keep every declaration, as the LSP's view rebuilding needs them. - The plugins of nested includes now run breadth first as well. - The loader cache restored every plugin as file 0, so a hit would have run an included repeat; `CachedPlugin` gains `file_id` (loader CACHE_VERSION 78 -> 79), WASM pin 79 and WASM CACHE_VERSION 137 -> 138 (the `Ledger` archives plugin output). - Tests: loader unit + integration (non-idempotent implicit_prices and check_commodity, nested includes, different config, one-file repeat, breadth-first rename order), drift guards across process, WASM `Ledger` (and restored), ffi-wasi, the LSP (current-file and multi-file paths), and the CLI cold and on a cache hit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/dedup-repeated-plugins
branch
from
November 26, 2026 06:33
7de2417 to
98c150d
Compare
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
When the same plugin is declared in more than one file of a ledger (the main file and its includes), rledger now runs each
(name, config)pair once, from the first file that declares it in beancount's breadth-first include order (SourceMap::parse_ranks, #3037). The same name with a different config is a different plugin and still runs.Why
bean-check 3.2.3 ignores
plugindirectives in included files. rledger runs them on purpose (so a sub-ledger that declaresauto_accountsfor itself still works when included), and that is kept. But a plugin declared in both main and an include ran once per declaration. That is harmless for idempotent plugins and wrong for plugins that add entries:implicit_pricesadded two identicalprices, andcheck_commodityreported each error twice.How
rustledger_loader::plugins_in_run_order(plugins, source_map). It sorts the declarations by breadth-first file rank (each file's own declarations stay in order) and runs each pair only from its first file. The deviations from Python are documented there and at the dispatch site, per the Python Compatibility Policy.run_pluginsapplies it. So every surface runs the same list:rledger checkand everything that callsprocess, the WASMLedger, ffi-wasi and the FFI component, and the LSP (which callsrun_pluginson a view's declarations). The FFI's reportedpluginslist and thesplit/mergeequivalence fingerprint also use it.LoadResult::pluginsandLedger::pluginsstill hold every declaration in file-id order. The LSP'sview_pluginsneeds the full list: a buffer can delete the first of two declarations, and the second must then run.mainincludesxtheny, andxincludesz.y's plugins now run beforez's; they used to run after. This matters for chainedrename_accounts.Decision taken: a repeat within one file still runs as written
The rule dedupes across files, not inside a file. beancount runs every declaration in the top-level file, including a repeat, and
plugin_conformance::python_plugins_back_to_back_after_a_timeoutrelies on that (it declaresnap.pytwice in one file). A stricter "once everywhere" rule would make single-file ledgers differ from bean-check. If the maintainer wants a repeat inside one file collapsed too, it is a one-line change inplugins_in_run_order, plus that test.Cache
file_id: 0, so a cache hit would have treated a repeat from an include as a repeat within one file and run it twice. The CLI test caught this.CachedPlugingainsfile_id: u16(this is a breaking change to a public struct; see CHANGELOG). LoaderCACHE_VERSIONgoes from 78 to 79, and the WASM pin moves to 79.CACHE_VERSIONgoes from 137 to 138, because theLedgerpayload stores plugin output.Tests
plugins_in_run_order: breadth-first order, first file wins, repeat within one file kept, a different config or thepython:prefix counts as a different plugin.crates/rustledger-loader/tests/repeated_plugins_test.rs, using non-idempotent plugins (implicit_prices,check_commodity). Cases: main + include, nested and sibling includes, plugin declared only in an include, different config, repeat within one file, and breadth-first order shown with chainedrename_accounts.process, the multi-fileLedgerand the restoredLedger, and ffi-wasiload_file_with_fs(directives, errors and the reported plugin list).all_diagnosticswith each file open, andledger_diagnostics_multiwith every file in the view.rledger checkcold and on a cache hit.How to test locally:
cargo test --all-features -p rustledger-loader -p rustledger-wasm -p rustledger-lsp -p rustledger -p rustledger-ffi-wasi🤖 Generated with Claude Code