Repository navigation
refactor(load-balancing): seed Random and PowerOfTwo at construction instead of reaching for ambient entropy - #1412
Merged
Conversation
Random::next_available_backend and PowerOfTwo's two-candidate tie-break both reached for the ambient thread-local rand::rng(), the last two ambient-entropy sites in load_balancing.rs. Both now hold a rand::rngs::StdRng field, so selection no longer touches process entropy on the hot path. next_available_backend still advances the stored RNG on every call, so a sequence of calls keeps drawing a well-distributed spread of backends: the seed makes the sequence reproducible given the same seed and call sequence, not the pick itself constant. Seed source: new() reads a fresh seed from the OS (StdRng::try_from_rng(&mut rand::rngs::SysRng)) once, at construction, off the datapath. It deliberately does not seed from the existing DEFAULT_HASH_SEED constant Rendezvous/Maglev use for their hashers. An earlier revision of this change did share that constant, matching the Rendezvous/Maglev with_seed shape without noticing the mechanism is different: Rendezvous/Maglev feed their seed into a pure, stateless hash function, so sharing it fleet-wide is what gives them cross-worker/cross-restart agreement for a given key. Random/PowerOfTwo feed their seed into a stateful, advancing StdRng, where the n-th pick depends on the whole call history, so sharing a compile-time constant would make every worker, on every cold start, draw from a bit-for-bit identical keystream: every fresh worker's first pick (and every first PowerOfTwo tie-break, the common case since every backend starts at zero load) would be identical fleet-wide on every restart. That is the correlated-load event uniform selection exists to prevent, arriving at the worst possible moment: a synchronised redeploy, when every worker's call counter resets together and initial load is otherwise indistinguishable. DEFAULT_HASH_SEED stays exactly where it is, for Rendezvous/Maglev only. with_seed(seed) stays available on both Random and PowerOfTwo for tests and any future deterministic simulator. PowerOfTwo's tie-break stays seeded-random rather than switching to a deterministic rule (e.g. lowest backend id). Unlike Rendezvous/Maglev, PowerOfTwo carries no affinity key, so there is no same-key-same-backend requirement to preserve; but every backend starts at zero load, making ties the common case, not the rare one, so a deterministic tie-break would bias every worker toward the same backend on exactly the events (cold start, post-scale-up rebalance) power-of-two-choices exists to spread out. BackendList::new and BackendList::set_load_balancing_policy are the only two callers; both go through Random::new()/PowerOfTwo::new(metric). Adds a red-then-green regression test: on the pre-change code, two Random (respectively PowerOfTwo) instances built the same way and driven through the same 20-call sequence over a cloned backend list diverge. After the change, with_seed reproduces an identical, hardcoded-expected sequence (coupled to rand 0.10.2's exact StdRng algorithm, noted at the assertion), and a separate 5,000-draw smoke check confirms neither collapses onto a single backend (a coarse bound, documented as such rather than oversold as a uniformity test). Two more tests, random_new_instances_are_not_correlated and power_of_two_new_instances_are_not_correlated, guard the shared-seed defect directly: two new() instances must diverge. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 00:00
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 22, 2026
…_TWO `PowerOfTwo::next_available_backend` walked every backend keeping the two lightest, then coin-flipped between them. That is neither the algorithm the name promises nor cheaper than `LeastLoaded`: it paid the same O(n) load reads per request and then discarded the ordering it had just computed. It now draws two DISTINCT backends uniformly at random and keeps the less loaded of the two, reading two backend loads whatever the cluster size. An exact tie is still broken by the seeded coin flip introduced in #1412: ties are the common case (every backend starts at zero load) and awarding them by index would herd every worker onto the same backend, which is the effect P2C exists to prevent. That is a claim about load READS, not an O(1)-per-request claim. Every selection, under every policy, first builds the candidate set in `BackendList::available_backends` (lib/src/backends.rs), which walks the cluster's backend list and clones each healthy backend into a fresh Vec; `next_available_backend_with_key` calls it before any policy is consulted. All six policies are therefore O(n) per request and none of them removes that walk. What P2C removes is the load reads layered on top of it: 2 instead of n. That is measurable work under `LoadMetric::ConnectionTime`, where every read is a `PeakEWMA::observe` call taking an `Instant::now()` stamp, and small under `Connections`/`Requests`. doc/configure.md, bin/config.toml, doc/lifetime_of_a_session.md and doc/architecture.md say so now, and they no longer advise picking P2C to shorten a per-request scan that lives in the caller: the reason to prefer it over LEAST_LOADED is balance without a global minimum, not cost. What the old code did was also worse than "near least loaded", measured by restoring the fold under the new tests. Over 5000 selections across four equally loaded backends it sent backends 0 and 1 exactly zero requests and split the rest between the last two it walked; on two backends carrying 7 and 1 connections it returned the 7-connection backend on the very first call; and with one uniquely light backend among 100 it returned that backend 0 times out of 100_000, an estimated sample size of 0.00 rather than the N/2 a reading of the fold that assumed it retained the minimum would predict. No configuration reproduces that distribution, and nothing should want to. Renaming the variant to describe the old behaviour was the other candidate resolution and was rejected on evidence, not preference. `LoadBalancingAlgorithms` derives serde with `rename_all = "SCREAMING_SNAKE_CASE"`, and two live surfaces carry the value as the STRING `"POWER_OF_TWO"`: the TOML cluster config (`FileClusterConfig::load_balancing`, command/src/config.rs) and the hot-upgrade payload (`UpgradeData::config`, serialized with serde_json in bin/src/upgrade.rs). A rename would therefore refuse every existing config file at startup and break a hot upgrade across the version boundary. Fixing the algorithm breaks no external surface at all: the variant keeps its name and its protobuf tag 3, and the saved state file already encodes `Cluster.load_balancing` as that integer, never as the name (command/tests/state_compat_v1_1_1.rs). The rewrite also removes a latent bug in the old fold. Its trailing `else` branch fired both when the new measure was lighter than `first` AND when it was heavier than `second`, evicting both candidates in the second case. On backend loads [0, 1, 5] that left the pair inverted, tripping the function's own `first <= second` debug_assert (a debug-build panic) and, in a release build, coin-flipping the HEAVIEST backend into the result half the time. The two-read bound is measured rather than asserted structurally, because a test that only checks "a backend came back" passes for the O(n) fold too: `power_of_two_touches_exactly_two_backends` counts the per-backend `PeakEWMA::observe` timestamps one selection leaves behind (64 backends in, exactly 2 measured; the old fold measured all 64), and `power_of_two_sample_size_is_two_not_the_whole_set` recovers the same sample size from the selection distribution alone. The tie-break needed its own test: the sampled pair is uniform, so the two sample positions are exchangeable and the marginal distribution cannot see which member of a tie won — substituting `true` for the coin flip leaves `power_of_two_tie_break_distribution_does_not_collapse` green. `power_of_two_tie_break_is_decided_by_the_coin_flip_not_by_sample_position` pins it directly, by freezing the peak-EWMA decay so two equally loaded backends tie exactly while `PeakEWMA::observe` still stamps `last_event`, which makes the order the two samples were measured in readable from outside. Under that substitution it reports 0 of 2000 ties resolved in favour of the second-measured sample. doc/configure.md, bin/config.toml and doc/lifetime_of_a_session.md also say which policies read `load_balancing_parameters.weight`, because the first draft of that paragraph claimed RANDOM was the only one and three of the six policies were never checked. Verified at source: RANDOM reads it inline (lib/src/load_balancing.rs:311), `Rendezvous::score` scales its rendezvous score by `backend_weight` (:632) and `Maglev::rebuild` hands out lookup-table slots in proportion to it (:813); the RoundRobin (:180-216), LeastLoaded (:352-396) and PowerOfTwo (:517-581) impls read no weight at all. HRW and Maglev both fall back to RoundRobin when called with no affinity key (:659-662, :940-942), so their weight is live only on the UDP datapath, which is the one caller that passes `Some(key)` (lib/src/udp.rs:1347). The captured-sequence test's recapture note now scopes itself to both kinds of legitimate change -- a `rand` upgrade and a deliberate change to the selection procedure -- and states the rule that distinguishes a legitimate recapture from papering over a regression: recapture only when that literal is the only failing assertion and every semantic `power_of_two_*` test is green with its body untouched. A prose-to-prose citation is checked by no rule in .github/scripts/check_doc_citations.py, which resolves source targets only, so this changeset silently rotted `doc/configure_admin_ops.md:230` by moving its target 46 lines down doc/configure.md. The citation is re-pointed and the script's header now names the blind spot, the three citations it covers, and why a fourth rule is not worth writing for three. BREAKING CHANGE: traffic distribution changes for every cluster configured with POWER_OF_TWO. No configuration key, CLI value, protobuf tag, saved state file or hot-upgrade payload changes, and no setting restores the old distribution. Refs #1411 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 22, 2026
…_TWO `PowerOfTwo::next_available_backend` walked every backend keeping the two lightest, then coin-flipped between them. That is neither the algorithm the name promises nor cheaper than `LeastLoaded`: it paid the same O(n) load reads per request and then discarded the ordering it had just computed. It now draws two DISTINCT backends uniformly at random and keeps the less loaded of the two, reading two backend loads whatever the cluster size. An exact tie is still broken by the seeded coin flip introduced in #1412: ties are the common case (every backend starts at zero load) and awarding them by index would herd every worker onto the same backend, which is the effect P2C exists to prevent. That is a claim about load READS, not an O(1)-per-request claim. Every selection, under every policy, first builds the candidate set in `BackendList::available_backends` (lib/src/backends.rs), which walks the cluster's backend list and clones each healthy backend into a fresh Vec; `next_available_backend_with_key` calls it before any policy is consulted. All six policies are therefore O(n) per request and none of them removes that walk. What P2C removes is the load reads layered on top of it: 2 instead of n. That is measurable work under `LoadMetric::ConnectionTime`, where every read is a `PeakEWMA::observe` call taking an `Instant::now()` stamp, and small under `Connections`/`Requests`. doc/configure.md, bin/config.toml, doc/lifetime_of_a_session.md and doc/architecture.md say so now, and they no longer advise picking P2C to shorten a per-request scan that lives in the caller: the reason to prefer it over LEAST_LOADED is balance without a global minimum, not cost. What the old code did was also worse than "near least loaded", measured by restoring the fold under the new tests. Over 5000 selections across four equally loaded backends it sent backends 0 and 1 exactly zero requests and split the rest between the last two it walked; on two backends carrying 7 and 1 connections it returned the 7-connection backend on the very first call; and with one uniquely light backend among 100 it returned that backend 0 times out of 100_000, an estimated sample size of 0.00 rather than the N/2 a reading of the fold that assumed it retained the minimum would predict. No configuration reproduces that distribution, and nothing should want to. Renaming the variant to describe the old behaviour was the other candidate resolution and was rejected on evidence, not preference. `LoadBalancingAlgorithms` derives serde with `rename_all = "SCREAMING_SNAKE_CASE"`, and two live surfaces carry the value as the STRING `"POWER_OF_TWO"`: the TOML cluster config (`FileClusterConfig::load_balancing`, command/src/config.rs) and the hot-upgrade payload (`UpgradeData::config`, serialized with serde_json in bin/src/upgrade.rs). A rename would therefore refuse every existing config file at startup and break a hot upgrade across the version boundary. Fixing the algorithm breaks no external surface at all: the variant keeps its name and its protobuf tag 3, and the saved state file already encodes `Cluster.load_balancing` as that integer, never as the name (command/tests/state_compat_v1_1_1.rs). The rewrite also removes a latent bug in the old fold. Its trailing `else` branch fired both when the new measure was lighter than `first` AND when it was heavier than `second`, evicting both candidates in the second case. On backend loads [0, 1, 5] that left the pair inverted, tripping the function's own `first <= second` debug_assert (a debug-build panic) and, in a release build, coin-flipping the HEAVIEST backend into the result half the time. The two-read bound is measured rather than asserted structurally, because a test that only checks "a backend came back" passes for the O(n) fold too: `power_of_two_touches_exactly_two_backends` counts the per-backend `PeakEWMA::observe` timestamps one selection leaves behind (64 backends in, exactly 2 measured; the old fold measured all 64), and `power_of_two_sample_size_is_two_not_the_whole_set` recovers the same sample size from the selection distribution alone. The tie-break needed its own test: the sampled pair is uniform, so the two sample positions are exchangeable and the marginal distribution cannot see which member of a tie won — substituting `true` for the coin flip leaves `power_of_two_tie_break_distribution_does_not_collapse` green. `power_of_two_tie_break_is_decided_by_the_coin_flip_not_by_sample_position` pins it directly, by freezing the peak-EWMA decay so two equally loaded backends tie exactly while `PeakEWMA::observe` still stamps `last_event`, which makes the order the two samples were measured in readable from outside. Under that substitution it reports 0 of 2000 ties resolved in favour of the second-measured sample. doc/configure.md, bin/config.toml and doc/lifetime_of_a_session.md also say which policies read `load_balancing_parameters.weight`, because the first draft of that paragraph claimed RANDOM was the only one and three of the six policies were never checked. Verified at source: RANDOM reads it inline (lib/src/load_balancing.rs:311), `Rendezvous::score` scales its rendezvous score by `backend_weight` (:632) and `Maglev::rebuild` hands out lookup-table slots in proportion to it (:813); the RoundRobin (:180-216), LeastLoaded (:352-396) and PowerOfTwo (:517-581) impls read no weight at all. HRW and Maglev both fall back to RoundRobin when called with no affinity key (:659-662, :940-942), so their weight is live only on the UDP datapath, which is the one caller that passes `Some(key)` (lib/src/udp.rs:1347). The captured-sequence test's recapture note now scopes itself to both kinds of legitimate change -- a `rand` upgrade and a deliberate change to the selection procedure -- and states the rule that distinguishes a legitimate recapture from papering over a regression: recapture only when that literal is the only failing assertion and every semantic `power_of_two_*` test is green with its body untouched. A prose-to-prose citation is checked by no rule in .github/scripts/check_doc_citations.py, which resolves source targets only, so this changeset silently rotted `doc/configure_admin_ops.md:230` by moving its target 46 lines down doc/configure.md. The citation is re-pointed and the script's header now names the blind spot, the three citations it covers, and why a fourth rule is not worth writing for three. BREAKING CHANGE: traffic distribution changes for every cluster configured with POWER_OF_TWO. No configuration key, CLI value, protobuf tag, saved state file or hot-upgrade payload changes, and no setting restores the old distribution. Refs #1411 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 22, 2026
…_TWO (#1437) `PowerOfTwo::next_available_backend` walked every backend keeping the two lightest, then coin-flipped between them. That is neither the algorithm the name promises nor cheaper than `LeastLoaded`: it paid the same O(n) load reads per request and then discarded the ordering it had just computed. It now draws two DISTINCT backends uniformly at random and keeps the less loaded of the two, reading two backend loads whatever the cluster size. An exact tie is still broken by the seeded coin flip introduced in #1412: ties are the common case (every backend starts at zero load) and awarding them by index would herd every worker onto the same backend, which is the effect P2C exists to prevent. That is a claim about load READS, not an O(1)-per-request claim. Every selection, under every policy, first builds the candidate set in `BackendList::available_backends` (lib/src/backends.rs), which walks the cluster's backend list and clones each healthy backend into a fresh Vec; `next_available_backend_with_key` calls it before any policy is consulted. All six policies are therefore O(n) per request and none of them removes that walk. What P2C removes is the load reads layered on top of it: 2 instead of n. That is measurable work under `LoadMetric::ConnectionTime`, where every read is a `PeakEWMA::observe` call taking an `Instant::now()` stamp, and small under `Connections`/`Requests`. doc/configure.md, bin/config.toml, doc/lifetime_of_a_session.md and doc/architecture.md say so now, and they no longer advise picking P2C to shorten a per-request scan that lives in the caller: the reason to prefer it over LEAST_LOADED is balance without a global minimum, not cost. What the old code did was also worse than "near least loaded", measured by restoring the fold under the new tests. Over 5000 selections across four equally loaded backends it sent backends 0 and 1 exactly zero requests and split the rest between the last two it walked; on two backends carrying 7 and 1 connections it returned the 7-connection backend on the very first call; and with one uniquely light backend among 100 it returned that backend 0 times out of 100_000, an estimated sample size of 0.00 rather than the N/2 a reading of the fold that assumed it retained the minimum would predict. No configuration reproduces that distribution, and nothing should want to. Renaming the variant to describe the old behaviour was the other candidate resolution and was rejected on evidence, not preference. `LoadBalancingAlgorithms` derives serde with `rename_all = "SCREAMING_SNAKE_CASE"`, and two live surfaces carry the value as the STRING `"POWER_OF_TWO"`: the TOML cluster config (`FileClusterConfig::load_balancing`, command/src/config.rs) and the hot-upgrade payload (`UpgradeData::config`, serialized with serde_json in bin/src/upgrade.rs). A rename would therefore refuse every existing config file at startup and break a hot upgrade across the version boundary. Fixing the algorithm breaks no external surface at all: the variant keeps its name and its protobuf tag 3, and the saved state file already encodes `Cluster.load_balancing` as that integer, never as the name (command/tests/state_compat_v1_1_1.rs). The rewrite also removes a latent bug in the old fold. Its trailing `else` branch fired both when the new measure was lighter than `first` AND when it was heavier than `second`, evicting both candidates in the second case. On backend loads [0, 1, 5] that left the pair inverted, tripping the function's own `first <= second` debug_assert (a debug-build panic) and, in a release build, coin-flipping the HEAVIEST backend into the result half the time. The two-read bound is measured rather than asserted structurally, because a test that only checks "a backend came back" passes for the O(n) fold too: `power_of_two_touches_exactly_two_backends` counts the per-backend `PeakEWMA::observe` timestamps one selection leaves behind (64 backends in, exactly 2 measured; the old fold measured all 64), and `power_of_two_sample_size_is_two_not_the_whole_set` recovers the same sample size from the selection distribution alone. The tie-break needed its own test: the sampled pair is uniform, so the two sample positions are exchangeable and the marginal distribution cannot see which member of a tie won — substituting `true` for the coin flip leaves `power_of_two_tie_break_distribution_does_not_collapse` green. `power_of_two_tie_break_is_decided_by_the_coin_flip_not_by_sample_position` pins it directly, by freezing the peak-EWMA decay so two equally loaded backends tie exactly while `PeakEWMA::observe` still stamps `last_event`, which makes the order the two samples were measured in readable from outside. Under that substitution it reports 0 of 2000 ties resolved in favour of the second-measured sample. doc/configure.md, bin/config.toml and doc/lifetime_of_a_session.md also say which policies read `load_balancing_parameters.weight`, because the first draft of that paragraph claimed RANDOM was the only one and three of the six policies were never checked. Verified at source: RANDOM reads it inline (lib/src/load_balancing.rs:311), `Rendezvous::score` scales its rendezvous score by `backend_weight` (:632) and `Maglev::rebuild` hands out lookup-table slots in proportion to it (:813); the RoundRobin (:180-216), LeastLoaded (:352-396) and PowerOfTwo (:517-581) impls read no weight at all. HRW and Maglev both fall back to RoundRobin when called with no affinity key (:659-662, :940-942), so their weight is live only on the UDP datapath, which is the one caller that passes `Some(key)` (lib/src/udp.rs:1347). The captured-sequence test's recapture note now scopes itself to both kinds of legitimate change -- a `rand` upgrade and a deliberate change to the selection procedure -- and states the rule that distinguishes a legitimate recapture from papering over a regression: recapture only when that literal is the only failing assertion and every semantic `power_of_two_*` test is green with its body untouched. A prose-to-prose citation is checked by no rule in .github/scripts/check_doc_citations.py, which resolves source targets only, so this changeset silently rotted `doc/configure_admin_ops.md:230` by moving its target 46 lines down doc/configure.md. The citation is re-pointed and the script's header now names the blind spot, the three citations it covers, and why a fourth rule is not worth writing for three. BREAKING CHANGE: traffic distribution changes for every cluster configured with POWER_OF_TWO. No configuration key, CLI value, protobuf tag, saved state file or hot-upgrade payload changes, and no setting restores the old distribution. Refs #1411 Signed-off-by: Florentin Dubois <[email protected]>
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.
Part of the sans-io conversion: no ambient clock, entropy or I/O reached for inside a core. Load
balancing was already almost there and deliberately so —
RendezvousandMaglevcarry an explicitDEFAULT_HASH_SEEDwhose doc comment says it is not aRandomStateprecisely so selection is"reproducible across workers and across process restarts".
Two sites still called the thread-local
rng():Random::next_available_backendPowerOfTwo's coin flip between its two candidatesBoth now hold a
StdRngseeded once at construction.with_seed(...)gives a fixed, reproduciblesequence for tests and any future simulator.
The seed source is OS entropy, deliberately not
DEFAULT_HASH_SEEDAn earlier revision of this branch seeded from that shared constant, to match the shape
Rendezvous/Maglevuse. That was wrong, and the distinction is worth stating because it is exactlythe kind of thing a later "simplification" would undo.
RendezvousandMaglevfeed the seed intohash_backend(seed, key, addr)— a pure, statelessfunction. Same inputs, same output, whatever the call history. Sharing it fleet-wide is the whole
point: it is what makes an affinity key land on the same backend across workers and restarts.
RandomandPowerOfTwouse a seed to initialise a stateful, advancingStdRng, where the n-thpick depends on the entire call history. Seeding that from a shared compile-time constant means every
worker, on every machine, on every cold start, with an identically-ordered backend list, draws from a
bit-for-bit identical keystream — so every fresh worker's first pick over four equal-weight backends is
the same backend index, fleet-wide, every restart. That is the correlated-load event uniform selection
exists to prevent, arriving at the worst possible moment: a synchronised redeploy, when every worker's
call counter resets together and initial load is otherwise indistinguishable. The previous
OS-entropy-seeded thread-local
rng()did not have that property.The earlier revision's own determinism test proved the defect by construction — two independent
instances, which is structurally two worker processes, producing the same literal 20-pick sequence.
So
new()reads the OS once at construction, off the datapath, which satisfies the sans-io rulecompletely:
This is
quinn-proto's shape — fully deterministic under an injected seed, independently seeded whennone is given.
DEFAULT_HASH_SEEDis untouched and is no longer referenced byRandomorPowerOfTwo; it staysRendezvous/Maglev-only. The full argument lives in both structs' doccomments, not only here.
PowerOfTwo's tie-break stays random, argued rather than assumedA deterministic tie-break — lowest backend id — was considered and rejected.
Rendezvous/Maglevneed cross-worker agreement because they carry an affinity key;
PowerOfTwoignores its_keyentirely, so every call is an independent unlabelled event and there is no agreement to preserve. What
the sans-io rule actually required was a seed instead of ambient entropy, not identical output across
workers.
And a deterministic tie-break would be a real regression here: every backend starts at zero load, so
ties are the common case at cold start and after a scale-up, not the rare one. Lowest-id-wins would
bias every worker toward the same backend on exactly the events that spreading exists for.
Separately — and not changed here —
PowerOfTwoscans every backend and then picks randomlybetween the two lightest, which is neither power-of-two-choices nor cheaper than
LeastLoaded. Thatis tracked as #1411. This changeset makes its coin flip reproducible and leaves the algorithm alone.
Tests
Red, on the pre-fix code: two instances built the same way diverge.
Green, with each determinism test pairing reproducibility (
seq1 == seq2) against an absoluteexpected sequence hardcoded as a literal, so it distinguishes "reproducible" from "reproducible and
correct". A determinism assertion alone is green even when the value is uniformly wrong — a trap this
project has paid for before.
Two correlation guards against the defect described above coming back:
random_new_instances_are_not_correlatedandpower_of_two_new_instances_are_not_correlatedbuild twonew()instances and assert their sequences differ over 32 and 48 calls — collision probability around4⁻³² and 2⁻⁴⁸ if genuinely independently seeded, so not a flake source. Run 10 times consecutively,
10/10 clean.
Two smoke checks, named honestly:
random_distribution_does_not_collapseand itsPowerOfTwosibling assert each backend lands within 65–135% of uniform over 5,000 draws. That is roughly ±12σ, so
it reliably catches full collapse or gross bias — the realistic regression this refactor could
introduce — while a systematic 20–25% skew would pass. The σ arithmetic is written at each assertion so
nobody reads more into the name than the assertion delivers.
One brittleness note is recorded beside the hardcoded literals: they are coupled to
rand0.10.2'sexact
StdRng(ChaCha12) andseed_from_u64's splitmix64 expansion. Arandbump may break them forreasons unrelated to Sōzu's logic — recapture the literal, do not "fix" the algorithm.
Validation, both feature shapes
The bare-defaults build and clippy are run because CI's
msrv-barecell sees a feature-off tree thatan
--all-features-only chain cannot.No new dependency:
SysRngcomes fromrand's defaultsys_rngfeature, already enabled, andCargo.lockis unchanged.Refs #1411.