Skip to content

fix(parser): a push or pop whose line has an error changes no state, and its errors are on its own line - #3034

Merged
robcohen merged 1 commit into
mainfrom
fix/push-pop-invalid-date
Nov 26, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/push-pop-invalid-date

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

A pushtag, poptag, pushmeta or popmeta whose line has an error now pushes or pops nothing, the same as beancount 3.2.3. The tags and metadata on later transactions follow from that. A pop error is now reported on the pop's own line.

Why

beancount's grammar never reduces a statement whose line fails. An invalid date also fails the line, because beancount's lexer raises it. The push/pop walk in convert.rs skipped the state change only when the line had an ERROR_TOKEN. As a result:

  • pushtag #a 2024-02-30 still tagged later transactions #a, and was reported as never popped.
  • poptag #a 2024-02-30 still popped, so the next transaction lost its tag.

The pop errors, unclosed pushes and the deprecated | used the directive node's span. That span starts at the blank and comment lines stored before the node, so the error landed on the comment line.

How

  • push_pop_header_fails: one rule for all four directives. A header line fails when it has any of these:

    • an invalid token;
    • a token the statement does not take, found by first_header_defect, the rule that reports it (poptag #a #b, poptag #a 2024-01-01, popmeta kk: "v");
    • an invalid date (invalid_value_date).

    pushmeta_value no longer keeps its own copies of the last two checks.

  • node_content_span: one canonical helper for a node's span without its leading trivia. It is used for InvalidPoptag / InvalidPopmeta, for the unclosed-push spans and for DeprecatedPipeSymbol. fixup_directive_spans used to compute the same start inline and now calls it too. A probe that adds ; zz before every column-0 line of the matrix and tracked inputs finds no other error that lands on a comment line.

  • One error per key: a key pushed twice and never popped is one UnclosedPushmeta, as in beancount (leftover metadata 'v, w').

Results (beancount 3.2.3)

Input beancount main this PR
P pushtag #a / poptag #a 2024-02-30 0 3 3 0 3
P pushmeta kk: "v" / popmeta kk: 2024-02-30 0 3 3 0 3
P pushtag #a 2024-02-30 / poptag #a 2 3 2 2 3
P pushtag #a 2024-02-30 / T 2, untagged 0 2, #a 2, untagged
pushtag #a 2024-02-30 / ; c / poptag #a 1 3 1 1 3
pushmeta kk: "v" $ / ; c / popmeta kk: 1 3 1 2 1 3
pushtag #a $ / ; c / poptag #a 1 3 1 2 1 3
pushmeta k: "v" $ / ; c / popmeta k: 1x2 3 1x2 3 1x2 3

Every row also matches at load level (rledger check against loader.load_string). With a transaction after a failed pop, it keeps #a / kk: "v", as in beancount.

  • Generated differential: 6,827 inputs. They combine 17 push shapes × 14 pop shapes (valid and invalid dates, invalid tokens, extra tags and values) with comment, blank and indented lines between them, nested pushes, transactions, and CRLF and BOM variants. Each input compares per-line parse errors, per-line load errors and every transaction's tags and kk metadata across beancount, main and this branch.
    • Errors: 3,212 inputs gained, 0 regressed.
    • Tag state: 1,136 inputs gained, 0 regressed.
    • What is left is one class, not specific to push/pop: an indented comment line after a column-0 comment line (; c then ; d) is unexpected INDENT in beancount, and rledger reports nothing.
  • Includes: push/pop state is per file on both sides.
  • Parse-error parity: 92,606 → 92,739 inputs match, 0 regressions. The manifest is updated.
  • BOM matrix:
    • 7 rows now match and 1 is closer.
    • 1 row is relabeled as a listed exception, with its reason. Its Assets:X rewrite rule held only through the old bogus popmeta takes-no-metadata error. The line's own difference, one P0026 for two x<BOM>y runs after a failed line, also exists on main.
  • Caches:

Tests

  • crates/rustledger-parser/tests/push_pop_failed_header.rs covers:

    • the issue rows;
    • tag and metadata state, including nested pushes;
    • other header errors;
    • pops after a failed push;
    • leading-trivia spans;
    • one error per key;
    • CRLF and BOM;
    • the pipe span.

    Each count was checked with beancount 3.2.3, and the green and red converters must agree.

  • crates/rustledger-loader/tests/push_pop_failed_header_test.rs runs the full pipeline and checks error codes, lines and the booked transactions' tags and metadata.

How to test

cargo test -p rustledger-parser --test push_pop_failed_header
cargo test -p rustledger-loader --test push_pop_failed_header_test
printf '2024-01-01 open Assets:A\npushtag #a\npoptag #a 2024-02-30\n' > x.beancount && rledger check x.beancount

Closes #2995

🤖 Generated with Claude Code

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

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 39.9ms ± 0.6ms 555.6ms ± 0.3ms 13.9x 43.1 MB / 51.1 MB
investment 60.4ms ± 0.5ms 2098.9ms ± 15.9ms 34.7x 47.3 MB / 58.9 MB
fifo 58.9ms ± 0.3ms 11585.2ms ± 82.5ms 196.8x 49.0 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 39.8ms ± 0.3ms 39.9ms ± 0.6ms +0.4% ✅ within noise 43.3 MB → 43.1 MB (-0.6%)
investment 61.1ms ± 0.4ms 60.4ms ± 0.5ms -1.1% ✅ within noise 47.2 MB → 47.3 MB (+0.2%)
fifo 59.0ms ± 0.3ms 58.9ms ± 0.3ms -0.2% ✅ within noise 49.5 MB → 49.0 MB (-0.9%)

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

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Nov 25, 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

…and its errors are on its own line

beancount's grammar never reduces a statement whose line fails, and an
invalid date fails it too (the lexer raises it), so bean-check 3.2.3
neither pushes nor pops there. The push/pop walk skipped the state change
only for an ERROR_TOKEN, so `pushtag #a 2024-02-30` still tagged later
transactions and was reported never popped, and `poptag #a 2024-02-30`
still popped.

push_pop_header_fails, the one rule all four directives now ask, fails a
header line on an invalid token, any token the statement does not take
(first_header_defect: `poptag #a #b`, `poptag #a 2024-01-01`,
`popmeta kk: "v"`) or an invalid date (invalid_value_date). pushmeta_value
drops its own copies of the last two checks.

A pop error, an unclosed push and a deprecated `|` took the directive
node's span, which starts at the blank and comment lines before it.
node_content_span, the span from the first content token, is now used for
them and by fixup_directive_spans, which computed the same start inline.

A key pushed twice and never popped is one UnclosedPushmeta, as beancount
reports it.

Parse-error parity: 92,606 -> 92,739 inputs match, 0 regressions. A
generated differential of 6,827 push/pop sequences (beancount vs before vs
after, per-line parse and load errors plus every transaction's tags and
metadata): 3,212 error rows and 1,136 tag-state rows gained, 0 regressed.
BOM matrix: 7 rows now match, one closer, one relabeled as a listed
exception (its rewrite rule held only through the old popmeta error).
WASM cache 128 -> 130; loader cache stays 76 (directives move only for a
source with a parse error, which it never saves).

Closes #2995

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the fix/push-pop-invalid-date branch from 440b093 to 0bfed8d Compare November 26, 2026 00:15
@robcohen
robcohen merged commit 8e6feae into main Nov 26, 2026
62 of 63 checks passed
@robcohen
robcohen deleted the fix/push-pop-invalid-date branch November 26, 2026 00:37
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.

compat(parser): a pushtag, poptag or popmeta with an invalid date changes no state, and a pop error is on the pop's own line

1 participant