Skip to content

feat: add DeterministicRng to make a runtime deterministic#1689

Merged
drmingdrmer merged 1 commit intodatabendlabs:mainfrom
drmingdrmer:377-task-local
Mar 19, 2026
Merged

feat: add DeterministicRng to make a runtime deterministic#1689
drmingdrmer merged 1 commit intodatabendlabs:mainfrom
drmingdrmer:377-task-local

Conversation

@drmingdrmer
Copy link
Copy Markdown
Member

@drmingdrmer drmingdrmer commented Mar 18, 2026

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::::test_all().

Changes:

  • Add DeterministicRng with per-instance Cell 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: Build deterministic tests based on turmoil #639



This change is Reviewable

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
Copy link
Copy Markdown
Collaborator

@xp-trumpet xp-trumpet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xp-trumpet reviewed 6 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on drmingdrmer).

@drmingdrmer drmingdrmer added this pull request to the merge queue Mar 19, 2026
Merged via the queue into databendlabs:main with commit 83737aa Mar 19, 2026
39 checks passed
@drmingdrmer drmingdrmer deleted the 377-task-local branch March 19, 2026 10:31
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.

2 participants