feat: add DeterministicRng to make a runtime deterministic#1689
Merged
drmingdrmer merged 1 commit intodatabendlabs:mainfrom Mar 19, 2026
Merged
feat: add DeterministicRng to make a runtime deterministic#1689drmingdrmer merged 1 commit intodatabendlabs:mainfrom
drmingdrmer merged 1 commit intodatabendlabs:mainfrom
Conversation
Replaces the global AtomicU64 seed with per-instance seed stored in task-local storage. Each DeterministicRng instance owns its seed counter, set via set_seed() and propagated into block_on() via sync_scope. Seed derivation uses two SplitMix64 bijective mixers with different additive constants (golden ratio vs sqrt(2)) to prevent collisions in the spawn tree: child.seed = f(parent.seed), parent.seed = g(parent.seed). This ensures parent, child, and sibling tasks all get independent deterministic RNG sequences. Suite::test_all() is now sync — creates its own runtime internally, simplifying callers to just Suite::<Rt>::test_all(). Changes: - Add DeterministicRng<RT> with per-instance Cell<u64> seed - Add splitmix64() mixer, derive_spawn_seed(), advance_seed() - spawn() wraps child future in DETSIM_SEED.scope() with derived seed - Add DetsimSuite with 4 determinism tests (self-contained block_on) - Change Suite::test_all() from async to sync - Change ThreadLocalRng bound from RngCore to Rng - Part of: databendlabs#639
d25a792 to
4bea8c5
Compare
xp-trumpet
approved these changes
Mar 19, 2026
Collaborator
xp-trumpet
left a comment
There was a problem hiding this comment.
@xp-trumpet reviewed 6 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on drmingdrmer).
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.
Changelog
feat: add DeterministicRng to make a runtime deterministic
Replaces the global AtomicU64 seed with per-instance seed stored in
task-local storage. Each DeterministicRng instance owns its seed counter,
set via set_seed() and propagated into block_on() via sync_scope.
Seed derivation uses two SplitMix64 bijective mixers with different
additive constants (golden ratio vs sqrt(2)) to prevent collisions
in the spawn tree: child.seed = f(parent.seed), parent.seed = g(parent.seed).
This ensures parent, child, and sibling tasks all get independent
deterministic RNG sequences.
Suite::test_all() is now sync — creates its own runtime internally,
simplifying callers to just Suite::
Changes:
Add DeterministicRng
Add splitmix64() mixer, derive_spawn_seed(), advance_seed()
spawn() wraps child future in DETSIM_SEED.scope() with derived seed
Add DetsimSuite with 4 determinism tests (self-contained block_on)
Change Suite::test_all() from async to sync
Change ThreadLocalRng bound from RngCore to Rng
Part of: Build deterministic tests based on turmoil #639
This change is