Skip to content

fix(lsp): skip WASM and Python plugins in every build, as E8006 says - #2496

Merged
robcohen merged 4 commits into
mainfrom
fix/lsp-native-plugins-only-2486
Oct 8, 2026
Merged

robcohen merged 4 commits into
mainfrom
fix/lsp-native-plugins-only-2486

Conversation

@robcohen

@robcohen robcohen commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What

The LSP reports each WASM or Python plugin as skipped (E8006, "skipped in LSP"). That was only true when it was built alone:

$ cargo tree -p rustledger-lsp -i rustledger-loader -e features              # LSP alone
  cache, default, full, plugins, validation
$ cargo tree -p rustledger-lsp -p rustledger -i rustledger-loader -e features   # with the CLI
  cache, default, full, plugins, python-plugin-wasm, python-plugins, rustledger-plugin, validation, wasm-plugins

(re-checked on this branch.) A plain workspace cargo build/cargo install or the flake's package therefore gave the LSP both runtimes. Its LoadOptions::default() then resolved and ran those plugins on every reload. Built alone, the same plugins produced a spurious WASM plugin 'x' requires the wasm-plugins feature / E8005 error next to the E8006 note.

This implements option 1 from the issue.

  • LoadOptions::native_plugins_only (default false). When it is set, run_plugins skips WASM and Python references before resolution, so the outcome cannot depend on which runtimes were compiled in. A name that is neither native nor WASM/Python shaped (e.g. a misspelled native plugin) is still reported as E8001 "Plugin not found", the same in every build. The classification is the new rustledger_plugin::classify_external_plugin, which resolve_plugin itself now uses.
  • The LSP uses it everywhere it loads: both plugin passes in diagnostics.rs and the journal load in ledger_state.rs, through one lsp_load_options().
  • E8006 appears only on real WASM/Python references. It now also flags a python:-prefixed plugin (shown with its prefix), which is forced onto the Python runtime and so is skipped too. An unknown name no longer gets a misleading "Python plugin" E8006.
  • docs/development/lsp-support.md explains the skip, and the CHANGELOG has a ### Breaking entry. LoadOptions is not #[non_exhaustive], so a struct literal must set the field, as with plugin_max_time_secs in Plugins and importers: let the host configure the sandbox time budget #2484. Every in-repo literal uses ..Default::default() or was updated.

Tested

See the review comment for the all-shapes tests added in e8280d1. Original verification:

  • loader_test.rs::native_plugins_only_skips_wasm_and_python_plugins_2486: a ledger with auto_accounts, a garbage bad.wasm, bad_plugin.py and python:noduplicates. In native-only mode there are no errors at all, and auto_accounts still runs (no E1001). The default-options control reports bad.wasm, so the assertion is not vacuous.
  • diagnostics.rs::non_native_plugins_are_skipped_whatever_the_build_2486: all_diagnostics returns only the two E8006 notes, and LedgerState::load records no plugin-phase error.
  • Both pass with the runtimes compiled in (cargo test -p rustledger-lsp --features rustledger-loader/wasm-plugins,rustledger-loader/python-plugins, -p rustledger-loader --all-features) and without them.
  • Fail without the fix, in both builds. With the LSP option reverted, the test fails on WASM plugin /tmp/bad.wasm failed: failed to load (runtime compiled in) or requires the wasm-plugins feature (alone), plus E8004 for python:auto_accounts. With the dispatch skip disabled, the loader test fails the same way.
  • cargo test --all-features: rustledger-loader 254 passed, rustledger-lsp 346 passed. Workspace clippy --all-features --all-targets -D warnings is clean, and so is cargo doc -D warnings for both crates.

Closes #2486

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

The LSP tells the user (E8006) that it skips WASM and Python plugins.
That held only when it was built alone. Built with the CLI (a plain
workspace cargo build, or the flake's package), Cargo feature
unification turns on rustledger-loader's wasm-plugins and
python-plugins, and the LSP's LoadOptions::default() then resolved and
ran those plugins on every reload. Built alone, the same plugins
produced a "requires the wasm-plugins feature" / E8005 error next to
the E8006 note.

LoadOptions gains `native_plugins_only`. When set, run_plugins skips
every invocation that would not resolve to a native plugin (the same
registry lookup resolve_plugin tries first, plus python: forcing),
before resolution, so the outcome cannot depend on what was compiled
in. The LSP uses it for both its plugin passes and its journal load
(`lsp_load_options`). E8006 now also flags a `python:`-prefixed plugin,
which is skipped too.

Verified that features unify (`cargo tree -p rustledger-lsp -p
rustledger -i rustledger-loader -e features` lists wasm-plugins and
python-plugins; the LSP alone does not). New tests in the loader and
the LSP pass with and without the runtimes compiled in, and fail
without the fix in both builds: a load error for bad.wasm ("failed to
load" with the runtime, "requires the wasm-plugins feature" without)
and an E8004 for python:auto_accounts.

Closes #2486

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

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.2ms ± 2.1ms 831.9ms ± 4.3ms 18.4x 51.0 MB / 50.0 MB
investment 70.6ms ± 1.4ms 3071.5ms ± 15.9ms 43.5x 55.3 MB / 58.0 MB
fifo 67.0ms ± 0.7ms 15589.3ms ± 69.8ms 232.5x 55.2 MB / 58.0 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 44.4ms ± 0.3ms 45.2ms ± 2.1ms +1.8% ✅ within noise 51.0 MB → 51.0 MB (+0.1%)
investment 69.6ms ± 1.7ms 70.6ms ± 1.4ms +1.4% ✅ within noise 55.2 MB → 55.3 MB (+0.3%)
fifo 67.9ms ± 1.2ms 67.0ms ± 0.7ms -1.2% ✅ within noise 55.1 MB → 55.2 MB (+0.1%)

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

github-actions Bot commented Oct 7, 2026 •

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 817
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 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Review follow-up for #2486. The first version of native_plugins_only
skipped every non-native name, so a misspelled native plugin
(`autoaccounts`) lost its E8001 in the LSP and E8006 called it a
skipped "Python plugin".

rustledger_plugin::classify_external_plugin now holds the WASM / Python
/ unknown classification that resolve_plugin applies after its native
lookup (resolve_plugin uses it, unchanged in behavior). In native-only
mode the loader skips WASM and Python references and reports an unknown
name as E8001 "Plugin not found", without consulting system Python, so
it is identical in every build. The LSP emits E8006 only for real
WASM/Python references, and writes a `python:` reference with its
prefix.

Tests cover every shape (native, typo, relative/absolute/missing .wasm,
.py, ./path, dotted module, python:native and python:mod) in the loader
and the LSP, with and without the runtimes compiled in. They fail both
with the previous head's skip-everything behavior and with no
native-only mode at all.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

robcohen commented Oct 8, 2026 •

Copy link
Copy Markdown
Member Author

Review (adversarial pass)

Found and fixed in e8280d1: unknown names lost E8001. The first head skipped every non-native name in native-only mode. So a misspelled native plugin (plugin "autoaccounts") got no E8001 in the LSP, and E8006 called it a skipped "Python plugin". Main reports it as E8001 (alongside the misleading E8006).

The fix:

  • rustledger_plugin::classify_external_plugin(name, force_python) -> ExternalPluginKind { Wasm, Python, Unknown } is the text-only classification resolve_plugin applies after its native lookup. resolve_plugin now calls it, with the same order as before: .wasm first, then python: / .py / path separator / ..
  • In native-only mode the loader skips Wasm and Python references. An Unknown name gets E8001 Plugin not found: "<name>" without consulting system Python, so the result is the same in every build.
  • LSP E8006 is emitted only for Wasm/Python. A python: reference is shown with its prefix (python:auto_accounts), not as the bare native name.

Tests: every shape, both builds. The shapes are native auto_accounts, the typo autoaccounts, bad.wasm (garbage, exists), missing.wasm, /nonexistent/dir/plug.wasm, bad_plugin.py, missing.py, /nonexistent/dir/plug.py, ./plugins/myplug, pkg.module, python:auto_accounts / python:noduplicates, and python:some_mod.

  • The loader test asserts the error list is exactly [E8001 autoaccounts]. The LSP test asserts the exact E8006 set, that the only other diagnostic is that E8001 (no E1001, so auto_accounts ran), and the same plugin errors from LedgerState::load.
  • Both pass on -p rustledger-loader (default and --all-features) and on -p rustledger-lsp (alone and with --features rustledger-loader/wasm-plugins,rustledger-loader/python-plugins).
  • Fail without the fix, in all four builds: with the previous head's skip-everything behavior, and with no native-only mode at all (main).
  • Suites with --all-features: plugin 370, loader 254, LSP 346 passed. Workspace clippy and cargo doc -D warnings are clean. All runs used a per-worktree target dir.

Other LoadOptions consumers, checked; none should set the flag.

  • rustledger CLI (check/query/report/lint): runs WASM/Python plugins by design.
  • rustledger-wasm (and the MCP server, which runs on it), rustledger-ffi-wasi, rustledger-ffi-component: they ship as wasm32 artifacts, where wasmtime (and so wasm-runtime/python-plugins) cannot be compiled in, so their behavior cannot depend on feature unification. They tell the user a WASM/Python plugin can't run through the existing "requires the … feature" / E8005 error. Setting the flag there would turn that into silent skipping, because they have no E8006 equivalent.
  • price_cmd, extract duplicate/ledger-profile: already run_plugins: false.
  • Test, bench and example loads: not product surfaces.

Second pass

CLI parity: rledger check resolves every reference shape as main does. I built main (184e9d1) and this branch into separate target dirs. I ran rledger check --no-cache on one ledger per shape and diffed the full stdout and stderr plus the exit code. The 23 shapes:

  • native auto_accounts / noduplicates, and the typo autoaccounts
  • .wasm: bad.wasm (garbage), missing.wasm, /nonexistent/dir/plug.wasm, BAD.WASM
  • .py: missing.py, good.py (a real plugin), MISSING.PY, /nonexistent/dir/plug.py
  • ./plugins/myplug, pkg.module
  • python:auto_accounts, python:some_mod, python:good.py, python:./plugins/x.py
  • an existing directory plugdir and plugdir/
  • my.pkg/sub.mod, C:\plugins\x.wasm, plugins\myplug, beancount.plugins.auto_accounts

21 of 23 are byte-identical. The other two are the cases that actually run good.py. On both binaries they fail with the same E8002 wasm trap: all fuel consumed by WebAssembly, and differ only in the wasm backtrace frames. Main's own output differs between two runs of the same binary, so the frames are run-to-run noise, not a resolution difference. With the frames stripped, both files are identical.

Side finding on main, not this PR: a trivial Python plugin runs out of fuel there. I'll propose it as a separate issue.

API. classify_external_plugin must be pub, because rustledger-loader and rustledger-lsp call it from other crates.

  • It sits next to resolve_plugin, is #[must_use], and its docs now say the extension test ignores case and the separator test uses the host's separator. That is unchanged: resolve_plugin has always used MAIN_SEPARATOR, so plugins\myplug is a Unknown name on Unix and a path on Windows, on main and here.
  • ExternalPluginKind is deliberately not #[non_exhaustive]. A caller has to decide per kind whether to skip or report, so a new kind should break its build rather than fall into a wildcard arm.
  • 35eded1 adds classify_tests::every_reference_shape, which pins .wasm before python:, uppercase extensions, the host separator, dotted names, python: forcing and bare unknowns. Swapping the order to check python: before .wasm makes it fail. rustledger-plugin --all-features: 371 passed.

Cross-PR (test merge). I merged this branch onto origin/main in a scratch worktree with its own target, then #2490, #2495, #2498, #2491, #2488 and #2487. There are no code conflicts. The only conflicts are in CHANGELOG.md, where each PR inserts an entry at the top of the same section:

The resolution is to keep both entries. Each of those PRs merges cleanly against main alone, so whichever lands second needs that one-line resolution. Semantically:

Merge order does not matter for correctness.

Third pass (code quality)

  • Found and fixed in 0511578: one implementation of "native". The native lookup existed three times: in resolve_plugin, as a copy in the loader (is_native), and as a pass-agnostic variant (!force_python && registry.has) in the LSP's E8006 path. All three now call rustledger_plugin::find_native_plugin(name, force_python, pass, registry). That function is resolve_plugin's first step, is pub and #[must_use], and is documented. The LSP doesn't know a plugin's pass, so it asks for both passes.
  • One implementation of the WASM/Python/unknown rule. classify_external_plugin is called by resolve_plugin, by the loader's native-only branch and by the LSP's E8006 path; nothing mirrors it. The .wasm/.py/separator logic now appears only inside it.
  • Unknown names. They are reported through the existing resolve_error_to_ledger(NotFound), so the E8001 wording has one source too.
  • Behavior is unchanged. The LSP runs WASM and Python plugins it says it skips, when built with the CLI #2486 loader and LSP tests pass with and without the runtimes compiled in. Suites with --all-features: plugin 371, loader 254, LSP 346. Workspace clippy is clean, and clippy::pedantic reports nothing on any line this PR adds.
  • Docs. The #[non_exhaustive] rationale is now in ExternalPluginKind's doc instead of a loose comment. The CHANGELOG names both shared functions. lsp-support.md no longer claims rledger check always says E8001 for an unknown name; the CLI can say E8004 when system Python finds a module of that name.

Review follow-up for #2486. resolve_plugin now delegates to
classify_external_plugin, so pin the classification it used inline
before: .wasm before python:, case-insensitive extensions, the host's
path separator, dotted module names, python:-forced names, and bare
unknown names. Mutating the order (python: before .wasm) fails it.

Document that the separator test is the host's, and why the enum is
deliberately not #[non_exhaustive]: callers decide per kind whether to
skip or report, so a new kind must break their build.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review follow-up for #2486. The native lookup lived in three places:
resolve_plugin, a mirror of it in the loader (is_native), and a
pass-agnostic variant in the LSP's E8006 path. All three now call
rustledger_plugin::find_native_plugin, the first step of resolve_plugin,
so the definition of "native" exists once, as the external
classification already does. Behavior is unchanged: the #2486 loader
and LSP tests pass in both feature builds, and plugin 371 / loader 254
/ LSP 346 tests pass.

Also folds the non_exhaustive rationale into the enum's doc, and makes
the CHANGELOG and LSP docs name the shared functions and stop claiming
the CLI always says E8001 for an unknown name (it can say E8004 when
system Python finds a module of that name).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
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.

LSP runs WASM and Python plugins it says it skips, when built with the CLI

1 participant