Skip to content

Fix dedupe/redirect nondeterminism#2628

Merged
jakebailey merged 3 commits intomainfrom
jabaile/fix-deduplication-flake
Feb 2, 2026
Merged

Fix dedupe/redirect nondeterminism#2628
jakebailey merged 3 commits intomainfrom
jabaile/fix-deduplication-flake

Conversation

@jakebailey
Copy link
Member

Noticed this in #1604 (and in other CI jobs with dedupes). Without this, redirected / deduplicated files randomly swap ordering because the inputs are randomly ordered.

The comparison change is the real fix, but I have also removed the stable sorts since that is misleading; allFileNames is a map!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes nondeterminism in module specifier generation that was causing test flakiness when handling redirected or deduplicated files. The root cause is that Go's map iteration order is intentionally randomized, so sorting results from maps.Values() requires a fully deterministic comparison function.

Changes:

  • Added a deterministic tiebreaker (filename string comparison) to the path comparison function when paths have the same redirect status and directory depth
  • Changed from SortStableFunc to SortFunc since the comparison function now provides total ordering

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/modulespecifiers/util.go Enhanced comparison function to add filename comparison as a tiebreaker for deterministic sorting
internal/modulespecifiers/specifiers.go Removed misleading stable sort calls since map iteration order is inherently random in Go

}

useCaseSensitiveFileNames := info.UseCaseSensitiveFileNames
comparePaths := func(a, b ModulePath) int {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually allocate, right? I assume it'll keep everything on the stack.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, or at worst it'll be a single slot on the stack for the closure object

@jakebailey jakebailey added this pull request to the merge queue Feb 2, 2026
Merged via the queue into main with commit 1ebc5a7 Feb 2, 2026
21 checks passed
@jakebailey jakebailey deleted the jabaile/fix-deduplication-flake branch February 2, 2026 07:30
Copilot AI pushed a commit that referenced this pull request Feb 25, 2026
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.

3 participants