Repository navigation
fix: refresh segment-only members when blocking orgs - #5169
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
[Medium impact] The PR affects organization blocking and member refresh workflows across the backend and workers. Fix the lost refreshes on retry and the script's skipped members before merging.
|
There was a problem hiding this comment.
🟡 Changes recommended
Both activities can lose pending member refreshes after enqueue or signal failures because retries cannot recover IDs from deleted affiliations, leaving segment-only members with stale activity relations.
2 open issues
What changed in this PR
This PR closes a gap in organization affiliation blocking: members linked only through segment affiliations now receive an explicit refresh to clear stale activity relations.
Changes:
- Add a data-access helper that soft-deletes segment affiliations and returns members not covered by organization-level refreshes.
- Queue those members for refresh across backend and worker blocking paths.
- Consolidate post-commit refresh logic for LF segment creation.
| File | Description |
|---|---|
services/libs/data-access-layer/src/member_segment_affiliations/index.ts |
Add organization-scoped deletion that returns segment-only members. |
services/apps/script_executor_worker/src/activities/block-project-organization-affiliations.ts |
Add returned members to the Redis recalculation set. |
services/apps/profiles_worker/src/activities/organization/fakeAnalysis.ts |
Trigger member refreshes when blocking fake organizations. |
backend/src/services/segmentService.ts |
Centralize post-commit organization and member refreshes. |
backend/src/services/organizationService.ts |
Signal segment-only members after the blocking transaction commits. |
Review effort: Balanced

Summary
Blocking an organization's affiliations soft-deletes its member segment affiliations, then relies on
organizationUpdateto refresh members. That workflow only finds members through activememberOrganizationsrows, so a member linked to the org solely by a segment affiliation is never refreshed and theiractivityRelationskeep pointing at the blocked org.This was caught by the Metaplane monitor "Organizations with blocked affiliations that still have activity relations" (Linux Kernel, one member, 1,867 stale rows). A manual
memberUpdatecleared it; this PR closes the gap going forward.Changes
deleteOrganizationSegmentAffiliationsto the data access layer. It soft-deletes an org's segment affiliations and returns only members with no activememberOrganizationsrow for that org, sinceorganizationUpdatealready refreshes the rest. Kept separate fromdeleteMemberSegmentAffiliationsto leave that shared function unchanged.OrganizationService.update: signalsmemberUpdateafter the transaction commits.SegmentService(org auto-blocked when an LF segment with the same name is created): same, after commit. The post-commit loop that was copied acrosscreateProjectGroup,createProjectandcreateSubprojectis now one privaterecalculateBlockedAffiliations.markOrganizationAsFake(profiles_worker): uses the existingtriggerMemberAffiliationsRefresh.setOrganizationAffiliationPolicyIfNotBlocked(script_executor_worker): adds the members to the Redis recalculation set the workflow already drains.Performance
ix_memberSegmentAffiliations_organizationIdplus an index-only probe onmemberOrganizationsper row; the table is about 16k rows.Type of change