Skip to content

fix: use correct meta key for user-deleted org tracking in V2#1536

Merged
TheLastCicada merged 1 commit into
v2-rc2from
fix/user-deleted-org-meta-key-mismatch
Mar 17, 2026
Merged

fix: use correct meta key for user-deleted org tracking in V2#1536
TheLastCicada merged 1 commit into
v2-rc2from
fix/user-deleted-org-meta-key-mismatch

Conversation

@TheLastCicada

@TheLastCicada TheLastCicada commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix meta key mismatch in V2 deleteAllOrganizationData: The function used a hardcoded 'userDeletedOrgUid' meta key instead of the 'userDeletedOrgs' constant defined in MetaV2. This meant sync-default-organizations-v2 could not find the deleted org in its check and would re-import it with is_home: false, silently removing a participant's home org status. Replaced the inline meta logic with MetaV2.addUserDeletedOrgUid() to match V1's correct pattern.
  • Fix importOrganization cleanup: The MetaV2.destroy() call used the wrong meta key and tried to match meta_value against a single orgUid when the actual value is a JSON array, so it never matched. Replaced with MetaV2.removeUserDeletedOrgUid().
  • Prevent syncOrganizationMeta from overwriting is_home/isHome: Added the home org flag to the _.omit() list in both V1 and V2 syncOrganizationMeta, so datalayer store data can never overwrite this CADT-internal field.

Root Cause

Investigated on the cadt-participant1-testing k8s pod. The org was deleted via the API at 17:32 UTC, recorded under meta_key = 'userDeletedOrgUid'. Within 40 seconds, sync-default-organizations-v2 ran, checked meta_key = 'userDeletedOrgs' (different key), found nothing, and re-imported the org with is_home: false.

Test plan

  • Verify V2 org delete followed by sync-default-organizations does NOT re-import the org
  • Verify V2 org import correctly removes the org from the user-deleted list
  • Verify syncOrganizationMeta does not overwrite is_home even if store data contains it
  • Existing integration tests pass

Note

Medium Risk
Touches V2 org delete/import flows and mutex timing; a mistake could cause orgs to be incorrectly re-imported or skipped during background sync.

Overview
Fixes V2 user-deleted organization tracking by replacing ad-hoc MetaV2.destroy/JSON-array manipulation with MetaV2.removeUserDeletedOrgUid() on import and MetaV2.addUserDeletedOrgUid() on delete, using the correct userDeletedOrgs meta key.

Adjusts V2 deletion to write the “user deleted” marker while still holding mutexes (after the DB transaction) to prevent sync-default-organizations-v2 from re-importing an org between deletion and meta update.

Prevents syncOrganizationMeta from overwriting the home-org flag by omitting isHome (V1) / is_home (V2) from store-driven updates.

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

Comment thread src/models/v2/organizations-v2.model.js
@TheLastCicada TheLastCicada force-pushed the fix/user-deleted-org-meta-key-mismatch branch from d3c1df6 to 844e3a5 Compare March 17, 2026 20:17

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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, enable autofix in the Cursor dashboard.

Comment thread src/models/v2/organizations-v2.model.js
The V2 deleteAllOrganizationData function used a hardcoded meta key
'userDeletedOrgUid' instead of the 'userDeletedOrgs' constant used
by MetaV2.getUserDeletedOrgUids(). This mismatch meant that after
deleting an org, sync-default-organizations-v2 would not find it in
the deleted list and would re-import it with is_home: false.

Replace the inline meta logic with MetaV2.addUserDeletedOrgUid() to
match V1's pattern. The call runs after transaction commit but before
mutex release so sync-default-organizations-v2 cannot race in and
re-import the org before the meta write completes. Also fix
importOrganization's cleanup call to use removeUserDeletedOrgUid()
instead of a raw destroy with the wrong key. Additionally, add
is_home/isHome to the omit list in syncOrganizationMeta for both V1
and V2 to prevent datalayer store data from overwriting the home org
flag.
@TheLastCicada TheLastCicada force-pushed the fix/user-deleted-org-meta-key-mismatch branch from 844e3a5 to 917baa5 Compare March 17, 2026 21:07
@TheLastCicada TheLastCicada changed the base branch from develop to v2-rc2 March 17, 2026 21:53
@TheLastCicada TheLastCicada merged commit 1e61baa into v2-rc2 Mar 17, 2026
23 of 24 checks passed
@TheLastCicada TheLastCicada deleted the fix/user-deleted-org-meta-key-mismatch branch March 17, 2026 21:54
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.

1 participant