Skip to content

fix(validate): no balance finding for a statement beancount's grammar discards - #3064

Merged
robcohen merged 1 commit into
mainfrom
feat/lalr-dropped-statements
Nov 27, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/lalr-dropped-statements

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Based on main (#3061, #3062, #3063 merged).

What

Phase 6, the dropped-statement part: the validator learns which statements beancount discards from the error oracle's reduction trace, instead of a hand-kept rule.

  • rustledger_parser::beancount_drops_directive(source) (new, public). It answers: does beancount's grammar build no statement starting at source's first token? It reads the oracle's trace of beancount's own parse with no deliberate differences applied, because the question is what beancount builds. source is the directive's text plus the line after it, so an invalid token on the next line that fails the statement counts too.
  • transaction_holds_invalid_token now delegates to it (after its "starts with a transaction" check). Its hand-kept rule goes: fails_inside, fails_the_statement's allow-list of error kinds, line_leads_with_an_invalid_token and holds_a_misgrouped_number. The oracle-backed answer agrees with every case those tests pin (txn_failed_statement, line_start_bom_recovery, bom_mid_line_run: 47 tests).
  • Validator. The late balance check, once it has reported something, asks dropped_by_beancount for the directive. If beancount discards the directive, the findings are dropped. The transaction residual path keeps using the predicate as before.

The three known cases

case before now (= bean-check 3.2.3)
casc2: Assets:A 1,23 USD in a transaction P0012 + E3001 residual P0012 alone
casc4: balance Assets:A 1 USD ~ 0.1 P0012 + E2002 P0012 alone
casc3: Assets:A 1 $ USD mid-posting, then balance Assets:A 0 USD P0012 + false E2001 unchanged; see below

casc2 and casc4 are surface-agreement cases, so rledger check, the LSP, WASM and the FFI surfaces are all held to them.

casc3 remains. The false E2001 comes from the dropped transaction's postings updating inventories. That update runs for every transaction, so asking the predicate there would re-lex every transaction of every ledger. It needs the locations of parse errors handed from the loader to the validator, so that only transactions holding a parse error are asked. That reaches SourceLines / ValidationOptions and the loader. It's the next step.

Measurements

  • Parse errors don't move: the predicate is the validator's. Parity --check, the BOM matrix and the corpus baselines pass unchanged on main, so nothing is re-pinned.
  • WASM cache v150, since a Ledger archives its validation findings. The loader cache stays at v82: every source this touches has a parse error, which the loader's cache is never saved for.
  • The validator asks only after a check has found something, so a clean ledger pays nothing.

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 09:00
@robcohen
robcohen force-pushed the feat/lalr-delete-recovery branch from a28c9b4 to cb6ff42 Compare November 27, 2026 12:25
Base automatically changed from feat/lalr-delete-recovery to main November 27, 2026 12:47
… discards

Which statements beancount drops now comes from the error oracle's
reduction trace: rustledger_parser::beancount_drops_directive (new, public)
asks whether beancount's grammar builds a statement at a directive's first
token. transaction_holds_invalid_token delegates to it, replacing its
hand-kept rule (fails_inside, fails_the_statement's allow-list,
line_leads_with_an_invalid_token, holds_a_misgrouped_number); it agrees with
every case those tests pin. The late balance check drops its findings for a
balance beancount discards.

So `Assets:A  1,23 USD` no longer adds an E3001 residual to its
transaction, and `balance Assets:A 1 USD ~ 0.1` no longer reports E2002:
bean-check 3.2.3 reports each statement's parse error alone. Both are pinned
on every surface by new surface-agreement cases. (A dropped transaction's
postings still update inventories, so a later balance can still fail:
casc3, which needs parse-error locations plumbed to the validator.) WASM
cache v150.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the feat/lalr-dropped-statements branch from 003ec88 to 8241eb4 Compare November 27, 2026 13:04
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 41.4ms ± 1.0ms 573.1ms ± 7.3ms 13.9x 43.2 MB / 51.0 MB
investment 63.3ms ± 1.7ms 2185.0ms ± 74.3ms 34.5x 47.1 MB / 58.9 MB
fifo 63.3ms ± 3.2ms 12077.7ms ± 288.6ms 190.8x 49.4 MB / 59.0 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 41.5ms ± 2.7ms 41.4ms ± 1.0ms -0.4% ✅ within noise 42.5 MB → 43.2 MB (+1.7%)
investment 62.0ms ± 1.0ms 63.3ms ± 1.7ms +2.0% ✅ within noise 47.1 MB → 47.1 MB (+0.1%)
fifo 61.0ms ± 1.4ms 63.3ms ± 3.2ms +3.7% ✅ within noise 49.4 MB → 49.4 MB (-0.0%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 1.3ms, investment 0.9ms, fifo 1.6ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 180 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

@robcohen
robcohen merged commit 27bfaf1 into main Nov 27, 2026
70 of 71 checks passed
@robcohen
robcohen deleted the feat/lalr-dropped-statements branch November 27, 2026 13:22
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