Repository navigation
fix(parser): report a repeated metadata key on a transaction or posting, keeping the first value - #2897
Merged
Conversation
…ng, keeping the first value Beancount builds a transaction's and a posting's metadata checking each key against the ones before: a repeat is `Duplicate metadata field on entry` / `Duplicate posting metadata field`, reported at the transaction's line, and the first value stands. rledger kept the last value silently. Every other directive takes the last value with no error in beancount too, and is unchanged. - core: `MetadataBuilder::build_keeping_first` (near-linear, like `build`) keeps each key's first entry. - parser: transaction and posting metadata, red and green, build with it; `report_duplicate_metadata` (one green pass over the transactions) reports each repeat. It replaces `report_posting_filename_lineno`: a posting starts with `filename` and `lineno` set, as in beancount. A counter test pins it linear. - fixtures: the lima MetadataTransactionRepeated cases expect these errors (their txtpb lists them); validation-errors.beancount loses its unimplemented "E6001 duplicate metadata key" section, which is now a parse error; metadata_many_keys expects the first value. - One parser-lima baseline row (examples_data_error-duplicates) moves. - Loader CACHE_VERSION 62, WASM 82. Closes #2893 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
# Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
…ing locations, and document the stricter repeat check - A META_ENTRY that holds its own error (a bad value, an invalid date) is no repeat, as in beancount. The duplicate check now runs after report_invalid_dates. - A posting's written `filename:` / `lineno:` is dropped from its metadata (red and green), so the real location stands as in beancount. - Document reporting a repeat with an identical value as a deliberate stricter-than-Python deviation (beancount compares by identity), with a regression test and a CHANGELOG note. - CHANGELOG: `rledger format` now refuses files with such repeats. - spec/impl/test-vectors.md: the duplicate key is a parser test now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a line, and share POSTING_LOCATION_KEYS A transaction whose metadata line holds an error is dropped whole by beancount, so the doc comments now say that and that rledger keeps the entry under its error-recovery policy. The posting location keys are one const, shared by the duplicate check's preset and drop_posting_location_keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The compat-corpus copy of lima's MetaData.MetadataTransactionRepeated now gets the duplicate-metadata parse error (#2893). Its source hash is unchanged, so only that row's output hash moves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 9, 2026
Resolves the WASM cache and CHANGELOG conflicts with #2897: v82 is #2897's (loader v62), and this branch's note moves to v83 over loader v62. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 9, 2026
Merges origin/main (#2897: loader cache v62, WASM v82). This branch keeps loader v63 and WASM v84; their notes now name v62 and v83 as predecessors. Review round 1 on #2903: - quiet_after_invalid_tokens drops a construct check that contains the invalid token on an indented line only when the line's posting or metadata grammar reaches that token (indented_grammar_reaches). Where the grammar fails first (`1 VV {}{$`: `unexpected LCURL`, then the token), both errors stand, as in beancount. - An `open` with an invalid token on its header gets no booking-method error (P0025), and a transaction with an invalid token anywhere in it gets no repeated-metadata-key error: beancount never builds either. - cr_outside_strings_present streams the lexer and stops at the first `\r` outside a string. - Parse-error parity manifest re-pinned with --update; --check is clean. 76,882 of 111,323 inputs match beancount 3.2.3 (main: 57,518). Refs #2872 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 29, 2026
…rror difference P12 beancount 3.2.3 stays silent on a transaction or posting metadata key repeated with the same value as its first one when that value is TRUE / FALSE, an empty or one-character string, an account, a tag or empty, and compares each repeat with the first value. rledger reports every repeat (#2897), on purpose. Document it as P12 in compatibility.md, restate the inline comment at report_duplicate_metadata from black-box observation, and extend the pinning test to postings, empty values and a repeat back to the first value. No behavior change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 29, 2026
…rror difference P12 beancount 3.2.3 stays silent on a transaction or posting metadata key repeated with the same value as its first one when that value is TRUE / FALSE, an empty or one-character string, an account, a tag or empty, and compares each repeat with the first value. rledger reports every repeat (#2897), on purpose. Document it as P12 in compatibility.md, restate the inline comment at report_duplicate_metadata from black-box observation, and extend the pinning test to postings, empty values and a repeat back to the first value. No behavior change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 29, 2026
…rror difference P12 (#3091) beancount 3.2.3 stays silent on a transaction or posting metadata key repeated with the same value as its first one when that value is TRUE / FALSE, an empty or one-character string, an account, a tag or empty, and compares each repeat with the first value. rledger reports every repeat (#2897), on purpose. Document it as P12 in compatibility.md, restate the inline comment at report_duplicate_metadata from black-box observation, and extend the pinning test to postings, empty values and a repeat back to the first value. No behavior change. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
A metadata key written twice on a transaction or a posting is now reported as beancount 3.2.3 reports it, and the first value stands:
kk: "first"/kk: "second"on a transactionDuplicate metadata field on entry, at the transaction's line; value"first""second""first"pk: 1/pk: 2on a postingDuplicate posting metadata field, at the transaction's line; value121pushmeta kk: "p", then a transaction writingkktwice"a"(first written)"b""a"kkon the transaction and on one of its postingskkwritten twice on anopen(or any other directive)Stricter than Python, deliberately (maintainer's decision): beancount checks a repeat with
if value is not posting_or_kv.value(grammar.py, the transaction and posting builders). That is an object-identity test, so it stays silent when the repeated value is the identical interned object:TRUE/TRUE,""/"", one-character strings, accounts,#t/#t. rledger reports every repeat. This follows the AGENTS.md checklist: a "Stricter than Python" comment atreport_duplicate_metadata, the regression testtest_parse_reports_a_repeat_with_an_identical_value_unlike_python, and a CHANGELOG note.rledger format: these are parse errors now, sorledger formatrefuses a file with a repeated transaction or posting key, as it refuses any file with errors.bean-formatstill formats such a file. This follows the existing policy for beancount's builder errors.The issue asked for the error "on the repeated line". bean-check reports it at the transaction's line, so this PR does the same. Beancount checks repeats only on transactions and postings; every other directive's metadata takes the last value with no error, which is what rledger already does, so that is left alone.
How it works:
MetadataBuilder::build_keeping_firstkeeps each key's first entry and drops the later ones. It usesMetadata::dedup_keys_keep_first: pairwise up to the existing threshold, and a hash set past it, so it stays near-linear.convert_meta_entries_keeping_first, and both green converters) build with it. The other directives keepbuild. Thepushmetamerge still lets a written key win over a pushed one, and it now sees the first written value.report_duplicate_metadatais one green-tree pass over the transactions that reports each repeat.report_posting_filename_lineno: a posting starts withfilenameandlinenoalready set, as in beancount, so writing either is the same kind of repeat. That message is kept.CACHE_VERSION62 (withFIXTURE_VERSION), WASM 82 (withLOADER_CACHE_VERSION_PIN62). WASM v81 is fix(validate): report a pad on a closed account, and pad whatever the accounts' state #2895's.Fixtures:
tests/fixtures/validation-errors.beancounthad a "Duplicate metadata key (E6001)" section, but no E6001 validator exists, and the shape is now a parse error. The file must parse clean (test_validation_errors_parses), so the section is removed.MetaData.MetadataTransactionRepeated*fixtures expect exactly these errors (their.txtpblists threeduplicate key test), so they join the expected-parse-error list.metadata_many_keysnow expects the first value.Why
Issue #2893 (found in the #2891 review). This matches beancount.
How to test
Verification
open,pushmeta, and transaction-vs-posting keys, run against full bean-check output. The error lines, counts and kept values all match.MetadataTransactionRepeatedfixtures (each in-tree, and one also in the compat corpus): 3 errors at line 1, as their.txtpband bean-check give;parser-lima/examples_data_error-duplicates.beancount:m1at line 5.examples_data_error-duplicatesrow inparser-corpus.manifestis updated. Its source hash is unchanged and its CST row does not move.STRICT_BASELINE=1passes.test_report_duplicate_metadata_is_linear_in_the_keysputs 20,000 keys, each written twice, on a transaction and 20,000 on a posting. It asserts at most 1,000 pairwise key comparisons, and a quadratic version would make about 2×10^8. The core test boundsbuild_keeping_firstat under 10 comparisons per entry for 50,000 entries.cargo test --workspace --all-features --no-fail-fastpasses (privateTMPDIR).cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depsandcargo fmt --checkpass.Review round 1
TRUE,"","x",Assets:A,#tand"ab"repeats. bean-check reports only the"ab"one.kk: "a"thenkk: (bad(andkk: 2024-02-30,kk: 1 2,kk: Assets:a) now gives only the line's own error, as bean-check does.report_duplicate_metadataskips aMETA_ENTRYthat holds an already-reported error. It now runs afterreport_invalid_dates, so date errors count.PRINTshows only theopen), so it has no kept value to match. rledger keeps the transaction under its existing error-recovery policy. Its metadata is visible only through LSP/WASM, because check, query and format refuse the file.rledger formatrefusal: noted in the CHANGELOG and above.filename:/lineno:is now dropped from its metadata by the red and green converters (drop_posting_location_keys), so the real location stands, as bean-query shows. The docs now say so, and there is a test.spec/impl/test-vectors.md, "Duplicate metadata key" moves from the validation checklist to the parser one, described as a parse error.Closes #2893
🤖 Generated with Claude Code