Skip to content

Preserve commodity-swap gains in the journal oracle - #10

Merged
jwiegley merged 1 commit into
mainfrom
johnw/fix-3314-swap-gains
Nov 5, 2026
Merged

jwiegley merged 1 commit into
mainfrom
johnw/fix-3314-swap-gains

Conversation

@jwiegley

@jwiegley jwiegley commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

The journal reader discarded lot annotations attached to an exchange cost,
so it omitted inferred gains when a commodity swap's two lots shared a base
currency. Exchanging 10 BTC at a 100 EUR basis for 20 ETH at a 50.02 EUR basis
produced no balancing offset in the oracle; Ledger correctly infers -0.4 EUR.

Retain the cost-side lot, keep the exchanged commodity's original balancing
contribution, and add the exact gain within the posting's own real or balanced
virtual group. Normalize total-lot precision on either side so fractional
inferred amounts retain their recovered precision. The rules cite the C++
implementation and the regression witnesses prepared for ledger/ledger#3317.

Validation: the Nix oracle build passed all 1,086 jobs, and all 34 focused
journals agreed with Ledger. Across the full corpus, all 3,837 comparable
journals agreed with the current Ledger integration, with no mismatches or unexpected
skips. The planted-defect and pristine-control detector checks also passed.

The correction is based on oracle revision 8342e12, preserving the quoted
commodity, bare format symbol, and account-header fixes. The downstream PR ledger/ledger#3317 will
consume it through the flake input; the removed submodule is not restored.

The reader discarded lot annotations attached to exchange costs, leaving
inferred gains absent from the balancing pool. Retain the cost-side lot
and the original exchanged-commodity contribution while booking the exact
common-currency gain within the posting's own group.

Normalize total-lot precision on either side so fractional inferred
amounts retain their precision. The rules cite the Ledger regressions
3314_lot_gains and 3314_swap_total prepared for PR 3317.

The Nix oracle build passed 1,086 jobs. All 34 focused journals and all
3,837 comparable journals in the full corpus agreed with Ledger; both
detector controls passed and no unexpected skip bins were populated.
jwiegley added a commit to ledger/ledger that referenced this pull request Nov 5, 2026
Preserve main's exact lot-gain calculations and rounding-residue bounds
while retaining independent real and balanced-virtual posting groups.
Cover sub-unit swap gains and total-lot precision in both groups.

Pin the companion oracle correction through the flake so the new
regressions participate in the full semantic comparison. Preserve the
upstream removal of the lean submodule and its current parser fixes.

Oracle: ledger/ledger-semantics#10
@jwiegley
jwiegley merged commit bbd5478 into main Nov 5, 2026
3 checks passed
@jwiegley
jwiegley deleted the johnw/fix-3314-swap-gains branch November 5, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant