Skip to content

fix: stop unmerge from leaving ui work history on the primary - #5170

Merged
skwowet merged 2 commits into
mainfrom
fix/unmerge-ui-work-history-leak
Nov 2, 2026
Merged

skwowet merged 2 commits into
mainfrom
fix/unmerge-ui-work-history-leak

Conversation

@skwowet

@skwowet skwowet commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a merge is reverted, work-history roles with source ui that came from the secondary stay on the primary. The restored secondary also gets them back from its backup, so both end up with the same roles. This affects member and organization unmerge. The dissect workflow reverts a whole merge chain, so one profile's ui roles end up on every member it restores.

Example: member B has a ui role at Acme (acme.com). Merge B into A, then unmerge. Before this PR, A and B both have the Acme role. After it, only B does.

Cause

Two ui exceptions in the unmerge path:

  • unmergeRoles keeps every ui role on the primary without checking where it came from.
  • The cleanup that runs after the secondary is restored skips ui roles, so nothing removes them. Dissect posts the raw merge backup and never calls unmergeRoles, so this alone causes the leak there.

Changes

  • unmergeRoles (used by both member and organization unmerge): a ui role is removed from the primary only if it matches a role in the secondary backup and none in the primary backup. ui roles the primary had before the merge, or that were added after it, stay. Other sources are unchanged.
  • unmergeMember: the cleanup also deletes ui roles that are missing from the primary payload and are being restored to the secondary.
  • OrganizationService.unmerge: the cleanup no longer skips ui roles. It already runs unmergeRoles on the organization's live roles, so the rule above decides which ones stay.
  • roleExistsInArray compares dates by value. It is now used by both cleanups. The backend reads live roles through Sequelize as Date objects, while backups and payloads hold date strings, so the old === check never matched a dated role.

Roles are matched on organization (or member, for organization unmerge), title, dateStart and dateEnd.

Because dated roles never matched before, the cleanup deleted every dated role on the primary, from any source, whenever the secondary had roles. With the date fix, the primary keeps the dated roles it had before the merge.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Performance improvement
  • Chore / dependency update
  • Documentation

Related issue

Refs linuxfoundation/lfx-cdp-insights-ops#855

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 14:37
@skwowet skwowet changed the title fix: stop unmerge from copying ui work history onto both members fix: stop unmerge from leaving ui work history on the primary Nov 2, 2026
@skwowet skwowet self-assigned this Nov 2, 2026
@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous date-matching issue is fixed.

Summary

Fixes work-history roles left on the primary after an unmerge.

  • Unmerge returns secondary-only UI work-history roles to the restored profile.

Reviews (2) · Last reviewed commit: "fix: compare unmerge role dates by value" · Reviewed by Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unmerge cleanup can delete primary role history from coalesced intervals, while strict Date-versus-string comparisons retain secondary-only history on both restored entities.

2 open issues
What changed in this PR

This PR targets duplicated UI-entered work history during member and organization unmerge, including repeated restores through the dissect workflow.

Changes:

  • Uses merge backups to identify UI roles belonging only to the secondary entity.
  • Extends member cleanup to remove matching secondary UI roles absent from the primary payload.
  • Allows organization cleanup to delete UI roles excluded by the shared unmerge logic.
File Description
services/​libs/​common_services/​src/​services/​member/​unmerge.ts Reuses role matching and extends stale-role cleanup to selected UI roles.
services/​libs/​common_services/​src/​services/​member-organization.ts Exports the role comparator and adds backup-based UI-role ownership checks.
backend/​src/​services/​organizationService.ts Removes the blanket UI-role exemption from organization unmerge cleanup.

Review effort: Balanced

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cleanup can misclassify a coalesced role as secondary-only and delete the primary’s original work history because neither unmerge path persists the restored primary stint.

2 open issues

Review effort: Balanced

@skwowet
skwowet merged commit 8bf19ef into main Nov 2, 2026
15 checks passed
@skwowet
skwowet deleted the fix/unmerge-ui-work-history-leak branch November 2, 2026 14:57
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