Repository navigation
fix(booking): reject empty-cost augmentations loudly (interim for #1705) - #1708
Merged
Merged
Conversation
An augmenting posting with a number-less cost spec ({}, {USD},
{2024-01-02}) booked an UNCOSTED lot (CostSpec::resolve() -> None),
silently corrupting every downstream cost read — gains, STRICT matching,
cost reports (#1705's worse, unreported half; the reported 2-unknowns
error only fired one transaction LATER, at the reduction).
Interim guard until cost-from-residual interpolation lands: booking an
augmentation whose cost spec has no number is now
BookingError::EmptyCostAugmentation, with the workaround in the message.
Scoped precisely:
- positive units only — a negative-units {} posting that didn't classify
as a reduction (empty inventory) is reduction INTENT, which the Late
validator's independent lot-matching pass already reports (two-phase
design preserved; test_book_no_inventory_for_account still passes);
- reductions with {} (wildcard lot match) and {*} merge specs unaffected.
test_book_augmentation_not_reduction previously pinned the silent
booking ('should not error - just skip lot matching') — flipped with the
history documented.
Refs #1705
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-03)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an interim safety guard in the booking engine to reject augmenting postings with an empty/numberless cost spec (e.g. {} / {USD} / {2024-01-02}) that would otherwise book an uncosted lot and corrupt downstream cost reads, pending the fuller book-first/interpolate-after fix planned for #1705.
Changes:
- Introduces
BookingError::EmptyCostAugmentationwith an actionable error message. - Adds a booking-time guard to error on positive-unit augmentations whose cost spec lacks a cost number (excluding merge specs).
- Updates fixtures’ stub
Cargo.lockfiles to reflectrustledger-plugin-typesv0.20.0 and adjusts the relevant booking test expectation.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/rustledger-booking/src/book.rs | Adds new error variant + guard for empty-cost augmentations; updates a test to expect the loud failure. |
| crates/rustledger-plugin/tests/fixtures/sample_stub/Cargo.lock | Updates stub lockfile to rustledger-plugin-types 0.20.0. |
| crates/rustledger-importer/tests/fixtures/sample_stub/Cargo.lock | Updates stub lockfile to rustledger-plugin-types 0.20.0. |
💡 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 |
This was referenced Jul 3, 2026
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
…etes #1706) (#1709) * fix(booking): infer augmenting empty-{} cost from the residual 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]> * test: 17-fixture differential edge matrix for #1705 ({} cost solving) 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]> * fix(booking): complete empty-{} cost inference — price precedence, negative 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]> --------- Co-authored-by: Yuren Ju <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
The interim guard from the #1705 review: converts the SILENT half of the bug (an augmenting
{}posting booking an uncosted lot, corrupting every downstream cost read) into a loud, actionable diagnostic:Scoping (the subtle part):
{}posting that didn't classify as a reduction (e.g. empty inventory) is reduction intent, which the Late validator's independent lot-matching pass already reports; the two-phase engine-lenient/validator-diagnoses design is preserved (test_book_no_inventory_for_accountstill passes unchanged).{}(wildcard lot-match syntax) and{*}merge specs unaffected.test_book_augmentation_not_reductionpreviously pinned the silent booking — flipped with history documented.The real fix (book-first-interpolate-after, per the #1705 analysis) is planned separately; this guard makes the interim safe. E2E: the issue's file now fails on the buy with the message above instead of silently mis-booking and failing one transaction later.
Refs #1705
🤖 Generated with Claude Code