core/priority: use stable sort for scored priorities - #4611
Merged
Conversation
Replace slices.SortFunc with slices.SortStableFunc when ordering scored priorities so that equal-score priorities keep first-seen order, with messages processed in ascending peer ID order. Go's sort is unstable for slices longer than ~12 elements, so the equal-score order depended on the sort implementation and could diverge across versions and other implementations. Add a regression test with 24 priorities where tied pairs arrive out of score order. category: bug ticket: none Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
KaloyanTanev
approved these changes
Jul 29, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4611 +/- ##
==========================================
- Coverage 57.59% 57.54% -0.06%
==========================================
Files 246 246
Lines 33707 33707
==========================================
- Hits 19415 19398 -17
- Misses 11849 11864 +15
- Partials 2443 2445 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.



Replaces
slices.SortFuncwithslices.SortStableFuncwhen ordering scored priorities, so equal-score priorities keep first-seen order, with messages processed in ascending peer ID order.Go's sort is unstable for slices longer than ~12 elements (below that, pdqsort falls back to insertion sort, which is stable in practice). For topics with 13+ priorities, the order of equal-score entries was unspecified: it could change whenever Go changes its sort implementation, making mixed-version clusters compute different
PriorityResultvalues from identical inputs, and other implementations could not reproduce Charon's result bytes. The serializedPriorityResultfeeds QBFT proposals, so ordering must be a pure deterministic function of the message set.Adds a regression test with 4 peers and a 24-priority topic where tied pairs arrive out of score order; it fails with
SortFuncand passes withSortStableFunc.category: bug
ticket: none