fix: add deterministic tiebreaker to RR host selection algorithm#28783
fix: add deterministic tiebreaker to RR host selection algorithm#28783SinghaAnirban005 wants to merge 4 commits intocalcom:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe change adds 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/features/bookings/lib/getLuckyUser.integration-test.ts (2)
449-449: Test name is now misleading after the fix.The test description says "should sort as per availableUsers" but the implementation now sorts by user ID, making it independent of
availableUsersorder. Consider updating the description to reflect the new deterministic behavior.📝 Suggested test name update
- it("should sort as per availableUsers if no other criteria like weight/priority/calibration", async () => { + it("should sort deterministically by user ID when no other criteria like weight/priority/calibration", async () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/features/bookings/lib/getLuckyUser.integration-test.ts` at line 449, The test description for the case starting with it("should sort as per availableUsers...") is now inaccurate because the implementation sorts deterministically by user ID rather than following availableUsers order; update the test name string to reflect the new behavior (e.g., "should sort deterministically by user ID when no weight/priority/calibration criteria") so the description matches the implementation in this test case.
540-542: Remove commented-out code.This appears to be leftover exploration/debug code. Consider removing these lines to keep the test file clean.
🧹 Remove commented-out code
- // const [firstTiedUser, secondTiedUser] = [user1WithWeight100, user2WithWeight100].sort((a, b) => a.id - b.id); - // // const expectedOrder = [userWithHighestWeight, firstTiedUser, secondTiedUser]; - expectLuckyUsers(luckyUsers, [🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/features/bookings/lib/getLuckyUser.integration-test.ts` around lines 540 - 542, Remove the leftover commented-out debug/exploration lines that define firstTiedUser, secondTiedUser, and the commented expectedOrder ([userWithHighestWeight, firstTiedUser, secondTiedUser]) in the getLuckyUser.integration-test.ts test; simply delete those commented lines (references: firstTiedUser, secondTiedUser, user1WithWeight100, user2WithWeight100, userWithHighestWeight, expectedOrder) so the test file contains only active test code and no vestigial comments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/features/bookings/lib/getLuckyUser.integration-test.ts`:
- Line 449: The test description for the case starting with it("should sort as
per availableUsers...") is now inaccurate because the implementation sorts
deterministically by user ID rather than following availableUsers order; update
the test name string to reflect the new behavior (e.g., "should sort
deterministically by user ID when no weight/priority/calibration criteria") so
the description matches the implementation in this test case.
- Around line 540-542: Remove the leftover commented-out debug/exploration lines
that define firstTiedUser, secondTiedUser, and the commented expectedOrder
([userWithHighestWeight, firstTiedUser, secondTiedUser]) in the
getLuckyUser.integration-test.ts test; simply delete those commented lines
(references: firstTiedUser, secondTiedUser, user1WithWeight100,
user2WithWeight100, userWithHighestWeight, expectedOrder) so the test file
contains only active test code and no vestigial comments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 47c84777-4520-4025-b121-8894515d4329
📒 Files selected for processing (2)
packages/features/bookings/lib/getLuckyUser.integration-test.tspackages/features/bookings/lib/getLuckyUser.ts
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
What does this PR do?
This PR addresses the TODO item in the RR host selection system by implementing deterministic ordering
When isRRWeightsEnabled: false and all hosts have the same priority and no bookings, the system was preserving the input order from availableUsers array instead of providing deterministic ordering.This led to non deterministic behavior where the same inputs could produce different outputs depending on array order.
Image Demo (if applicable):
Mandatory Tasks (DO NOT REMOVE)