-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fairness when routing #18550
base: main
Are you sure you want to change the base?
fix: Fairness when routing #18550
Conversation
@@ -27,18 +26,10 @@ afterEach(() => { | |||
}); | |||
|
|||
describe("filterHostByLeadThreshold", () => { | |||
it("skips filter if host is fixed", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed users are now type guarded.
it("skips filter if lead threshold is null", async () => { | ||
const hosts = [{ isFixed: false, createdAt: new Date(), user: { id: 1 } }]; | ||
const hosts = [ | ||
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to mark isFixed as const so it's not type hinted boolean
- passing a boolean type errors.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
if (contactOwnerEmail && aggregatedAvailability.length > 0) { | ||
// Fairness and Contact Owner disqualification reasons need Availability within 2 weeks | ||
// if not, we attempt to re-open. | ||
if (fallbackHosts && fallbackHosts.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joeauyeung rewritten this check, now any time there's fallbackHosts found I run the 2-weeks check; if there's not enough availability within the qualified users we use the fallbackHosts instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want that?
If reschedule with same host is enabled, we would do that too then. I think we shouldn't make that change in this PR
@@ -886,29 +875,6 @@ const calculateHostsAndAvailabilities = async ({ | |||
bypassBusyCalendarTimes: boolean; | |||
shouldServeCache?: boolean; | |||
}) => { | |||
const routedTeamMemberIds = input.routedTeamMemberIds ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to filterHostsBySameRoundRobinHost check.
E2E results are ready! |
|
||
return { | ||
qualifiedHosts: [...fixedHosts, ...hostsAfterContactOwnerMatching], | ||
fallbackHosts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fallbackHosts should never be the event type hosts.
Fallback hosts should ideally be hostsAfterFairnessMatching
. In case the contact owne has no availability for 2 weeks we would ignore all other logic (attribute routing, fairness,..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | ||
|
||
// We filter out users but ensure allHostUsers remain same. | ||
let users = allHostUsers; | ||
let users = [...qualifiedRRUsers, ...fallbackRRUsers, ...fixedUsers]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change naming of this.
these fallback users are different than the once returned from getQualified users. They are filtered don't don't include the qualified users
@@ -657,26 +710,6 @@ async function handler( | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is already handled in findQualifedUsers
@@ -1267,7 +1300,7 @@ async function handler( | |||
endTime: reqBody.end, | |||
contactOwnerFromReq, | |||
contactOwnerEmail, | |||
allHostUsers, | |||
allHostUsers: [...qualifiedRRUsers, ...fallbackRRUsers, ...fixedUsers], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need fallbackRRUsers here, take a look at what buildDryRunBooking exactly does
availableUsers, | ||
fixedUserPool, | ||
}); | ||
const luckyUsers: typeof users = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luckyUserPool already includes only the contact owner (if available)
|
||
return { | ||
qualifiedRRUsers, | ||
fallbackRRUsers, // without qualified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to make clear this is different from the fallback users returned form findQualifiedUsers
], | ||
eventType, | ||
allRRHosts: hosts, | ||
routingFormResponse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routingFormResponse is added here
contactOwnerEmail, | ||
loggerWithEventDetails, | ||
startTime, | ||
// adjust start time so we can check for available slots in the first two weeks | ||
startTime: startTime.isBefore(twoWeeksFromNow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the start time is within the first two weeks, make sure to load the whole two weeks starting today. Otherwise we have issues if it's end of a month and users already loads next month
bypassBusyCalendarTimes, | ||
shouldServeCache, | ||
}); | ||
if (!firstTwoWeeksAvailabilities.aggregatedAvailability.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a whole month (that's not within the first two weeks) isn't available, then check if the first two week are available. If they are also not available then fallback
Todo: Add more tests for this fallback logic
shouldServeCache, | ||
})); | ||
} | ||
// Merge qualified availability with fallback availabilities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still want to be qualified hosts to be bookable, they might be available after the two weeks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i might don't need this merge
@@ -1,90 +0,0 @@ | |||
import { describe, expect, it } from "vitest"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getUsersWithCredentialsConsideringContactOwner
was removed because all this logic is already handled in findQualifiedUsers
What does this PR do?
Rewrites the handling of pre-qualification due to various filters, correctly and adds fallback logic to whenever no users are returned. We intend to prevent no availability at no cost.
WIP: Pre-push of filters for partial review.