Skip to content

fix: handle verified organization identity collisions#4060

Merged
skwowet merged 3 commits intomainfrom
fix/org-identity-collision-enrichment
Apr 27, 2026
Merged

fix: handle verified organization identity collisions#4060
skwowet merged 3 commits intomainfrom
fix/org-identity-collision-enrichment

Conversation

@skwowet
Copy link
Copy Markdown
Collaborator

@skwowet skwowet commented Apr 27, 2026

Summary

  • Recover from verified organization identity uniqueness collisions during member enrichment.
  • Demote the colliding enriched identity to unverified, then add a merge suggestion for the existing verified owner and enriched org.
  • Respect organization no-merge records before creating merge suggestions.

Note

Medium Risk
Touches organization creation/identity handling inside the member enrichment transaction and introduces merge-suggestion side effects; mistakes could create incorrect org identities or noisy merge queues.

Overview
Member enrichment now recovers when creating an organization fails due to a verified organization-identity uniqueness collision.

On collision, it finds the existing organization that owns the verified identity, retries org creation without the colliding verified identities, re-adds those identities to the enriched org as unverified signals, and records high-similarity merge suggestions (skipping pairs marked as no-merge). Organization sync is also performed per created/updated org with structured logging instead of batching IDs.

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

@skwowet skwowet self-assigned this Apr 27, 2026
Copilot AI review requested due to automatic review settings April 27, 2026 13:04
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ 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

⚠️ 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

⚠️ 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>
@skwowet skwowet force-pushed the fix/org-identity-collision-enrichment branch from 464f826 to 05b339a Compare April 27, 2026 13:07
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ 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

⚠️ 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 improves the members enrichment worker’s organization upsert flow to recover from unique constraint collisions on verified organization identities, and to create organization merge suggestions when an enriched org’s verified identity is already owned by another organization.

Changes:

  • Add collision recovery around findOrCreateOrganization for the verified-identity unique index by retrying with the colliding identity demoted to verified: false.
  • When a collision occurs and the verified owner is found, create merge suggestions (raw + filtered) unless a no-merge record exists.
  • Simplify org syncing by syncing the organization immediately after it is created/updated (instead of maintaining an accumulating orgIdsToSync list).
Comments suppressed due to low confidence (1)

services/apps/members_enrichment_worker/src/activities/enrichment.ts:530

  • orgPromises are awaited via Promise.all(...) while each promise can open a nested qx.tx(...) (pg-promise SAVEPOINT). Running multiple nested transactions concurrently on the same underlying connection can interleave SAVEPOINT begin/release statements and break savepoint nesting, leaving the outer member update transaction in a failed/aborted state. Consider processing these org upserts sequentially (or otherwise ensure only one qx.tx runs at a time) when using savepoints for error recovery.
        )
      }

      await Promise.all(orgPromises)
      // ignore all organizations that were not created

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

Comment thread services/apps/members_enrichment_worker/src/activities/enrichment.ts Outdated
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ 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 merged commit 24204a6 into main Apr 27, 2026
15 checks passed
@skwowet skwowet deleted the fix/org-identity-collision-enrichment branch April 27, 2026 14:32
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