Repository navigation
fix(booking): prorate never rounds a nonzero half-floor share to zero - #3039
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
rust_decimal division breaks ties to even, so a share of exactly half of the 1e-28 floor (1e-25 * 0.002 / 4 = 5e-29) came back as 0 from the fast path, a nonzero share flushed to nothing, where the exact reference rounds it to 1e-28. A zero share of a nonzero product now falls through to the exact BigDecimal path; nonzero results are unaffected. Booked @@ splits can change, so the WASM cache moves to v135. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/prorate-tiny-values
branch
from
November 26, 2026 04:28
f90a562 to
cc9e3cf
Compare
robcohen
added a commit
that referenced
this pull request
Nov 26, 2026
…breadth-first order, each currency once (#3038) beancount 3.2.3 parses its files breadth first and `aggregate_options_map` merges `operating_currency` in that order, `uniquify`d (first occurrence wins, the top-level file's own repeats included). rledger merged it depth first and kept repeats: `main` (MMM) including `x` (XXX, including `z` ZZZ) then `y` (YYY) gave [MMM, XXX, ZZZ, YYY] against [MMM, XXX, YYY, ZZZ], and USD in main and an include gave [USD, USD, EUR] against [USD, EUR]. Auditing the other options beancount aggregates across files: `display_precision` is merged into the top-level file's display context with `DisplayContext::update_from`, which keeps a fixed precision, so the top-level file's value wins; rledger let the last file read win (an include's USD:0.001 rendered 1.23456 USD as 1.235 where bean-query gives 1.23). `insert_pythonpath` becomes a sorted set there (no order) and has no effect in rledger. Included plugins are ignored by beancount and run by rledger deliberately; their order is unchanged. - `Options::set_in_file_at` records each merged option's values with its file; `Options::merge_across_files(ranks)` is the one merge, called by `Loader::load` over `SourceMap::parse_ranks` before the display context and the cache see the options. Every surface (CLI, LSP, WASM, FFI) reads the loader's options or the cache's merged copy. - `apply` lists a repeated operating currency once, for options set without the loader. - Loader CACHE_VERSION 77 -> 78 (cached values change), WASM pin 78, WASM CACHE_VERSION 137 (135, 136 taken by #3039, #3040). - Tests: unit tests for the merge; loader tests for the issue's trees, a duplicate include, a disk glob and a cache round trip, all checked against bean-check 3.2.3; drift guards across the loader, WASM `Ledger` (and restored), ffi-wasi, the LSP, and the CLI cold and on a cache hit (`report returns` currency, `query` precision). Closes #3038 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 26, 2026
…breadth-first order, each currency once (#3041) * fix(loader): merge operating_currency across includes in beancount's breadth-first order, each currency once (#3038) beancount 3.2.3 parses its files breadth first and `aggregate_options_map` merges `operating_currency` in that order, `uniquify`d (first occurrence wins, the top-level file's own repeats included). rledger merged it depth first and kept repeats: `main` (MMM) including `x` (XXX, including `z` ZZZ) then `y` (YYY) gave [MMM, XXX, ZZZ, YYY] against [MMM, XXX, YYY, ZZZ], and USD in main and an include gave [USD, USD, EUR] against [USD, EUR]. Auditing the other options beancount aggregates across files: `display_precision` is merged into the top-level file's display context with `DisplayContext::update_from`, which keeps a fixed precision, so the top-level file's value wins; rledger let the last file read win (an include's USD:0.001 rendered 1.23456 USD as 1.235 where bean-query gives 1.23). `insert_pythonpath` becomes a sorted set there (no order) and has no effect in rledger. Included plugins are ignored by beancount and run by rledger deliberately; their order is unchanged. - `Options::set_in_file_at` records each merged option's values with its file; `Options::merge_across_files(ranks)` is the one merge, called by `Loader::load` over `SourceMap::parse_ranks` before the display context and the cache see the options. Every surface (CLI, LSP, WASM, FFI) reads the loader's options or the cache's merged copy. - `apply` lists a repeated operating currency once, for options set without the loader. - Loader CACHE_VERSION 77 -> 78 (cached values change), WASM pin 78, WASM CACHE_VERSION 137 (135, 136 taken by #3039, #3040). - Tests: unit tests for the merge; loader tests for the issue's trees, a duplicate include, a disk glob and a cache round trip, all checked against bean-check 3.2.3; drift guards across the loader, WASM `Ledger` (and restored), ffi-wasi, the LSP, and the CLI cold and on a cache hit (`report returns` currency, `query` precision). Closes #3038 Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(loader): don't link the private MERGED_ACROSS_FILES from public docs Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[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.
What changed
rustledger_booking::prorateno longer returns0for a nonzero share of exactly half ofDecimal's1e-28floor.The differential proptest (
tests/prorate_differential.rs) found this on a random draw. Shrunk case:prorate(1e-25, 0.002, 4). The product2e-28is exact, so the fast path divides it.rust_decimal'schecked_divbreaks ties to even, so5e-29becomes0. The exact reference rounds it half away from zero, to1e-28. The test's one-ulp tolerance allows tie-to-even everywhere else, but a nonzero share flushed to zero is the #2344 / #2346 failure class.Root cause
The cause is a tie-break at the scale limit, not the order of operations: the fast path's quotient is a tie whose even neighbor is zero. (The older saved seed,
1e-20 * 1e-9 / 0.1, was the product-underflow case, and the existing scale guard already sends it to the exact path.)Fix
The fast path now also falls through to the existing exact
BigDecimalpath when it gives a zero share of a nonzero product. Every other zero quotient is below half the floor, and the exact path rounds it to zero too, so the extra cost applies only to zero shares. Nothing changes on the hot path for nonzero results.Callers affected
book.rs: the sale value of a@@total price split across lots, which the gain is booked from.book.rs: the per-lot@@price annotation.rustledger-pluginvaluation plugin.rustledger-budgetaccrual split.In each one, a share of exactly ±5e-29 now comes out as ±1e-28 instead of 0. Booked directives can change, so the WASM
CACHE_VERSIONis bumped to 135 (133 and 134 are taken by other PRs). The loader cache archives only parsed directives, so it is not bumped.Tests
crates/rustledger-booking/tests/prorate.rs: the shrunk tie case with both signs, the older seed, and below-half-floor shares that stay zero.prorate_differential.proptest-regressions. Without the fix, the new seed fails deterministically with "fabricated zero".cargo clippy --all-features --all-targets -D warnings, and tests for booking, loader, validate, rustledger, plugin, budget and wasm.🤖 Generated with Claude Code