Repository navigation
fix(launch): give the job-array id real entropy (#710) - #711
Merged
Merged
Conversation
The suffix was documented as "random suffix (base36)" and was neither: it was time.Now().UnixNano() % 0xFFFFFF, formatted as hex. Two failure modes. On a coarse clock it simply repeats. time.Now() has MICROSECOND resolution on darwin, where two consecutive calls return the identical value, so any two ids minted in the same microsecond were equal. Even on a nanosecond clock the value wraps every 0xFFFFFF ns (~16.8 ms), so two launches that far apart collide deterministically. The keyspace was 16.8 ms of wall clock, not 24 bits, and it was predictable from outside. That un-fixes #691. #691 made the RunInstances ClientToken derive from this id precisely so two launches sharing a --job-array-name could not share a token; a colliding id brings the original failures back — EC2 either rejects the cohort with IdempotentParameterMismatch, or returns the FIRST launch's reservation, so spawn reports success holding instances that are already terminated. crypto/rand, not math/rand: the value reaches a ClientToken, and a predictable token is the mechanism by which an unrelated launch could be made to collide with yours deliberately. A CSPRNG failure falls back to the clock rather than refusing to launch, and says so rather than degrading silently. How this surfaced is worth recording. #691's own gate, TestMemberTokenDiffersBetweenLaunches, compares two consecutive calls — so it failed 5 runs out of 5 on macOS and passed in CI on Linux, where the clock is fine enough for two calls to differ. The one gate written for this hid the bug on exactly the machines that run it: a uniqueness assertion satisfied by clock granularity is not an assertion. The replacement mints 2000 ids in a tight loop, which outruns any wall clock on any platform, and a second test rejects a monotonically-increasing source so a regression to a counter is caught as well as a regression to a clock. Both verified to fail against the old generator.
scttfrdmn
force-pushed
the
fix/710-jobarray-id-entropy
branch
from
October 5, 2026 04:30
7148700 to
d1cb3e3
Compare
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.
Closes #710.
The bug
Documented as a "random suffix (base36)". It is neither random nor base36 — it is a clock reading in hex. Two failure modes:
It repeats on a coarse clock.
time.Now()has microsecond resolution on darwin, where two consecutive calls return the identical value:It wraps on a fine one.
0xFFFFFFns is ~16.8 ms, so two launches that far apart collide deterministically regardless of resolution. The keyspace was 16.8 ms of wall clock, not 24 bits — and predictable from outside.Why it matters
#691 made the
RunInstancesClientToken derive from this id, specifically so two launches sharing a--job-array-namecould not share a token. A colliding id brings #691's failures straight back: EC2 either rejects the cohort withIdempotentParameterMismatch, or returns the first launch's reservation — so spawn can report success while holding instance IDs that are already terminated.Now 32 bits from
crypto/rand. Notmath/rand: the value reaches a ClientToken, and a predictable token is the mechanism by which an unrelated launch could be made to collide with yours on purpose. A CSPRNG failure falls back to the clock rather than refusing a launch, and says so rather than degrading silently.How it surfaced, which is the more interesting part
#691's own gate —
TestMemberTokenDiffersBetweenLaunches— compares two consecutive calls. It was failing 5 runs out of 5 locally and passing in CI, because CI runs on Linux where the clock is fine enough for two calls to differ:Reproduced on a clean
origin/mainworktree, so it predates everything in flight. The one gate written for this hid the bug it was written to catch, on exactly the machines that run it. A uniqueness assertion satisfiable by clock granularity is not an assertion — that generalises past this fix.So the replacement does not rely on the clock being coarse or fine:
TestJobArrayIDSuffixIsNotTheClockmints 2000 ids in a tight loop, which outruns any wall clock on any platform.TestJobArrayIDSuffixUsesTheFullKeyspacerejects a monotonically-increasing source, so a regression to any counter is caught, not just to a clock — which pure uniqueness would miss.Both verified to fail against the old generator; the first names the colliding id and the two call indices.
The whole short suite is now green locally for the first time this session, which is the other confirmation: the pre-existing failure is gone, not suppressed.