Skip to content

feat(parity): name parse-error mismatches by category key through ptadiff - #3056

Merged
robcohen merged 3 commits into
mainfrom
feat/parity-categories
Nov 27, 2026
Merged

robcohen merged 3 commits into
mainfrom
feat/parity-categories

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What changed

The parse-error parity harness (scripts/compat-parse-error-parity.py) now runs through pta-standards' new differential package, ptadiff (rustledger/pta-standards#73). The manifest pins ptadiff by commit (#@ptadiff-rev). The harness now names every mismatch with a category key, not just a symptom bucket.

  • Batch protocol. parse_error_lines --jsonl speaks ptadiff's JSON-lines protocol ({id, text} in, {id, errors: [{line, code, msg}]} out). The harness talks to rledger through it and runs beancount in ptadiff's forked workers, with the same crash capture as before. The framed mode stays for scripts/bom-combination-matrix.py.

  • Category key. ptadiff's beancount shape key is built from four parts, all taken from the first line the two sides disagree on:

    • which side reports more errors there;
    • the error kinds of that side;
    • the line's kind;
    • the line's token shape, from beancount's black-box lex_iter_string.

    It uses no beancount grammar tables. The key is pluggable, so a parser-state key from the clean-room grammar can replace it later.

  • New gen input source. 12,000 inputs from ptadiff's seeded G1–G3(b) generators. They are pinned like the fuzz and matrix inputs (#@generators, #@inputs gen, per-input pins). The sample is identical across runs, worker counts (--jobs 3 vs 16) and Python 3.11/3.13.

  • Per-category pins. The manifest's new @ categories section, next to the symptom buckets, pins each key's count over the fixed sources (fuzz, matrix, gen).

    • A changed count is a stale pin.
    • A different ptadiff revision, key or generator sample is a coverage error.
    • Every existing pin is unchanged: the manifest diff only adds lines. That is checked, and a tampered category count fails --check.
  • Report. The job summary gains the category table, with the ten largest categories' examples minimized by ptadiff's key-preserving minimizer (--minimize 10). The full table is uploaded as an artifact (--categories-json).

  • BcLexer drift test. New test cst::bc_lexer_drift (rustledger-parser) compares BcLexer with beancount 3.2.3's lex_iter_string, token name and byte span, over:

    • the tracked ledgers;
    • the fuzz regressions;
    • the pinned fuzz corpus;
    • the stray-character matrix;
    • the generator sample.

    All 123,833 inputs agree. It runs in python-gated-cargo-tests in its own beancount==3.2.3 + ptadiff venv, with RLEDGER_BC_LEXER_DRIFT_REQUIRE=1 turning skips into failures, and its skip marker is added to the job's grep. Bc::Other did not need splitting: each Other token's text names exactly one beancount token, so the test maps it.

Why

This is phase 1 of the parser plan: turn parse mismatches into named, countable categories, so the remaining work can be picked by group size instead of by symptom.

Top categories (all sources, 3,830 mismatches in 540 keys)

# Inputs Key Minimized example
1 287 impl-fewer|oracle:lex:token+syn:INDENT|indented|INDENT error (orphan-INDENT double count) "\t\ufeff"
2 239 impl-more|impl:P0012|top|^ error "\^A\r2"
3 167 impl-more|impl:P0012|top|DATE error "2229-1-7B\r!"
4 164 impl-more|impl:P0012|indented|CAPITAL error "2305-2-3*\n\tG\tO+"
5 116 impl-fewer|oracle:lex:token+syn:NUMBER|top|NUMBER error "2\u0667\ufeff"

The top 10 keys cover 34.5% of mismatches, and the top 50 cover 69%.

Before merging

This PR pins ptadiff to 2b844dc, a commit on pta-standards' feat/differential-tooling branch. Once rustledger/pta-standards#73 merges, re-pin #@ptadiff-rev to the merge commit. The squash merge changes the SHA, and the branch commit stops being fetchable once the branch is deleted. Then run --update: the counts should not change, only the rev line.

How to test

rev=$(sed -n 's/^#@ptadiff-rev //p' tests/baselines/parse-error-parity.manifest)
pip install beancount==3.2.3 "ptadiff @ git+https://github.com/rustledger/pta-standards@${rev}#subdirectory=tooling/differential"
cargo build --release -p rustledger-loader --no-default-features --example parse_error_lines
python3 -I scripts/compat-parse-error-parity.py --self-test
python3 -I scripts/compat-parse-error-parity.py --rledger target/release/examples/parse_error_lines \
  --fuzz-dir "$FUZZ" --fuzz-commit "$COMMIT" --compat-dir tests/compatibility/files --check --minimize 10
RLEDGER_BEANCOUNT_PYTHON=$(which python3) RLEDGER_BC_LEXER_DRIFT_FUZZ_DIR="$FUZZ" RLEDGER_BC_LEXER_DRIFT_REQUIRE=1 \
  cargo test -p rustledger-parser --lib bc_lexer_drift -- --nocapture

Locally: cargo clippy --workspace --all-features --all-targets -- -D warnings is clean, and cargo test -p rustledger-parser -p rustledger-loader passes.

🤖 Generated with Claude Code

…diff

The parse-error parity harness now runs through pta-standards' differential
package (ptadiff, tooling/differential), pinned by commit in the manifest
(`#@ptadiff-rev`), and names every mismatch with ptadiff's beancount `shape`
category key: which side reports more on the first line the two disagree
on, that side's error kinds, the line's kind, and the line's token shape
from beancount's black-box lexer (lex_iter_string).

- parse_error_lines gains `--jsonl`, ptadiff's JSON-lines protocol; the
  harness talks to rledger through it, and runs beancount in ptadiff's
  forked workers (same crash capture as before)
- a new `gen` input source: 12000 inputs from ptadiff's seeded G1-G3(b)
  generators, pinned like the fuzz and matrix inputs (`#@generators`,
  `#@inputs gen`, per-input pins), identical across runs, worker counts
  and Python versions
- the manifest pins each category key's count over the fixed sources
  (`@ categories`, next to the symptom buckets); a changed count is a
  stale pin, and a different ptadiff revision, key or generator sample is
  a coverage error. Every existing pin is unchanged
- the report adds the category table, with the ten largest categories'
  examples minimized by ptadiff's key-preserving minimizer (`--minimize`);
  `--categories-json` writes it for the CI artifact
- a token-level drift test (`cst::bc_lexer_drift`) compares BcLexer with
  beancount 3.2.3's lex_iter_string, token name and byte span, over the
  tracked ledgers, fuzz regressions, pinned fuzz corpus, stray-character
  matrix and generator sample (123833 inputs, all agree), run in the
  python-gated-cargo-tests job with skips turned into failures

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

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 41.1ms ± 1.1ms 504.7ms ± 2.2ms 12.3x 43.2 MB / 51.1 MB
investment 61.4ms ± 0.8ms 2008.1ms ± 17.6ms 32.7x 47.4 MB / 59.2 MB
fifo 60.1ms ± 0.6ms 11622.6ms ± 101.6ms 193.4x 49.1 MB / 59.1 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 41.3ms ± 0.8ms 41.1ms ± 1.1ms -0.5% ✅ within noise 43.3 MB → 43.2 MB (-0.4%)
investment 61.7ms ± 0.5ms 61.4ms ± 0.8ms -0.4% ✅ within noise 47.0 MB → 47.4 MB (+0.7%)
fifo 60.3ms ± 0.8ms 60.1ms ± 0.6ms -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 0.6ms, 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

…dards#73)

The tooling/differential tree is identical to the feature-branch commit
it replaces, so no count changes.

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

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 128 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/bc_lexer_drift.rs 42.85% 128 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit f278620 into main Nov 27, 2026
62 of 63 checks passed
@robcohen
robcohen deleted the feat/parity-categories branch November 27, 2026 05:42
robcohen added a commit that referenced this pull request Nov 27, 2026
…_lexer_drift

The drift test from #3056 compared BcLexer, the recovery model's port of
beancount's lexer, with lex_iter_string. Point it at the oracle's reference
lexer, written from pta-standards' clean-room LEXICAL.md, which the
remaining recovery code is being replaced with: 123,833 pinned inputs agree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 27, 2026
…_lexer_drift

The drift test from #3056 compared BcLexer, the recovery model's port of
beancount's lexer, with lex_iter_string. Point it at the oracle's reference
lexer, written from pta-standards' clean-room LEXICAL.md, which the
remaining recovery code is being replaced with: 123,833 pinned inputs agree.

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

* feat(parser): a table-driven beancount error oracle, behind RLEDGER_ERROR_ORACLE

Replace the hand-modeled bison recovery step by step with beancount's own
grammar. This adds the pieces, off by default:

- scripts/gen-beancount-lalr-tables.py compiles pta-standards' clean-room,
  MIT-licensed beancount.y (vendored at 1463db773ac5, hash-checked) with the
  flake's bison 3.8.2 into cst/oracle/beancount/tables.rs; a new CI job
  regenerates and diffs them.
- cst/oracle/beancount/lr.rs replays yacc.c's semantics over the tables:
  default reductions, error shift and yyerrstatus 3, discard, a lexer
  YYerror entering recovery without a report, YYMAXDEPTH 10000, EOF abort.
  No recursion, no panics, linear time; slots plus a reduction trace.
- cst/oracle/beancount/lexer.rs: beancount's tokenization written from
  LEXICAL.md only.
- cst/oracle/mod.rs: the format-neutral ReferenceOracle / reconcile /
  DeviationOverlay seam; ten named overlays for the documented deliberate
  differences, each citing a new compatibility.md section.
- scripts/compat-beancount-oracle-drift.py (in the parity job) holds the
  model to beancount itself: 122,917 of 122,917 inputs agree on tokens and
  syntax errors.

With RLEDGER_ERROR_ORACLE=1 the parity harness matches 119,952 of 123,304
inputs where main matches 119,048, with no regression. The oracle runs only
when rledger's own parse reports an error, so a clean ledger pays nothing.

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

* test(parser): check the error oracle's lexer, not BcLexer, in cst::bc_lexer_drift

The drift test from #3056 compared BcLexer, the recovery model's port of
beancount's lexer, with lex_iter_string. Point it at the oracle's reference
lexer, written from pta-standards' clean-room LEXICAL.md, which the
remaining recovery code is being replaced with: 123,833 pinned inputs agree.

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.

1 participant