Skip to content

fix(ffi)!: hash a note's tags and links in meta.hash - #2636

Merged
robcohen merged 4 commits into
mainfrom
fix/note-hash-tags-links
Oct 12, 2026
Merged

robcohen merged 4 commits into
mainfrom
fix/note-hash-tags-links

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

compute_directive_hash (surfaced as meta.hash) now hashes a note's tags and links, exactly as a document's and a transaction's are: the tag count and the link count always, then each element, length-prefixed (crates/rustledger-ffi-wasi/src/hash.rs, Note arm).

Why

Notes carry tags and links since #2588, but the Note arm still left both out of the digest, so two notes differing only in tags or links shared an identity. This implements the decision recorded on the issue (option A): counts always, so every note's hash changes, untagged ones included. That is the same trade the Document fix made; the rejected alternative was a suffix emitted only when non-empty.

Breaking for meta.hash consumers: every note's meta.hash changes. rustfava's snapshots need regenerating together with the next release (they already need it for the expected 8 failures). CHANGELOG entry under Breaking.

How tested

  • New note_tags_and_links_are_part_of_the_identity in hash_identity_properties.rs: a tag vs none, a link vs none, different tag, different link, the same name as a tag vs a link, tags [a,b] vs tags [a] links [b], links [a,b] vs tags [a] links [b], tag "ab" vs tags [a,b]. With the fix reverted, all 8 cases collide (test fails); with it, none do.
  • cargo test -p rustledger-ffi-wasi --all-features, workspace clippy (--all-features --all-targets -D warnings), cargo doc -D warnings.
  • No loader/wasm cache stores meta.hash (it is computed on conversion), so no CACHE_VERSION bump.

Closes #2598

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

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
@robcohen
robcohen requested a review from a team as a code owner October 12, 2026 02:30
@codecov

codecov Bot commented Oct 12, 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 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.6ms ± 1.1ms 822.9ms ± 8.2ms 18.0x 51.4 MB / 50.0 MB
investment 69.6ms ± 0.3ms 3094.8ms ± 35.6ms 44.5x 57.3 MB / 58.2 MB
fifo 71.6ms ± 1.0ms 15545.1ms ± 351.4ms 217.0x 57.3 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 44.9ms ± 0.3ms 45.6ms ± 1.1ms +1.6% ✅ within noise 51.5 MB → 51.4 MB (-0.1%)
investment 69.8ms ± 0.9ms 69.6ms ± 0.3ms -0.3% ✅ within noise 57.4 MB → 57.3 MB (-0.3%)
fifo 72.4ms ± 0.7ms 71.6ms ± 1.0ms -1.0% ✅ within noise 57.5 MB → 57.3 MB (-0.3%)

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

@robcohen

Copy link
Copy Markdown
Member Author

Review loop

Round Scope Findings Fix
1 Full diff; collision classes for notes; Tag/LinkSet order; persisted hashes; test vacuity Wording: notes carry tags/links since #2185, not #2588 2464b02
2 Round-1 change; tags_links_set_properties.rs re-read None —

Converged after round 2. The note hash test fails with the fix reverted (all 8 pairs collide).

🤖 Generated with Claude Code

@robcohen robcohen closed this Oct 12, 2026
@robcohen robcohen reopened this Oct 12, 2026
@robcohen
robcohen merged commit 7e8dec9 into main Oct 12, 2026
58 of 60 checks passed
@robcohen
robcohen deleted the fix/note-hash-tags-links branch October 12, 2026 22:03
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.

meta.hash leaves out a note's tags and links

1 participant