Skip to content

docs(wit): state the stability contract for meta.hash - #2113

Merged
robcohen merged 2 commits into
mainfrom
docs/meta-hash-stability
Aug 22, 2026
Merged

robcohen merged 2 commits into
mainfrom
docs/meta-hash-stability

Conversation

@robcohen

Copy link
Copy Markdown
Member

Closes #2111.

meta.hash was declared as a bare string with no statement of what consumers may rely on:

    hash: string,

That silence is what made #1961 a surprise downstream. It length-prefixed every field fed into compute_directive_hash — correct, and it fixed three real collisions, the worst being a transaction with a payee hashing identically to one without — but it changed every digest, and rustfava was pinning them in committed snapshots (#1967).

Why this is documentation and not a fix

rustfava#280 stopped pinning the digest rather than versioning it, which is the better outcome: a future format change no longer costs a regeneration downstream. So nothing is broken today. What's missing is the written contract, so the next person changing the hash format knows what they are and aren't promising.

The comment records that the algorithm is an implementation detail, that the value is stable only within a WIT package version, and that it must not be persisted, pinned in tests, or compared across versions. It also notes that comments are excluded (#1968), so two directives differing only in their comments share a digest — a property a consumer might otherwise discover the hard way.

Field-level doc comments are an established pattern in this file (3 of 37 records already use them).

Verification

Comment-only, but the docs are not inert — wit_bindgen::generate! is a proc macro, so they expand into Rust doc comments and are lintable even though nothing lands on disk. Checked accordingly:

check result
wasm-tools component wit parses
cargo check -p rustledger-ffi-component builds
cargo +1.97.0 clippy --all-targets -- -D warnings clean
RUSTDOCFLAGS="-D warnings" cargo doc clean

I confirmed the WIT parse check can actually fail before trusting it, by appending a deliberate syntax error (exit 1) and restoring (exit 0).

Clippy was run under 1.97.0 via rustup, not the nix shell's 0.1.96 — the toolchain skew that previously hid a doc_markdown red for several commits, and exactly the lint a prose-heavy doc comment would trip.

Closes #2111.

`meta.hash` was declared as a bare `string` with no statement of what
consumers may rely on. That silence is what made #1961 a surprise
downstream: it length-prefixed every field fed into
`compute_directive_hash` — correct, and it fixed three real collisions,
the worst being a transaction with a payee hashing identically to one
without — but it changed every digest, and rustfava was pinning them in
committed snapshots (#1967).

Nothing is broken now: rustfava#280 stopped pinning the digest rather
than versioning it, so a future format change no longer costs a
regeneration downstream. What was missing is the written contract, so
the next person changing the hash format knows what they are and are not
promising.

Records that the algorithm is an implementation detail, that the value
is stable only within a WIT package version, and that it must not be
persisted, pinned in tests, or compared across versions. Also notes that
comments are excluded (#1968), so two directives differing only in their
comments share a digest — which is a property a consumer might otherwise
discover the hard way.

Field-level doc comments are an established pattern in this file (3 of
37 records already use them).

Comment-only: the WIT still parses (verified the check can fail, by
feeding it a deliberate syntax error), the component crate builds, and
clippy 1.97 with -D warnings plus rustdoc with -D warnings are both
clean — the docs reach generated Rust through the `wit_bindgen::generate!`
proc macro, so they are lintable even though nothing lands on disk.
@robcohen
robcohen requested a review from a team as a code owner August 22, 2026 15:38
Copilot AI lite review requested due to automatic review settings August 22, 2026 15:38

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 updates the WIT contract documentation for types.meta.hash in rustledger-ffi-component to explicitly describe the intended stability guarantees and consumer expectations for the directive identity digest.

Changes:

  • Add a field-level doc comment to types.meta.hash explaining that the hash algorithm is an implementation detail.
  • Document that meta.hash should not be persisted/pinned/compared across versions, and that comments are excluded from the digest.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 22, 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

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
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
    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

Addresses review feedback on the previous commit.

It said the digest is "stable only within a WIT package version". That
reads as a guarantee the project does not actually keep: #1961 changed
the hash format in an ordinary release and did not touch the WIT package
version (verified against its merge commit, 2f707c6 — it edits
hash.rs and a test, and the `package rustledger:ledger@...` line is
untouched). Documenting a promise nobody honors is worse than
documenting nothing, because a consumer could reasonably rely on it.

Now states what is true: the digest is deterministic for a given build,
and carries no cross-version guarantee, with #1961 cited as the
precedent for it changing in a normal release.

Two smaller points from the same review, both fair:

- "within a single loaded session" understated determinism. The value is
  reproducible across runs; the real caveat is across versions, not
  across runs.
- "hashes the directive's content" sat oddly against the later note that
  comments are excluded. The exclusion is now stated up front, as part
  of what the digest covers.

Left out deliberately: the suggestion to require a WIT package version
bump on any hash-format change. That is a policy decision about the
release process, not something a doc comment should assert unilaterally
— and asserting it here would re-create the same gap, since the practice
does not currently work that way.

WIT parses; clippy 1.97 with -D warnings clean.
@robcohen
robcohen merged commit 47bae52 into main Aug 22, 2026
51 checks passed
@robcohen
robcohen deleted the docs/meta-hash-stability branch August 22, 2026 16:13
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.

docs(wit): state the stability contract for meta.hash

2 participants