Repository navigation
fix(validate): report a pad on a closed account, and pad whatever the accounts' state - #2895
Merged
Merged
Conversation
… accounts' state Both checked against full bean-check 3.2.3 output: - A pad dated after one of its accounts' close loaded clean; beancount reports `Invalid reference to inactive account`. It is now E1003, for the target and the source. On the close date itself the account is still active, as for a posting. - A pad with an unopened (or not yet opened) account was dropped after its E1001, so the balance after it failed too (E2001), or, with an unopened target, the pad was never reported unused where beancount reports `Unused Pad entry`. Beancount inserts the padding before it validates anything, so the pad is now registered in every case; the half whose account was never opened has no inventory to land in, and a balance on an unopened target still uses (and so does not leave unused) the pad. `effective_pads` is the one rule for which pads a balance can use, shared by both paths. `pad_balance_and_note_before_the_open_are_unopened` expected the old E2001; bean-check reports no balance failure there, so it no longer does. WASM CACHE_VERSION 81 (v80 is #2891's): its cached error lists change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
# Conflicts: # crates/rustledger-wasm/src/cache.rs
…ck, and cross-reference process_pads Review round 1 on the pad gaps: - The one-error-per-account choice is now a documented, deliberate divergence (maintainer decision): bean-check reports a pad account a second time against its synthesized padding transaction when the padding is non-zero; rledger pads inline and reports it once, at the pad. Code comment at the pad check, CHANGELOG, PR body. - `effective_pads` and `rustledger_booking::process_pads` name each other as two implementations of which pad a balance uses, with a revisit condition. - E2004 (multiple pads) is one helper, used on the opened-target and the unopened-target paths alike; a zero amount on an unopened target uses no pad, as on an opened one. - Tests: a zero balance on an unopened target and an unopened-account pad with no balance are unused (E1001s plus E2003); E2004 on both paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rule as it is Review round 2 on the pad gaps: - `test_validate_pad_with_an_unopened_account_still_pads` asserts the exact E1001 list per shape (one per unopened account at the pad, plus the balance's own on an unopened target), as the closed-account test does, so it actually pins the one-error-per-account divergence it is cited for. - The zero-balance test's doc no longer contradicts itself. - The `effective_pads` / `process_pads` cross-references describe the current rule: a superseded earlier pad stays usable in the validator, where beancount keeps only the latest, a bug on main that #2896 fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 9, 2026
`plan_pads` summed each padded balance's subtree by scanning every account, so `rledger check` and the LSP, which now run it on any ledger with a pad, were quadratic: 40k accounts with a pad and a balance each took 46 s. It now keeps a lexical index of its accounts and visits a subtree by range query, through `rustledger_core::for_each_strict_subaccount`, which the validator's `sum_account_subtree` now shares. It also keeps units per currency instead of lot inventories, the only thing a pad reads. A regression test counts the inventories read: 2,000 for 2,000 padded balances, where the scan read 4,003,999. Also corrects the #2895 CHANGELOG entry (no E2004, both padding halves land) and the PadCorrect spec comment (padding is dated at the pad). Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 9, 2026
…E2004 (#2898) * fix(validate): apply one pad rule to padding and balance checks, as beancount does The validator padded its own inventories with a second copy of the pad rule in `rustledger_booking::process_pads`, and the two drifted from each other and from beancount (#2896). Both now go through one `rustledger_booking::PadTracker`, beancount's `ops/pad.py` rule: the latest pad dated before a balance, once per currency, a zero difference using the currency up without using the pad, and a superseded pad never used again. Each side keeps its own inventories, and a new drift guard (`pad_parity_test`) compares them end to end on the #2896 shapes. - An unopened target's own postings count: bean-query 100 / -130, where it padded 70 / -100. One its postings already satisfy is not padded, and the pad is unused. - A balance on an unopened account is compared (E2001). - `pad`, `balance 0`, `balance 10` is E2003 plus E2001. - A superseded pad no longer pads a later balance (E2003 plus E2001). - A pad or balance before the account's later open says the account is inactive, not never opened. WASM cache v83 (v82 is #2893's). Closes #2896 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(validate)!: pad from the shared plan at the pad's date, and drop E2004 The validator now takes its padding from `rustledger_booking::plan_pads`, the computation `process_pads` is built on, instead of a rule of its own, and adds each padding entry to its inventories at the `pad`, where beancount dates it. A balance on the pad's source between the pad and the balance it satisfies no longer fails falsely. BREAKING CHANGE: E2004 (multiple pads for one balance) is removed, with `ErrorCode::MultiplePadForBalance`. A superseded pad is an unused pad (E2003), as in beancount, and E2004 fired falsely on a pad that had already padded another currency. The code is retired in the docs. - A pad amount that cannot be computed or applied is reported at its balance, which is not compared, as before. - One not-yet-open wording for postings, pads and balances: "is inactive on D (not opened until O)". - `account_inventory` uses the entry API. - Drift guard and integration tests cover the pad-date shape and the currency case (p15), both clean in bean-check. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(booking): measure padded balances through a prefix index `plan_pads` summed each padded balance's subtree by scanning every account, so `rledger check` and the LSP, which now run it on any ledger with a pad, were quadratic: 40k accounts with a pad and a balance each took 46 s. It now keeps a lexical index of its accounts and visits a subtree by range query, through `rustledger_core::for_each_strict_subaccount`, which the validator's `sum_account_subtree` now shares. It also keeps units per currency instead of lot inventories, the only thing a pad reads. A regression test counts the inventories read: 2,000 for 2,000 padded balances, where the scan read 4,003,999. Also corrects the #2895 CHANGELOG entry (no E2004, both padding halves land) and the PadCorrect spec comment (padding is dated at the pad). Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(booking): count the accounts a pad subtree sum reads, not its matches The complexity test counted matches inside `subtree_units`, so a plain scan that adds only the matching accounts passed it. Account totals are now a newtype whose `get` and iteration count each account where it is read: 2,000 reads for 2,000 padded balances, and 4,003,999 with that scan swapped in. A core test pins `for_each_strict_subaccount` on 8,655 generated names (deep trees, Unicode, prefix siblings such as Assets:A / Assets:AB, the same paths under several roots): it visits exactly the strict subtree, and reads few keys per query through a counting `Borrow<str>` key, so a filtered full scan in core fails it (8,655 keys per query). The function is generic over the key for that. Also notes that units alone cannot answer beancount's pad-at-cost check (#2901), and that `PadInventories::add` skips `Inventory::add`'s near-ceiling check (#2554). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- 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
These are the two pad gaps found in the #2890 review. Both already exist on main, and both are checked here against full bean-check 3.2.3 output.
1. A pad on a closed account
pad Assets:A Equity:Oafterclose Equity:O, then a balanceInvalid reference to inactive account 'Equity:O'(x2)E1003close Assets:A(the target)Assets:A(x2)E1003Unused Pad entry+ inactiveE2003onlyE1003+E2003closeon the pad's own dateBoth accounts are checked. On the close date itself the account is still active, by the same rule as a posting (
lifecycle_errors), because aclosesorts after the other entries of its day.2. A pad with an unopened account still pads
Beancount inserts the padding before it validates anything, so a pad with an unopened account is reported but still pads. rledger dropped such a pad after its
E1001.Equity:OE1001+E2001E1001Equity:OE1001+E2001E1001Assets:AE1001E1001E1001sE1001sUnused Pad entry, balance failed, unknown accountE1001+E2001E1001+E2001+E2003How the fix works:
effective_padsis now the one rule for which pads a balance can use. It is shared by the padding path and the unopened-target path.pad_balance_and_note_before_the_open_are_unopenedexpected the oldE2001. bean-check reports no balance failure on that shape, so the test no longer expects one.Cache
WASM
CACHE_VERSION81 (loader v61), because the cached error lists change. The loader cache is unaffected.Known divergence: one error per account (maintainer's decision)
When the padding is non-zero, bean-check reports each inactive or unknown pad account twice: once for the
pad, and once against the padding transaction it synthesizes. rledger pads inline, with no synthesized transaction, so it reports each account once, at the pad. The error lines agree with bean-check; only the count differs.The maintainer kept this as a deliberate divergence. Per the AGENTS.md checklist:
validate_pad.test_validate_pad_reports_a_closed_accountandtest_validate_pad_with_an_unopened_account_still_pads.Why
Found in the #2890 review. Matches beancount.
How to test
Verification
E2003 Unused Pad entry:GrammarExceptionsPad,ParserComplete.NoEmptyLines,ParserEntryTypes.Pad(each in-tree and in the compat corpus) andexamples_data_account-types: bean-check reportsUnused Pad entryon the same line in every case.examples_data_full: bean-check drops that pad and balance over syntax errors (tags on them), so the file is not comparable there. rledger refuses it for parse errors anyway.cargo test --workspace --all-features --no-fail-fastpasses (privateTMPDIR).STRICT_BASELINE=1corpus and CST baselines pass. No parser change.cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depsandcargo fmt --checkpass.Review round 1
cache.rs, perf(core)!: store metadata as an ordered vector with interned keys #2891's v80 note now comes before the v81 note, the v81 note says loader v61, andLOADER_CACHE_VERSION_PINis 61.effective_pads(validator) andrustledger_booking::process_padsnow cross-reference each other at both sites, with a revisit condition.E1001s plusE2003;E1001plusE2003;E2004is reported on both paths.E2003shapes were checked against bean-check (Unused Pad entry).STRICT_BASELINE=1corpus and CST baselines, clippy-D warnings, rustdoc-Dwarningsandcargo fmt --checkpass.🤖 Generated with Claude Code