Skip to content

fix(plugin)!: carry a note's tags and links through plugins and the FFI - #2588

Merged
robcohen merged 3 commits into
mainfrom
fix/plugin-note-tags-links
Oct 11, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/plugin-note-tags-links

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

A note's tags and links now survive every boundary they used to be dropped at:

Surface Change
Plugin wire (rustledger_plugin_types::NoteData) tags, links fields; conversion both ways in rustledger-plugin
WASM plugin ABI ABI_VERSION 1 → 2
Component WIT (note-dir, input-note) tags, links; contract 3.13.0 → 3.14.0, API_VERSION 3.14
FFI input (InputEntry::Note) tags, links (serde(default), so old payloads still parse)
WASM build JSON (DirectiveJson::Note) tags, links, left out when empty; bindings regenerated
Plugin WIT sketch beancount:[email protected], note record gains them
Python compat layer Note has beancount 3's tags/links (default empty, so 4-field construction still works)

Documents (the issue asked to check them too): the wire already carried their tags. Checking them turned up a separate bug in the Python compat layer: it read a document's file name from filename, the key that holds the entry's source file, so a plugin saw the ledger's path as the document's. It also wrote the name back under filename, which the host does not read as the path, so any Python plugin that returned a ledger holding a document failed with data did not match any variant of untagged enum OutputEntry. Fixed by using path.

Why the ABI bump

Every struct crosses the plugin wire as a MessagePack array, and rmp_serde rejects an array longer than the struct (LengthMismatch). A version-1 guest handed a version-2 note would trap mid-run on the first note. ABI_VERSION's own doc says to bump it for a changed PluginInput shape, and with the bump a version-1 plugin or importer is refused at load with the existing clear mismatch error. Version-1 guests need a rebuild against the new rustledger-plugin-types. The hand-written WAT test guests now advertise 2.

Another option was to keep version 1 and leave the new fields off the wire when they are empty. Old guests would then keep working on ledgers without tagged notes, and trap on the first one with them. I chose the documented policy instead; it is easy to switch if you prefer that.

How tested (each fails without the fix)

  • plugin_conformance::tags_and_links_survive_a_plugin_round_trip: ledger with pushtag + a tagged/linked note and document, run through (a) the conformance WASM guest in a new rebuild mode that returns every directive as Modify (so each crosses the wire both ways), (b) a Python passthrough plugin that also reports the document's path. Asserts tags/links via SELECT type, tags, links FROM #entries, that the plugin ran, and that the path came through. Without the fix: WASM leg loses ntag; with only the compat fix reverted, the Python leg fails on the document path.
  • convert::tests::test_roundtrip_note_tags_and_links_2573 (plugin conversion both legs).
  • tags_links_set_properties proptests extended to notes for the plugin round trip and the FFI input (plugin_output_is_normalized, ffi_input_is_normalized fail without the fix).
  • rustledger-ffi-component note_tags_and_links_round_trip: note-dir out, back in via the loaded-directive path and via input-note.
  • Full suites: plugin-types, plugin, ops, ffi-wasi, ffi-component, wasm, importer, rustledger (RLEDGER_REQUIRE_* set), all green apart from python_plugins_back_to_back_after_a_timeout. That 2-second-budget case failed while four other builds loaded the machine, and it fails the same way on the unrelated fix(plugin): hand a Python plugin its inputs on stdin, never on disk #2587. clippy --workspace --all-features --all-targets -D warnings, fmt, and cargo doc -D warnings for the five changed library crates are clean.

Not changed: compute_directive_hash still leaves a note's tags out of meta.hash, as before. Including them would change every note's hash, and rustfava pins those hashes, so that needs its own decision.

Closes #2573

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

A note's tags and links (its own and, since #2565, a pushtag block's)
had no place in the plugin wire's NoteData, the component's note-dir
and input-note, or the FFI's InputEntry::Note, so a note passing through
any plugin or the FFI came back without them. All of them carry tags
and links now, as documents do, as does the WASM build's JSON note.

Structs cross the plugin wire as MessagePack arrays, so a version-1
guest cannot decode the longer note: ABI_VERSION is 2 and a version-1
WASM plugin or importer is refused at load. The component contract
moves to 3.14.0 and the plugin WIT sketch to beancount:[email protected].

The Python compat layer's Note gains beancount 3's tags and links, and
a document keeps its path through a Python plugin: the layer read it
from the key holding the entry's source file and wrote it back under one
the host rejects, so any Python plugin returning a ledger with a
document failed.

Closes #2573

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner October 10, 2026 21:33
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 42.8ms ± 1.5ms 578.1ms ± 7.4ms 13.5x 51.1 MB / 50.1 MB
investment 63.3ms ± 1.5ms 2188.2ms ± 30.6ms 34.6x 57.3 MB / 58.0 MB
fifo 64.9ms ± 2.1ms 12642.9ms ± 41.6ms 194.7x 57.3 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 41.8ms ± 1.0ms 42.8ms ± 1.5ms +2.4% ✅ within noise 51.3 MB → 51.1 MB (-0.4%)
investment 63.3ms ± 0.7ms 63.3ms ± 1.5ms -0.0% ✅ within noise 57.4 MB → 57.3 MB (-0.2%)
fifo 64.8ms ± 1.0ms 64.9ms ± 2.1ms +0.3% ✅ within noise 57.4 MB → 57.3 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.8ms, investment 0.7ms, fifo 1.0ms), 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

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
crates/rustledger-plugin/src/convert/mod.rs 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@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 819
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

…links

# Conflicts:
#	crates/rustledger/tests/plugin_conformance.rs
@robcohen

Copy link
Copy Markdown
Member Author

Review loop

Round Scope Finding Fix
1 Every producer and consumer of a note's shape: NoteData literals across the workspace and examples/, the plugin conversion both ways, the component note-dir/input-note and the loaded-directive path back in, InputEntry::Note, DirectiveJson::Note and its regenerated bindings, the Python layer (Note defaults; tags=None from a plugin), the hand-written WAT guests' ABI literals, and the docs citing the ABI and WIT versions none n/a
2 After merging main (#2585): the conformance suite again (41 pass), and a check that no new WAT guest or NoteData literal came in with main none n/a

The loop converged at round 1. The required checks are green on d766791. Downstream rustfava shows the expected 8 failed, 671 passed: the WIT 3.14 bump adds no new failures.

@robcohen

Copy link
Copy Markdown
Member Author

Decision (robcohen): bump the plugin ABI 1 → 2 (option A, as implemented). An old guest is refused at load with a clear rebuild message.

A crates.io reverse-dependency check (rustledger-plugin-types has only rledger's own crates as dependents) and a GitHub code search for wasm_plugin_main!/wasm_importer_main!/__rustledger_abi_version found no third-party WASM plugins or importers. So the rebuild cost falls on in-tree fixtures, which this PR rebuilt. Rejected: sending the fields only when non-empty, where old guests would fail mid-run depending on the data; and a dual-version host, which would keep the note-tag data loss for v1 guests.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

@robcohen
robcohen merged commit 280e2bb into main Oct 11, 2026
66 of 68 checks passed
@robcohen
robcohen deleted the fix/plugin-note-tags-links branch October 11, 2026 08:15
robcohen added a commit that referenced this pull request Oct 11, 2026
robcohen added a commit that referenced this pull request Oct 11, 2026
* fix(plugin)!: native validation plugins report as beancount's do

The plugins rledger has both natively and in Python reported the same
ledger differently depending on which ran. The native check_commodity,
leafonly, coherent_cost, onecommodity, unique_prices, commodity_attr and
noduplicates now match beancount 3: its messages, as errors, at the
entries beancount names. check_commodity is an error, not a warning, and
reads the config ignore map; leafonly reports each parent once at its
open; coherent_cost catches a currency held with and without cost;
onecommodity reads its config, opt-out, costs and balances; unique_prices
allows agreeing repeats; commodity_attr reads tuples. The python:
built-ins match too. A conformance case holds each pair to bean-check's
output.

Deliberate divergences, documented: leafonly ignores a note, document,
close or custom on a parent; noduplicates names the duplicate instead of
printing Python reprs; set-joined lists are in a stable order.

Closes #2539

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

* test(plugin): give the leafonly alignment test's note its tags and links

NoteData gained tags and links in #2588.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
robcohen added a commit that referenced this pull request Oct 12, 2026
* fix(ffi)!: hash a note's tags and links in meta.hash

Notes carry tags and links since #2588, but compute_directive_hash left
both out of a note's digest, so two notes differing only in tags or
links shared an identity. Hash them exactly as a document's are: the
tag and link counts always, then each element length-prefixed. Every
note's meta.hash changes, untagged ones included (decided on #2598).

Closes #2598

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

* docs(ffi): date note tags and links to #2185 in the hash comments

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

plugin/FFI note records carry no tags or links; a plugin drops pushtag tags on notes

1 participant