Repository navigation
fix(booking): answer a bare price sigil instead of ignoring it - #1919
Conversation
`100.00 USD @` asks for the price to be COMPUTED. rledger read the bare
sigil as "no price" and weighed the posting at its units, so the request
went unanswered and the posting silently stopped competing for the
residual it was supposed to cancel.
Assets:A 100.00 USD @ was E3001 does not balance
Assets:B -50.00 EUR now @ 0.50 EUR, balanced
`@` weighs `units x price` and `@@` weighs `total x signum(units)`, so
each is inverted accordingly. A `@@` is answered with a TOTAL and stays a
`@@`; beancount normalizes it to a per-unit rate, but the weight is
identical and keeping the author's form is the ADR-0008 position.
NOT what beancount computes. It solves the MAGNITUDE, |residual|/|units|,
which balances only when the other side happens to be opposite-signed. On
the `IncompleteInputs.PriceMissing` vector - `100.00 USD @` against a
POSITIVE `120.00 CAD` - it fills `@1.2 CAD`, giving two +120.00 CAD
weights, and then reports the 240 CAD imbalance it just created. The
value that balances is -1.2, and a negative price is not a price, so the
honest answer is to refuse and say which number the balance was asking
for. That mirrors the existing NegativeInferredCost rule for `{}` specs.
The sigil is also an unknown for the one-per-currency-group rule, which
is what #1915 was filed for. Its group is resolved from the residual it
has to cancel, falling back to the other postings' WEIGHT currencies when
nothing is known yet - not their units currencies, since a price
redenominates the weight. An earlier draft used units currencies and put
`? CAD @ 1.2 USD` in CAD, which split the two unknowns into separate
groups and hid a real ambiguity.
Alongside a cost the sigil is inert and stays untouched: cost beats
price, so it feeds implicit price directives and never the balance.
`cost_unknowns_by_currency` is renamed `weight_unknowns_by_currency`,
which is what it has always counted and now visibly holds two shapes.
Sweep of 995 corpus files under auto_accounts (without it, E1001 masks
the whole IncompleteInputs family): exactly two change status, both
ok -> ERR, and beancount rejects both -
UnitsMissingCurrencyWithPrice (CategorizationError) and
UnitsMissingNumberWithPrice (InterpolationError). The latter is the
regression #1913 introduced and #1915 recorded, so this closes it.
All eleven hand-built shapes now match beancount's accept/reject. Six of
the seven new tests were confirmed to fail against the pre-fix logic; the
seventh guards against over-reach on the cost path, which the neuters do
not exercise.
Closes #1915
📊 Benchmark Results
vs main branch (2026-08-01)
What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes booking interpolation so a bare price sigil (@ / @@ with no amount, e.g. 100 USD @) is treated as a request to compute the price (an unknown weight), rather than being ignored as “no price”. This aligns interpolation with the intended residual-cancellation semantics and closes #1915.
Changes:
- Treat bare price sigils as per-currency unknown weights for the one-unknown-per-currency-group rule, and resolve their currency from residuals (with a fallback when residuals are all zero).
- Solve
@(per-unit) and@@(total) bare sigils from the residual and write the computed price back into the posting; refuse negative inferred prices with a dedicated error. - Add focused unit tests in
interpolate.rsand an end-to-end loader test ensuring the full pipeline answers the bare sigil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-booking/src/interpolate.rs | Implements bare-sigil grouping + inference, adds new error variants, and adds unit tests covering @/@@, grouping, and refusal cases. |
| crates/rustledger-loader/tests/loader_test.rs | Adds an end-to-end regression test verifying loader + booking fills a bare @ price to balance a cross-currency transaction. |
Suppressed comments (1)
crates/rustledger-booking/src/interpolate.rs:1081
- When a bare price sigil has zero units and the residual is non-zero, this returns
AmbiguousBarePriceCurrency, but the currency was already determined (currencyis known here). The failure is that a zero-units posting cannot affect the balance, so the error message is misleading and makes debugging harder.
return Err(InterpolationError::AmbiguousBarePriceCurrency {
account: transaction.postings[idx].account.clone(),
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 93% |
| Full AST Match | 100% |
| Total Files | 812 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
…er it Found while investigating whether beancounts abs() is intentional (#1915 follow-up on the same branch). - the form beancounts own parser docs call recommended - states the answers currency and leaves only the number to compute. The first draft inferred the currency for every sigil, so Assets:A 100.00 USD @ CAD Assets:B -50.00 EUR was written back as : a currency the author never wrote, substituted silently. That is the same fabrication this module refuses everywhere else. A declared currency now wins outright and only a fully bare / is inferred. When the declared currency has no residual to cancel, the balance determines nothing, so the sigil is left unanswered rather than filled with the the arithmetic implies - and the currency that actually fails to balance is reported instead: before @ 0.50 EUR, accepted after E3001 does not balance: residual -50.00 EUR The balance validator still runs on such a transaction because the units are complete, so nothing is swallowed. Confirmed to fail when the declared-currency rule is neutered.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
crates/rustledger-booking/src/interpolate.rs:394
bare_price_currency()’s fallback path says it uses other postings’ weight currencies, but it callscrate::price_currency_of(posting)which intentionally returnsNoneforIncompleteAmount::CurrencyOnlyprices (e.g.@ USD). That causes the inference to fall back to the posting’s units currency in cases where the weight currency is already known/declared, which can mis-group unknowns and make currency inference fail or pick the wrong group.
let currency = crate::price_currency_of(posting).or_else(|| match &posting.units {
Some(IncompleteAmount::Complete(amount)) => Some(amount.currency.clone()),
Some(IncompleteAmount::CurrencyOnly(currency)) => Some(currency.clone()),
_ => None,
});
crates/rustledger-booking/src/interpolate.rs:1102
- When
units.number.is_zero()and the residual is non-zero, this returnsAmbiguousBarePriceCurrency, but the currency is already known at this point (currencyis selected in the earlier pass). The resulting error message (“cannot tell which currency…”) is misleading; the real issue is that a price cannot affect balance when units are zero, so the sigil cannot be solved from residuals.
if residual.is_zero() {
continue;
}
return Err(InterpolationError::AmbiguousBarePriceCurrency {
account: transaction.postings[idx].account.clone(),
});
Copilot review catch on #1919. The fallback candidate list is documented as the other postings WEIGHT currencies, but it walked price-then-units and skipped cost specs. A cost-bearing posting weighs in its COST currency, so was offering HOOL instead of USD. Reachable whenever every other posting is itself an unknown, which is exactly when the fallback runs: Assets:A 100.00 USD @ Assets:B HOOL {300.00 USD} Both unknowns weigh in USD and genuinely compete. Grouping the sigil under HOOL made them look disjoint, so instead of naming the real problem rledger reported a bare imbalance: before E3001 does not balance after multiple postings ... for currency USD (2 unknowns) which is what beancount reports too (Too many missing numbers for currency group USD). The ladder is now cost, then price, then units, matching the residual scan. A spec naming no currency contributes no candidate rather than falling through to the commodity being bought. Confirmed to fail when the cost arm is removed.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
crates/rustledger-booking/src/interpolate.rs:406
- In
bare_price_currency’s all-residuals-zero fallback, cost-bearing postings don’t use the existing cost-currency inference path (infer_cost_currency_from_postings) when the cost spec omits a currency (e.g.{100}). That can make the bare-sigil currency look ambiguous (and mis-group unknowns) even when the cost currency is inferable from other postings, becausecost_currency_of(posting, || None)returnsNonein that shape.
let currency = if posting.cost.is_some() {
crate::cost_currency_of(posting, || None)
} else {
crates/rustledger-booking/src/interpolate.rs:973
- Zero-unit postings with a bare price sigil (
0 USD @/0 USD @@) have a weight of 0 regardless of the (unknown) price, so they aren’t an “unknown” for the one-per-currency-group interpolation budget. Right now they’re always registered inweight_unknowns_by_currency, which can incorrectly triggerMultipleMissingand prevent solving an otherwise-solvable missing posting in that currency.
for (idx, units, kind) in bare_price {
let Some(currency) = bare_price_currency(transaction, idx, &residuals) else {
return Err(InterpolationError::AmbiguousBarePriceCurrency {
account: transaction.postings[idx].account.clone(),
});
};
… price Self-review of #1919. A zero-units posting carrying a bare sigil reused AmbiguousBarePriceCurrency, whose message tells the author to write the price currency. The currency is KNOWN in that branch; what fails is that no price gives zero units any weight. The advice was wrong and would not have helped: Assets:A 0.00 USD @ Assets:B -50.00 EUR before cannot tell which currency the bare price ... should be computed in; write the price currency after cannot compute the price for the Assets:A posting: the posting has zero units, so no price gives it any weight, and the transaction does not balance without one New UnsolvablePrice variant, symmetric with UnsolvableUnits. The already-balanced case still returns quietly, since the sigil is then unanswerable but harmless. Python beancount raises decimal.DivisionByZero on this same input, at booking_full.py:1003, where the sibling COST_PER branch guards with . Reported upstream on beancount#1040.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
crates/rustledger-booking/src/interpolate.rs:416
- In the
candidates.is_empty()fallback, the “other postings’ weight currency” ladder usescrate::price_currency_of(posting)which only returns a currency forIncompleteAmount::Complete. That means a posting with a declared price currency but missing number (@ USD/@@ USD→IncompleteAmount::CurrencyOnly) is incorrectly treated as having no price currency and falls back to its units currency. This can mis-group unknowns in the all-residuals-zero path and defeat the one-unknown-per-currency-group rule.
let currency = if posting.cost.is_some() {
crate::cost_currency_of(posting, || None)
} else {
crate::price_currency_of(posting).or_else(|| match &posting.units {
Some(IncompleteAmount::Complete(amount)) => Some(amount.currency.clone()),
crates/rustledger-loader/tests/loader_test.rs:2246
- The test fixture string uses
\n \line continuations, which introduces trailing spaces into the generated .beancount file (e.g. after the transaction header and posting lines). This makes the fixture harder to read and can hide whitespace-sensitive parsing issues; it’s clearer to build the file content without embedding those extra spaces.
"2010-01-01 open Assets:A\n\
2010-01-01 open Assets:B\n\
\n\
2010-05-28 * \"bare price sigil\"\n \
Assets:A 100.00 USD @\n \
Two Copilot review catches on #1919. 1. writes the price NUMBER and elides only its currency. It was being treated as a bare sigil, so the authors rate was overwritten with whatever balanced the books: Assets:A 100.00 USD @ 1.20 Assets:B -100.00 USD before @ 1.00 USD, accepted after @ 1.20 USD, E3001 residual 20.0000 USD The number is data. Only the currency is inferred now, the same rule the units path uses for a bare . This also restores agreement with , which has its own test pinning that an incomplete price carrying a number is not re-solved. Beancount does exactly this: keeps 1.20, infers USD, and reports the 20.0000 USD imbalance the authors own rate implies. 2. The fallback candidate scan used , which reads only a COMPLETE price amount and so cannot see . A posting priced that way offered its UNITS currency instead, splitting two unknowns that genuinely compete: Assets:A 100.00 EUR @ Assets:B 200.00 CAD @ USD before two disjoint groups, silently accepted after multiple postings ... for currency USD (2 unknowns) which is what beancount reports too (Too many missing numbers for currency group USD). Added , deliberately wider than and documented as such: the narrow reading is right where a prices numeric contribution matters, but the question here is which currency a postings weight lands in, and answers that. Both confirmed to fail when neutered.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
crates/rustledger-booking/src/interpolate.rs:85
AmbiguousBarePriceCurrencyis also returned when the price number is written but the currency is elided (e.g.@ 1.20). The current error text says "bare price", which is inaccurate for that case and may confuse users trying to fix the input.
#[error(
"cannot tell which currency the bare price on the {account} posting should be \
computed in; write the price currency (e.g. `@ 1.20 USD`)"
)]
crates/rustledger-booking/src/interpolate.rs:81
- Docstring for
AmbiguousBarePriceCurrencysays this is only for a bare sigil (@/@@with no amount), but the variant is also used when the price number is present and only the currency is missing (e.g.@ 1.20). Updating the wording will keep the docs consistent with actual usage.
/// A bare price sigil (`@` / `@@` with no amount) asks for the price to be
/// computed, but no single currency stands out to compute it in (#1915).
crates/rustledger-loader/tests/loader_test.rs:2246
- In tests, prefer
expect(...)over a bareunwrap()so failures show what operation failed (especially helpful under CI).
.unwrap();
A posting written as a number with no currency (`120.00`) was either
silently rewritten or silently dropped, and the transaction was accepted
however unbalanced it was. `rledger check` reported success.
2010-05-28 * "currency omitted by typo"
Assets:A 120.00
Assets:B -999.00 USD
before check: no errors; Assets:A booked as 999.00 USD
after E3001 does not balance: residual -879.00 USD
Assets:A booked as 120.00 USD
The number the author typed was discarded and replaced by whatever
balanced the books. A dropped currency is a one-character typo, so this
turned a typo into a fabricated amount.
The number is DATA, not something to solve for. Only the currency is read
off the balance now, and the posting no longer routes through
`unassigned_missing`, which exists for postings that have no number
either and are solved from the residual. Conflating the two is what
overwrote the number.
With a cost or price present the units currency is unknowable: a cost or
price names ITS OWN currency, never the commodity being counted, so
`10 {300.00 USD}` is ten of something and nothing says what. Those are
now refused. Previously they left the posting unfilled AND unreported, so
`validate_transaction_balance` took its documented early return (which is
only sound when interpolation has already reported the failure, the
invariant from #1911) and an arbitrarily unbalanced transaction passed
silently. Python beancount refuses the same shapes with "Could not
resolve units currency".
Matches beancount on every case tested: it accepts the bare form and
infers the currency while keeping the number, and rejects both the cost
and price forms.
One pre-existing test asserted the old behavior and has been rewritten.
`interpolate_number_only_infers_currency_and_balances` pinned a
NumberOnly leg with `@ 1 USD` contributing its raw number to the PRICE
currency's residual. Beancount rejects that input outright. The unit
multiplier of 1 is what made it look harmless; at any other price the
residual was wrong too, since the arm added the number without applying
the multiplier.
`number_only_currency`, extracted in #1919, loses its only caller here
and is removed.
Corpus: over 995 files under auto_accounts, exactly two change status,
both `IncompleteInputs.UnitsMissingCurrencyWithCost` (the same vector in
two copies), both ok -> ERR, and beancount rejects both.
Four of the five new or rewritten tests were confirmed to fail against
the pre-fix logic. The fifth covers the accepted case, where old and new
happen to agree.
Closes #1920
A posting written as a number with no currency (`120.00`) was either
silently rewritten or silently dropped, and the transaction was accepted
however unbalanced it was. `rledger check` reported success.
2010-05-28 * "currency omitted by typo"
Assets:A 120.00
Assets:B -999.00 USD
before check: no errors; Assets:A booked as 999.00 USD
after E3001 does not balance: residual -879.00 USD
Assets:A booked as 120.00 USD
The number the author typed was discarded and replaced by whatever
balanced the books. A dropped currency is a one-character typo, so this
turned a typo into a fabricated amount.
The number is DATA, not something to solve for. Only the currency is read
off the balance now, and the posting no longer routes through
`unassigned_missing`, which exists for postings that have no number
either and are solved from the residual. Conflating the two is what
overwrote the number.
With a cost or price present the units currency is unknowable: a cost or
price names ITS OWN currency, never the commodity being counted, so
`10 {300.00 USD}` is ten of something and nothing says what. Those are
now refused. Previously they left the posting unfilled AND unreported, so
`validate_transaction_balance` took its documented early return (which is
only sound when interpolation has already reported the failure, the
invariant from #1911) and an arbitrarily unbalanced transaction passed
silently. Python beancount refuses the same shapes with "Could not
resolve units currency".
Matches beancount on every case tested: it accepts the bare form and
infers the currency while keeping the number, and rejects both the cost
and price forms.
One pre-existing test asserted the old behavior and has been rewritten.
`interpolate_number_only_infers_currency_and_balances` pinned a
NumberOnly leg with `@ 1 USD` contributing its raw number to the PRICE
currency's residual. Beancount rejects that input outright. The unit
multiplier of 1 is what made it look harmless; at any other price the
residual was wrong too, since the arm added the number without applying
the multiplier.
`number_only_currency`, extracted in #1919, loses its only caller here
and is removed.
Corpus: over 995 files under auto_accounts, exactly two change status,
both `IncompleteInputs.UnitsMissingCurrencyWithCost` (the same vector in
two copies), both ok -> ERR, and beancount rejects both.
Four of the five new or rewritten tests were confirmed to fail against
the pre-fix logic. The fifth covers the accepted case, where old and new
happen to agree.
Closes #1920
Also, from Copilot review: the fill calls accumulate_residual AFTER the
blanket unrepresentable gate has already run, so an overflow there would
record the currency and carry on, letting a partial residual reach the
public InterpolationResult while units had already been written into the
posting. That contradicts the gate's own rationale, so it is checked at
the point of use, matching the guard the price paths carry.
A posting written as a number with no currency (`120.00`) was either
silently rewritten or silently dropped, and the transaction was accepted
however unbalanced it was. `rledger check` reported success.
2010-05-28 * "currency omitted by typo"
Assets:A 120.00
Assets:B -999.00 USD
before check: no errors; Assets:A booked as 999.00 USD
after E3001 does not balance: residual -879.00 USD
Assets:A booked as 120.00 USD
The number the author typed was discarded and replaced by whatever
balanced the books. A dropped currency is a one-character typo, so this
turned a typo into a fabricated amount.
The number is DATA, not something to solve for. Only the currency is read
off the balance now, and the posting no longer routes through
`unassigned_missing`, which exists for postings that have no number
either and are solved from the residual. Conflating the two is what
overwrote the number.
With a cost or price present the units currency is unknowable: a cost or
price names ITS OWN currency, never the commodity being counted, so
`10 {300.00 USD}` is ten of something and nothing says what. Those are
now refused. Previously they left the posting unfilled AND unreported, so
`validate_transaction_balance` took its documented early return (which is
only sound when interpolation has already reported the failure, the
invariant from #1911) and an arbitrarily unbalanced transaction passed
silently. Python beancount refuses the same shapes with "Could not
resolve units currency".
Matches beancount on every case tested: it accepts the bare form and
infers the currency while keeping the number, and rejects both the cost
and price forms.
One pre-existing test asserted the old behavior and has been rewritten.
`interpolate_number_only_infers_currency_and_balances` pinned a
NumberOnly leg with `@ 1 USD` contributing its raw number to the PRICE
currency's residual. Beancount rejects that input outright. The unit
multiplier of 1 is what made it look harmless; at any other price the
residual was wrong too, since the arm added the number without applying
the multiplier.
`number_only_currency`, extracted in #1919, loses its only caller here
and is removed.
Corpus: over 995 files under auto_accounts, exactly two change status,
both `IncompleteInputs.UnitsMissingCurrencyWithCost` (the same vector in
two copies), both ok -> ERR, and beancount rejects both.
Four of the five new or rewritten tests were confirmed to fail against
the pre-fix logic. The fifth covers the accepted case, where old and new
happen to agree.
Closes #1920
Also, from Copilot review: the fill calls accumulate_residual AFTER the
blanket unrepresentable gate has already run, so an overflow there would
record the currency and carry on, letting a partial residual reach the
public InterpolationResult while units had already been written into the
posting. That contradicts the gate's own rationale, so it is checked at
the point of use, matching the guard the price paths carry.
fix(booking): keep the number when only the currency is elided
A posting written as a number with no currency (`120.00`) was either
silently rewritten or silently dropped, and the transaction was accepted
however unbalanced it was. `rledger check` reported success.
2010-05-28 * "currency omitted by typo"
Assets:A 120.00
Assets:B -999.00 USD
before check: no errors; Assets:A booked as 999.00 USD
after E3001 does not balance: residual -879.00 USD
Assets:A booked as 120.00 USD
The number the author typed was discarded and replaced by whatever
balanced the books. A dropped currency is a one-character typo, so this
turned a typo into a fabricated amount.
The number is DATA, not something to solve for. Only the currency is read
off the balance now, and the posting no longer routes through
`unassigned_missing`, which exists for postings that have no number
either and are solved from the residual. Conflating the two is what
overwrote the number.
With a cost or price present the units currency is unknowable: a cost or
price names ITS OWN currency, never the commodity being counted, so
`10 {300.00 USD}` is ten of something and nothing says what. Those are
now refused. Previously they left the posting unfilled AND unreported, so
`validate_transaction_balance` took its documented early return (which is
only sound when interpolation has already reported the failure, the
invariant from #1911) and an arbitrarily unbalanced transaction passed
silently. Python beancount refuses the same shapes with "Could not
resolve units currency".
Matches beancount on every case tested: it accepts the bare form and
infers the currency while keeping the number, and rejects both the cost
and price forms.
One pre-existing test asserted the old behavior and has been rewritten.
`interpolate_number_only_infers_currency_and_balances` pinned a
NumberOnly leg with `@ 1 USD` contributing its raw number to the PRICE
currency's residual. Beancount rejects that input outright. The unit
multiplier of 1 is what made it look harmless; at any other price the
residual was wrong too, since the arm added the number without applying
the multiplier.
`number_only_currency`, extracted in #1919, loses its only caller here
and is removed.
Corpus: over 995 files under auto_accounts, exactly two change status,
both `IncompleteInputs.UnitsMissingCurrencyWithCost` (the same vector in
two copies), both ok -> ERR, and beancount rejects both.
Four of the five new or rewritten tests were confirmed to fail against
the pre-fix logic. The fifth covers the accepted case, where old and new
happen to agree.
Closes #1920
Also, from Copilot review: the fill calls accumulate_residual AFTER the
blanket unrepresentable gate has already run, so an overflow there would
record the currency and carry on, letting a partial residual reach the
public InterpolationResult while units had already been written into the
posting. That contradicts the gate's own rationale, so it is checked at
the point of use, matching the guard the price paths carry.
… its findings The axis shipped without a way to record a deliberate deviation, so every settled divergence stayed in the report forever. That is how a signal gets muted, which is the failure #1902 exists to prevent. `KNOWN_POSTING_DIVERGENCES` is keyed by (basename, FIELD), not by file. A whole-file mask would also swallow a DIFFERENT field diverging on that file later - exactly the regression a registry is supposed to keep visible. Every entry carries its reason; an entry without one is indistinguishable from one added to make a run look clean. TRIAGE OF THE 10 FINDINGS Pinned, 10 fields across 5 files: rust_decimal 28-29 digit ceiling (2 files). The price needs 30 digits to round-trip. CLAUDE.md records this as not fixable locally; the recovery side channel was prototyped and rejected in PR #1613. Negative inferred price (2 files). `100.00 USD @` against `120.00 CAD` has both postings positive, so the price would have to be -1.20 CAD. beancount takes the magnitude; #1919 decided to refuse it and say so, because silently flipping the sign hides a sign error in the user's own ledger. issue-520 (1 file), the tracked regression fixture compat.yml names. Left surfaced on purpose, 5 files: The `{# total}` / `{per # }` compound-cost divergence, now filed as #1943. beancount treats a `#` spec as incomplete and SOLVES it from the residual, discarding what the author wrote: `{# 9.95}` against -19.90 cash books 1.990, not 0.995. We honor the written number and report E3001. Real, undecided, and it should stay in anyone's face until it is decided. `UnitsMissingNumberWithCost` cost_date and `Transactions.ZeroPrices` - triaged only far enough to know what they are. Pinning them would assert a conclusion nobody has reached. A LIMITATION #1943 EXPOSED IN THE ERROR AXIS Those compound-cost files were NOT flagged by axis 2. beancount emits ValidationError (unknown account) on the corpus copies while rledger emits E3001, so both "error" and the axis scores agreement. Not comparing error taxonomies is still the right call - there is no honest mapping between Python exception classes and our codes - but the cost is that a genuine semantic divergence can hide behind incidental agreement on WHETHER a file errs. Noted in the issue so a future clean error report is not over-read. SELF-TEST Extended with the property that matters for a field-keyed registry: a pin suppresses the field it names, and a pin on a DIFFERENT field leaves the finding visible. Verified by sabotage - rewriting the lookup to match on filename alone fails exactly that check.
…cle (#1940) * feat(compat): compare per-posting cost, price and lot date in the oracle The oracle summed units per (account, currency). That cancels compensating per-posting errors, and it never looked at cost or price at all. #1915 is the case in point: `100.00 USD @` was read as "no price", and the UNITS were identical before and after the fix, so no sum could ever have shown it. This adds a third axis comparing each posting on date, account, number, currency, cost_number, cost_currency, cost_date and price, as an ordered multiset. FIRST CORPUS RUN FOUND A REAL BUG #1939: an arithmetic expression in a COST SPEC is truncated to its first operand, while the same expression in a PRICE annotation evaluates correctly. Assets:Something 2 HOOL {10.00 * 3 USD} @ 20.00 * 2 USD beancount cost 30.00 price 40.00 rledger cost 10.00 price 40.00 Consequences are a wrong cost basis, and then a FALSE E3001 rejecting a file beancount accepts, because the weight follows the truncated cost. DESIGN DECISIONS, AND WHY Reference side is the beancount PYTHON API, not bean-query. beanquery has bugs of its own (beanquery#279 is pinned in the BQL suite for exactly that reason) and an oracle that inherits the reference implementation's query-layer bugs is not an oracle. Our side is read as JSON, NOT CSV. This is the whole ballgame and it cost a full corpus run to learn: CSV renders every number through DisplayContext, so a price written `56.0763 USD` in a ledger whose USD is mostly 2-decimal comes back as `56.08`. The first run reported 32 files diverging on price_number, and every single one was the harness comparing beancount's STORED value against rledger's RENDERED one. None was a defect. JSON carries the stored value. Generalized: a differential oracle must not read the other side through a presentation layer. Lot dates and currencies compare EXACTLY. A lot date is either the right lot or it is not, and softening that would defeat the reason the axis exists. Only the three money fields get the precision tolerance, and it is the same one `compare()` already uses for units after #1909 - quantize to beancount's own exponent, because beancount rounds when it books and rledger rounds when it displays. TWO HARNESS BUGS THE RUN EXPOSED, BOTH FIXED HERE - CSV vs JSON, above: 32 false findings. - Signed zero. Decimal keeps the sign of zero and the tools do not always agree on it, so `-0.00` and `0.00` sorted differently, every row after the first signed zero was compared against the wrong partner, and one file reported five bogus `number` differences that were really one misalignment. SELF-TEST Extended to the new comparator, on synthetic rows rather than fixtures because the interesting cases are ones no ledger we have produces on demand: a wrong cost, a wrong lot date, a one-sided price, a row-count mismatch, and - the one that matters most - a difference that is REPRESENTATION and must NOT be reported, paired with one AT beancount's precision that must be. Verified by sabotage, twice: gutting the comparator, and widening the tolerance to always agree. Both are caught, the second reporting exactly the two checks that distinguish a real difference from a representational one. REMAINING FINDINGS, NOT YET TRIAGED 12 files diverge. Beyond #1939 they include two known rust_decimal ceiling cases (30 significant digits, documented in CLAUDE.md as not fixable locally), a `{# 2000 USD}` total-cost reading where we say 200 and beancount says 2000, and several IncompleteInputs fixtures where beancount computes a price we leave unset. None is pinned: an untriaged finding should stay surfaced. Refs #1902. * docs(compat): _dec is format-neutral now, say so It parses JSON amount strings as well as CSV cells since the axis switched to --format json. The docstring still said "CSV cell", which invites misuse. Also states the trade the None return makes: unparsable reads as absent rather than crashing, which is right for a corpus sweep (one bad file must not abort the other 700) but relabels a garbled field as present/absent. It is still reported either way. * feat(compat): add a pin registry for the per-posting axis, and triage its findings The axis shipped without a way to record a deliberate deviation, so every settled divergence stayed in the report forever. That is how a signal gets muted, which is the failure #1902 exists to prevent. `KNOWN_POSTING_DIVERGENCES` is keyed by (basename, FIELD), not by file. A whole-file mask would also swallow a DIFFERENT field diverging on that file later - exactly the regression a registry is supposed to keep visible. Every entry carries its reason; an entry without one is indistinguishable from one added to make a run look clean. TRIAGE OF THE 10 FINDINGS Pinned, 10 fields across 5 files: rust_decimal 28-29 digit ceiling (2 files). The price needs 30 digits to round-trip. CLAUDE.md records this as not fixable locally; the recovery side channel was prototyped and rejected in PR #1613. Negative inferred price (2 files). `100.00 USD @` against `120.00 CAD` has both postings positive, so the price would have to be -1.20 CAD. beancount takes the magnitude; #1919 decided to refuse it and say so, because silently flipping the sign hides a sign error in the user's own ledger. issue-520 (1 file), the tracked regression fixture compat.yml names. Left surfaced on purpose, 5 files: The `{# total}` / `{per # }` compound-cost divergence, now filed as #1943. beancount treats a `#` spec as incomplete and SOLVES it from the residual, discarding what the author wrote: `{# 9.95}` against -19.90 cash books 1.990, not 0.995. We honor the written number and report E3001. Real, undecided, and it should stay in anyone's face until it is decided. `UnitsMissingNumberWithCost` cost_date and `Transactions.ZeroPrices` - triaged only far enough to know what they are. Pinning them would assert a conclusion nobody has reached. A LIMITATION #1943 EXPOSED IN THE ERROR AXIS Those compound-cost files were NOT flagged by axis 2. beancount emits ValidationError (unknown account) on the corpus copies while rledger emits E3001, so both "error" and the axis scores agreement. Not comparing error taxonomies is still the right call - there is no honest mapping between Python exception classes and our codes - but the cost is that a genuine semantic divergence can hide behind incidental agreement on WHETHER a file errs. Noted in the issue so a future clean error report is not over-read. SELF-TEST Extended with the property that matters for a field-keyed registry: a pin suppresses the field it names, and a pin on a DIFFERENT field leaves the finding visible. Verified by sabotage - rewriting the lookup to match on filename alone fails exactly that check. * fix(compat): make the posting sort token lossless and context-free Copilot caught a real defect. `_row_sort_key` canonicalized Decimals with `f"{+v:+040.10f}"`, which has two problems: - `:.10f` rounds to 10 FRACTIONAL digits, and the values this comparison most cares about are exactly the ones that do not survive that. The rust_decimal ceiling cases carry ~30 fractional digits, so two genuinely different prices flattened to the same key. - unary `+` applies the active decimal context, so the token depended on ambient state no caller sets deliberately. The sort key exists to PAIR corresponding rows. Colliding keys mean distinct rows pair arbitrarily, which can invent differences or hide them - and it would have been at its worst on the high-precision entries the registry pins, i.e. the ones nobody looks at twice. Rebuilt from `as_tuple()`, which is context-free. Trailing zeros are stripped by hand rather than via `normalize()` (which also consults the context), so 0.10 and 0.1 agree; an all-zero coefficient drops its sign, so -0.00 and 0.00 agree, which is the signed-zero misalignment fixed earlier. Ordering only has to be TOTAL and identical on both sides. It does not have to be numeric, and pretending it did is what invited the rounding in the first place. Self-test now pins both directions, including the two cases the old token got wrong. Verified by putting the old token back: SELF-TEST FAILED: sort token for 0.0096938775510204081632653061 22 vs 0.0096938775510204081632653061: same=True, expected False SELF-TEST FAILED: sort token for 1.00000000001 vs 1.00000000002: same=True, expected False Corpus result is unchanged - 10 fields pinned, 5 files surfaced - so this fixes a latent hazard rather than a live miscount.
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, and make --auto load beancount's auto plugin (#3059) * fix(booking): refuse a price to compute beside a cost, as beancount does 1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price ignored (#1919). beancount reports "Cannot infer price for postings with units held at cost" (and then crashes); rledger now refuses it as a booking failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER without a currency (@ 12) still takes the cost currency (#3047). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(loader)!: report bytes that are not UTF-8 where beancount does A non-UTF-8 file was decoded lossily and accepted. The decode stays lossy (no panic, the text is still shown), but SourceText now remembers where the invalid sequences were, and the loader reports them as beancount 3.2.3 does: an invalid token outside strings (one per run), one error per string on its last line (UnicodeDecodeError), nothing in a comment. Loader cache v81. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(check)!: --auto runs auto_accounts and implicit_prices, as bean-check --auto does bean-check --auto adds beancount.plugins.auto; rledger --auto ran auto_accounts alone. LoadOptions::auto_accounts now runs both parts, each in its own pass, through plugin_parts. check also renders parse-error snippets of a non-UTF-8 file from the lossily decoded text the loader parsed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(compat): fix stale sections, mark the decided upstream checks covered, bump caches compatibility.md sections 1 (beancount refuses unbalanced multi-currency transactions too), 3 (rledger reports all four push/pop mistakes) and 4 (unknown options are E7001, deprecated E7004) described old behavior. checks.toml: the bare-price row is covered, the lexer row names the UTF-8 test. WASM cache v145. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(cache): WASM v147 / loader v82, after #3060's v146 / v81 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
What
100.00 USD @asks for the price to be computed. rledger read the bare sigil as "no price" and weighed the posting at its units, so the request went unanswered and the posting silently stopped competing for the residual it was meant to cancel.E3001 Transaction does not balance@ 0.50 EUR, balanced@weighsunits × priceand@@weighstotal × signum(units), so each is inverted accordingly. A@@is answered with a total and stays a@@— beancount normalizes it to a per-unit rate, but the weight is identical and keeping the author's chosen form is the ADR-0008 position.Where this deliberately departs from beancount
beancount solves the magnitude,
|residual| / |units|, which balances only when the other side happens to be opposite-signed. On the canonicalIncompleteInputs.PriceMissingvector it does this:It fills a price that cannot balance, then reports the imbalance it just created. The value that would balance is
-1.2, and a negative price is not a price — so the honest answer is to refuse and name the number the balance was asking for:That mirrors the existing
NegativeInferredCostrule for{}cost specs, so the two inference paths now refuse for the same stated reason.The grouping subtlety
The sigil is also an unknown for the one-per-currency-group rule — which is what #1915 was actually filed for. Its group is resolved from the residual it has to cancel, falling back to the other postings' weight currencies when nothing is known yet.
Not their units currencies: a price redenominates the weight, so
? CAD @ 1.2 USDweighs in USD. An earlier draft of this PR read CAD off the units, which put the two unknowns in separate groups and hid a genuine ambiguity. There is a test named for exactly that.Alongside a cost the sigil is inert and left untouched — cost beats price, so it feeds implicit price directives and never the balance.
Verification
Sweep of 995 corpus files under
auto_accounts. Without the plugin,E1001masks the entireIncompleteInputsfamily on both sides and the sweep reports a vacuous "no change" — worth knowing for the next sweep. With it, exactly two files change status, bothok → ERR, and beancount rejects both:IncompleteInputs.UnitsMissingCurrencyWithPriceCategorizationErrorIncompleteInputs.UnitsMissingNumberWithPriceInterpolationErrorThe second is the regression #1913 introduced and #1915 recorded, so this closes it. Both were being silently accepted by main.
@/@@, bare-plus-elided in same and different groups, two bare sigils, cost-plus-sigil, and both-unknowns-on-one-posting.-D warnings;rustdoc -D warningsclean.Incidental
cost_unknowns_by_currency→weight_unknowns_by_currency. That is what it has always counted, and it now visibly holds two shapes rather than one.Closes #1915