Repository navigation
fix(booking): infer augmenting empty-{} cost from the residual (completes #1706) - #1709
Merged
Merged
Conversation
An augmenting posting with an empty cost spec `{}` was accepted by
bean-check but rejected by `rledger check` as "2 unknowns". Beancount
books, then interpolates the single remaining unknown, so `1000 USD {}`
against one `-900 EUR` leg is booked at the inferred 0.90 EUR/unit.
Root cause: the pipeline books before interpolating, but `interpolate`
only ever filled missing *units*, never a cost *number* — an augmenting
`{}` was counted as one unknown and then never solved. The lot entered
inventory with no cost basis, so a later `-100 USD {}` reducing it
could no longer match a cost-bearing lot and became a spurious second
unknown beside the elided PnL leg. Fixing the augmentation fixes the
reduction by cascade.
Fix (interpolate.rs only): for an empty, price-less `{}` that is the
sole unknown in its cost currency group, infer the per-unit cost from
the residual (stored as `PerUnitFromTotal` to preserve precision). A
priced `{}` still defers to booking-time lot matching (keeps #1026).
Compat-policy bucket 1 — not a breaking change.
Closes #1705
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Every fixture cross-checked against bean-check 3.2.3 (matrix in the #1705 plan comment). Encodes: residual solve, currency/date-only specs, 2-unknown rejections, price-vs-residual precedence (residual wins), negative-cost rejection, ambiguous-currency rejection, NONE method, STRICT ambiguity, multi-lot FIFO reduce, missing-units sell-all. For cherry-pick into #1706. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…gative and ambiguous-currency rejection Finishes #1706 (the solver core is @yurenju's work, preserved as the parent commit) with the four items from its review, each pinned against bean-check 3.2.3 via the 17-fixture matrix (committed here as tests/compatibility/files/interpolation/): - Remove the #1708 interim guard: it fired in book() before interpolation could run, making the solver dead code on rebase. Its book.rs test returns to not-an-error with the full history documented. - Solve regardless of price annotations: beancount infers from the residual even when a price is present AND when they disagree ({} @ 0.90 with a 0.95 residual books {0.95} — verified, silent). - Reject a negative solved cost (bean: "Cost is negative") instead of booking a negative-cost lot. - Reject an ambiguous cost currency: when the spec names none and more than one candidate currency exists among complete cost-less postings, bean fails to categorize. Candidates exclude currencies owning their own missing-amount unknown (disjoint groups stay legal), and the check defers to the more specific unassigned+cost-unknown rejection when a fully-unassigned posting exists. Matrix: 17/17 accept/reject parity with bean-check; solved values match to the cent (0.90 inferred; 0.95 residual-over-price). The issue's original file passes end-to-end. Closes #1705 Closes #1706 Co-Authored-By: yurenju <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-07-03)
What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the booking/interpolation pipeline to match Beancount’s behavior when encountering augmenting postings with an empty cost spec ({}): it now infers a per-unit cost from the transaction residual (including when a price annotation is present), and replaces the prior interim “guard” error with the actual solver behavior.
Changes:
- Implement residual-based inference for empty-cost augmentations in
interpolate.rs, including new rejection paths for negative inferred costs and ambiguous cost-currency inference. - Remove the interim booking-time guard that rejected empty-cost augmentations, allowing interpolation to solve them as intended.
- Add a compatibility fixture matrix under
tests/compatibility/files/interpolation/and update the fixture.gitignorerules to include it.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-booking/src/interpolate.rs | Adds residual-based inference of per-unit cost for empty cost specs, plus new error cases and unit test coverage. |
| crates/rustledger-booking/src/book.rs | Removes the interim booking guard/error for empty-cost augmentations and updates tests accordingly. |
| tests/compatibility/files/.gitignore | Allows the new interpolation/ compatibility fixture directory to be tracked. |
| tests/compatibility/files/interpolation/e01_augment_empty.beancount | Adds compatibility fixture for basic empty-cost augmentation inference. |
| tests/compatibility/files/interpolation/e02_reduce_empty_auto.beancount | Adds compatibility fixture for reduction with {} and auto-filled residual posting. |
| tests/compatibility/files/interpolation/e03_augment_currency_only.beancount | Adds compatibility fixture for augmentation with cost currency-only spec ({EUR}). |
| tests/compatibility/files/interpolation/e04_augment_date_only.beancount | Adds compatibility fixture for augmentation with cost date-only spec ({YYYY-MM-DD}). |
| tests/compatibility/files/interpolation/e05_two_empty_augments.beancount | Adds compatibility fixture covering multiple empty-cost augmentations in one txn. |
| tests/compatibility/files/interpolation/e06_empty_plus_auto.beancount | Adds compatibility fixture combining empty-cost augmentation with an auto posting. |
| tests/compatibility/files/interpolation/e07_empty_plus_price.beancount | Adds compatibility fixture ensuring price annotations don’t block cost solving. |
| tests/compatibility/files/interpolation/e08_none_augment_empty.beancount | Adds compatibility fixture for empty-cost augmentation under booking method NONE. |
| tests/compatibility/files/interpolation/e09_none_reduce_empty.beancount | Adds compatibility fixture for {} reduction under booking method NONE. |
| tests/compatibility/files/interpolation/e10_strict_reduce_empty_ambiguous.beancount | Adds compatibility fixture for STRICT booking method and {} reduction ambiguity. |
| tests/compatibility/files/interpolation/e11_fifo_reduce_empty_two_lots.beancount | Adds compatibility fixture for FIFO reduction spanning multiple lots with {}. |
| tests/compatibility/files/interpolation/e12_double_broken.beancount | Adds compatibility fixture for multiple empty-cost postings causing multiple-unknown behavior. |
| tests/compatibility/files/interpolation/e13_missing_units.beancount | Adds compatibility fixture for missing-units interpolation in a later transaction. |
| tests/compatibility/files/interpolation/e14_negative_residual.beancount | Adds compatibility fixture for rejecting negative inferred costs. |
| tests/compatibility/files/interpolation/e15_multicurrency_residual.beancount | Adds compatibility fixture for ambiguous cost-currency inference in multicurrency residuals. |
| tests/compatibility/files/interpolation/e16_price_vs_residual.beancount | Adds compatibility fixture for price-vs-residual conflict (residual wins for inferred cost). |
| tests/compatibility/files/interpolation/e17_price_plus_auto.beancount | Adds compatibility fixture combining price annotation with an auto posting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
Patch release: augmenting empty-{} cost specs now infer the per-unit
cost from the transaction residual, matching beancount exactly (#1705,
reported and first implemented by @yurenju in #1706, completed in #1709
with bean-check-verified edge semantics: residual wins over a
disagreeing price annotation; negative and ambiguous-currency solves
are rejected). The #1708 interim guard is superseded. No wire or API
changes.
Workspace 0.20.0 -> 0.20.1; packages/mcp-server bumped to match.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Merged
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
Patch release: augmenting empty-{} cost specs now infer the per-unit
cost from the transaction residual, matching beancount exactly (#1705,
reported and first implemented by @yurenju in #1706, completed in #1709
with bean-check-verified edge semantics: residual wins over a
disagreeing price annotation; negative and ambiguous-currency solves
are rejected). The #1708 interim guard is superseded. No wire or API
changes.
Workspace 0.20.0 -> 0.20.1; packages/mcp-server bumped to match.
Co-authored-by: Claude Opus 4.8 <[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.
Builds directly on @yurenju's #1706 — the solver core is their work (parent commit preserved; Co-Authored-By carried through the squash) — finishing the four review items so this ships now rather than round-tripping:
book()before interpolation ran, making the solver dead code post-rebase (all 11 augmentation fixtures verified dying in the guard on a trial merge).{} @ 0.90with a 0.95 residual books{0.95}, silently (verified). Theprice.is_none()skip re-opened the silent-corruption path for annotated postings.{-0.90}lot.Validation
17-fixture matrix (committed as
tests/compatibility/files/interpolation/, every row cross-checked against real bean-check 3.2.3 in the compat container): 17/17 accept/reject parity, solved values match to the cent, the issue's original file passes end-to-end. Full methodology + ground-truth table in the #1705 plan comments. 108/108 booking suite · clippy-D warnings· fmt.Closes #1705
Closes #1706 — @yurenju thank you for the report AND the fix; the maintainer preferred to land it immediately, so review items were applied directly rather than requested.
🤖 Generated with Claude Code