Skip to content

feat: add recalculate all affiliation (IN-1083)#4038

Open
ulemons wants to merge 8 commits intomainfrom
feat/optimize-fetch-for-affiliation-recalculation
Open

feat: add recalculate all affiliation (IN-1083)#4038
ulemons wants to merge 8 commits intomainfrom
feat/optimize-fetch-for-affiliation-recalculation

Conversation

@ulemons
Copy link
Copy Markdown
Contributor

@ulemons ulemons commented Apr 21, 2026

Note

Medium Risk
Medium risk because it introduces a new bulk remediation script that runs wide DB scans and can enqueue large volumes of memberUpdate Temporal workflows, potentially impacting load and data correctness if misused.

Overview
Adds a new recalculate-all-affiliations script (wired into script_executor_worker package.json) to find members whose activityRelations.organizationId references aren’t present as active memberOrganizations.

The script pages through member IDs, reports/limits results in --dry-run, and in live mode triggers memberUpdate workflows (configurable concurrency/delays, resume cursor, max pages) to recompute affiliations and sync to OpenSearch.

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

@ulemons ulemons self-assigned this Apr 21, 2026
Copilot AI review requested due to automatic review settings April 21, 2026 07:58
@ulemons ulemons added the Bug Created by Linear-GitHub Sync label Apr 21, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Adds a new script to detect members with stale activityRelations.organizationId values (relative to non-deleted memberOrganizations) and trigger memberUpdate Temporal workflows to recalculate affiliations.

Changes:

  • Introduces recalculate-all-affiliations.ts to page through members, detect stale org attributions, and trigger memberUpdate workflows with concurrency controls.
  • Exposes the script via a new pnpm run recalculate-all-affiliations package.json entry.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
services/apps/script_executor_worker/src/bin/recalculate-all-affiliations.ts Implements paging + detection query + Temporal workflow triggering for affiliation recalculation.
services/apps/script_executor_worker/package.json Adds a runnable script entry for the new recalculation tool.

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

Copilot AI review requested due to automatic review settings April 21, 2026 08:35
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

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.


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

Copilot AI review requested due to automatic review settings April 21, 2026 08:47
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

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.


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

Copilot AI review requested due to automatic review settings April 23, 2026 07:57
ulemons added 7 commits April 23, 2026 09:57
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
@ulemons ulemons force-pushed the feat/optimize-fetch-for-affiliation-recalculation branch from 521c6dd to b9782ca Compare April 23, 2026 07:57
@ulemons ulemons marked this pull request as ready for review April 23, 2026 07:57
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

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.


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

Comment thread services/apps/script_executor_worker/src/bin/recalculate-all-affiliations.ts Outdated
@ulemons ulemons requested a review from skwowet April 23, 2026 08:07
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.

Reviewed by Cursor Bugbot for commit c0a7980. Configure here.

memberOrganizationIds: activeOrgIds,
syncToOpensearch: true,
},
],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale orgs excluded from OpenSearch sync after recalculation

Medium Severity

The memberOrganizationIds passed to the memberUpdate workflow only contains activeOrgIds, but staleOrgIds are also needed. After refreshMemberOrganizationAffiliations recalculates affiliations in the DB, activities previously attributed to stale orgs get re-attributed. The stale orgs' data in OpenSearch remains outdated because syncOrganization is never called for them. Both activeOrgIds and staleOrgIds need to be included so all affected organizations are synced.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c0a7980. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants