Skip to content

Stop TestJobArrayIDSuffixIsNotTheClock flaking on a random collision (#1044) - #1048

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1044
Oct 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1044

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1044

Verified

The test called generateJobArrayID 2000 times and failed on the first duplicate. The suffix is 32 bits from crypto/rand. The birthday bound for 2000 draws is n²/2^33 ≈ 4.7 × 10⁻⁴. On main, go test ./cmd -run '^TestJobArrayIDSuffixIsNotTheClock$' -count=20000 failed 6 times out of 20000. The duplicates were far apart in the sequence (for example calls 724 and 1066), so they were real random collisions, not a clock.

Fix: the test, not the id

The test exists to catch #710: a suffix derived from the clock. That source duplicates massively. Against the old UnixNano()%0xFFFFFF code on darwin, the loop now reports 1362 duplicates in 2000 calls. Entropy produces two or more duplicates with probability about λ²/2 ≈ 1.1 × 10⁻⁷. So the test now fails on more than one duplicate.

  • duplicateIDs(gen, n) collects every repeat, and the failure message reports the count and the first five.
  • New: TestDuplicateToleranceStillCatchesAClock checks that deterministic clock-like sources still exceed the tolerance. They repeat every 2, 4 and 100 calls (the last gives 20 duplicates).
  • With the fix, -count=20000 passes.

Watched failing, with reverts that compile:

Why not widen the suffix

A production collision needs all three parts of the id to match: the same --job-array-name, the same YYYYMMDD, and the same 32-bit suffix. For k launches sharing a name on one day, P ≈ k²/2^33. That is about 1.2 × 10⁻⁶ at 100 launches and 1.2 × 10⁻⁴ at 1000. The date already bounds the window to roughly EC2's ClientToken idempotency window. Widening would change the id's length and format, which appears in tags, DNS group registration and spawn array output, for no measurable gain.

Checks

  • make check (credentials stripped): the only failure is the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.
  • make check-nested: 9 modules clean.
  • golangci-lint (new from main): 0 issues.

Caveat

The comment on the original test claims the tight loop catches a clock suffix "on any platform". On Linux's nanosecond clock, 2000 calls take well under the ~16.8 ms wrap, so the old suffix might not repeat at all within the loop. This PR does not change that, and it was already true.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…1044)

The test failed on the first duplicate among 2000 generateJobArrayID calls.
The suffix is 32 bits from crypto/rand, so 2000 draws collide with
probability n^2/2^33 = 4.7e-4: about one run in 2000, 6 of 20000 measured.

A clock-derived suffix, the #710 regression the test exists to catch,
duplicates hundreds of times in the loop (1362 of 2000 against the old
UnixNano()%0xFFFFFF code on darwin). Entropy duplicates more than once with
probability about 1.1e-7. The test now fails on more than one duplicate, and
TestDuplicateToleranceStillCatchesAClock checks that the tolerance still
rejects clock-like sources.

The id is unchanged. A production collision needs the same name on the same
day (P about k^2/2^33 for k such launches).
@scttfrdmn
scttfrdmn merged commit 50a4d82 into main Oct 16, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1044 branch October 16, 2026 21:26
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.

TestJobArrayIDSuffixIsNotTheClock flakes: 2000 draws from a 32-bit suffix collide about 1 run in 2000

1 participant