Repository navigation
docs(wit): state the stability contract for meta.hash - #2113
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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.hashexplaining that the hash algorithm is an implementation detail. - Document that
meta.hashshould 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2111.
meta.hashwas declared as a barestringwith 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).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:wasm-tools component witcargo check -p rustledger-ffi-componentcargo +1.97.0 clippy --all-targets -- -D warningsRUSTDOCFLAGS="-D warnings" cargo docI 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_markdownred for several commits, and exactly the lint a prose-heavy doc comment would trip.