fix: prevent overlapping orgs from splitting inferred stints (CM-1143)#4073
Merged
fix: prevent overlapping orgs from splitting inferred stints (CM-1143)#4073
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
…tion service Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the email-domain member-organization stint inference logic to avoid splitting stints when another organization merely overlaps concurrently, which fits the cron-based affiliation inference flow in common_services and the cron worker that applies those inferred changes.
Changes:
- Replaced the old overlap-based “conflict” check with a narrower “separator” check.
- Kept the existing debounce/extend behavior when no separator is detected.
- Clarified the inline comments around multi-stint splitting behavior.
Findings:
- The new separator predicate is too narrow and misses
A → B → Acases where the middle org overlaps the edge of the first/lastAstint before occupying the gap. In those cases the code now merges the twoAperiods instead of starting a new stint.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… prevent overlaps Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
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
This PR fixes a stint-inference bug in the email-domain cron flow that could generate many one-day
memberOrganizationsrows for the same(member, organization).The root cause was the multi-stint guard: it treated any long overlap from another org as a break, which made the job insert new stints repeatedly instead of extending the existing one.
The logic now treats another org as a separator only when one of its date boundaries falls between the nearest same-org stint and the incoming activity date. Fully overlapping/concurrent rows stay on the normal debounce/extend path. This preserves intended multi-stint behavior (A → B → A) while preventing overlap-driven row explosion.
Note
Medium Risk
Changes stint-inference splitting logic, which can affect how
memberOrganizationsrows are inserted/extended and therefore impacts historical data shape. While scoped to a small block, edge cases in date-boundary detection could still alter multi-stint outcomes.Overview
Prevents inferred
memberOrganizationsstints from being split just because another organization has a long overlapping stint.Replaces the previous “gap overlap” conflict check with a stricter separator rule that only starts a new stint when another org’s
dateStart/dateEndfalls between the nearest same-org stint and the incomingtargetDate; otherwise the existing stint continues to use the normal debounce/extend path.Reviewed by Cursor Bugbot for commit b4461a9. Bugbot is set up for automated code reviews on this repo. Configure here.