Repository navigation
Seat the v7 counter below the version nibble - #907
Merged
Merged
Conversation
KodrAus
requested changes
Sep 3, 2026
| // the payload of a version 7 UUID starts at bit 123: `rand_a` runs from bit | ||
| // 123 down to bit 112, the variant occupies bits 111 and 110, and `rand_b` | ||
| // runs from bit 109 down to bit 48. | ||
| const PAYLOAD_TOP: u32 = 123; |
Member
There was a problem hiding this comment.
This constant isn't pulling any weight. We can just inline it.
new_v7 placed the counter's most significant bit at bit 127 of the payload, where the version nibble overwrites it, so the top four counter bits never reached the UUID. With with_additional_precision those are the sub-millisecond bits, so two UUIDs from one context inside a millisecond could sort backwards; a 42-bit counter carrying into bit 38 sorted lower instead of higher.
lenamonj
force-pushed
the
v7-counter-placement
branch
from
September 3, 2026 00:51
1eab10c to
34ec102
Compare
Contributor
Author
|
Thanks for the review. Pushed 34ec102: doc comment reduced to your wording, the explanatory comments replaced with a bit diagram, PAYLOAD_TOP inlined, the helper returns (u16, [u8; 4]) and moved into the test, tests renamed as suggested. cargo test --all-features and cargo hack --each-feature test --lib green. |
KodrAus
approved these changes
Sep 8, 2026
1 task
kodiakhq Bot
pushed a commit
to pdylanross/fatigue
that referenced
this pull request
Sep 14, 2026
Bumps uuid from 1.26.0 to 1.26.1. Release notes Sourced from uuid's releases. v1.26.1 What's Changed Seat the v7 counter below the version nibble by @lenamonj in uuid-rs/uuid#907 Don't panic in overflowing Timestamp to SystemTime conversion by @KodrAus in uuid-rs/uuid#909 Prepare for 1.26.1 release by @KodrAus in uuid-rs/uuid#910 New Contributors @lenamonj made their first contribution in uuid-rs/uuid#907 Full Changelog: uuid-rs/[email protected] Commits 9f92712 Merge pull request #910 from uuid-rs/cargo/v1.26.1 d4df8f0 prepare for 1.26.1 release 5613f23 Merge pull request #909 from uuid-rs/fix/ts-conversion-overflow fda00eb don't panic in overflowing Timestamp to SystemTime conversion c82e88c Merge pull request #907 from lenamonj/v7-counter-placement ac065a6 Align the counter diagram 34ec102 Seat the v7 counter below the version nibble See full diff in compare view Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: @dependabot rebase will rebase this PR @dependabot recreate will recreate this PR, overwriting any edits that have been made to it @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.
Uuid::new_v7shifts the counter so its most significant bit lands at bit 127 of the 128-bit value it hands toBuilder::from_unix_timestamp_millis, but that builder spends the top four bits of the first payload byte on the version nibble. The top four bits of any counter are therefore discarded.Measured at
cdc96a8, from a scratch crate:rand_a/rand_bas a counter of zero; a counter of all ones givesrand_a = 0xff3, not0xfff0x3fffffffffto0x4000000000produces a UUID that sorts lowerContextV7::new().with_additional_precision()the discarded bits are the sub-millisecond ones, so two UUIDs drawn from one context at two instants inside the same millisecond can sort backwardsChange: seat the counter at bit 123 (the top of
rand_a), open the two-bit variant gap only when the counter reaches pastrand_a, and keep the 74 most significant bits of a wider counter. Two tests: every bit of a 42-bit counter reaches the UUID and a carry sorts upwards; additional precision sorts within a millisecond.Verified on a fresh clone at
cdc96a8: the two tests fail before the change and pass after;cargo test --all-features,--doc,cargo hack test --lib --each-feature,--all-features, the examples crate and the 1.85.0 smoke-test build are green. wasm not run here.Found by an automated audit loop (Claude); patch and description reviewed by me.