Repository navigation
fix: keep the backend order in middlewares - #319
Merged
Merged
Conversation
The task distribution middlewares removed duplicate backends with `set()`, which loses the order of `custom.tes.service_list` and the discovered backends; with hash randomization, the order even differed between processes. They now keep the first occurrence of each backend, in order: the base class forwards in the configured order, the distance-based middleware keeps that order for backends at the same distance, and the random order depends on the random state only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test of the reproducible random order compares with the literal order for `random.seed(1)`, so it fails with the old `set()`-based order, which depends on the hash seed. Refs #314 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR replaces hash-dependent set deduplication with insertion-order-preserving logic throughout task distribution middleware processing, ensuring configured backends precede discovered ones, equal-distance ranking is stable, and seeded random distribution is reproducible; documentation and regression tests capture these guarantees. Flow diagram for order-preserving backend distributionflowchart LR
A["Configured service_list"] --> C["TaskDistributionBaseClass._set_tes_urls"]
B["Discovered backends"] --> C
C --> D["dict.fromkeys: remove duplicates, preserve order"]
D --> E["tes_urls"]
E --> F["Distance middleware: stable distance sort"]
E --> G["Random middleware: seeded shuffle"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
uniqueg
marked this pull request as ready for review
October 24, 2026 23:06
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #319 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 2469 2469
=========================================
Hits 2469 2469 ☔ 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.
Summary
The task distribution middlewares removed duplicate backends with
list(set(...)), which loses the order ofcustom.tes.service_listand of the discovered backends (and, with hash randomization, differs between processes). They now usedict.fromkeys(...), which removes duplicates the same way and keeps the order. In the distance middleware, backends at the same distance keep their configured order (stable sort). The random middleware shuffles from a fixed starting order, so a seeded shuffle is reproducible.Verification
Run locally:
PYTHONHASHSEEDvalues (checked by the reviewer and after the fix)mkdocs build --strict: passedReviewed with the adversarial and quality reviewer subagents: no high or medium findings. The low finding (a test that couldn't fail on the old code) is fixed: it now compares against the literal order for
random.seed(1).Not run locally: the Docker Compose smoke test and the MongoDB 7.0 CI entry.
Open questions
None.
Closes #314
🤖 Generated with Claude Code
Summary by Sourcery
Preserve backend ordering across task-distribution middlewares while retaining duplicate removal and deterministic seeded shuffling.
Bug Fixes:
Documentation:
Tests: