Skip to content

fix!: refuse a price to compute beside a cost, report non-UTF-8 bytes, and make --auto load beancount's auto plugin - #3059

Merged
robcohen merged 5 commits into
mainfrom
fix/upstream-decisions
Nov 27, 2026
Merged

robcohen merged 5 commits into
mainfrom
fix/upstream-decisions

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What

Implements the maintainer's three decisions on the ambiguous cases left by the upstream check table (#3054), and fixes three stale compatibility.md sections. Stacked on #3057, which provides rustledger_plugin::plugin_parts; it will be rebased onto main as #3054 and #3057 merge.

1. A price to compute beside a cost is refused (breaking)

1 HOOL {10 USD} @ USD, or a bare @, @@, @@ USD, used to be accepted with the price ignored (#1919, a_bare_price_beside_a_cost_is_inert). It is now a booking failure (BOOK) on the posting, which is beancount's Cannot infer price for postings with units held at cost. bean-check 3.2.3 records that error and then crashes, so the table row keeps python_crash. A price number written without a currency (@ 12) still takes the cost's currency, as #3047 made it. Implemented as the new InterpolationError::PriceBesideCost, and the old "inert" test is replaced with a test for the refusal.

2. Bytes that are not UTF-8 are reported where beancount reports them (breaking)

The decode stays lossy, so nothing panics and the text is still shown. What changes is that SourceText::from_utf8_lossy now records where each invalid sequence was (SourceText::invalid_utf8), and the loader reports them as bean-check 3.2.3 does (probed shape by shape):

where beancount rledger
in a token (account, currency, a line of its own) Invalid token: '\xe9', one per run P0012 invalid token, one per run
in a string literal UnicodeDecodeError, one per string, on the line the string ends P0012, one per string, on its last line
in a comment accepted accepted
  • rledger check now renders the snippet from the same decoded text. Before, read_to_string gave it an empty text.
  • The parse-error-parity harness compares UTF-8 inputs only and the parser itself is unchanged, so the manifest does not move. The fuzz targets take &str and are unaffected.
  • The CHANGELOG has a "convert the file to UTF-8" note (iconv).

3. rledger check --auto runs beancount's auto plugin (breaking)

bean-check --auto adds beancount.plugins.auto, which is auto_accounts followed by implicit_prices. rledger check --auto ran auto_accounts alone. LoadOptions::auto_accounts now runs both parts, each in its own pass, through plugin_parts. check is the only command whose --auto loads plugins; extract --auto is unrelated (it infers the importer).

Stale compatibility.md sections

  • §1: beancount refuses an unbalanced multi-currency transaction too. The only difference is that it reports one error, where rledger reports one E3001 per currency.
  • §3: both report all four push/pop mistakes.
  • §4: unknown options are E7001 and deprecated ones E7004.

Caches

  • Loader v82: a non-UTF-8 file had no errors and was cached, so an older entry would keep serving the error-free load.
  • WASM v147: validation findings move.

The numbers follow #3060's v81/v146, which is expected to merge first.

How to test

cargo test -p rustledger-booking --lib refuses_a_bare_price_beside_a_cost
cargo test -p rustledger-loader --lib invalid_utf8
cargo test -p rustledger-loader --all-features --test invalid_utf8_test --test auto_plugin_test
RLEDGER_UPSTREAM_PYTHON=/path/to/python3-with-beancount cargo test -p rustledger --test upstream_checks_test
printf '2020-01-01 open Assets:Caf\xe9\n' > /tmp/l.beancount && rledger check /tmp/l.beancount   # P0012

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 04:48
@robcohen
robcohen force-pushed the fix/upstream-missing-checks branch from e0a0213 to 31b2f17 Compare November 27, 2026 05:01
@robcohen
robcohen force-pushed the fix/upstream-decisions branch from c087915 to 58e3f16 Compare November 27, 2026 05:02
@robcohen
robcohen force-pushed the fix/upstream-missing-checks branch from 31b2f17 to a94980e Compare November 27, 2026 06:06
@robcohen
robcohen force-pushed the fix/upstream-decisions branch from 58e3f16 to f6b2ec8 Compare November 27, 2026 06:31
@robcohen
robcohen force-pushed the fix/upstream-missing-checks branch from a94980e to 97164b4 Compare November 27, 2026 06:50
@robcohen
robcohen force-pushed the fix/upstream-decisions branch from f6b2ec8 to fbd3ffd Compare November 27, 2026 06:59
Base automatically changed from fix/upstream-missing-checks to main November 27, 2026 08:02
@robcohen
robcohen force-pushed the fix/upstream-decisions branch from fbd3ffd to 26d5c60 Compare November 27, 2026 08:07
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 43.9ms ± 0.7ms 519.5ms ± 2.2ms 11.8x 43.2 MB / 51.1 MB
investment 64.1ms ± 0.6ms 2022.1ms ± 27.2ms 31.6x 47.0 MB / 59.2 MB
fifo 63.8ms ± 0.5ms 11678.0ms ± 303.0ms 183.1x 49.1 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 43.8ms ± 0.5ms 43.9ms ± 0.7ms +0.2% ✅ within noise 43.3 MB → 43.2 MB (-0.2%)
investment 64.7ms ± 0.6ms 64.1ms ± 0.6ms -1.0% ✅ within noise 47.2 MB → 47.0 MB (-0.6%)
fifo 63.8ms ± 1.4ms 63.8ms ± 0.5ms -0.1% ✅ within noise 49.1 MB → 49.1 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.4ms, investment 0.4ms, fifo 0.7ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 828
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 Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.37107% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-booking/src/interpolate.rs 96.77% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

robcohen and others added 5 commits November 27, 2026 03:57
1 HOOL {10 USD} @ USD (or a bare @, @@, @@ USD) was accepted and the price
ignored (#1919). beancount reports "Cannot infer price for postings with
units held at cost" (and then crashes); rledger now refuses it as a booking
failure on the posting (InterpolationError::PriceBesideCost). A price NUMBER
without a currency (@ 12) still takes the cost currency (#3047).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A non-UTF-8 file was decoded lossily and accepted. The decode stays lossy
(no panic, the text is still shown), but SourceText now remembers where the
invalid sequences were, and the loader reports them as beancount 3.2.3 does:
an invalid token outside strings (one per run), one error per string on its
last line (UnicodeDecodeError), nothing in a comment. Loader cache v81.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…heck --auto does

bean-check --auto adds beancount.plugins.auto; rledger --auto ran
auto_accounts alone. LoadOptions::auto_accounts now runs both parts, each in
its own pass, through plugin_parts. check also renders parse-error snippets
of a non-UTF-8 file from the lossily decoded text the loader parsed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…vered, bump caches

compatibility.md sections 1 (beancount refuses unbalanced multi-currency
transactions too), 3 (rledger reports all four push/pop mistakes) and 4
(unknown options are E7001, deprecated E7004) described old behavior.
checks.toml: the bare-price row is covered, the lexer row names the UTF-8
test. WASM cache v145.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the fix/upstream-decisions branch from 0a14c5f to d743034 Compare November 27, 2026 10:03
@robcohen
robcohen merged commit 7ed38a3 into main Nov 27, 2026
71 of 72 checks passed
@robcohen
robcohen deleted the fix/upstream-decisions branch November 27, 2026 10:39
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