Repository navigation
Conversation
Refs linuxfoundation/lfx-cdp-insights-ops#1288 Signed-off-by: Uroš Marolt <uros@marolt.me>
PR SummaryMedium Risk Overview Both member and org lookup SQL in New Reviewed by Cursor Bugbot for commit 11d73b3. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
@themarolt I'm starting review 1 of this pull request now (started 2026-12-03 09:58 UTC using review agent v0.1.34). This usually takes a few minutes. I'll update this comment with the summary when I'm done. If there's no summary here after about 45 minutes, the review stopped: push a new commit, or post a comment that begins with a mention of me followed by Hi @themarolt, thanks for the clear write-up and the production numbers. SummaryThis pull request adds a deterministic Decision✅ Approved with minor comments 🟡 1 minor 📝 Documentation reminder: changed DetailsOverall impression: The 🟡 Minor: 1 issue: No spec covers the new backup ordering Other reviewers and CI checks: Cursor Bugbot posted a summary only, with no findings to reconcile. The required Documentation reminder: changed Rule files: read Questions, problems, or feedback: https://github.com/linuxfoundation/lfx-review-agent/issues |
lfx-one
left a comment
There was a problem hiding this comment.
The ordering change is correct and consistent across all three findMergeBackup queries. One minor gap: the bug fix has no spec.
Documentation
This pull request changes behavior that may also be described outside this repository, such as product pages or an external docs site. I can't read those, so please check them; the author and maintainers own those updates. Changed here:
findMergeBackupunmerge backup selection (behavior now prefers the newestmergedaction)
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; the remaining organization test coverage is non-blocking. Summary
No new issues found. Tests were not run. Reviews (2) · Last reviewed commit: "fix: pick the latest merge when a pair i..." · Reviewed by Greptile |
There was a problem hiding this comment.
🟡 Changes recommended
A critical ordering bug can select an older backup after members are re-merged because the reused merge-action row retains its original timestamp, also affecting eligibility checks.
1 open issue
What changed in this PR
Makes unmerge backup selection deterministic for members and organizations, aiming to avoid restoring stale data after re-merges.
Changes:
- Prioritizes completed merges over other matching actions.
- Orders matching actions by creation time, newest first, across all three lookups.
| File | Description |
|---|---|
services/libs/data-access-layer/src/mergeActions/repo.ts |
Adds ordering to the shared member backup lookup. |
backend/src/database/repositories/mergeActionsRepository.ts |
Adds matching ordering to backend member and organization lookups. |
Review effort: Balanced
A member unmerge restores the secondary with its old id, so merging that pair again reuses the merge action row and only refreshes updatedAt. Order by updatedAt and cover the selection with tests. Refs linuxfoundation/lfx-cdp-insights-ops#1288 Signed-off-by: Uroš Marolt <uros@marolt.me>
|
@themarolt I'm starting review 2 of this pull request now (started 2026-12-03 10:13 UTC using review agent v0.1.34). This usually takes a few minutes. I'll update this comment with the summary when I'm done. If there's no summary here after about 45 minutes, the review stopped: push a new commit, or post a comment that begins with a mention of me followed by Hi Uros Marolt, thanks for the quick follow-up: you fixed the earlier feedback in one commit. SummaryThis round moves the Decision✅ Approved DetailsOverall impression: The change is small and well targeted. 👏 Nice work: You traced the Copilot finding to the upsert in
Other reviewers and CI checks: Copilot's "re-merge reuses a stale merge action backup" finding is fixed by the Rule files: read Questions, problems, or feedback: https://github.com/linuxfoundation/lfx-review-agent/issues |
lfx-one
left a comment
There was a problem hiding this comment.
The new commit switches all three findMergeBackup queries to updatedAt ordering, which matches how addMergeAction re-merges a pair (the upsert refreshes updatedAt and keeps createdAt). It also adds repo.test.ts with four cases on the member query. I found no new issues.
There was a problem hiding this comment.
🔵 Needs a closer look
Domain-owner validation is needed because newest-backup precedence for organizations sharing an identity remains unresolved and controls restored attributes, affiliations, and slug ownership.
No open issues 🎉
1 resolved since last review
Review effort: Balanced

Summary
When an organization or member is unmerged,
findMergeBackuppicks the merge action to undo. It had noORDER BY, so when several merge actions of the primary hold the identity, it restored from whichever row Postgres returned first. It now prefers a finished merge and, among those, the latest.Changes
ORDER BY (ma.state = 'merged') DESC, ma."updatedAt" DESCin the threefindMergeBackupqueries: organization and member branches inbackend/.../mergeActionsRepository.ts, and the member query indata-access-layer/src/mergeActions/repo.ts.merged, with its backup. After merge → unmerge → re-merge, both actions match; the latest is the merge in effect. Before, the older one could be picked, restoring stale data and passing the oldsecondaryIdtorestoreAfterUnmerge, so the restored organization did not get its slugs back.createdAtstays,updatedAtis refreshed by the upsert inaddMergeAction. That is why the order usesupdatedAt.services/libs/data-access-layer/src/mergeActions/repo.test.ts: four cases on the member query (latest of two merges, a pair re-merged after an unmerge, merged over a newer error, error as fallback). The re-merge case fails withcreatedAtordering. The organization query is in the Sequelize repository inbackend/, which has no Postgres test harness; it uses the same clause.erroractions still count, but only when nomergedone matches. Some of them did merge (13 organization actions areerrorat stepmerge-done), so filtering them out would stop those from being reverted.Production, read-only: 11,836 (primary, identity) pairs match more than one organization merge action. 6 are merge → unmerge → re-merge and 65 mix a
mergedand anerroraction; this picks the right one for both. The rest are several merged-away organizations that shared the identity (e.g. a domain); those now resolve to the newest merge instead of an arbitrary one, and choosing between them stays open on the issue.EXPLAINon production: sameprimaryIdindex scan, plus a sort of the few matching rows.Type of change
Related issue
Refs linuxfoundation/lfx-cdp-insights-ops#1288