fix: offload delete member and try to handle member identities conflicts better (CM-1054)#3974
fix: offload delete member and try to handle member identities conflicts better (CM-1054)#3974
Conversation
…cts better Signed-off-by: Uroš Marolt <uros@marolt.me>
There was a problem hiding this comment.
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.
services/apps/git_integration/src/crowdgit/services/commit/commit_service.py
Show resolved
Hide resolved
Signed-off-by: Uroš Marolt <uros@marolt.me>
Signed-off-by: Uroš Marolt <uros@marolt.me>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
services/libs/data-access-layer/src/old/apps/data_sink_worker/repo/member.repo.ts
Show resolved
Hide resolved
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>

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 inmergeIfAllowed(used by both member creation and activity identity-error handling).Improves git activity identity keys and DB performance. Git commit activities now set
usernameto the author/committer email (matching stored identities), the data-sink overrides mismatchedactivity.usernameto the member’s platform identity value to avoid lookup misses, and a migration drops unusedactivityRelationsindexes/constraint while adding an index onorganizationSegmentsAggfor(organizationId, segmentId)includingmemberCount.Written by Cursor Bugbot for commit b85e84d. This will update automatically on new commits. Configure here.