Skip to content

fix(parser): green compound-cost conversion retries unparsable numbers like red - #1714

Merged
robcohen merged 3 commits into
mainfrom
fix/green-red-divergence
Jul 4, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/green-red-divergence

Conversation

@robcohen

@robcohen robcohen commented Jul 4, 2026

Copy link
Copy Markdown
Member

Closes #1713 (the fuzz_green_eq_red divergence found on #1711's fuzz run).

Root cause — an asymmetry introduced in #1704: red got two number semantics (cost_compound_numbers retries past unparsable NUMBER tokens on each side of the #; the plain path latches the first token via cs.number()), but green kept a single latched tracker satisfying only the plain path. On garbage like {<unparsable> 2 # ...}, red retried to per_unit: 2 while green latched None → 0.

Fix: green carries both — a retried pre-hash tracker for the compound path alongside the latched first-token tracker for the plain path; the post-hash side switches from latch to retry, matching red.

Verification

  • The 418-byte fuzzer input is pinned as a regression test (green==red asserted).
  • CACHE_VERSION 13→14 + changelog (parse output changes for garbage-adjacent compound costs; stale caches would resurrect the divergence). Tripwire fixture versions advance; rkyv layouts unchanged.
  • Fuzz-validated: 5.34M executions / 9 min on the fixed converter — zero artifacts.
  • Workspace: clippy -D warnings, fmt, doc, parser + loader suites all clean.

Drive-bys: pre-existing typos in cache.rs comments (hook-enforced); sample_stub fixture lockfiles regenerated for 0.20.1 (missed by the release bump; their staleness broke prek pre-push stash handling).

🤖 Generated with Claude Code

robcohen and others added 2 commits July 4, 2026 02:59
…s like red

fuzz_green_eq_red found (#1713) an input where the green-wired parse
and parse_red_only disagree on a compound cost: red produced
Compound { per_unit: 2, .. } while green produced per_unit: 0.

Root cause: #1704 gave red TWO number semantics — cost_compound_numbers
retries past unparsable NUMBER tokens on each side of the hash
(is_none() guards re-arm when the parse fails), while the plain path
latches the first NUMBER token via cs.number() — but green kept a
single latched tracker, satisfying only the plain path. On garbage
like `{<unparsable> 2 # ...}` red retried to 2; green latched
None -> 0.

Green now carries both: a retried pre-hash tracker for the compound
path plus the existing latched first-token tracker for the plain path
(and the post-hash side switches from latch to retry, matching red).

- Regression test pins the 418-byte fuzzer input
  (fuzz_regressions/diverge_compound_cost_unparsable_number.bin).
- CACHE_VERSION 13 -> 14 (+ changelog): parse output changes for
  inputs with garbage around compound costs; stale caches would
  resurrect the divergence. Tripwire fixture versions advance
  (layouts unchanged).
- Fuzz-validated: 5.34M executions / 9 min on the fixed converter,
  zero artifacts.

Closes #1713

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The v0.20.1 release bump did not regenerate these, so every cargo
invocation re-pins rustledger-plugin-types 0.20.0 -> 0.20.1 and dirties
the tree — which breaks prek pre-push stash handling.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings July 4, 2026 03:03
@robcohen
robcohen requested a review from a team as a code owner July 4, 2026 03:03

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

Fixes a green/red converter parity bug in rustledger-parser for compound cost specs when NUMBER tokens are present but unparsable, ensuring green’s recovery behavior matches red’s and preventing directive divergences found by fuzzing (#1713).

Changes:

  • Updated green CST cost-spec conversion to carry both “latched first NUMBER token” semantics (plain path) and “retry until parse succeeds” semantics (compound {a # b} path), matching red.
  • Added a pinned regression test fixture asserting parse (green-wired) exactly matches parse_red_only for the reported divergence input.
  • Bumped loader cache version (13→14) and advanced cache tripwire fixture versions to prevent stale caches from resurrecting the old behavior; refreshed sample stub lockfiles.

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rustledger-plugin/tests/fixtures/sample_stub/Cargo.lock Fixture lockfile bump for rustledger-plugin-types 0.20.1.
crates/rustledger-parser/tests/fuzz_regressions.rs Adds a regression test asserting green/red directive equality for the #1713 input.
crates/rustledger-parser/src/cst/green.rs Fixes green compound-cost number tracking to match red retry/latch semantics.
crates/rustledger-loader/src/cache.rs Bumps CACHE_VERSION to 14 and updates related fixture-version tripwires and changelog notes.
crates/rustledger-importer/tests/fixtures/sample_stub/Cargo.lock Fixture lockfile bump for rustledger-plugin-types 0.20.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 38.8ms ± 2.8ms 23.7 MB
beancount 788.7ms ± 10.7ms 50.6 MB
Comparison 20.3x faster 2.1x less

vs main branch (2026-07-03)

Metric main this PR Change
Time 34.9ms 38.8ms +11.2% 🔴
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 810
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

The function was replaced by cost_compound_numbers in #1704; the module
doc and a parity-corpus comment still narrated the old latch semantics.
The corpus entry still passes because BOTH parsers now retry past the
unparsable post-hash number and agree on Compound{7, 0} — the comment
now says so. (Copilot review catch on #1714.)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen

robcohen commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Good catch — cost_total_after_hash died in #1704. Fixed both references in 872d4eb; the parity-corpus comment also narrated the old latch semantics, so it now describes the retry-on-both-sides behavior it actually pins (Compound{7, 0} agreement).

@robcohen
robcohen merged commit 6ece65c into main Jul 4, 2026
55 of 56 checks passed
@robcohen
robcohen deleted the fix/green-red-divergence branch July 4, 2026 05:52
@robcohen robcohen mentioned this pull request Jul 4, 2026
robcohen added a commit that referenced this pull request Jul 4, 2026
* chore: release v0.20.2

- fix(query): typed scalar functions propagate NULL, beanquery parity (#1711)
- fix(parser): green compound-cost conversion retries unparsable numbers (#1714)

Fixture sample_stub lockfiles regenerated with the version bump this
time (v0.20.1 missed them, which broke prek pre-push stash handling).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* chore: drop generated changelog block (curated doc, per v0.20.1 precedent)

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

parser: green/red divergence found by fuzz_green_eq_red (pre-existing; reproduces on main)

2 participants