Repository navigation
fix(loader)!: keep an option's previous value when its new value is rejected, and refuse queries over a rejected booking_method - #2923
Merged
Conversation
…jected beancount 3.2.3's grammar.option returns on the converter's ValueError without assigning the option, so an invalid value is one error and has no other effect. rledger reported the error (E7008, E7002) and applied the value anyway: `option "name_equity" "capital"` renamed the equity root, and `open Equity:A` then failed with E1005. Every validating setter now rejects through one path (`Options::reject`) that reports the error and leaves the option at its default or an earlier valid setting: all five name_* roots, all seven account_* leaves (account_rounding included, without the E7007 no-effect notice for a value it did not take), booking_method (now case-sensitive, as beancount's Booking[...] lookup is), plugin_processing_mode, and the numeric and map options that already kept their value. A rejected value is not recorded in set_options, so it raises no E7003 or E7010 and cannot gate effective_booking_method. The WASM account_types_from_raw copied the raw name_* tuples itself; it now reads them through rustledger_loader::Options, so it cannot apply a root the loader rejected. Loader cache v68 and WASM cache v90: cached options and the WASM account-type names held the rejected value. Closes #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
An invalid `option "booking_method"` (E7002, for example the lowercase "fifo") keeps the previous method, as in beancount, so every lot reduction would be booked with a method the ledger did not ask for. `rledger query` and `rledger report` now refuse instead of printing those figures, with the existing refusal's exit code and a message naming the option, its value and its file:line. `check` is unchanged. This is a deliberate deviation: bean-query answers with the STRICT figures. The refusal is part of the one query rule. `Options` records the rejected booking_method (with its site, which the loader now passes via `set_scoped_at`) and exposes `query_refusal`; `Ledger::blocks_queries` is the whole rule (a blocking error, or that refusal), and `Ledger::query_refusal` gives it as a blocking `LedgerError` for surfaces that list only ledger errors. The CLI gate shared by query and report, the WASM `query`, `queryMultiFile`, `Ledger` and `ParsedLedger` (and the MCP server through WASM), and the FFI component's loads all apply it. The shared query_answer_rule cases gain an invalid, a valid booking_method and another rejected option, so every surface's drift guard pins it. Another rejected option keeps its default and answers. Refs #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #2908 (strict account validator; loader v66, WASM v87), #2919 and #2924. Keeps this branch at loader v68 / WASM v90 with one note per version, drops the merged warn_if_invalid_root (rejection now goes through check_root), and adds the issue's `A😀` root to the rejected-name tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… cases Round-1 review of #2923: - The FFI component's booking_method_from resolves through Options::effective_booking_method instead of parsing the wire string; WASM extract_options reads title and operating currencies through Options, so no surface reads a raw option value. - docs/reference/options.md: booking_method values are case-sensitive, as in beancount and as the open directive's booking method (P0025). - An end-to-end load test that `booking_method "fifo"` books STRICT with E7002 (and the ambiguous sale STRICT reports), and node tests that the WASM Ledger and ParsedLedger report the issue's `A😀` root as E7008 alone and refuse a query over an invalid booking_method. Refs #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 10, 2026
Brings in #2922. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r asks Round-2 review of #2923. The refusal recorded the first rejected booking_method and never cleared it, so `"fifo"` then `"FIFO"` booked FIFO yet refused. Now the last value wins: an accepted booking_method clears an earlier rejection, and a rejected value whose case-insensitive reading names the method actually booked (`FIFO` then `fifo`) does not refuse. `fifo` alone, `bogus`, and `FIFO` then `bogus` still refuse. `Options::query_refusal` takes the method booked, and the message names only the rejected value as wrong: `"<value>" is not a booking method (E7002); ... booked with <method>`. The three orderings join the shared query_answer_rule cases. In the FFI the refusal moves out of the load's `errors` into a separate `query_refusal`, listed on query results only, so `load`, `validate` and `info()` do not show it and a session still runs the host's plugins. A host-supplied `booking-method` the loader would reject is reported as a session error and replaced by STRICT. `query_refusal_error` sits above the `ledger_error_to_ffi` doc block. Refs #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng method as sent Round-3 review of #2923. - `bogus` then `FIFO` joins the shared query_answer_rule cases and the refusal unit test: `bogus` names no method, so only the clearing by a later accepted value lets it answer. Deleting that clearing now fails the loader, CLI, FFI and WASM tests; it passed them all before. - FFI `held_booking_method` no longer trims. Only the empty string is the default; the stored value is validated exactly as sent, so `"FIFO "` is rejected as the loader and beancount reject it, reported quoted as the host sent it, and replaced by STRICT. - `refused_errors` and `held_booking_method` move above the doc blocks they had split. - `Options::rejected_booking_method` and `bail_on_booking_errors` describe the round-2 rule; the CHANGELOG Breaking entry lists the new pub fields on exhaustive structs. Refs #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tch refusal Round-4 review of #2923: BATCH_REFUSED and its doc hold for a refusal by a rejected booking_method (whose reason follows it in each query, not in the load); errors.md scopes "the value is not applied" to the options beancount validates, naming the boolean exception (#2925), and gains an E7008 entry; the LedgerError::blocks_queries doc is rewrapped. Refs #2911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #2926 (loader v67, WASM v89). This branch stays at loader v68 and WASM v90 (pin 68), with one note per version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 10, 2026
Brings in #2926. WASM cache v91 (main holds v89, #2923 claims v90), loader pin 67. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 10, 2026
Brings in #2923. WASM cache v91 (main holds v90), loader pin 68. The held-options session keeps both checks: the tolerance multiplier and the booking method. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 changed
An option value that fails its check is now reported and not applied. The option keeps its default or an earlier valid setting, as in beancount 3.2.3, whose
grammar.optionreturns on the converter'sValueErrorwithout assigning the option.Options::set_innerapplies each value throughOptions::apply, which returns whether the value was accepted. Every validating arm rejects through one helper,Options::reject, which reports the error and leaves the field alone. This covers:name_*roots (E7008, viacheck_root);account_*leaves (E7002, viacheck_leaf):account_previous_balances,account_previous_earnings,account_previous_conversions,account_current_earnings,account_current_conversions,account_unrealized_gainsandaccount_rounding;booking_method;plugin_processing_mode;tolerance_multiplier,inferred_tolerance_default,display_precision,long_string_maxlines).is_valid_account_name_strict), merged from main.set_options. As a result it raises noE7003"last value wins" warning, which would be false because the rejected value did not win. It raises noE7010either, and it cannot gateeffective_booking_method.account_roundingis only theE7002. It no longer also raises theE7007no-effect notice for a value it did not take.booking_methodis checked case-sensitively, as beancount'sBooking[value]is and as anopendirective's booking method already is (P0025).fifoisE7002and keepsSTRICT; rledger used to book it asFIFOsilently. Documented indocs/reference/options.md.account_types_from_rawandextract_optionsnow read throughrustledger_loader::Options;booking_method_fromresolves throughOptions::effective_booking_method;ledger-options.booking-methodis that effective method.Invalid
booking_methodrefusesqueryandreportWhen the last
booking_methodvalue is rejected, the option keeps its previous method. If that is not the method the ledger asks for, every lot reduction would be booked with a method the ledger did not ask for, andrledger queryandrledger reportnow refuse instead of printing those figures. They exit 1, the existing refusal's code, with:checkis unchanged: it reports theE7002and the STRICT booking's findings, as bean-check does.This is a deliberate Python deviation, commented at
Options::query_refusal. bean-query answers with the kept method's figures; we refuse because they would silently use a booking method the user did not ask for. Onlybooking_methodtriggers this refusal; any other rejected option keeps its default and answers.The refusal is part of the one query rule (#2861, #2881):
Optionsrecords the rejectedbooking_methodwith its site. The loader now passes the site throughOptions::set_scoped_at.Options::query_refusal(booked_with)exposes it, only when the ledger is booked with a method other than the one the last value asks for (see Review round 2).Ledger::blocks_queriesis the whole rule: a blockingLedgerError, or that refusal.Ledger::query_refusalreturns the refusal as aLedgerErrorfor whichLedgerError::blocks_queriesholds, for surfaces that list only ledger errors.Detection reads the rejected option itself, never message text.
Surfaces that go through it:
queryandreport: viabail_on_booking_errors, the gate both share.query,queryMultiFile,Ledger,ParsedLedger: viaload_and_book/Ledger::blocks_queries.queryMultiFileandqueryWithHostappend the refusal reason;query(source),LedgerandParsedLedgerlist the plain optionE7002.queryandParsedLedger.query,batch,query-file,batch-file, sessions):ffi-wasi's loads carry the refusal in a separatequery_refusalfield, whichLoadResult::blocks_queriesand the session'squery_blockedread. It is listed on query results only, never among the load'serrors, soload,validateandinfo()are unchanged and the session plugins still run. The batch refusal text names it, and a refused batch lists the reason beside it.The shared
query_answer_rulecases gain seven cases, so every surface's drift guard pins them (loader, CLI, FFI and WASM):booking_method(refuses);FIFO(answers);account_rounding(answers);fifothenFIFO(answers);FIFOthenfifo(answers);FIFOthenbogus(refuses);bogusthenFIFO(answers; only the clearing by the later accepted value lets it).Mutation checks:
Options::query_refusalreturnNonefails the loader rule test, the CLI rule test and both new CLI refusal tests.self.rejected_booking_method = None;in thebooking_methodarm passed every test before round 3. It now fails the loader unit test and the shared rule tests on every surface (see Review round 3).No BQL compat corpus file has an invalid
booking_method: the fetched corpus holds onlyFIFO,NONEandSTRICT. So nothing is registered underKNOWN_RUST_DIVERGENCES.Review round 2
"fifo"then"FIFO"booked FIFO yet refused "with FIFO rather than the method the ledger asks for". Now:booking_methodclears an earlier rejection (last wins);FIFOthenfifobooks FIFO);fifoalone,bogus,FIFOthenbogus).Options::query_refusaltakes the method booked (Ledger::booking_method), so the comparison sees the effective method, including an embedder's default.option "booking_method" at <file>:<line>: "<bad value>" is not a booking method (E7002); refusing to derive figures, which would be booked with <effective>.errorsintoquery_refusal(above):SessionState::from_fileno longer gates the host's session plugins on it, pinned bytest_from_file_invalid_booking_method_refuses_queries_only, which runscheck_commodityas a session plugin;load(),validate()andinfo()no longer show the refusal text.E7002for it, as on main.booking-methodthe loader would reject (from-entries-with-options, for example lowercasefifo) is reported as a session error and replaced bySTRICT, whichinfo()echoes, the way fix(validate)!: pad parents, sub-accounts, tolerances and cost lots as beancount does #2920 reports an unparsable tolerance multiplier. An empty value is the default, with no error. Pinned bytest_from_entries_with_options_reports_an_invalid_booking_method.ffi-wasi, the misplacedpush_query_refusalis replaced byquery_refusal_error, which sits above theledger_error_to_ffidoc block, so each function keeps its own doc.docs/commands/query.md,docs/commands/report.md,docs/reference/options.mdand the CHANGELOG Breaking entry describe the last-wins rule.Review round 3
bogusthenFIFO(must answer) joinsQUERY_RULE_CASESandtest_query_refusal_only_when_booking_differs_from_the_request.bogusnames no method, so only the clearing by the later accepted value lets it answer. Deletingself.rejected_booking_method = None;now fails tests on every surface: the loader unit test andtest_blocks_queries_gives_each_case_its_answer, the CLItest_query_answers_or_refuses_by_the_shared_rule, both FFI shared-rule tests (source and file), and both WASM shared-rule tests (wasm-pack test --node). Before this round every test passed.held_booking_methodno longer trims. Only the empty string is the default. The value is validated exactly as stored, through the loader'sOptions, which rejects"FIFO "as beancount does. A rejected value is reported quoted as the host sent it and replaced bySTRICT, soinfo()and the booking agree. Tests cover lowercase, a trailing space and a leading space.refused_errorsandheld_booking_methodnow sit above the doc blocks ofwith_load_errorsandsanitize_options. A scan of the whole diff for an insertion between a doc comment and its item finds no other.Options::rejected_booking_methodis documented as the latest rejection, cleared by a later accepted value.bail_on_booking_errors(doc and# Errors) states the round-2 rule, and says bean-query answers with the kept method.#[non_exhaustive]:Options::rejected_booking_method,cache::CachedOptions::rejected_booking_method, andrustledger_ffi_wasi::helpers::{LoadResult, FileLoad}::query_refusal.Caches
CachedOptionsgainsrejected_booking_method, so a cache hit still refuses. NoCostNumberorMetaValueencoding moved, so those byte and layout fixtures stand, and only theirFIXTURE_VERSIONadvances.query_refusedis now set for a rejectedbooking_method.Before / after against bean-check 3.2.3
Error counts.
E7003is a warning and is not counted.name_equity "A😀"+open Equity:A(issue example)E1005; root accepted before #2908)E7008)name_equity "capital"+open Equity:AE7008,E1005)E7008)name_assets ""E7008,E1005)name_income "revenue"(lowercase)name_expenses "Exp:Sub"name_income "Assets"(collides with a root)Invalid account name: Income:A)E1005)E1005), rename applied in all threename_equity "Capital"then"bad", opensCapital:A,Equity:BEquity:B); keepsCapitalE7008,E1005x2)E7008,E1005onEquity:B)name_equity "bad"then"Capital"CapitalE7003warning)account_*options ="bad:leaf"account_rounding2 (E7002,E7007)account_current_conversions ""account_previous_balances "Anfang"then"x"Anfangx(+E7003)Anfangaccount_previous_balances "x"then"Anfang"AnfangE7003)Anfangbooking_method "FIFO"then"XYZ"FIFOXYZ(so bookedSTRICT)FIFObooking_method "fifo"+ an ambiguous saleAmbiguous matches); STRICTFIFOE7002,E4003); STRICT;query/reportrefuseplugin_processing_mode "default"then"bogus"defaultbogusdefaulttolerance_multiplier "0.6"then"abc"0.6E7003);0.60.6inferred_tolerance_default "USD:abc"/display_precision "USD"Out of scope, tracked in #2925: beancount's boolean options have no rejecting converter (any other word reads as false, with no error). rledger still reports
E7002for an unrecognizedrender_commas/infer_tolerance_from_costword while setting the samefalse. #2925 also covers the tolerance and included-file option differences.How to test
New tests:
options.rs:test_set_invalid_name_option_keeps_default(includesA😀)test_set_invalid_name_option_keeps_earlier_valid_valuetest_set_name_option_colliding_root_is_appliedtest_set_invalid_account_option_keeps_defaulttest_set_invalid_account_option_keeps_earlier_valid_valuetest_set_two_valid_values_still_warn_duplicatetest_set_invalid_booking_method_keeps_earlier_valuetest_set_invalid_plugin_processing_mode_keeps_earlier_valuetest_set_invalid_numeric_option_keeps_earlier_valuetest_query_refusal_only_when_booking_differs_from_the_requestrustledger-loader/tests/invalid_option_keeps_default_test.rs(full pipeline):test_load_invalid_name_option_keeps_default_root(issue'sA😀andcapital)test_load_invalid_name_option_keeps_earlier_valid_roottest_load_invalid_account_option_keeps_earlier_valid_leaftest_load_lowercase_booking_method_books_strictrustledger/tests/invalid_booking_method_refusal_test.rs:test_query_invalid_booking_method_refusestest_report_invalid_booking_method_refusestest_query_and_report_valid_booking_method_answertest_query_and_report_other_rejected_option_answersrustledger-wasm/tests/wasm_invalid_option.rs(node):Ledger/ParsedLedgererror lists for the issue's case (E7008alone)test_account_types_from_raw_rejected_root_keeps_earlier_value.query_answer_rulecases.test_from_entries_with_options_reports_an_invalid_booking_method(lowercase, trailing and leading space),test_from_file_invalid_booking_method_refuses_queries_only.Gates run:
-D warnings,cargo doc -Dwarnings;rustledger-loader,rustledger,-ffi-wasi,-ffi-component,-wasm,-lsp,-validate,-parser,-plugin;The parser corpus baselines are unaffected because the changes are loader-side.
Closes #2911
🤖 Generated with Claude Code