Skip to content

docs(migration): document the same-day repeated-lot divergence (#2118) - #2121

Merged
robcohen merged 3 commits into
mainfrom
docs/lot-pooling-divergence
Aug 24, 2026
Merged

robcohen merged 3 commits into
mainfrom
docs/lot-pooling-divergence

Conversation

@robcohen

Copy link
Copy Markdown
Member

Closes the documentation half of #2118.

Python beancount's Inventory is keyed by (currency, cost), so acquisitions sharing a cost, date and label pool into a single position. rustledger keeps one lot per acquisition. When a lot at a different cost was acquired between two that pool, the engines consume in different orders — and a holding bought more than once in a day reports a different cost basis and different realized gains.

We decided to keep rustledger's behavior: it respects acquisition order and Python's cannot, because Cost carries a date and no time, so the two purchases are genuinely one lot under its model. That decision makes documenting it the deliverable — anyone reconciling figures against Python needs to know why they differ, and nothing warned them.

Goes in Known Differences in the migration guide, which is where someone comparing the two engines will actually be looking.

Both the example and the workaround were run, not reasoned about.

The worked example reproduces exactly as written: rustledger leaves 10 @10.00 + 5 @20.00, Python leaves 5 @10.00 + 10 @20.00 — Python consuming the third lot while the second, acquired earlier, goes untouched.

The suggested fix is advice users will follow, so I checked it rather than assuming: giving the repeated purchases distinct labels makes them separate lots on both sides and the two engines then agree (10 @10.00 + 5 @20.00 each).

Independent of #2119 and #2120 — this documents behavior that is not changing.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

Python's inventory is keyed by (currency, cost), so acquisitions sharing a
cost, date and label pool into one position; rustledger keeps a lot per
acquisition. With a third lot at a different cost acquired between them the
two consume in different orders, and a holding bought twice in one day
reports a different cost basis and different realized gains.

We decided to keep rustledger's behavior -- it respects acquisition order,
and Python's cannot, since `Cost` carries a date and no time -- so the
answer is to tell people rather than to change it. Anyone reconciling
against Python needs to know why the figures differ.

Both the worked example and the suggested fix were run against both
engines: distinct labels make the purchases separate lots on either side
and the two agree.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Copilot AI lite review requested due to automatic review settings August 24, 2026 03:08
@robcohen
robcohen requested a review from a team as a code owner August 24, 2026 03:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents the same-day repeated-lot divergence between rustledger and Python beancount.

Changes:

  • Adds a FIFO example showing differing cost bases.
  • Explains the differing inventory models.
  • Recommends distinct lot labels as a workaround.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/migration/from-beancount.md Resolved
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The block was presented as reproducible and was not: it carried no
`booking_method` option and no `open` directives, so pasting it into a file
reports E1001 "Account Income:Gains was never opened" and never reaches the
booking behavior it exists to show. The default is STRICT, not FIFO, so even
opened it would not have demonstrated the FIFO case described.

I had trimmed the setup from the ledger I actually tested, which is the way
to turn a verified example into an unverified one.

Both engines were re-run against the block exactly as it now appears:
`rledger check` is clean, rustledger leaves 10 @10.00 and 5 @20.00, and
beancount leaves 5 @10.00 and 10 @20.00 -- the figures the surrounding text
quotes.

Reported by Copilot on #2121.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

Copy link
Copy Markdown
Member Author

Correct on both counts — fixed in 35cfc11.

Reproduced before fixing: the block as written fails rledger check with E1001 Account Income:Gains was never opened, so it never reaches the booking behavior it exists to demonstrate. And you are right that the default is STRICT, so even with the accounts opened it would not have shown the FIFO case the text describes.

The cause is worth naming: I verified this example against a ledger that did carry the setup, then trimmed it for the doc. That is exactly how a verified example becomes an unverified one.

The block now carries option "booking_method" "FIFO" and the three open directives, and both engines were re-run against it as it now appears in the page, extracted from the markdown rather than retyped:

  • rledger check — clean
  • rustledger — 10 @10.00, 5 @20.00
  • beancount — 5 @10.00, 10 @20.00

which are the figures the surrounding prose quotes.

The section said figures may differ. The fuzzer then showed the divergence
also causes ACCEPTANCE differences in both directions: pooling changes which
lots survive a reduction, so a later reduction naming an explicit cost can
find its lot drained on one engine and present on the other.

That is a different class of problem for someone migrating -- a ledger that
does not load, reporting "Not enough units" with nothing in the message
pointing at same-day repeated lots as the cause. Worth meeting in the
migration guide rather than in the error.

Evidence and both worked cases are on #2118.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen merged commit fe2c30e into main Aug 24, 2026
45 checks passed
@robcohen
robcohen deleted the docs/lot-pooling-divergence branch August 24, 2026 10:38
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.

2 participants