Skip to content

fix: validate after a parse error on every surface, as rledger check does - #2952

Merged
robcohen merged 16 commits into
mainfrom
fix/validate-after-parse-error
Nov 12, 2026
Merged

robcohen merged 16 commits into
mainfrom
fix/validate-after-parse-error

Conversation

@robcohen

@robcohen robcohen commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What changed

rledger check and bean-check 3.2.3 report a syntax error and still validate the entries that did parse. WASM (validateSource, ParsedLedger, validateMultiFile, validateWithHost), the FFI component (validate, load) and the LSP validated nothing once a file failed to parse, so one bad line hid every other finding (#2949).

bean-check 3.2.3 on one bad line (garbage, line 8) plus an unbalanced transaction (line 4) and a failing balance (line 10) reports all three:

c.beancount:8: Invalid token: 'garbage'
c.beancount:10: Balance failed for 'Assets:Bank': expected 0 USD != accumulated 100 USD (100 too much)
c.beancount:4: Transaction does not balance: (10 USD)

rledger check reports P0012 at line 8, E3001 at line 4 (residual 10 USD) and E2001 at line 10 (got 100 USD). After this PR every surface reports exactly those three.

Each surface now follows the rule of the validating loader (process): no load error stops validation. Each gate is removed rather than replaced, and each surface reaches validation through the code it already shares.

  • WASM single-source (load_and_book, under validateSource and ParsedLedger): the early return on a parse error is gone. The loader keeps what parsed, process books it, and run_validation validates it. The parse errors are still reported one by one with their code, line and span.
  • WASM multi-file (validateMultiFile / validateWithHost): these stopped on any load error except a duplicate include, an include cycle or an empty glob, so an unreadable include (an I/O error) also stopped validation. They now do what check does: report every load error, then run process with those errors cleared. bean-check also validates after a missing include. load_error_is_fatal is gone.
  • Parse errors one by one: the new rustledger_loader::LoadResult::take_parse_errors takes the parse errors out of a load, so a surface reports each one with its code and line. Left in, process folds them into a single parse errors in <path> with no line. Three paths use it: WASM single-source, Ledger.fromFiles (which already validated but reported that folded error) and the FFI string load (ffi-wasi load_source). Whether a query refuses still comes from LoadError::blocks_queries on what was taken out.
  • FFI component: semantic_validation_errors drops its phase == "parse" gate (3 lines). The rest of the FFI change is in ffi-wasi load_source and a few comments that described the old gate. It is kept small because fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 also touches these files.
  • LSP: validation_would_run keeps only the size cap. The code lens follows it, so the balance lens shows a verdict after a parse error, because one was now computed. In a multi-file ledger the published buffer's own diagnostics come from its text and its own plugin lines, parse error or not, so they are what check reports for that text, with one caveat: the set and order of the files come from the LSP's last load, so an added, removed, changed or reordered include line takes effect on the next load (pre-existing); the order matters as plugins run file by file in it. Every other file is validated with each open buffer's last text that parsed cleanly, directives and plugin lines (fix(lsp): validate multi-file ledgers once, not once per file (#1799) #1813), so a half-typed buffer never changes what is published for another file. See Review rounds 2, 3 and 5. A buffer saved broken counts as loaded once the ledger is reloaded (Review round 5, F1).

Cache: the WASM CACHE_VERSION goes from 102 to 103. A ParsedLedger now archives the directives and validation errors of a source with a parse error. A Ledger now archives each parse error with its code and line. The loader cache is unchanged, because the raw LoadResult it archives does not move.

Built on #2947, which has merged (squashed as 4bc5bd8). It reuses that PR's surface_agreement drift guards and booking_refused. The branch is updated from main by a merge, so the diff against main is this PR's changes only.

Behavior to review

  • The LSP's rule for which text each file is validated against (Review round 2, documented on MainLoopState::publish_diagnostics). A deliberate difference from check: while a buffer is broken, the OTHER files are validated with its last text that parsed cleanly (as loaded, if it has not parsed cleanly since it was opened), not with its broken text, so they do not flap on each keystroke (fix(lsp): validate multi-file ledgers once, not once per file (#1799) #1813).
  • validateMultiFile / validateWithHost render only the parse errors themselves (code and line, through take_parse_errors) and leave every other load error to process, as Ledger.fromFiles does. A duplicate include and a missing include keep the code LOAD and the place process gives them: the missing include's file and line, none for the duplicate (as rledger check prints it).

Tests

  • The shared cases (crates/rustledger-loader/tests/surface_agreement/cases.rs) gain "validation after a parse error", with exactly P0012 at 8, E3001 at 4 and E2001 at 10. The following run it:
    • loader: surface_agreement_test. The parse errors are read from the raw load, as check reads them.
    • CLI: rledger check --format json.
    • WASM: validateSource, validateMultiFile, ParsedLedger fresh and from cache, and Ledger.fromFiles fresh and from cache, under wasm-pack test --node. The multi-file surfaces prefix a parse message with ledger.beancount: ; the test requires that prefix.
    • FFI component: validate, and load with and without expand_pads.
    • LSP: all_diagnostics.
  • LoadResult::take_parse_errors: test_take_parse_errors_leaves_the_other_load_errors.
  • Updated tests:
    • The WASM and LSP cost/price-currency tests now expect the sale's booking note beside its parse error, as check reports it.
    • The WASM cache round-trip fixture with a parse error now loads directives.
    • The LSP lens and zero-validation tests now exercise the size cap, which is the only remaining skip.

Mutation check. Each mutation restores one gate, in its own worktree with a fresh target dir. The drift guard fails each time:

Mutation Failing test Result
WASM run_validation returns nothing on a parse error wasm_surfaces_report_the_shared_findings via validateSource: 1 finding, expected 3
WASM validateMultiFile stops on a load error that leaves the ledger incomplete wasm_surfaces_report_the_shared_findings via validateMultiFile: 1 finding, expected 3
FFI semantic_validation_errors parse-phase gate convert::surface_agreement via validate: 1 finding, expected 3
LSP all_diagnostics skips on parse errors handlers::diagnostics::surface_agreement 1 finding, expected 3

How to test

cargo test -p rustledger-loader --test surface_agreement_test --test loader_test
cargo test -p rustledger --test surface_agreement_test
cargo test -p rustledger-ffi-component --lib surface_agreement
cargo test -p rustledger-lsp --all-features --lib
(cd crates/rustledger-wasm && wasm-pack test --node)

Passing locally:

  • cargo fmt --check
  • cargo clippy --all-features --all-targets -D warnings
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps
  • cargo test --all-features for loader, validate, wasm, ffi-wasi, ffi-component, lsp and rustledger
  • wasm-pack test --node

Review round 1

  • LSP plugins after a parse error (regression of fix(lsp): validate multi-file ledgers once, not once per file (#1799) #1813, restored). Superseded in round 2. Dropping the primary_parse.errors.is_empty() guard in ledger_diagnostics_multi let a buffer broken mid-edit replace the stored plugin list with what it recovered. With main = plugin "auto_accounts" + include "b.beancount" on disk and b using accounts it never opens, the buffer plugin "auto_acc⏎include "b.beancount" (the unterminated string swallows the include; the recovered plugin is named auto_acc\ninclude ) or @@@ not valid beancount put 2 E1001s on b.beancount, though rledger check on that text never loads b. The guard is back. broken_current_parse_keeps_stored_plugins_for_cross_file_validation is back too, driving both buffers through the overlay the main loop builds; it fails with the guard removed.
  • LSP directive overlay of a broken buffer: kept, with the unopened files held. Superseded in round 2. The same flap exists through the directives: typing one " makes a string of every line up to the next quote, opens included. rledger check on include "b.beancount" / 2024-01-01 * "oops / the two opens / 2024-01-05 * "z" + postings reports P0012 at 5 and E1001 twice at line 2 of main and twice in b, and the next keystroke takes them away again. Restoring the old guard (overlay the current file only when it parses) is not the answer: the edited file's own diagnostics would then come from its stale on-disk entries, mapped onto the buffer's text (wrong lines, or errors the buffer no longer has; with this PR the file is validated, so this is no longer hidden). So the broken buffer stays overlaid, its own diagnostics are exactly check's for its text, and while it has a parse error the unopened files are not remapped or republished; they keep what was last published and are recomputed when it parses again (or a clean buffer is edited).
  • Other open buffers with a parse error: overlaid (kept). Superseded in round 2. What parsed in them is what check validates, and they do not change while another file is edited, so they cannot flap. The stale on-disk entries they replace can be wrong in the other direction: an open buffer c that opens Assets:Z (not yet saved) would otherwise give the edited main an E1001 on Assets:Z.
  • WASM multi-file load errors. validateMultiFile / validateWithHost rendered every load error themselves and then cleared them, so a duplicate include and a missing include lost the code LOAD that Ledger.fromFiles gives them. They now do what Ledger::from_file_map does: take_parse_errors, render only those, leave the rest to process. The "Behavior to review" bullet that presented the lost code as matching check is corrected. New drift guard validate_and_ledger_report_load_errors_alike asserts both surfaces give identical code/file/line for a duplicate include, a missing include and a parse error, and that validation runs past them.
  • Cache comment. v100 is not held by an open PR; the comment now says v98 is held by fix(parser): keep each header string in its own field after an invalid token #2944, v99 by fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945 and fix(ffi)!: report option errors, and validate file loads as rledger check does #2946, and v100 was never released.
  • Left alone (per review): the inline parse-error mapping in ffi-wasi load_source. Whichever of fix(ffi)!: report option errors, and validate file loads as rledger check does #2946 / fix: validate after a parse error on every surface, as rledger check does #2952 merges second switches it to fix(ffi)!: report option errors, and validate file loads as rledger check does #2946's rustledger_loader::parse_errors_to_ledger_errors.

New tests, each driven through the real path:

Test Through Pins
handlers::diagnostics::tests::broken_current_parse_keeps_stored_plugins_for_cross_file_validation ledger_diagnostics_multi with the broken buffer overlaid stored plugins while the primary parse has errors
main_loop::tests::a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_files MainLoopState didOpen / didChange, published notifications broken current buffer validated from its text (E3001 on the buffer's line, exactly check's P0012 + 2 E1001 for the quote case); unopened b not republished while broken, republished once clean
main_loop::tests::a_broken_other_open_buffer_is_overlaid_with_what_parsed MainLoopState, two open buffers another broken open buffer is overlaid
api::load_error_tests::validate_and_ledger_report_load_errors_alike validate_with_filesystem vs Ledger::from_file_map identical code/file/line for load errors

Mutation check, one scratch copy, run sequentially, reverted after each (cargo test -p rustledger-lsp --all-features --lib; WASM --lib load_error_tests):

Mutation Fails
drop the plugin guard in ledger_diagnostics_multi broken_current_parse_keeps_stored_plugins_for_cross_file_validation (b: E1001, E1001)
M2: skip other open buffers whose parse has errors a_broken_other_open_buffer_is_overlaid_with_what_parsed (main: E1001 at line 3)
M3: overlay the current file only when its parse is clean a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_files (only P0012; the E3001 is gone)
no hold of the unopened files while the buffer is broken a_broken_ledger_buffer_is_validated_from_its_text_and_holds_unopened_files (b gets 4 E1001s)
WASM: render every load error in validate_with_filesystem again validate_and_ledger_report_load_errors_alike (code None vs LOAD)

(The LSP tests and mutations in the two tables above are replaced in round 2.)

Gates on 00c8866, against a cleaned target dir: cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, and wasm-pack test --node in crates/rustledger-wasm: all pass.

Review round 2

Updated from main by a merge (no rebase, no force-push). #2947 merged as 4bc5bd8; for its hunks main's side was taken, and this PR's own changes (6c601ddc147..00c886632dd) were applied on top. git diff origin/main is exactly those changes plus this round. The one semantic conflict was the test tail of main_loop.rs, where #2941's mod coalescing meets this PR's tests: both are kept, and the test helper change_doc flushes the debounced pass (flush_pending_diagnostics) before reading publishes.

Refined in round 3 (below): the clean view keeps a broken buffer's last clean text instead of falling back to the ledger as loaded, and takes the plugin lines of every buffer in it.

The LSP rule, redesigned (F1, F2, F3). Round 1's hold was state carried between passes, and it was wrong three ways: a main file saved with a syntax error never published its includes (F1, a regression); editing a clean buffer while another was broken recomputed the unopened files against the broken one and the flapping E1001s stuck (F2); and the restored plugin guard made a broken buffer's own diagnostics differ from check's on its text (F3). It is replaced by a stateless rule with two views:

  • The clean view: the ledger as loaded, with every open buffer that parses cleanly overlaid. A broken open buffer is left out; its file stays as last loaded from disk. Every file other than the one being published (the unopened includes, and the other open buffers in their own passes) is validated against it. It does not depend on which buffer is being published, so no edit of any buffer can make another file flap, and nothing has to be held: every file is published on every pass.
  • A buffer's own view: the clean view plus that buffer's text, parse error or not, with its own plugin lines. Its diagnostics are check's for the ledger with that text.

For a clean buffer the two views are the same, so the all-clean path still runs ONE validation, as before. Only a broken ledger buffer costs a second validation, for its own diagnostics. A file saved broken is in the ledger as loaded with its parse error, so its includes are validated as check validates them (F1). didClose now republishes the unopened files from the clean view without the closed buffer, so its unsaved text stops counting.

Removed: the hold flag, multi_file_diagnostics' with_unopened parameter, the primary_parse.errors.is_empty() plugin guard in ledger_diagnostics_multi (the caller passes a primary only when its parse belongs in the view), and the unit test broken_current_parse_keeps_stored_plugins_for_cross_file_validation, which only pinned that guard; its cases now run through MainLoopState. A changed behavior: another open buffer with a parse error is no longer overlaid (round 1 overlaid it); with c broken and opening Assets:Z only in its unsaved text, the edited main reports Assets:Z unopened, as check does with c on disk.

Also fixed: two stale comments that still said a parse error skips LSP validation (docs/development/lsp-support.md and a test doc comment).

New tests, all through MainLoopState (didOpen, didChange with a flush, didClose, root adoption / revalidation, didChangeWatchedFiles), reading the published notifications:

Test Pins
a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk E3001 on the buffer's own line; for the * "oops buffer exactly check's P0012 + 2 E1001 in main; b keeps its own E1001 on every pass
a_saved_broken_main_still_publishes_its_includes (F1) saved broken main: b gets its E1001 on didOpen (configured journal), on root adoption, and on a watched-file change
editing_a_clean_buffer_while_another_is_broken_does_not_flap (F2) main broken by * "oops, c open and edited: b unchanged; main closed: b republished from disk
closing_a_buffer_republishes_the_unopened_files_from_disk a clean unsaved open in main clears b's error; closing main unsaved brings it back
a_broken_buffer_uses_the_plugins_it_declares (F3) broken buffer adding plugin "beancount.plugins.auto_accounts": P0012 alone, as check reports
a_broken_buffer_does_not_drop_its_plugins_from_other_files (#1813) plugin "auto_acc⏎include "b.beancount" and @@@ not valid beancount: no E1001 published into b
a_broken_other_open_buffer_is_validated_as_loaded another broken open buffer counts as on disk

Mutation check, one scratch copy with its own target dir, run sequentially, reverted after each (cargo test -p rustledger-lsp --all-features --lib):

Mutation (rule component) Fails
broken open buffers kept in the clean view editing_a_clean_buffer_while_another_is_broken_does_not_flap, a_broken_other_open_buffer_is_validated_as_loaded
broken current buffer (and its plugins) put in the clean view a_broken_buffer_does_not_drop_its_plugins_from_other_files, a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk, a_saved_broken_main_still_publishes_its_includes, a_broken_buffer_uses_the_plugins_it_declares, editing_a_clean_buffer_while_another_is_broken_does_not_flap
own view without the buffer's text a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk
plugin guard restored in ledger_diagnostics_multi a_broken_buffer_uses_the_plugins_it_declares
no republish on didClose closing_a_buffer_republishes_the_unopened_files_from_disk, editing_a_clean_buffer_while_another_is_broken_does_not_flap
round 1's hold reintroduced (no cross-file publish while the current buffer is broken) a_saved_broken_main_still_publishes_its_includes, a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk

CHANGELOG (F4). It no longer says parse errors are reported one by one "on every surface that loads through the loader". It names them: WASM validateSource, ParsedLedger, validateMultiFile, validateWithHost, Ledger.fromFiles, and the FFI component's string surfaces (load, validate, and validate_file, which validates the file's text alone without following its includes). The FFI's load_file still reports one line-less parse errors in <path> per file, under its load-only contract. The LSP entry describes the new rule.

Cache: v101 is still above main's 97 and claimed by no other open PR (#2944: 98, #2945 / #2946: 99).

Gates on 5b20a12 (the merged tree): cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, and wasm-pack test --node in crates/rustledger-wasm: all pass.

Review round 3

Round 3 found the code right on the tested paths but two documented promises not kept (F1, F2), plus docs (F3, F5) and a stale-diagnostics gap on close (F4). F1 and F2 are fixed, not documented away; both turned out contained.

F1: a broken buffer's last clean text stays in the clean view (fix). The clean view said a broken buffer's file is "as last loaded from disk", which is the stored LedgerState load (startup, root adoption, watched-file change; there is no didSave), so breaking a buffer with unsaved CLEAN edits undid those edits for every other file. With b unopened and its own E1001 at line 3: adding an unsaved open Assets:Q to main cleared b, typing 2024-01-06 * "typing (swallows nothing) brought the E1001 back, closing the quote cleared it again. Each open buffer now keeps its last clean parse (vfs::Document::last_clean_parse, dropped on close; since round 4, F2, recorded only by diagnostics passes), and its clean-view entry is its current parse when clean, else that last clean parse, else the stored load (never parsed cleanly since open). publish_diagnostics now parses the published buffer through the VFS cache (when the VFS holds that text), so its own clean parses are recorded too.

F2: the clean view's plugins come from every buffer in it (fix). ledger_diagnostics_multi replaced only the PRIMARY's plugin lines, and publish_unopened_diagnostics used the stored plugins, so the clean view depended on which buffer was published: with main declaring an unsaved plugin "auto_accounts", b was [] from main's pass and [E1001@0, E1001@0] from c's, a single revalidation published b twice with different content, and closing c left the two E1001s. ledger_diagnostics_multi now takes the view as (file_id, &ParseResult) and drops primary_file_id / primary_parse: every file in the view contributes its directives AND its plugin lines, which replace that file's stored plugins (view_plugins); the own view replaces the published buffer's entry with its current parse. (Corrected in round 4: as first written, view_plugins appended the plugins of a file that had none stored at the END, in the order the view listed its files, so the plugin ORDER, and with it the result, still depended on the published buffer and on the VFS's HashMap order. It now orders them as the loader does; see Review round 4, F1.)

F3: caveat on "what rledger check reports" (docs). The own view's file set is always the stored load's, so a buffer whose include lines changed is validated with the old set until the next load (pre-existing on main). Stated on MainLoopState::publish_diagnostics, in the CHANGELOG and above. (Extended in round 5, F2: the ORDER of the files comes from the last load too.)

F4: closing a buffer republishes the other open buffers (fix). on_did_close republished only the unopened files, so an open buffer validated against the closed buffer's unsaved text kept stale diagnostics until edited. It now republishes every other open ledger buffer from its own view (which republishes the unopened files too), or the unopened files alone when no other ledger buffer is open.

F5: stale FFI docs (docs). world.wit's balance-dir.diff no longer says it is none after a parse error. Comment-only: scripts/check-wit-version-bump.sh reports no interface change, so no version bump; scripts/check-wit-version-citations.sh passes. ffi-wasi's query_refusal_error comment and ledger_error_to_ffi rustdoc no longer describe the removed parse gate (the wire phase now only feeds validate's parse-error-count; query blocking is carried by error_blocks_queries).

F6: out of scope, filed as #2955 ("LSP: a scratch buffer outside the ledger shows the whole ledger's errors"), with a repro checked by a throwaway MainLoopState test on this branch.

New tests:

Test Pins
main_loop::tests::a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view (F1) the exact round-3 sequence through MainLoopState: b stays clean on every step
main_loop::tests::the_clean_view_takes_every_clean_buffers_plugins (F2) main's unsaved auto_accounts: b clean after main's edit, after editing c, after closing c; two E1001s back once main is closed
main_loop::tests::a_revalidation_publishes_each_file_the_same_way_every_time (F2) one revalidate_open_documents publishes b at least twice, every publish identical (b unbalanced so each pass sends it)
main_loop::tests::closing_a_buffer_republishes_the_other_open_buffers (F4) open b validated against main's unsaved open; closing main republishes b with its E1001
main_loop::tests::a_clean_pass_is_one_validation_and_a_broken_one_two cost: a clean pass is ONE whole-ledger validation with other buffers open; a broken one is two, with or without a last clean parse
vfs::tests::test_clean_view_parse_keeps_the_last_clean_parse_until_close last clean parse kept across broken edits, replaced by a newer one, dropped on close
handlers::diagnostics::tests::test_view_plugins_replaces_each_view_files_plugins_in_place plugin replacement, untouched files kept (round 4 extends it to pin the loader's order)

Existing tests updated: the ledger_diagnostics_multi call sites take the view; multi_file_vs_check loses its unused primary; two round-2 test docs now say "last clean text (here as loaded)".

Mutation check, one scratch copy with its own target dir, run sequentially, reverted after each (cargo test -p rustledger-lsp --all-features --lib):

Mutation (rule component) Fails
M1 no last clean parse (clean_view_parse returns None when broken) a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view, test_clean_view_parse_keeps_the_last_clean_parse_until_close
M2 published buffer parsed outside the VFS (its last clean parse not used for it) a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view
M3 plugins from the first view entry only (the old primary-only rule) the_clean_view_takes_every_clean_buffers_plugins, a_revalidation_publishes_each_file_the_same_way_every_time
M3b stored plugins only the two above and a_broken_buffer_uses_the_plugins_it_declares
M4 view plugins appended instead of in place test_view_plugins_replaces_each_view_files_plugins_in_place
M5 own view keeps the clean-view entry beside the current parse a_broken_ledger_buffer_is_validated_from_its_text_and_others_from_disk, a_broken_buffer_uses_the_plugins_it_declares
M6 didClose republishes the unopened files only closing_a_buffer_republishes_the_other_open_buffers
M7 clean pass runs the own-view validation too a_clean_pass_is_one_validation_and_a_broken_one_two
M8 broken published buffer falls back to the stored load a_broken_buffer_keeps_its_last_clean_text_in_the_clean_view

Gates on 3cf52d6: cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, wasm-pack test --node in crates/rustledger-wasm, and (the WIT file changed, comments only) cargo build -p rustledger-ffi-component --target wasm32-wasip2 plus cargo test -p rustledger-ffi-component-tests --lib --tests (no skip marker): all pass.

Review round 4

F1: a view's plugins run in the loader's order (fix). view_plugins appended the plugins of a view file that had none stored at the END, in the order the view listed its files (the published buffer first, then the other buffers in VFS HashMap order). Plugins run in list order, so that order changed results: with b declaring rename_accounts B -> C and main's unsaved buffer adding A -> B, b's Expenses:A stayed unopened (E1001 on b line 3) where check on the saved texts says b is clean; and with both renames in buffers (main A -> B, c B -> C), editing c published b with an E1001, editing main published it clean, and one revalidation published b twice with different content (with 3+ buffers it followed HashMap order). The loader gives a file its id and pushes its plugins in the same step, before following its includes, so its list is in file_id order, each file's in declaration order (checked for nested includes and a plugin declared after an include). view_plugins now drops the view files' stored plugins, adds their parses' plugins, and stable-sorts by file_id: the loader's order, whatever order the view lists its files in. The loader's order is pinned by a new loader test, so the LSP's sort cannot silently drift from it. Docs corrected: view_plugins and ledger_diagnostics_multi rustdoc, MainLoopState::publish_diagnostics, the CHANGELOG, and round 3's F2 above.

F2: the clean view no longer depends on request timing (fix). last_clean_parse was recorded whenever parse_result() ran, so a hover, semantic-tokens or workspace-symbols request that parsed a clean text between two passes changed what a broken buffer contributed. It is now recorded only in Document::clean_view_parse, which only diagnostics passes call: a broken buffer's part of the clean view is the last text a diagnostics pass saw parse cleanly. Contained to vfs.rs.

F3: cache comment (docs). crates/rustledger-wasm/src/cache.rs no longer says v100 was never released; it lists the numbers held by open PRs when it was written (v98 #2944, v99 #2945 and #2946, v100 #2931).

Info: unique_prices error at main line 0. Pre-existing: reproduced on main (4bc5bd8) with a throwaway MainLoopState probe, check at b.beancount:4, the LSP at main.beancount line 0. The LSP keeps plugin errors as (severity, code, message) and shows them in file 0 at line 0. Filed as #2957.

New tests:

Test Pins
main_loop::tests::a_buffers_plugins_run_in_checks_order (F1, scenario 1) main's unsaved A -> B before b's stored B -> C: b as check reports it on the saved texts ([]; on disk E1001@3)
main_loop::tests::the_clean_views_plugin_order_does_not_depend_on_the_published_buffer (F1, scenario 2) both renames in buffers: after editing c, after editing main, and on every publish of one revalidate_open_documents, b equals check on the saved texts ([]; on disk E1001@2)
handlers::diagnostics::tests::test_view_plugins_replaces_each_view_files_plugins_in_place (extended) a view file with no stored plugins between two that have some lands in file_id order, for two listing orders of the view
rustledger-loader tests::test_load_plugins_are_collected_in_file_id_order the loader's plugin list is in file_id order with nested includes and a plugin after an include (the invariant view_plugins reproduces)
vfs::tests::test_clean_view_parse_ignores_clean_texts_only_a_request_parsed (F2) a clean text only a request parsed is not the broken buffer's clean view; the last pass's is

rename_accounts is a native plugin (beancount_reds_plugins.rename_accounts.rename_accounts), so it runs in the LSP tests. The F1 tests compute the reference with rustledger_loader::load(.., LoadOptions::default()) on the saved texts, and assert it is clean while the on-disk state is not, so equality cannot hold vacuously.

Mutations, in place, sequential, reverted after each (cargo test -p rustledger-lsp --all-features --lib):

Mutation Fails
no sort in view_plugins a_buffers_plugins_run_in_checks_order, the_clean_views_plugin_order_does_not_depend_on_the_published_buffer, test_view_plugins_replaces_each_view_files_plugins_in_place
parse_result records the last clean parse again test_clean_view_parse_ignores_clean_texts_only_a_request_parsed

Gates on 8688510: cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, and wasm-pack test --node in crates/rustledger-wasm: all pass. (Round 4 touches no WIT file.)

Review round 5

F1: a buffer saved broken is validated as loaded (fix). Document::clean_view_parse returned the last clean parse whenever the current text was broken, and nothing dropped it on a reload. So with main opened clean (opening Assets:X, Equity:E, Assets:Q; b uses Assets:X and Assets:Q), then edited to drop the Assets:Q open and add garbage, then SAVED broken (watched-file change, reload), b was still validated against main's old clean text and published clean, where rledger check on disk reports E1001 Assets:Q in b. After every successful load of the ledger (watched-file reload, and both root-adoption paths), MainLoopState::forget_clean_parses_of_loaded_buffers now drops the last clean parse of every open buffer whose current text equals the text that load read for its file (Document::forget_last_clean_parse): such a buffer is as loaded, so until it next parses cleanly its file is validated as check validates the saved text. A buffer edited past what was saved (its text differs from the loaded one) keeps its last clean parse. No didSave handler or new client capability: the watched-file change a save raises, and its reload, is the save signal; matching the loaded TEXT rather than the event also covers a root adopted from a file already saved broken. Docs: MainLoopState::publish_diagnostics, Document::last_clean_parse, the CHANGELOG.

F2: the set AND ORDER of files come from the last load (docs). Reordering include lines in an unsaved buffer changes check's plugin order (plugins run file by file) and same-day tie-breaks between files, but view_plugins sorts by the stored load's file_id. The caveat now reads "the set and order of the files come from the last load" on MainLoopState::publish_diagnostics, on view_plugins, in the CHANGELOG and in this body; "plugins run in the order check runs them for those texts" now says "with the files in the order of the last load".

F3: the loader's plugin order on disk (test). The parallel pre-parse branch in load_recursive is taken for ONE include that resolves to more than one file (a glob) on a filesystem that supports_parallel_read (valid_paths.len() > 1 && self.fs.supports_parallel_read()); separate sibling include lines each go through the sequential branch, and VirtualFileSystem never takes it. New test_load_plugins_are_collected_in_file_id_order_on_disk loads from a temp dir with include "sub/*.beancount" (a.beancount with a nested include and a plugin after it, then b.beancount) and a plugin after the glob include in main, and asserts the same file_id order and source-map order. That it exercises the parallel branch is shown by mutation: merging that branch's siblings in reverse fails it while the VFS variant passes.

New tests:

Test Pins
main_loop::tests::a_buffer_saved_broken_is_validated_as_loaded (F1) the exact sequence above: before the save b is clean (main's last clean text); after save + didChangeWatchedFiles, b equals rustledger_loader::load on disk ([E1001@3], asserted non-empty), main stays [P0012@1]; a further still-broken edit keeps b as loaded
main_loop::tests::a_buffer_edited_past_its_saved_text_keeps_its_last_clean_text (F1) a reload that read a text other than the buffer's leaves b validated against main's last clean text ([])
rustledger-loader tests::test_load_plugins_are_collected_in_file_id_order_on_disk (F3) plugin and source-map order through the parallel branch

Mutations, on a scratch copy with its own target dir, sequential:

Mutation Fails
reload does not call forget_clean_parses_of_loaded_buffers a_buffer_saved_broken_is_validated_as_loaded
forget every loaded buffer's last clean parse, regardless of its text a_buffer_edited_past_its_saved_text_keeps_its_last_clean_text
parallel branch merges its siblings in reverse test_load_plugins_are_collected_in_file_id_order_on_disk (the VFS variant passes)

Gates on d95af80 (round 5 plus a merge of main at e6c8054): cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, wasm, lsp, ffi-wasi, ffi-component and rustledger, and wasm-pack test --node in crates/rustledger-wasm: all pass. (Round 5 touches no WIT file.)

Merge of main (#2945)

git merge origin/main at 526f833 (#2945: located option diagnostics, options in included files validated, loader cache v71, WASM cache v99). Resolutions:

Surface comparison after the merge (rledger check vs each surface; findings as code@line):

Case rledger check WASM validateMultiFile / validateWithHost / Ledger.fromFiles WASM validateSource / ParsedLedger (main text only) FFI validate / load (main text only) LSP
(a) parse error + Balance failed P0012@6 x3, E2001@7 same (each) same same same
(b) parse error in an include sub P0012@4 x2, main E2001@4 (got 5 USD) same (each) include not read: LOAD@1, E2001@4 (got 0) include not followed: E2001@4 (got 0) same as check, on sub and main
(c) option error + parse error in an include sub P0012@2 x2, sub E7008@1, main E2001@4 same (each) LOAD@1, E2001@4 E2001@4 same as check
(d) missing include + validation errors failed to read missing.beancount, E1002@5, E2001@4 LOAD@1 (file main), E1002@5, E2001@4 (each) LOAD@1, E1002@5, E2001@4 E1002@5, E2001@4 E1002@5, E2001@4 (no missing-include diagnostic: pre-existing, the LSP's ledger_state discards the loader's errors; neither PR touches it)
Gates on 29ae298 (the merge): cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger (2654 passed, 0 failed), and wasm-pack test --node in crates/rustledger-wasm: all pass.

Review round 6

  • A saved-broken file with a BOM (main_loop.rs, forget_clean_parses_of_loaded_buffers). The loader keeps a file's leading BOM (DiskFileSystem::read), while editors send the buffer without it, so the round-5 text match never held for a BOM-prefixed file: its last clean parse was never forgotten, and the files it includes stayed validated against that clean text after it was saved broken. Both texts are now compared as the parser reads them, through the canonical rustledger_parser::bom::strip_leading. New tests a_buffer_saved_broken_with_a_bom_is_validated_as_loaded (main on disk with a BOM, opened without one, saved broken: b gets [("E1001", 3)], as check reports on disk) and a_buffer_saved_broken_with_crlf_is_validated_as_loaded (CRLF in both buffer and disk), sharing the helper b_after_saving_main_broken. Mutation: comparing without stripping fails the BOM test ([] vs [("E1001", 3)]); the CRLF and round-5 tests keep passing.
  • This body. "What changed" now reads CACHE_VERSION "from 99 to 101" (main is at 99).

Gates on a411148: cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features -p rustledger-lsp (392 unit tests and the integration suites pass), and cargo check --workspace --all-features --all-targets: all pass.

Merge of main (#2944)

git merge origin/main at 8773d67 (#2944: header strings kept in their own fields after an invalid token, loader cache v73, WASM cache v102). Conflicts only in the cache note and the CHANGELOG:

  • WASM cache (cache.rs). Main's v102 note kept; this PR's note follows it as v103 ("loader v73, unchanged"), says what a stale blob would serve (a ParsedLedger with no directives and no validation errors for a source with a parse error, a Ledger with one line-less parse error per file), and that v101 was never released. CACHE_VERSION = 103, above main's 102; v104 is held by fix(parser): run a mid-line BOM's invalid token to the next blank, as beancount does #2931. LOADER_CACHE_VERSION_PIN stays at main's 73: this PR does not move the loader cache.
  • CHANGELOG. Both entries kept; this PR's bullet now says the WASM cache moves to v103.

Gates on a5096d3 (the merge): cargo fmt --all --check, cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps, cargo test --all-features for loader, validate, wasm, lsp, ffi-wasi, ffi-component and rustledger, wasm-pack test --node in crates/rustledger-wasm, and the scripts/check-*.sh scripts CI runs: all pass.

Closes #2949

🤖 Generated with Claude Code

robcohen and others added 6 commits November 11, 2026 00:57
ParsedLedger.fromCache and Ledger.fromCache threw "Deserialization
failed: unaligned pointer ... alignment 8" on any ledger with a custom
directive or a metadata entry.

Root cause: rkyv::from_bytes reads the archive in place, so every
archived value must sit at its own alignment in memory. ArchivedMetaValue
needs 8 bytes (its Int(i64) variant, added in #1513), and every custom
value and metadata entry archives one. The WASM cache blob puts its
archive 12 bytes in, after the magic and version header, so even in a
16-aligned blob those values sat 4 bytes off. The blob itself is not
aligned either: wasm-bindgen copies a JS Uint8Array into wasm memory with
alignment 1.

Fix: decoding copies the payload into an rkyv AlignedVec before reading
it, which does not depend on where the caller's bytes lie. The cache
format is unchanged, so CACHE_VERSION stays at 94 and blobs already
written restore as they are.

The loader's on-disk cache reads its header separately, so it does not
have the offset bug, but it read the archive into a plain Vec<u8>, whose
alignment is 1 by contract and 16 only because the system allocator
happens to give it. It now reads straight into an AlignedVec. Its format
is unchanged too.

Tests: a round trip over one ledger per directive type, per metadata
value type and per custom value type, plus error cases, comparing
directives, errors and options on both ParsedLedger and Ledger, natively
and under wasm-pack test --node; a native round trip over every
.beancount file in the repository's test corpora; a decode of each
payload at every offset from a 16-byte boundary; and a loader save/load
of custom values and metadata. All but the loader test fail without the
fix.

Closes #2934

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ter a booking error

Two cases where the diagnostic surfaces disagreed (#2937), settled by
bean-check 3.2.3:

- Closing an account that still holds a balance (E1004). bean-check does
  not flag it, with or without auto_accounts / currency_accounts, and
  `rledger check` stays silent to match (`lint closed-nonempty` reports
  it). WASM, the FFI component and the LSP reported it. They now leave
  it out through the one predicate, `ErrorCode::is_advisory_only`.
- Validation after a booking error. bean-check and `check` report an
  ambiguous STRICT reduction and the `Balance failed` that follows it,
  the refused transaction left out of the balance. WASM `validateSource`
  and `ParsedLedger` skipped validation on any load error, and the FFI
  counted the refused transaction into the balance (-1600 USD where
  bean-check says -2100 USD). The loader now records which transactions
  booking refused (`Ledger::booking_refused`), and both surfaces set them
  aside as the validating loader does: Early sees them, Late does not,
  and the session reports the account errors Early held for them.

A shared case file (`rustledger-loader/tests/surface_agreement/cases.rs`)
drives one drift-guard test per surface: the loader, `rledger check`,
WASM (`validateSource`, `validateMultiFile`, `ParsedLedger`, `Ledger`,
fresh and from cache), the FFI component (`validate`, `load`) and the
LSP, each comparing codes (the FFI wire error has none: line and
message), lines and messages.

The WASM cache moves to v97: both payloads' archived errors change.
WASM `fromCache` now reads the archive from an aligned copy: it starts 12
bytes into the blob, and the new cache round trip hit an "unaligned
pointer" refusal on it. The format is unchanged.

Closes #2937

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The AlignedVec copy in deserialize_parsed / deserialize_ledger duplicates
the fix in #2942 (#2934), which also covers the loader cache and has its
own tests. #2942's branch is merged in next, so this PR's WASM cache round
trip still decodes; #2947 depends on #2942 landing first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2947's WASM cache round trip needs #2942's aligned decode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Rewrite the comments that still said run_validation gates on load.errors
  or skips on has_fatal (helpers.rs, api.rs, parsed_ledger.rs).
- run_validation: drop the span-length-mismatch branch, which set refused
  transactions aside without noting them; load_and_book always keeps one
  span per directive, now a debug_assert.
- CHANGELOG: Ledger::booking_refused listed under Breaking, as
  PluginError::failed was.
- Cache notes: v93 and v96 were never released; #2931 holds v95.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does

`rledger check` and bean-check 3.2.3 report a syntax error and still
validate the entries that did parse. WASM (`validateSource`,
`ParsedLedger`, `validateMultiFile`, `validateWithHost`), the FFI
component (`validate`, `load`) and the LSP validated nothing once a file
failed to parse, so one bad line hid every other finding.

Each surface now follows the validating loader's rule, under which no
load error stops validation:

- WASM `load_and_book` no longer returns early on a parse error; the
  loader keeps what parsed and `process` books it, and `run_validation`
  validates it. `validateMultiFile` / `validateWithHost` report every
  load error, then run `process` with them cleared, as `check` does.
- `LoadResult::take_parse_errors` (new) takes the parse errors out of a
  load so a surface reports them one by one with code and line, rather
  than `process` folding them into one line-less `parse errors in
  <path>`. WASM's single-source load, `Ledger.fromFiles` and the FFI
  string load use it.
- The FFI's `semantic_validation_errors` drops its parse-phase gate.
- The LSP's `validation_would_run` keeps only the size cap, and an open
  buffer with a parse error is overlaid in a multi-file ledger.

The shared surface_agreement cases gain one parse error plus an
unbalanced transaction and a failing balance (P0012 line 8, E3001 line
4, E2001 line 10, bean-check's three findings on the same lines),
asserted on the CLI, the loader, WASM, the FFI and the LSP.

WASM cache v101.

Closes #2949

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 11, 2026 15:47
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.86148% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-lsp/src/main_loop.rs 98.52% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 52.2ms ± 1.9ms 835.4ms ± 17.7ms 16.0x 44.1 MB / 51.1 MB
investment 80.2ms ± 2.6ms 2977.3ms ± 46.6ms 37.1x 47.1 MB / 59.1 MB
fifo 76.3ms ± 0.9ms 14880.3ms ± 282.0ms 195.1x 49.1 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 52.2ms ± 2.0ms 52.2ms ± 1.9ms -0.0% ✅ within noise 45.0 MB → 44.1 MB (-2.0%)
investment 80.6ms ± 0.8ms 80.2ms ± 2.6ms -0.4% ✅ within noise 47.3 MB → 47.1 MB (-0.5%)
fifo 76.5ms ± 1.2ms 76.3ms ± 0.9ms -0.3% ✅ within noise 49.1 MB → 49.1 MB (+0.0%)

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

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 826
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 added a commit that referenced this pull request Nov 11, 2026
…heck does

Review round 2 of #2946.

- A plugin the host asks for (`load-file`, `session.from-file`) reported
  its errors as a bare message: no code, file, line or severity, and its
  text unescaped. The loader's per-error mapping is now the public
  `rustledger_loader::plugin_error_to_ledger_error`, which
  `record_plugin_errors` and ffi-wasi's `apply_plugins` (which gains the
  load's `source_map`) both use. A drift test compares a host-requested
  and a ledger-declared `leafonly`.
- Parse errors were one line-less `parse errors in <path>`, an included
  file's too. `LoadResult::take_parse_errors` (the same method as #2952)
  takes them out before `process`, and the new
  `rustledger_loader::parse_errors_to_ledger_errors` reports each with its
  code, file, line and column, as `check` does. `load(src, name)` names
  the given file on them. New shared case `parse-error-in-include`.
- `batch` and a session from source name their errors `<stdin>`, as their
  entries, not the loader's `<string>`.
- `query_option_errors` shares `query_refusal_error`'s conversion.
- Pin the refusal's site match (an include repeating the main file's bad
  `booking_method` keeps its plain E7002) and the refusal's phase on
  every query surface; both mutation-checked.
- world.wit: both behaviors for a plugin-made directive's finding, line 0
  as the exception to 1-based, and the `version()` example is "4.0".
  Stale comments fixed in ffi-wasi `Error` and the parity cases.
- ffi-component-tests compile the component once per test binary
  (`compiled_component`). Every `parity` / `corpus_parity` test compiled
  the 93 MB debug component on its own `Engine`, the check-parity test once
  per case, many at once on parallel threads: the `parity` binary held
  10-12 GB for 20+ minutes. The crate's tests now take 26 s at 0.9 GB peak.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 3 commits November 11, 2026 15:15
- LSP: restore the #1813 guard in `ledger_diagnostics_multi`, so a buffer
  broken mid-edit no longer replaces the stored plugins the unopened files
  are validated with, and re-add
  `broken_current_parse_keeps_stored_plugins_for_cross_file_validation`.
- LSP: keep overlaying a broken current buffer (its own diagnostics come
  from its text, as in `rledger check`), but hold the unopened files'
  diagnostics while it has a parse error, so a half-typed string that
  swallows an `open` cannot make them flap. Keep overlaying other broken
  open buffers. Pin both through `MainLoopState`.
- WASM: `validateMultiFile` / `validateWithHost` take only the parse errors
  and leave the other load errors to `process`, as `Ledger.fromFiles` does,
  so they keep the code `LOAD`; drift guard
  `validate_and_ledger_report_load_errors_alike`.
- WASM cache comment: v100 is not held by an open PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2947 merged as 4bc5bd8. Its hunks take main's side; this PR's own
changes (6c601dd..00c8866) are applied on top. In the test tail of
the LSP main loop, #2941's coalescing tests and this PR's tests are both
kept, and change_doc flushes the debounced diagnostics pass before the
publishes are read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review round 2 of #2952. Round 1 held the unopened files' diagnostics
while the edited buffer had a parse error. That hold never published
the includes of a main file saved with a syntax error, let a clean
buffer's edit recompute them against another broken buffer, and the
restored plugin guard made a broken buffer's own diagnostics differ
from rledger check on its text.

Replace it with a stateless rule. Every file other than the one being
published is validated against the clean view: the ledger as loaded
with each open buffer that parses cleanly overlaid, a broken one left
as on disk. The published buffer's own diagnostics come from the clean
view plus its own text and plugins, as check reports them. For a clean
buffer the two views coincide, so the all-clean path still runs one
validation. didClose republishes the unopened files from disk.

Removed: the hold flag, multi_file_diagnostics' with_unopened, and the
parse-error plugin guard in ledger_diagnostics_multi. The changelog now
names the surfaces that report parse errors one by one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lugins in the clean view

Review round 3 of #2952.

- The clean view used the stored load for a broken buffer, so breaking a
  buffer with unsaved clean edits undid them for every other file. Each
  open buffer now keeps its last clean parse (dropped on close) and
  contributes it while its current text is broken.
- The clean view applied only the published buffer's plugin lines, so
  one revalidation could publish a file twice with different content.
  ledger_diagnostics_multi now takes the view as parses: every file in
  it contributes its directives and its plugin lines, replaced in place.
- didClose republishes every other open ledger buffer, not only the
  unopened files.
- Docs: the own view's file set is the stored load's (an include edit
  takes effect on the next load); the WIT balance diff and the ffi-wasi
  error-phase docs no longer describe the removed parse gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ean parse only in diagnostics passes

Review round 4 of #2952.

- view_plugins appended the plugins of a view file that had none stored
  at the end, in the order the view listed its files (the published
  buffer first, then VFS HashMap order), so two chained rename_accounts
  ran in a different order than rledger check runs them and the clean
  view depended on which buffer was published. It now stable-sorts by
  file_id, the loader's order (pinned by a new loader test).
- last_clean_parse was recorded by every parse_result() call, request
  handlers included; it is now recorded only by clean_view_parse, which
  only diagnostics passes call.
- The wasm cache comment no longer calls v100 unreleased.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 11, 2026 21:46
…r's plugin order on disk

Review round 5 of #2952 (issue #2949).

- After every successful load of the ledger (watched-file reload, root
  adoption), an open buffer whose current text equals the text that load
  read for its file drops its last clean parse: it was saved, so until it
  next parses cleanly its file is validated as `rledger check` validates
  the saved text. A buffer edited past what was saved keeps it. Before,
  a buffer saved broken kept validating its includes against its old
  clean text, hiding the E1001 `check` reports on disk.
- Docs: the set AND ORDER of the files come from the last load (plugin
  order and same-day tie-breaks follow it), on `publish_diagnostics`,
  `view_plugins` and in the CHANGELOG.
- Loader test: the plugin `file_id` order on disk, through the parallel
  pre-parse branch (a glob include matching several files).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
#2945 took loader v71 and WASM v99, so this branch keeps loader v73 and
moves WASM to v102 (v100 and v101 are held by #2931 and #2952).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the WASM conflicts so both behaviors hold: #2945's located option
diagnostics (`option_warnings_to_errors`, through the loader's canonical
mapping) on validateMultiFile, validateWithHost and Ledger.fromFiles, and
this branch's validation of whatever loaded after a parse or load error.

- validate_with_filesystem: drop the early stop on a "fatal" load error.
  `rledger check` reports and validates past a missing, unreadable or
  directory include, a duplicate include, an include cycle and an empty
  glob, and stops only when the entry file cannot be loaded (the `Err`
  arm here). Option diagnostics follow the ledger's errors, in the same
  order as Ledger.fromFiles.
- load_and_book: the parse-error early return stays deleted; a source
  with a parse error gets its located option diagnostics from the loader.
- Ledger::from_file_map: parse errors, then ledger errors, then options.
- WASM cache: main's v99 note, then this branch's v101 (loader v71).
- LSP: adapt #2945's option_diagnostics_are_located_like_check to the
  view form of ledger_diagnostics_multi.
- CHANGELOG: keep both entries; reword for the merged behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen and others added 2 commits November 12, 2026 00:00
…s a BOM

The loader keeps a file's leading BOM, while editors send the buffer
without it, so the round-5 "saved broken" check never matched a
BOM-prefixed file and kept validating other files against its last
clean text. Compare both texts with the parser's canonical
`bom::strip_leading`, and pin the BOM and CRLF cases with tests.

Review round 6 of #2952.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG and WASM cache conflicts with #2944. Main is now at
WASM cache v102 (loader v73), so this PR moves its WASM CACHE_VERSION from
101 to 103, with its note after main's v102 note; v101 was never released.
LOADER_CACHE_VERSION_PIN stays at main's 73, since this PR does not move
the loader cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
Loader cache v74 and WASM cache v104 for #2931, above main's v73 / v102
(#2944) and #2952's WASM v103.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit 48fccee into main Nov 12, 2026
69 of 70 checks passed
@robcohen
robcohen deleted the fix/validate-after-parse-error branch November 12, 2026 11:11
robcohen added a commit that referenced this pull request Nov 12, 2026
#2952 keeps loading past a parse error on every surface. Resolved:

- ffi-wasi `load_source`: parse errors through
  `parse_errors_to_ledger_errors` (via `parse_errors_of`), with code,
  line and column; #2952's per-error `Error::new` mapping is not kept.
- ffi-component: #2952's removal of the parse gate in
  `semantic_validation_errors` is taken.
- wasm `load_and_book`: #2952's no-early-return load, with this PR's
  `query_option_errors` through the canonical, and the parse errors through
  `parse_errors_to_wasm` (character columns).
- wasm `Ledger::from_file_map`: `query_errors` is built after the parse
  errors are in `errors`, so `Ledger.query` lists them; the processing-error
  branch chains them too.
- wasm cache: main's v103 note kept, this PR's v105 after it.
- `load_errors_to_errors` is `pub` (clippy `redundant_pub_crate`).

Follow-ups in the same commit:

- `CHECK_PARITY_CASES` gains `parse-error-single-file`, so the source-text
  surfaces run a parse error too.
- `query_option_errors/cases.rs` gains `parse_errors` and a
  `refused-booking-method-with-parse-error` case, run by the FFI's query
  surfaces, WASM `query`, `ParsedLedger.query` and `Ledger.query`;
  `queryMultiFile` skips it (issue #2960).
- #2960 shrinks to `query_with_filesystem`: the `Ledger::query_option_errors`
  and `ProcessedLedger::query_option_errors` docs and the CHANGELOG say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
… it was hiding (#2962)

The Check, Clippy and Documentation jobs ran cargo without --workspace,
so they acted on default-members only, which leaves out rustledger-wasm,
rustledger-ffi-wasi, rustledger-ffi-component and
rustledger-ffi-component-tests. All four build on the host target, so
--workspace needs no extra target or feature set.

That gap let #2952 land a redundant_pub_crate failure in rustledger-wasm
(pub(crate) load_errors_to_errors inside the private api module). Make it
pub; the module stays private, so visibility is unchanged.

Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
 review round 6)

The paired comments at parse_error_fields and parse_errors_to_ledger_errors
said a LedgerError has no end position. It does: source_span and file_id
carry it; only ErrorLocation is a point. The copy exists because WASM's
single-source surfaces build no LoadError or SourceMap. The multi-file
surfaces report null ends for validation findings only because
From<LedgerError> for Error does not locate them, and that conversion also
drops the hint: both pre-existing, now issue #2964, cited from the
comments, the From impl and wasm_error_columns.rs. The revisit condition
is now "if the single-source surfaces come to build a LoadError".

The load_errors_to_errors comment also names parse_error_mapping_parity
as a test that strips the #2961 path prefix.

Formats the include!d ffi_check_parity/cases.rs with rustfmt (a chain
from the #2952 merge exceeded the chain width).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
…heck does (#2946)

* fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic

beancount parses each included file with its own Builder and fresh
options: every value an option's converter rejects is an error at the
included file's line (bean-check exits 1), and only the top-level file's
values are kept. rledger reported every included option as the E7009
warning, valid or not, and exited 0.

set_scoped_inner now reads an included non-accumulating option into a
scratch Options, keeps its diagnostics and drops the value. E7009 is left
for a value the converter accepts. An included name_* root still does
not root that file's own accounts (E1005), a deliberate deviation now
commented and pinned.

Every option diagnostic (E7001 to E7011) carries the option's file and
line: OptionWarning gains `site`, stamped by set_scoped_at, and E7006 /
E7010 are located from the applied values. rledger check (text, JSON, and
ag-rledger check through it), the LSP (diagnostic on the option line, in
the file it is in), WASM option_errors and multi-file Ledger errors read
it. WASM validateMultiFile now reports option diagnostics at all.

Drift guards pin check's JSON and text, the LSP's two paths and WASM's
two multi-file paths to the loader's sites. WASM cache v99; the loader
cache never stores a ledger with option diagnostics, so it stays at v69.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(loader): one canonical option-diagnostic mapping, and keep a ledger's options off unrelated LSP buffers

Review round 1 of #2945.

- rustledger_loader::option_warnings_to_errors maps OptionWarning::site to
  LedgerError::location (column 1). rledger check, the LSP and WASM (via
  From<LedgerError>) read it; the WASM helper is a one-argument wrapper
  and single-source entry points drop the file with without_files.
- LSP: a buffer the ledger does not include gets its own options'
  diagnostics, never the ledger's drawn on its lines.
- LSP option range stops before a `; comment`; the live-buffer limitation
  is documented.
- Options::locate is by occurrence, so a repeated documents value is
  located at each of its lines.
- validate_with_filesystem reports option diagnostics beside a fatal load
  error or a processing failure.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ffi): report option errors, and validate file loads as rledger check does

The FFI component never reported a ledger's option diagnostics (E7001 to
E7011): ffi-wasi built `errors` from `ledger.errors` only. They now travel
in a separate, non-gating `option_errors` list on `LoadResult` and
`FileLoad`, mapped by `rustledger_loader::option_warnings_to_errors`, the
canonical function the WASM surface now calls too, and are appended to the
outgoing `errors` last, after the host's plugins and validation have run,
so an invalid option neither skips validation, nor stops session plugins,
nor counts in `parse-error-count`. `valid` and the host-plugin gate go by
severity, which fixes two older bugs: a ledger plugin's warning skipped the
host's plugins, and `valid` was false over a warning alone. Query results
list the option diagnostics, as the WASM query does, and so no longer list
the booking-method refusal beside its E7002 (#2929).

`load-file` reported no validation errors and `validate-file` validated the
entry file's text as one source. Both now validate through the canonical
pipeline (`load_file_with_fs(..., validate: true)`), and the validator's
findings, told apart by the new `LedgerError::is_validation_finding`, are
kept out of the host-plugin gate, so a failed balance does not stop the
host's plugins. Each finding keeps its own file and line. A source-text
finding maps to a line only when its span is in the text (file id 0), as
on WASM; a plugin directive's finding was mapped to an unrelated line
(#2935).

A drift guard pins `rledger check` and the component's `load`,
`load-file`, `validate` and `validate-file` to one list of diagnostics
(codes, messages, files and lines) on a multi-file and a single-file
ledger with a balance failure, a padded cost lot and invalid options, run
natively and through the built wasip2 component.

WIT contract rustledger:[email protected] (behavior only, no shape change).
No cache payload changes.

Closes #2929
Closes #2935

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ffi)!: WIT 4.0.0 error code and filename, and keep the query refusal

Review round 1 of #2946.

- The WIT `error` record gains `code` and `filename`, filled for every
  error with a location (an included file's own path, the name given to
  `load` for source text, a plugin's placeholder name), so a line can say
  which file it is in. A record change: package rustledger:[email protected],
  `API_VERSION` 4.0, docs cite @4.x.
- Query surfaces (`query`, `query-file`, `batch`, `batch-file`,
  `session.query`) list a rejected booking_method as the refusal again, in
  place of its plain E7002, through one loader canonical,
  `Ledger::query_option_errors`; `load` and `info()` keep the plain E7002.
- Option diagnostics come from #2945's located
  `option_warnings_to_errors` (this branch is rebased onto it), so they
  carry the option's file and line on every surface, and the drift guard
  pins those lines.
- Validation findings leave out the advisory-only E1004 on every surface,
  as `rledger check` does, and are kept beside an unrun plugin's error
  (E8001, E8004, E8005), as `check` keeps them.
- The host-plugin tests assert `check_commodity`'s exact finding, so the
  mutations that put option errors in the plugin gate fail them.
- The file-id span rule cites its WASM twin, and the WASM rule cites it.

No cache payload changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(loader): ignore an included documents option as beancount does, and locate query's option diagnostics

Review round 2 of #2945.

- documents leaves ACCUMULATE_ACROSS_INCLUDES: beancount 3.2.3 keeps only
  the top-level file's (load_file gives documents == [] for an included
  root and bean-check exits 0 with it missing), so an included value is
  read by the scratch converter and ignored with E7009, never scanned or
  checked (no E7006).
- rledger query prints option diagnostics through the canonical mapping,
  with file and line; ag-rledger's query warnings carry them.
- WASM Ledger::from_file_map's processing-error arm keeps the option
  diagnostics, as validate_with_filesystem does.
- LSP option_error_file_id uses SourceFile::id.
- Tests pin site_of's last-line choice (E7010), without_locations
  clearing every site, and included documents.

Refs #2925

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ffi): locate each parse error and host plugin error, as rledger check does

Review round 2 of #2946.

- A plugin the host asks for (`load-file`, `session.from-file`) reported
  its errors as a bare message: no code, file, line or severity, and its
  text unescaped. The loader's per-error mapping is now the public
  `rustledger_loader::plugin_error_to_ledger_error`, which
  `record_plugin_errors` and ffi-wasi's `apply_plugins` (which gains the
  load's `source_map`) both use. A drift test compares a host-requested
  and a ledger-declared `leafonly`.
- Parse errors were one line-less `parse errors in <path>`, an included
  file's too. `LoadResult::take_parse_errors` (the same method as #2952)
  takes them out before `process`, and the new
  `rustledger_loader::parse_errors_to_ledger_errors` reports each with its
  code, file, line and column, as `check` does. `load(src, name)` names
  the given file on them. New shared case `parse-error-in-include`.
- `batch` and a session from source name their errors `<stdin>`, as their
  entries, not the loader's `<string>`.
- `query_option_errors` shares `query_refusal_error`'s conversion.
- Pin the refusal's site match (an include repeating the main file's bad
  `booking_method` keeps its plain E7002) and the refusal's phase on
  every query surface; both mutation-checked.
- world.wit: both behaviors for a plugin-made directive's finding, line 0
  as the exception to 1-based, and the `version()` example is "4.0".
  Stale comments fixed in ffi-wasi `Error` and the parity cases.
- ffi-component-tests compile the component once per test binary
  (`compiled_component`). Every `parity` / `corpus_parity` test compiled
  the 93 MB debug component on its own `Engine`, the check-parity test once
  per case, many at once on parallel threads: the `parity` binary held
  10-12 GB for 20+ minutes. The crate's tests now take 26 s at 0.9 GB peak.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ffi-component-tests): use parking_lot for the shared compiled component

CI's Sync Primitives check forbids std::sync locks in non-test library code
(#1076), and `compiled_component` lives in the crate's lib. Switch it to
parking_lot::Mutex (no poisoning, so the PoisonError recovery goes), end
the guard explicitly after the first compile, and split the doc's first
paragraph for clippy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(wasm): list query option errors through the canonical, and pin columns (#2946 review round 3)

- WASM query surfaces (free `query`, `ParsedLedger.query`,
  `queryMultiFile`, `Ledger.query`) list option diagnostics through
  `Ledger::query_option_errors`, as the FFI does: the rejected
  `booking_method`'s E7002 is the refusal. Shared drift guard
  `rustledger-loader/tests/query_option_errors/cases.rs` across the
  loader, the FFI and WASM. WASM cache v105 (both payloads archive
  what a query lists). A source that fails to parse still differs
  (#2960), documented at both sites.
- The check parity rows compare `column`; `load` and `validate` now
  give a validation finding its column, as `check` does. A mid-line
  parse error after a two-byte character pins character columns.
- Paired comments between `parse_errors_to_ledger_errors` and
  `check`'s inline parse-error arm.
- Pin `batch` errors named `<stdin>` and the host-plugin `source_map`
  argument (file names with a tab).
- `session.from-entries` option errors carry code E7002.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ffi,wasm): locate every finding through one canonical, and count WASM columns in characters (#2946 review round 4)

- loader: `SourceMap::locate(file_id, offset)` replaces the private
  `error_location`; the loader, the FFI component's validation findings and
  the WASM surface all locate through it.
- ffi-component: `semantic_validation_errors` calls `SourceMap::locate`
  instead of re-deriving it.
- check parity: BOM-prefixed cases (LF and CRLF) put a line-1 finding at
  column 2, so a hardcoded column 1 no longer passes.
- wasm: `validateSource`, `ParsedLedger.getErrors`, `parse` and `format`
  counted columns in bytes (4 after a BOM); parse errors now go through the
  loader's `LineIndex` and validation findings through `SourceMap::locate`.
  `LineLookup` keeps lines only. Native and wasm-bindgen tests pin a BOM and
  a multi-byte character before an error.
- WIT: the `error` record's doc says `column` is 1-based in characters and
  0 at a plugin placeholder (doc only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(ffi,wasm): pin a parse error's refusal, WASM's file-id rule and end positions, and map WASM parse errors once (#2946 review round 5)

- query_option_errors/cases.rs: new refused-by-parse-error-alone case
  (a parse error and no option diagnostic must refuse), run by the
  canonical, the FFI query surfaces and every WASM query surface,
  queryMultiFile included; the component's
  query_short_circuits_on_parse_error gains the same ledger. Moves a
  comment glued to `},` onto its own line.
- wasm: test_a_plugin_directives_finding_maps_to_no_source_line, the
  counterpart of the FFI test; end_line/end_column pinned natively and
  in wasm_error_columns on every surface.
- wasm: parse_error_fields maps a parse error's message, code, phase
  and hint once for parse_error_to_wasm and load_errors_to_errors, with
  paired comments against the loader's parse_errors_to_ledger_errors
  and a drift guard (parse_error_mapping_parity).
- The multi-file path prefix on parse error messages points at #2961.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(wasm,loader): say why WASM keeps its own parse-error mapping (#2946 review round 6)

The paired comments at parse_error_fields and parse_errors_to_ledger_errors
said a LedgerError has no end position. It does: source_span and file_id
carry it; only ErrorLocation is a point. The copy exists because WASM's
single-source surfaces build no LoadError or SourceMap. The multi-file
surfaces report null ends for validation findings only because
From<LedgerError> for Error does not locate them, and that conversion also
drops the hint: both pre-existing, now issue #2964, cited from the
comments, the From impl and wasm_error_columns.rs. The revisit condition
is now "if the single-source surfaces come to build a LoadError".

The load_errors_to_errors comment also names parse_error_mapping_parity
as a test that strips the #2961 path prefix.

Formats the include!d ffi_check_parity/cases.rs with rustfmt (a chain
from the #2952 merge exceeded the chain width).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

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.

fix: WASM, FFI and LSP skip validation after a parse error, while rledger check validates

1 participant