Skip to content

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

Open
skwowet wants to merge 7 commits intomainfrom
hotfix-member-org-affiliation-timeline
Open

fix: prevent stale activityRelations in affiliations refresh (CM-1132)#4088
skwowet wants to merge 7 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
Updates the affiliation refresh logic and SQL update criteria for activityRelations, which can affect large batches of rows and correctness of organization attribution across segments.

Overview
Fixes affiliation refresh so memberSegmentAffiliations no longer cause some segments’ activityRelations.organizationId to remain stale.

The timeline build is split into a base (global) pass from memberOrganizations and a manual (per-segment) pass from MSAs; buildTimeline now accepts a single affiliations list and can omit the fallback range. TimelineItem adds skipManualAffiliationSegments, and processAffiliationActivities uses it to add a NOT EXISTS guard so the base pass won’t overwrite rows covered by MSAs; SQL conditions were also updated to consistently use the ar alias.

Reviewed by Cursor Bugbot for commit ef5ebae. 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

@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 b20038a. Configure here.

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

AND msa."segmentId" = ar."segmentId"
AND msa."organizationId" IS NOT NULL
AND (msa."dateStart" IS NULL OR ar."timestamp" >= msa."dateStart"::date)
AND (msa."dateEnd" IS NULL OR ar."timestamp" < msa."dateEnd"::date + interval '1 day')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we have dateEnd + interval '1 day' here?

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