Repository navigation
fix: hash snapshots from their canonical encoding - #907
Merged
zachdaniel merged 1 commit intoOct 25, 2026
Merged
Conversation
The snapshot hash was taken over `inspect/1` of the snapshot term. Map key order in that output depends on the order atoms were created in the running VM, so the same resource could hash differently between environments (e.g. different OTP versions, dependencies or module load order). It was also computed before the snapshot was normalised for writing, so it didn't match the contents of the file it was stored in. Compute it when writing instead, over the key-sorted JSON being persisted.
Contributor
|
🚀 Thank you for your contribution! 🚀 |
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.
ash_postgresusesinspect/1to provide the inputs to a hash function and the resulting hash is included in snapshots (presumably as a fingerprint). The problem is thatinspect/1is non-deterministic, as its output can depend on the state of the VM's atom table, causing subtle ordering changes where Map is used, hence non-deterministic hash values.Also, the hash was computed before a merge step that normalises snapshots (e.g. those sharing a table are merged together), so it wasn't accurately using the input of the written snapshot. This PR computes it when writing instead, to fix that. The test covers this issue too, because the merge step changes the inputs to hash even in simple cases such as the setup in the test.
Existing snapshots keep working and nothing is regenerated on upgrade as nothing reads the hash back (
--checkand migration generation compare the snapshot fields). This isn't causing any user-facing problems today, but the value is wrong, and anything that relied on it later would be too. It is something I asked in Discord and Zach said we should fix. (general channel, 2026-10-23).Contributor checklist
Leave anything that you believe does not apply unchecked.