Skip to content

harden: mix random bits into migration ID generation#125

Merged
kacy merged 1 commit intomainfrom
security/ember-cluster
Feb 14, 2026
Merged

harden: mix random bits into migration ID generation#125
kacy merged 1 commit intomainfrom
security/ember-cluster

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Feb 14, 2026

summary

mixes 16 bits of randomness into migration IDs to prevent collisions when
the system clock is unavailable.

previously, MigrationId::new() used unwrap_or_default() on
SystemTime::now(), which returns Duration::ZERO on clock failure. this
made the ID degenerate to just the slot number (0 ^ slot), so two
migrations of the same slot would produce identical IDs.

now the ID combines timestamp, slot, and random bits:
ts ^ (slot as u64) ^ ((noise as u64) << 48)

rand was already a dependency of ember-cluster.

what was tested

all 59 ember-cluster tests pass.

when SystemTime::now() is unavailable (returns Duration::ZERO via
unwrap_or_default), migration IDs degenerated to just the slot number,
causing collisions if the same slot was migrated more than once.

mix 16 bits of randomness into the upper bits of the ID so uniqueness
doesn't depend solely on clock availability.
@kacy kacy merged commit 04ea75f into main Feb 14, 2026
7 checks passed
@kacy kacy deleted the security/ember-cluster branch February 14, 2026 21:49
kacy added a commit that referenced this pull request Feb 19, 2026
…#125)

when SystemTime::now() is unavailable (returns Duration::ZERO via
unwrap_or_default), migration IDs degenerated to just the slot number,
causing collisions if the same slot was migrated more than once.

mix 16 bits of randomness into the upper bits of the ID so uniqueness
doesn't depend solely on clock availability.
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.

1 participant