Skip to content

fix: prevent overlapping orgs from splitting inferred stints (CM-1143)#4073

Merged
skwowet merged 3 commits intomainfrom
bugfix/CM-1143
May 5, 2026
Merged

fix: prevent overlapping orgs from splitting inferred stints (CM-1143)#4073
skwowet merged 3 commits intomainfrom
bugfix/CM-1143

Conversation

@skwowet
Copy link
Copy Markdown
Collaborator

@skwowet skwowet commented May 5, 2026

Summary

This PR fixes a stint-inference bug in the email-domain cron flow that could generate many one-day memberOrganizations rows 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 memberOrganizations rows 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 memberOrganizations stints 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/dateEnd falls between the nearest same-org stint and the incoming targetDate; 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.

skwowet added 2 commits May 5, 2026 22:29
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
…tion service

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this May 5, 2026
Copilot AI review requested due to automatic review settings May 5, 2026 17:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 → A cases where the middle org overlaps the edge of the first/last A stint before occupying the gap. In those cases the code now merges the two A periods instead of starting a new stint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/libs/common_services/src/services/member-organization.ts Outdated
… prevent overlaps

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet merged commit 3d4ef53 into main May 5, 2026
17 checks passed
@skwowet skwowet deleted the bugfix/CM-1143 branch May 5, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants