Skip to content

fix: offload delete member and try to handle member identities conflicts better (CM-1054)#3974

Open
themarolt wants to merge 9 commits intomainfrom
fix/identity-issue-CM-1054
Open

fix: offload delete member and try to handle member identities conflicts better (CM-1054)#3974
themarolt wants to merge 9 commits intomainfrom
fix/identity-issue-CM-1054

Conversation

@themarolt
Copy link
Copy Markdown
Contributor

@themarolt themarolt commented Mar 30, 2026

Note

Medium Risk
Touches member identity creation/merge and introduces async orphan deletion, which can impact data integrity if conflict detection or workflows misfire. DB index drops/creates may affect query performance during migration execution.

Overview
Reduces duplicate/orphan members from identity conflicts. Member creation now deduplicates incoming identities, detects partial inserts caused by verified-identity uniqueness conflicts, finds the existing owning member(s), optionally auto-merges conflicting existing members (respecting memberNoMerge), transfers any inserted verified identities, and reuses the existing member while scheduling the orphan for deletion.

Offloads cleanup and unifies merge checks. Orphan member deletion is triggered via a new Temporal workflow deleteOrphanMember, and merge/no-merge checks are centralized in mergeIfAllowed (used by both member creation and activity identity-error handling).

Improves git activity identity keys and DB performance. Git commit activities now set username to the author/committer email (matching stored identities), the data-sink overrides mismatched activity.username to the member’s platform identity value to avoid lookup misses, and a migration drops unused activityRelations indexes/constraint while adding an index on organizationSegmentsAgg for (organizationId, segmentId) including memberCount.

Written by Cursor Bugbot for commit b85e84d. This will update automatically on new commits. Configure here.

…cts better

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings March 30, 2026 04:30
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 data-sink member creation/update behavior when identities conflict, and offloads orphan-member cleanup to the entity-merging Temporal worker. It also aligns git activities’ username with the identity key used for member lookups, and includes a DB migration that drops unused indexes/constraints and adds a covering index for org segment aggregates.

Changes:

  • Add a Temporal workflow (deleteOrphanMember) and workflow ID enum for asynchronously deleting orphan members.
  • Adjust member identity insertion to optionally fail on conflict and return inserted row count; add conflict-resolution logic during member creation (including optional auto-merge).
  • Update git activity payloads to use author/committer email as username, plus a DB migration for index cleanup/optimization.

Reviewed changes

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

Show a summary per file
File Description
services/libs/types/src/enums/temporal.ts Adds workflow ID constant for orphan-member deletion.
services/libs/data-access-layer/src/old/apps/data_sink_worker/repo/member.repo.ts Updates insertIdentities to accept conflict behavior and return inserted count.
services/libs/data-access-layer/src/members/identities.ts Adds helper to find a member by a verified identity.
services/apps/git_integration/src/crowdgit/services/commit/commit_service.py Ensures git activities use email-based username to match identity keys.
services/apps/entity_merging_worker/src/workflows/all.ts Adds deleteOrphanMember workflow that calls deleteMember.
services/apps/entity_merging_worker/src/workflows.ts Re-exports the new workflow.
services/apps/data_sink_worker/src/service/member.service.ts Implements identity-conflict handling, auto-merge logic, and schedules orphan deletion via Temporal.
services/apps/data_sink_worker/src/service/activity.service.ts Normalizes activity.username to the member identity value; refactors merge logic via mergeIfAllowed.
backend/src/database/migrations/V1774609007__data-sink-worker-optimizations.sql Drops unused activityRelations indexes/constraint; adds index on organizationSegmentsAgg.
backend/src/database/migrations/U1774609007__data-sink-worker-optimizations.sql Empty undo migration placeholder.

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

Signed-off-by: Uroš Marolt <uros@marolt.me>
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.

Signed-off-by: Uroš Marolt <uros@marolt.me>
Signed-off-by: Uroš Marolt <uros@marolt.me>
Signed-off-by: Uroš Marolt <uros@marolt.me>
Signed-off-by: Uroš Marolt <uros@marolt.me>
joanagmaia
joanagmaia previously approved these changes Mar 30, 2026
Signed-off-by: Uroš Marolt <uros@marolt.me>
Copy link
Copy Markdown
Collaborator

@skwowet skwowet left a comment

Choose a reason for hiding this comment

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

lgtm

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.

4 participants