Skip to content

fix: prevent stale activityRelations in affiliations refresh (CM-1132)#4088

Merged
skwowet merged 9 commits intomainfrom
hotfix-member-org-affiliation-timeline
May 8, 2026
Merged

fix: prevent stale activityRelations in affiliations refresh (CM-1132)#4088
skwowet merged 9 commits intomainfrom
hotfix-member-org-affiliation-timeline

Conversation

@skwowet
Copy link
Copy Markdown
Collaborator

@skwowet skwowet commented May 7, 2026

Summary

When a member had memberSegmentAffiliations (MSA) rows, the affiliation timeline builder mixed them together with memberOrganizations into a single timeline. selectPrimaryWorkExperience would pick the MSA as the primary org for any overlapping date range (MSAs have highest precedence), producing a TimelineItem with a segmentId.

processAffiliationActivities then applied WHERE segmentId = X for that item, so activities in other segments were never updated. This left stale organizationId values in activityRelations for the unprocessed segments.

What changed

The timeline is now split into two passes:

  1. Base timeline
    Built from memberOrganizations only, without a segmentId, and applies globally across all segments. When MSAs exist, each item is flagged with skipManualAffiliationSegments.

  2. Manual timeline
    Built per MSA group (grouped by segmentId), with each item scoped to its segment. Gap items (null org) are discarded since the base timeline already covers those date ranges.

In processAffiliationActivities, the skipManualAffiliationSegments flag adds a NOT EXISTS (SELECT 1 FROM memberSegmentAffiliations ...) condition so the base pass skips activity rows already covered by an MSA. Those rows are then handled by the manual pass.

This ensures every activityRelations row is updated exactly once, with no double updates and no missed rows.


Note

Medium Risk
Touches timeline generation and the SQL update criteria used to rewrite activityRelations.organizationId, so mistakes could mis-assign orgs or skip updates across segments despite being a targeted fix.

Overview
Fixes affiliation refresh so activityRelations updates don’t get skipped for members with memberSegmentAffiliations.

The timeline build is split into a global base pass (from memberOrganizations) and a per-segment manual pass (from MSAs). Base items can be flagged with skipManualAffiliationSegments, and processAffiliationActivities now adds a NOT EXISTS guard so the base pass won’t overwrite rows covered by MSAs; the manual pass then updates those segment-scoped rows. Also adds an option to omit fallback ranges when building manual timelines and removes redundant try/catch wrappers in the enrichment worker activity functions.

Reviewed by Cursor Bugbot for commit 8261823. Bugbot is set up for automated code reviews on this repo. Configure here.

skwowet added 2 commits May 7, 2026 18:50
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this May 7, 2026
Copilot AI review requested due to automatic review settings May 7, 2026 14:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@skwowet skwowet requested a review from epipav May 7, 2026 14:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

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 fixes a correctness issue in affiliation refresh where memberSegmentAffiliations (manual, segment-scoped) could prevent updates to activityRelations in other segments, leaving stale organizationId values. The approach splits affiliation processing into a global “base” pass (member organizations only) plus per-segment “manual” passes, and ensures the base pass skips rows covered by manual affiliations.

Changes:

  • Extend TimelineItem with skipManualAffiliationSegments to control base-pass skipping behavior.
  • Split timeline building into base (global) vs manual (per segment) passes, and discard manual “gap” items.
  • Update the activityRelations update query to use alias-qualified columns and add a NOT EXISTS guard to avoid overwriting rows covered by manual affiliations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
services/libs/data-access-layer/src/member-organization-affiliation/types.ts Adds skipManualAffiliationSegments to timeline items to support multi-pass processing.
services/libs/data-access-layer/src/member-organization-affiliation/index.ts Splits timeline generation into base/manual passes and updates the batch update query with manual-coverage skipping logic.

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

Comment thread services/libs/data-access-layer/src/member-organization-affiliation/index.ts Outdated
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copilot AI review requested due to automatic review settings May 7, 2026 14:54
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread services/libs/data-access-layer/src/member-organization-affiliation/index.ts Outdated
…imeline func

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@skwowet skwowet changed the title fix: prevent stale activityRelations in affiliations refresh fix: prevent stale activityRelations in affiliations refresh (CM-1132) May 7, 2026
Copy link
Copy Markdown
Collaborator

@epipav epipav left a comment

Choose a reason for hiding this comment

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

looks good 👍 added one comment

Copilot AI review requested due to automatic review settings May 8, 2026 11:26
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bb9c576. Configure here.

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet merged commit 15d59ff into main May 8, 2026
15 checks passed
@skwowet skwowet deleted the hotfix-member-org-affiliation-timeline branch May 8, 2026 12:14
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.

3 participants