Skip to content

fix(parser): refuse a tag or link line after a transaction's first posting - #2618

Merged
robcohen merged 3 commits into
mainfrom
fix/tag-after-posting
Oct 12, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/tag-after-posting

Conversation

@robcohen

@robcohen robcohen commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

What beancount does

Beancount 3.2.3, checked with the oracle on the corpus file and on variants:

  • Its grammar accepts a tags-and-links line anywhere in a transaction's posting list (posting_or_kv_list includes tags_links), but the builder (grammar.py, Builder.transaction) refuses one that comes after the first posting: ParserError("Tags or links not allowed after first Posting: TagsLinks(...)"), one per such line, at any indent.
  • It keeps the transaction, without those tags. bean-check exits 1.
  • A tags line between the header and the first posting still joins the transaction.

So the grammar's intent is that tags/links lines continue the header, and only before the postings start. parser-lima/test-cases_Transactions.TagsAfterFirstPosting is such a file, and lima's own fixture records it as an anomaly.

What was wrong

rledger added the late tags to the transaction with no error. A file bean-check rejects loaded clean, and SELECT tags reported a tag beancount never attaches.

What changed

Beancount's behavior, which is also the correct reading of the grammar: such a line is a parse error at the line itself (naming its tags), and the transaction is kept without them.

  • One rule, body_tag_joins_transaction(posting_seen), and one error constructor, tags_after_posting_error (convert.rs).
  • Both conversion paths use them: red convert_transaction and green convert_transaction_header skip body TAG/LINK tokens after the first POSTING node. Both body checks report the line: red transaction_body_check and green tl_transaction_body_check, at a newline and at EOF. A line that also has junk on it still gets "unexpected input" instead, as before.
  • Loader CACHE_VERSION 39 and WASM CACHE_VERSION 39 (+ LOADER_CACHE_VERSION_PIN, and the two tripwire fixture versions). A cached parse of such a file holds the late tags and no error.
  • The lima fixture moves to the expected-parse-error list in fixture_tests.rs.
  • tests/baselines/parser-corpus.manifest: the parser-output hashes of the two corpus files above move (source hashes unchanged), checked with STRICT_BASELINE=1 over the full corpus.
  • The F2-bis unit test asserted that the late tag joins the set. Its point, that the comment before a tag line survives, is kept; the tag assertion is reversed.

How tested

  • tags_after_first_posting_are_an_error_and_dropped (parser integration): on both parse and parse_red_only, a pre-posting tag joins and a post-posting tag and link (indented, and at EOF without a newline) are dropped. Exactly one error per late line, with its tags in the message and its span on that line. The transaction and its postings are kept.
  • parse_green_eq_red_corpus gained four inputs (late tag line, indented + EOF, no trailing newline, junk on the line). green_txn_header_matches_red gained a pre/post mix.
  • Fail-without-fix: with convert.rs/green.rs reverted to main (tests kept), the integration test and the updated F2-bis test fail. (The lima allowlist entry is one-sided, as fixture_tests.rs documents, so it permits the error rather than requiring it; the integration test is what pins it.)
  • Corpus (742 files): exactly two files now get the new error, the lima fixture and parser-lima/examples_data_full.beancount. bean-check rejects both too (the latter also for unrelated syntax errors).
  • Suites: cargo test --all-features for rustledger-parser, -loader, -wasm, rustledger; clippy workspace -D warnings and the release-feature clippy; cargo doc -D warnings.

Closes #2575

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

…sting

Beancount's builder refuses a tags-and-links line that comes after a
transaction's first posting ("Tags or links not allowed after first
Posting") and keeps the transaction without those tags. rledger added
them to the transaction silently, so a file bean-check rejects loaded
clean with a tag beancount never attaches.

Such a line is now a parse error at the line, and its tags are not
kept; a tags line before the first posting still joins the
transaction. One rule and one error constructor serve both the red and
green conversions and body checks. Loader and WASM CACHE_VERSION 39.

Closes #2575

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner October 11, 2026 17:48
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 48.2ms ± 3.4ms 852.4ms ± 12.1ms 17.7x 51.4 MB / 50.1 MB
investment 74.9ms ± 1.8ms 3180.5ms ± 78.4ms 42.4x 57.5 MB / 58.2 MB
fifo 72.7ms ± 1.1ms 16707.9ms ± 1304.4ms 229.9x 57.5 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 46.0ms ± 0.5ms 48.2ms ± 3.4ms +4.7% ✅ within noise 51.5 MB → 51.4 MB (-0.2%)
investment 76.1ms ± 1.1ms 74.9ms ± 1.8ms -1.5% ✅ within noise 57.4 MB → 57.5 MB (+0.2%)
fifo 73.6ms ± 1.5ms 72.7ms ± 1.1ms -1.3% ✅ within noise 57.4 MB → 57.5 MB (+0.0%)

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

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 819
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

The two corpus files with a tag line after a transaction's first
posting (the lima fixture and parser-lima/examples_data_full) now parse
with an error and without those tags (#2575). Only their parser-output
hashes move; source hashes are unchanged.

Refs #2575

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

Copy link
Copy Markdown
Member Author

Review log

Round Scope Checks Finding Fix
1 Whole change, before push bean-check 3.2.3 on the fixture and variants (indented, two lines, pre- vs post-posting); green/red mirrors read side by side; parser/loader/wasm/CLI suites; clippy Test helper closures tripped redundant_closure_for_method_calls. The PR body's fail-without-fix claim for the lima fixture was wrong (that allowlist is one-sided). Closures replaced. Claim corrected: the integration and F2-bis tests are the ones that fail without the fix.
2 CI after push Parser Baselines The corpus parser-output manifest pinned the old output of the two affected corpus files Refreshed only those two hashes (source hashes unchanged); STRICT_BASELINE=1 corpus_baseline and cst_baseline pass locally over the full corpus
3 Re-read of the diff (rule helper, both conversions, both body checks, EOF path, cache bumps) required checks; rustfava advisory 8 failed / 671 passed (expected) none none

Beancount 3.2.3 (bean-check), on a minimal file with the account opened:

d.beancount:2: Tags or links not allowed after first Posting: TagsLinks(tags={'tag1'}, links=set())

exit 1. The transaction is kept, with tags {'basetag'} only.

@robcohen robcohen closed this Oct 12, 2026
@robcohen robcohen reopened this Oct 12, 2026
# Conflicts:
#	CHANGELOG.md
#	crates/rustledger-wasm/src/cache.rs
@robcohen
robcohen merged commit c6c21ce into main Oct 12, 2026
66 of 68 checks passed
@robcohen
robcohen deleted the fix/tag-after-posting branch October 12, 2026 21:16
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.

A #tag after a transaction's first posting is kept by rledger, not by beancount

1 participant