Skip to content

fix(parser): hold parse errors to beancount's grammar by default - #3062

Merged
robcohen merged 1 commit into
mainfrom
feat/lalr-oracle-on
Nov 27, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/lalr-oracle-on

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Based on main (#3061 merged).

What

This turns the parser's error oracle on by default (RLEDGER_ERROR_ORACLE=0 turns it off, for comparison), and fixes what turning it on exposed.

  • Builder checks the oracle didn't replay. beancount's recovery sometimes builds a poptag/popmeta in the middle of a line rledger fails (2024-01-03 2024-01-04 poptag #t, or $ then \t1poptag #t), and its builder then reports the tag as never pushed. The oracle now replays the pushed-tag and pushed-key counts over the statements its grammar builds and emits a slot there. Tests cover it, including a linear-time shape.
  • Which diagnostic keeps a slot. When several of rledger's diagnostics fall on the one token beancount rejects, the tightest keeps the slot: an invalid date inside an amount wins over the amount's "trailing tokens". The window is capped, so this stays linear.
  • Order. The reconciler now keeps rledger's order among diagnostics that start at the same byte. Without this, one corpus file's STRICT_BASELINE hash changed while every count stayed the same.
  • Never clean. A parse rledger found an error in keeps at least one error. Without this, an indented comment at the top of a file (a deliberate difference: rledger reads it as a comment) could leave an invalid next line inside beancount's recovery window, and rledger would silently accept it. This also keeps the loader cache contract: a source has a parse error exactly when it had one.
  • WASM cache v148. It is one above main's v147. The loader cache stays at v82, since it is never saved for a source with a parse error.

Tests whose expectations moved

Each was checked against bean-check 3.2.3. In every case the new count is beancount's, and the old one was the hand model's miss.

Test Input Before Now (= beancount)
bison_recovery_model::test_parse_date_on_an_indented_line_does_not_end_the_recovery option "title" "x" in a txn body, then a posting lines 2, 6 lines 2, 3, 6
bom_account_and_tag_recovery::test_parse_bom_account_no_longer_stands_in_for_a_missed_error Assets:A ~$ <BOM><BOM>Assets:B -$ / % $x … 2 / 1 3 / 2
indented_star_line::test_parse_star_after_bom_is_reported <BOM><BOM>* h x 1 3
open_booking_method_failed_line::…keeps_its_error an orphan hh after open … "XYZ" 1 on the line 2 (indent + invalid token)

The BOM matrix is re-pinned with BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1:

  • 13,349 rows match where 12,917 did (+432).
  • known goes from 519 rows to 88.
  • The one hand-kept exception now matches and is removed.
  • All 21 worse_than_main lines are no longer worse and are removed.
  • 104 rows keep their counts but name tokens differently: a synthesized diagnostic names the invalid token, which is why the update needed RELABEL.
  • Four test_cause_* unit tests pinned rows that now match beancount. They keep pinning each rule's conditions on the old counts, set explicitly.
  • test_check_row_excepts_only_listed_exception_lines now needs 5 distinct causes instead of 10, because the other causes' rows match now.

Measurements

main this PR
parse-error parity: matching inputs (on main after #3061) 119,192 / 123,394 120,099 (manifest re-pinned; --check passes, 0 regressions, 1,100 pins move to match)
BOM combination matrix: matching rows 12,917 13,349
STRICT_BASELINE corpus tests pass pass (no hash moves)
clean 10.8 MB ledger — unchanged (the oracle runs only when rledger reports an error; see #3061)

Parser, loader, LSP, WASM and CLI test suites pass with the oracle on, and so does workspace clippy.

What remains

These are the next PRs:

  • Deletions. Delete the hand-modeled recovery one piece per commit: quiet_bison_recovery and the phantom recursion, accepts(), model_stray_cr_lines / stray_cr_analog, the convert.rs quieting passes, BcLexer and the logos patches that depend on it. Each deletion is gated on parity --check, the BOM matrix, STRICT_BASELINE and the parser suite.
  • Dropped statements. Use the trace's "statement dropped" bit in validation (casc2–4).

🤖 Generated with Claude Code

Turn the error oracle on (RLEDGER_ERROR_ORACLE=0 turns it off), and fix
what turning it on exposed:

- replay beancount's pushed-tag and pushed-key counts over the statements
  its grammar builds, so a poptag/popmeta its recovery builds mid-line still
  reports its tag or key as never pushed;
- of several rledger errors on the one token beancount rejects, the tightest
  keeps its message; rledger's order among errors starting together is kept;
- a parse rledger found an error in never comes out clean.

Four tests whose counts were the hand model's misses now pin bean-check's;
the BOM matrix, its exceptions and worse-than-main lists, and the parity
manifest are re-pinned. Parity: 120,099 of 123,394 inputs match beancount
3.2.3 where 119,192 did, none lost; BOM matrix 13,349 rows where 12,917.
WASM cache v148; the loader cache is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the feat/lalr-oracle-on branch from a2acccc to 02039dd Compare November 27, 2026 11:35
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

🔴 Slower than base on: simple

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 47.9ms ± 2.9ms 559.9ms ± 26.3ms 11.7x 43.3 MB / 51.0 MB
investment 67.7ms ± 2.6ms 2033.6ms ± 7.8ms 30.0x 47.4 MB / 59.0 MB
fifo 65.2ms ± 0.8ms 11902.3ms ± 124.9ms 182.5x 49.4 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 45.3ms ± 0.5ms 47.9ms ± 2.9ms +5.6% 🟡 slower 43.2 MB → 43.3 MB (+0.2%)
investment 66.2ms ± 0.8ms 67.7ms ± 2.6ms +2.3% ✅ within noise 47.4 MB → 47.4 MB (-0.1%)
fifo 65.7ms ± 0.8ms 65.2ms ± 0.8ms -0.6% ✅ within noise 49.1 MB → 49.4 MB (+0.6%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 1.3ms, investment 1.2ms, fifo 0.5ms), 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 828
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.82609% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../rustledger-parser/src/cst/oracle/beancount/mod.rs 96.93% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 19ec6b3 into main Nov 27, 2026
65 of 66 checks passed
@robcohen
robcohen deleted the feat/lalr-oracle-on branch November 27, 2026 12:00
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.

1 participant