Skip to content

fix(parser): push and pop take effect exactly where beancount builds them - #3096

Merged
robcohen merged 1 commit into
mainfrom
fix/pushpop-oracle-state
Nov 29, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/pushpop-oracle-state

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

A pushtag, poptag, pushmeta or popmeta now takes effect exactly where beancount 3.2.3's grammar builds it, around syntax errors too. The converter replays its tag and metadata stacks over the push/pop directives the error oracle records as built (oracle::beancount::built_state_directives, new), instead of re-deriving "a push or pop whose line has an error changes no state" (#2995) itself.

Why

That rule missed the pushes and pops beancount's error recovery builds in the middle of a broken line:

pushtag #trip
2024-01-01 open Assets:A
2024-01-01 open Assets:B
2024-01-02 * "first"
  kk: 1
  poptag #trip
2024-01-03 * "second"
  Assets:A  1 USD
  Assets:B

bean-check: one error (6: syntax error, unexpected POPTAG). The pop takes effect, so "second" has no tags. rledger reported P0021 pushtag 'trip' was never popped as well, and tagged "second" with trip. Likewise P popmeta where: (the P an invalid token) now pops, and option "operating_currency" "USD"pushtag #x now pushes: it reports the unbalanced tag and tags what follows, as bean-check does.

How

  • cst/convert.rs: the push/pop arms only collect their nodes. After every error pass, push_pop_directives picks the ones that take effect: all of them in a file with no error (beancount's grammar reads it whole, and the oracle is not run), otherwise the oracle's built ones. A built one with no node of its own in rledger's tree is read from its own text. replay_push_pop_state then applies the stacks to each directive and reports absent pops and unclosed pushes. push_pop_header_fails and the invalid_value_date helper it alone used are removed.
  • The full-trace reference is computed once per parse and shared with the reconciliation (full_reference, reconcile_errors_with), so a file with errors pays for the oracle no more than before.
  • cst/oracle/mod.rs::reconcile: a semantic slot (beancount's builder error, such as a pop of something never pushed) is now covered first by rledger's own standing builder error on that line. Before, a stray \r (P3) or a leftover syntax diagnostic could fill the slot as well, which reported the line twice once rledger's pop took effect.

Docs: compatibility.md §3. Loader cache v83, WASM cache v165 (parser output moves; every affected source has a parse error, so the bump is only a safeguard). The parse-error manifest drops 52 inputs that now match: the eof pins for unbalanced pushes, and the impl-more absent-pop pins.

Parity

Parse-error parity (123,394 inputs): 122,378 → 122,430 matches. 52 inputs newly match and none regress. Semantic parity --check passes with the manifest unchanged.

Testing

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 29, 2026 00:32
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 39.2ms ± 0.8ms 558.1ms ± 0.3ms 14.2x 37.1 MB / 51.0 MB
investment 60.4ms ± 0.4ms 2103.0ms ± 4.5ms 34.8x 45.0 MB / 59.0 MB
fifo 59.7ms ± 0.4ms 11698.8ms ± 98.8ms 196.0x 55.2 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 39.0ms ± 1.7ms 39.2ms ± 0.8ms +0.4% ✅ within noise 37.0 MB → 37.1 MB (+0.2%)
investment 61.2ms ± 0.3ms 60.4ms ± 0.4ms -1.2% ✅ within noise 59.1 MB → 45.0 MB (-23.8%)
fifo 59.8ms ± 0.3ms 59.7ms ± 0.4ms -0.2% ✅ within noise 59.2 MB → 55.2 MB (-6.8%)

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

github-actions Bot commented Nov 29, 2026 •

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 force-pushed the fix/pushpop-oracle-state branch from f9ff33b to 93d7d43 Compare November 29, 2026 01:16
…them

A pushtag/poptag/pushmeta/popmeta its error recovery builds in the middle
of a broken line (`  poptag #trip` in a transaction body, `P popmeta k:`,
`option "a" "b"pushtag #x`) now pushes or pops: the converter replays its
tag and metadata stacks over the directives the error oracle records as
built (`built_state_directives`), instead of re-deriving "a push or pop
whose line has an error changes no state" (#2995). The full-trace
reference is computed once and shared with the reconciliation.

A semantic slot (beancount builder error, e.g. a pop of an absent tag)
is now covered first by rledger standing builder error on the line, so a
stray \r or a leftover syntax diagnostic no longer reports it twice.

Parse-error parity: 122,378 -> 122,430 of 123,394 (52 pins dropped, no
regressions). Loader cache v83, WASM cache v165.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the fix/pushpop-oracle-state branch from 93d7d43 to acda85b Compare November 29, 2026 02:59
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.36709% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/convert.rs 99.02% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 0b16606 into main Nov 29, 2026
66 of 71 checks passed
@robcohen
robcohen deleted the fix/pushpop-oracle-state branch November 29, 2026 04:08
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