Skip to content

refactor(parser): classify builder checks by EntryCheck, drop RLEDGER_ERROR_ORACLE - #3093

Merged
robcohen merged 1 commit into
mainfrom
refactor/oracle-classify-kinds
Nov 29, 2026
Merged

robcohen merged 1 commit into
mainfrom
refactor/oracle-classify-kinds

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Two code smells in the parser's error oracle, plus a gap in the parse-error parity harness.

(a) Builder checks are classified by a value, not by wording. oracle/beancount/mod.rs::classify decided whether an rledger diagnostic is a builder check (stands) or a syntax error (held to beancount's slots) partly by matching the message: convert.rs::is_a_builder_message (contains("as beancount reports"), contains("as in beancount"), several prefixes), starts_with("negative prices are not allowed"), and is_a_builder_error's TOO_MANY_STRINGS prefix. Rewording any of those messages would have silently reclassified the error.

  • New rustledger_parser::EntryCheck (non-exhaustive) and ParseError::check: Option<EntryCheck>, set with ParseError::with_check at every place a builder check is made: duplicate cost component, per-unit cost in {{ }}, negative price, @@ without units, cost/price currency mismatch, tags after the first posting, duplicate metadata, too many header strings.
  • classify returns Other for any error with a check; the P4 overlay (TagLineAfterFirstPosting) matches EntryCheck::TagsAfterFirstPosting instead of a substring. is_a_builder_message / is_a_builder_error are deleted.
  • Codes (P0012), messages and lines are unchanged. tests/baselines/parser-corpus.manifest moves for 52 files only because the baseline hashes ParseError's Debug, which now prints the new field. Only rows whose source hash matches were updated; rows whose local corpus copy has drifted were left alone. No cache bump: neither cache archives ParseError, and the loader never caches a load with parse errors.

(b) RLEDGER_ERROR_ORACLE=0 is removed. It still changed what every parse reported, and its docs (oracle/mod.rs, convert.rs) described hand-modeled passes that have since been deleted. The reconciliation now always runs. Only the drift tooling's gate_skips_grammar parses without it, through a scoped oracle::without_reconciliation. The unused, doc-hidden cst::set_error_oracle_on_this_thread is removed, and the stale comments are rewritten.

(c) Harness: tags_after_posting_lines and multi-line strings. It scanned from the line after the header and stopped at the first line that wasn't indented, so a header holding a multi-line string (2024-01-02 * "x\ny") ended the scan at the string's continuation line. beancount's Tags or links not allowed after first Posting then stayed on the header line instead of moving to the tag line. It now tracks string state across lines, so continuation lines in the header, a posting or a metadata value are skipped. Three self-test cases were added; the old function returns [] for the first one.

Not changed (noted)

Two other overlays still match on message prefixes: invalid arithmetic expression (P9) and invalid number in amount (likely exceeds (P10). Neither is a builder check, so EntryCheck doesn't cover them. They could get the same treatment in a follow-up.

Testing

  • cargo test -p rustledger-parser: all pass, including the new test_classify_reads_the_check_not_the_wording and test_parse_marks_each_builder_check (one input per EntryCheck). cargo clippy -p rustledger-parser --all-features --all-targets -D warnings is clean, and cargo check --workspace --all-targets passes.
  • compat-parse-error-parity.py --self-test and --check: 122,378 / 123,394 matched, identical to main, no regressions, manifest unchanged.
  • compat-semantic-parity.py --check: 9,563 match, 7 mismatch, 1,116 deliberate (99.93%), unchanged, no regressions.

🤖 Generated with Claude Code

…_ERROR_ORACLE

The error oracle's `classify` told a check beancount's builder makes of a
read entry from a syntax error by the message's wording
(`is_a_builder_message`: "as beancount reports", "as in beancount",
prefixes; "negative prices are not allowed"; the too-many-strings prefix),
so rewording a message could turn a builder check into a syntax error the
reconciler drops. Each such error now carries `ParseError::check`, a new
`EntryCheck`, set where the check is made; `classify` and the P4 overlay
match on it, and `is_a_builder_message` / `is_a_builder_error` are gone.
Codes, lines and messages are unchanged; the parser corpus baseline moves
only because `ParseError`'s `Debug` prints the new field.

`RLEDGER_ERROR_ORACLE=0` still changed every parse's diagnostics, and its
docs described hand-modeled passes that were deleted. The env switch is
removed; the drift tooling's `gate_skips_grammar` uses a scoped
`oracle::without_reconciliation` instead, and the doc-hidden
`cst::set_error_oracle_on_this_thread` is removed.

The parse-error parity harness's `tags_after_posting_lines` stopped at the
continuation line of a multi-line string in the header (or a posting or
metadata value) and found no tag line; it now reads past string
continuations. Self-test cases added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 29, 2026 00:07
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 52.3ms ± 0.8ms 791.0ms ± 1.1ms 15.1x 45.1 MB / 51.1 MB
investment 77.6ms ± 0.5ms 2884.9ms ± 19.7ms 37.2x 47.0 MB / 59.1 MB
fifo 77.2ms ± 0.5ms 14664.9ms ± 124.6ms 190.0x 49.0 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 52.4ms ± 0.3ms 52.3ms ± 0.8ms -0.3% ✅ within noise 45.1 MB → 45.1 MB (-0.0%)
investment 78.9ms ± 0.8ms 77.6ms ± 0.5ms -1.7% ✅ within noise 47.0 MB → 47.0 MB (-0.0%)
fifo 78.2ms ± 0.9ms 77.2ms ± 0.5ms -1.4% ✅ within noise 49.1 MB → 49.0 MB (-0.1%)

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.95402% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/oracle/mod.rs 14.28% 6 Missing ⚠️
.../rustledger-parser/src/cst/oracle/beancount/mod.rs 97.82% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 879f9c8 into main Nov 29, 2026
65 of 67 checks passed
@robcohen
robcohen deleted the refactor/oracle-classify-kinds branch November 29, 2026 00:38
robcohen added a commit that referenced this pull request Nov 29, 2026
…#3112)

#3093 added ParseError::check, which ParseError's Debug prints, so the
parser corpus hash of every file with a builder-check error moved. Its
regeneration ran on a local corpus that lacked
parser-lima/test-cases_MetaData.MetadataTransactionRepeated and
parser-lima/test-cases_TotalsAndSigns.TotalPriceWithMissing (present in
CI's cached corpus), so those two entries kept their pre-#3093 hashes and
the Corpus output baseline job has failed on main since. Source hashes are
unchanged; the new parser hashes are exactly the ones CI reports.

Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 30, 2026
A 31-digit number in a cost spec (`{N USD}`, `{{N USD}}`, either side of
`#`) was dropped with no parse error: the cost became unknown and the
only diagnostic was booking's `interpolation failed`. On a `price` or
`balance` line the directive got a generic `unexpected input` over the
line, and in a balance tolerance, a metadata, `custom` or `pushmeta`
value the number was dropped with no error at all. Each is now reported
at the number (`invalid number in cost (likely exceeds 28-digit Decimal
precision)`, `in amount`, `in metadata value`, ...), as an amount's and
an `@` price's always were (that wording is unchanged). An expression
holding such a number is reported at the number rather than as an
unevaluable expression. beancount 3.2.3 accepts these numbers: P10.

The error oracle's `divide-by-zero` (P9) and `decimal-precision` (P10)
overlays matched these errors by the start of their message. They now
match a typed discriminator, `ParseError::number_error`
(`NumberError::{UnevaluableExpression, BeyondPrecision}`, new), set at
every emitting site, following #3093's `check`. P10 is now claimed, like
P9, only on a line beancount reads and reports nothing on, so an invalid
token after such a number keeps its name.

Cost-spec numbers are checked in the shared cost-spec rule of both tree
walks and the tree builder's recorder; metadata and `pushmeta` values in
the metadata line check; `custom` values in the shared value walk.

Loader cache v86, WASM cache v170: a file that loaded clean (a cost or
metadata number beyond precision) now has a parse error.

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.

1 participant