Repository navigation
feat(plugin): let the host set the WASM plugin and importer time budget - #2485
Conversation
Every WASM plugin and importer call got a fixed 30-second budget, and no user setting reached it: the CLI, the loader's `plugin` directives and `importers.toml` all used the defaults. - rledger config: `[plugins] max_time_secs`, merged across the system, user and project files like every other section. A misspelled key is an error, not a silent fall back to 30 seconds. - A global `--plugin-max-time-secs <SECS>` overrides it for one run. `rledger` sets it once at startup (`rustledger::plugin_budget`), so every command reads the same value: `plugin` directives in check, query, report and lint, `check --plugin`, and extract's importers. ag-rledger takes it from the config file. - Library: `LoadOptions::plugin_max_time_secs` (None keeps the default) reaches dispatch through the new `ResolvedPlugin::run_with_max_time_secs`; `ImporterRegistry` gained `register_wasm_from_path_with_config` and `register_wasm_dir_with_config`. Existing methods are unchanged. - `WasmImporterError::Runtime` prints its cause chain, so an importer's fuel trap says `all fuel consumed by WebAssembly`. The budget is the host's, never the ledger's: a ledger that could raise it would let its author spend unbounded CPU on any service that loads it. Python plugins keep their own fixed budget. Tests run a plugin (and an importer) that burns 3-4G fuel: within the default 30 s, trapped at 1 s. They cover dispatch, the importer registry, and the binary (flag, config file, flag over config, and `query`). Each was shown to fail with the wiring removed. Closes #2484 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
📊 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?
|
…econd The sandbox floors a budget at one second, so `max_time_secs = 0` or `--plugin-max-time-secs 0` quietly meant one second, where many tools read zero as "no limit". The config field is now `NonZeroU64`, so the file fails to parse and names itself; the flag takes `1..`. Also drops an intra-doc link to `crate::sandbox` from `run_with_max_time_secs`, which broke rustdoc without `wasm-runtime`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Deep reviewCoverage of the setting. I checked every way a command can reach a WASM plugin or importer:
Fixed in 9238302.
Checked and fine:
Second passFixed in a747b94. The trust boundary is "not the beancount file", not "not the ledger's repository". A project Checked and fine: Third pass (independent reviewer + me)Fixed in c272351:
Moved to #2486: the LSP point from this pass was confirmed in pass 4. Details below. 1759 tests pass across plugin, importer, loader and CLI, and workspace clippy is clean. Fourth passConfirmed and filed as #2486 (older than this PR, out of scope). When the LSP is built together with the CLI, its loader gets Checked and fine: No open findings in this PR. |
The project config is found from the working directory, so running rledger inside someone else's repository applies their `max_time_secs` (as it already applies their aliases and default file). Nothing in a beancount file can raise it; the docs now say where the boundary actually is. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
… is a bound - Alias expansion took the first non-flag argument as the command and knew only `-P`/`--profile` take a value, so `rledger --plugin-max-time-secs 120 <alias>` read `120` as the command and clap rejected the alias. Value-taking global flags are now one list (`GLOBAL_VALUE_FLAGS`), with a test. - "Seconds of CPU" overstated the budget 5-20x: fuel is converted at a deliberately low 1G/s, so a call never outlasts its budget and most code runs out much sooner. The flag help, config template and docs now call it a time budget and an upper bound. - The no-trap tests assert the plugin ran to completion (its empty output's decode error), not only that it did not trap. - `PluginsConfig` is `#[non_exhaustive]`; the CHANGELOG names `Config`'s new `plugins` field as breaking for struct literals, and scopes the flag and the misspelled-key/zero errors to `rledger` (`ag-rledger` has no flag and ignores a config that fails to load). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Summary
Lets whoever runs rustledger set the CPU budget for WASM plugins and importers. Until now every call got a fixed 30 seconds, and no user setting reached it.
rledger --plugin-max-time-secs 120 check ledger.beancount # overrides the config for one runIt applies to:
plugindirectives incheck,query,reportandlint;check --plugin;extract's WASM importers.Defaults are unchanged.
Host-side only, deliberately
The budget is never set from the ledger. A ledger that could raise its own plugins' budget would let its author spend unbounded CPU on any service that loads it: hosted rustfava, a server, CI checking contributed ledgers. A ledger-level setting would also need syntax beancount rejects (#2484 has the reasoning).
Type of change
LoadOptionsfield)Changes
config.rs): new[plugins]section,PluginsConfig { max_time_secs }.[price], so project config overrides user, which overrides system.deny_unknown_fields, so a misspelled key is an error, not a silent 30 s.NonZeroU64) and the flag (range(1..)). The sandbox floors budgets at 1 s, so 0 would otherwise quietly mean one second.rledger.rs,plugin_budget.rs):--plugin-max-time-secsoverrides the config.rledgersets the value once at startup inrustledger::plugin_budget, and every command reads it from there.ag-rledgertakes it from the config file.LoadOptions::plugin_max_time_secs: Option<u64>.ResolvedPlugin::run_with_max_time_secs;rundelegates withNone.ImporterRegistry::register_wasm_from_path_with_config/register_wasm_dir_with_config.WasmImporterError::Runtimenow prints its cause chain ({0:#}), so a fuel trap readsall fuel consumed by WebAssembly, as fix: grant WASM plugins the 30 seconds of fuel their time budget promises #2449 did for plugins.Not covered: Python plugins keep
PYTHON_FUEL, which still needs re-measuring, and the LSP never runs WASM plugins.Testing
The tests use a plugin (and an importer) that burns 3–4G fuel, measured by bracketing the budget. That is within the default 30 s and trapped at 1 s, independent of host speed.
dispatch::tests::wasm_plugin_runs_under_the_host_time_budget: default, 1 s and 60 s.wasm::tests::registry_loads_importers_under_the_host_time_budget: both registry methods.tests/plugin_time_budget.rs, through the binary:query.cargo testacross plugin, importer, loader and CLI: 1758 passed, 0 failed.cargo clippy --workspace --all-features --all-targets -D warningsis clean, as are the feature-gated builds of the plugin, loader, importer and CLI crates.cargo doc -D warningsis clean.Closes #2484
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr