Skip to content

feat: dedup + format-loaded on the component import surface - #1765

Merged
robcohen merged 3 commits into
mainfrom
feat/component-import-dedup-format
Jul 12, 2026
Merged

robcohen merged 3 commits into
mainfrom
feat/component-import-dedup-format

Conversation

@robcohen

Copy link
Copy Markdown
Member

Pre-release gap check on the 3.5.0 importer interface (#1764): I walked the rustfava ingest flow end-to-end and found two things a backend would hit immediately. Both land in the still-unreleased 3.5.0.

  • importer.dedup(candidates, existing) -> list<bool> — fava's extract modal flags entries already in the ledger; without this the host would re-implement fuzzy dedup in Python against the canonical. Delegates to rustledger_ops::dedup::is_duplicate, the same matcher rledger extract --existing uses, so the review UI and CLI agree. Per-candidate conversion keeps flags aligned with input order.
  • format.format-loaded(entries) — the extract flow ends with writing entries into the ledger file, but format-entries only accepts input-directive while extract returns loaded directive. The loaded→input down-conversion now happens inside the component (the same one session.from-entries/query-entries use).

Deliberately deferred to 3.6: ML category suggestions (needs a trained-model story; UI works without it).

Testing: unit test covering the extract → dedup → format-loaded loop; parity suite (21 tests) green against the rebuilt wasip2 component, now exercising the new surface end-to-end; clippy/fmt clean.

🤖 Generated with Claude Code

Closes the two gaps a rustfava ingest backend would hit immediately
(walked the fava import flow end-to-end against 3.5.0 before cutting
the release):

- importer.dedup(candidates, existing) -> list<bool> flags duplicate
  entries via the canonical rustledger_ops::dedup::is_duplicate — the
  same fuzzy matcher 'rledger extract --existing' filters with, so
  the review UI and the CLI agree on what counts as a duplicate.
  Per-candidate conversion keeps flags aligned with input order even
  when a candidate fails conversion.
- format.format-loaded(entries) renders LOADED directives (extract
  output, session entries) to canonical beancount text, with the
  loaded->input down-conversion inside the component — previously
  only input-directive could be formatted, forcing hosts to reshape
  directives themselves to save extracted entries.

Both land in the still-unreleased 3.5.0. Parity suite (21 tests)
passes against the rebuilt wasip2 component, now exercising the full
extract -> dedup -> format-loaded loop.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 12, 2026 14:05
@robcohen
robcohen requested a review from a team as a code owner July 12, 2026 14:05

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

This PR extends the rustledger-ffi-component WASI component surface (WIT world) to close the “extract → review → save” import UX loop for hosts by adding (1) duplicate-flagging over the component boundary and (2) formatting for loaded directives.

Changes:

  • Add importer.dedup(candidates, existing) -> list<bool> backed by rustledger_ops::dedup::is_duplicate.
  • Add format.format-loaded(entries: list<directive>) -> result<string, string> to render importer.extract/session-loaded directives without host reshaping.
  • Add native/unit and parity-suite coverage for the extract → dedup → format-loaded loop.

Reviewed changes

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

File Description
crates/rustledger-ffi-component/wit/world.wit Adds format-loaded and importer.dedup to the public WIT surface.
crates/rustledger-ffi-component/src/lib.rs Wires new WIT methods to conversion/ops helpers in the component guest impls.
crates/rustledger-ffi-component/src/convert.rs Implements format_loaded and import_dedup, plus a unit test for the host loop.
crates/rustledger-ffi-component-tests/tests/parity.rs Extends component parity tests to exercise dedup + format-loaded over the boundary.

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

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.2ms ± 0.3ms 23.6 MB
beancount 891.6ms ± 7.7ms 50.6 MB
Comparison 27.7x faster 2.1x less

vs main branch (2026-07-12)

Metric main this PR Change
Time 31.7ms 32.2ms +1.6% ✅
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

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The version gate is right: 3.5.0 landed on main in #1764, so this
PR's interface additions need their own minor. API_VERSION tracks it
(parity-enforced).

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
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
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Redesigns the 3.6.0 additions per the WIT design review before
anything ships:

- dedup moves from importer.dedup(candidates, existing) to
  session.dedup(candidates). One move fixes three findings: the host
  no longer re-marshals the full ledger per import (the exact pattern
  the session resource exists to kill); the held side's
  conversion-drop policy is the documented, info()-observable
  from-entries one instead of a silent comparison-set shrink; and the
  implementation uses the batch canonical find_fuzzy_duplicates,
  which precomputes held keys once instead of rebuilding every key
  per candidate.
- extract-result.warnings becomes list<error> (severity "warning",
  phase "extract") — the structured diagnostic record every other
  surface uses, so line/field attribution is additive later rather
  than a record-shape break.
- format-loaded errors now name the failing entry index, so a host
  can exclude one bad entry instead of losing the whole batch.
- WIT dedup doc corrected: the matcher requires the SAME date (plus
  amount and text similarity) — "date proximity" promised behavior
  the canonical does not have.
- format_loaded rustdoc version tag fixed (3.6.0, not 3.5.0).
- The parity dedup guard now checks a fuzzy near-miss (reworded
  narration) against the NATIVE matcher's verdict, not just
  degenerate identity/empty inputs; extract warnings assert message
  parity plus severity/phase.

Remaining design debt (options-less entries surfaces) is tracked in
issue #1766 rather than patched piecemeal here.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robcohen
robcohen merged commit a14d6c9 into main Jul 12, 2026
51 checks passed
@robcohen
robcohen deleted the feat/component-import-dedup-format branch July 12, 2026 15:06
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