Repository navigation
fix(loader): normalize @@ prices in the shared finalize phase - #1654
Merged
Merged
Conversation
v0.17.0 regression (#1462): `7 USD @@ 10 EUR` surfaced through the FFI component (rustfava) as the raw total price (10) instead of the Beancount per-unit price (10/7 ≈ 1.428). `rledger check` was unaffected. Root cause: the @@→@ normalization (`normalize_prices`) lived ONLY in the CLI `check.rs`, not in the loader's shared `process()` pipeline. When #1462 routed the FFI/MCP surface through that shared pipeline to deduplicate the loader, it lost the normalization the CLI still did separately — so `process()` returned a `Finalized` ledger that wasn't actually finalized. The price invariant was a per-consumer responsibility: the classic drift category (cf. #1648). Fix — put the invariant in the type, not the consumer: - Call `normalize_prices` in the `finalize` transition (LateValidated → Finalized). It runs AFTER Late validation, so exact totals still survive for the precise balance-residual check (#1240) — the reason normalization is deferred rather than done during booking. - `Finalized` is the only publicly-exposed phase and `process()` is the only path to a `Ledger`, so 'prices are normalized' is now an invariant every consumer (CLI, FFI/MCP component, BQL) gets by construction — none can drift. - Remove the now-redundant normalize loop (+ unused import) from `check.rs`. Tests: - Loader: `process()`/finalize normalizes `@@` to per-unit (invariant; no wasm). - FFI component parity: the component surfaces `7 USD @@ 10 EUR` as per-unit 1.42857…, matching `check` — the CLI-vs-FFI parity guard. No regressions: 16 FFI parity + 92 loader + 105 booking + 362 CLI + 163 query + 104 ops tests pass; clippy -D warnings clean. 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-06-30)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Merged
robcohen
added a commit
that referenced
this pull request
Jun 30, 2026
Patch release to ship the @@ total-price normalization fix (#1654): the FFI component (rustfava) was exposing the raw @@ total instead of the per-unit price. Workspace 0.17.0 -> 0.17.1 (cargo set-version); 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 bug
A v0.17.0 regression:
7 USD @@ 10 EURsurfaces through the FFI component (what rustfava reads) as the raw total price10instead of the Beancount-style per-unit price10/7 ≈ 1.428.rledger checkwas unaffected.Root cause
The
@@→@normalization (normalize_prices) lived in exactly one place — the CLI'scheck.rs— not in the loader's sharedprocess()pipeline. PR #1462 (fix(ffi): route load_source through the canonical pipeline) routed the FFI/MCP surface through that shared pipeline to deduplicate the loader, and in doing so dropped the normalization the CLI still did separately. Soprocess()returned aFinalizedledger that wasn't actually finalized.This is the same drift category as #1648 (LSP-vs-
check): a step that should be a pipeline invariant is instead a per-consumer responsibility, so the next consumer to route through the pipeline silently diverges.Fix — put the invariant in the type, not the consumer
normalize_pricesin the loader'sfinalizetransition (LateValidated → Finalized). It runs after Late validation, so exact totals still survive for the precise balance-residual check (Replace rust_decimal with arbitrary-precision decimal to close last Python compat divergence #1240) — which is the entire reason normalization is deferred rather than done during booking.finalizeis the unique correct home.Finalizedis the only publicly-exposed phase andprocess()is the only path to aLedger, so "prices are normalized" is now an invariant every consumer gets by construction — CLI, FFI/MCP component, BQL. None can drift, and the compiler enforces it (you cannot obtain a non-finalized ledger).Directiveimport) fromcheck.rs.Tests
process.rs):process()/finalize normalizes@@to a per-unit@price (runs without the wasm).parity.rs): the component surfaces7 USD @@ 10 EURas per-unit1.42857…, matchingcheck— the CLI↔FFI parity guard the regression slipped past.Verification
No regressions: 16 FFI parity + 92 loader + 105 booking + 362 CLI + 163 query + 104 ops tests pass;
clippy -D warningsclean;fmtclean. The onlynormalize_pricescaller is nowprocess::finalize.🤖 Generated with Claude Code