App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-25] [$250] An admin is unable to submit a report because it is stuck in a Review duplicates loop.

Open m-natarajan opened this issue 3 months ago • 106 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: Reproducible in staging?: Needs Reproduction (Unable to reproduce) Reproducible in production?: Needs Reproduction If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @clarajones-expensify Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Open a report containing a transaction with an active duplicate violation.
  2. Attempt to submit the report.
  3. Observe that the primary action is Review duplicates instead of Submit.
  4. Open Review duplicates.
  5. Resolve the duplicate and proceed through the confirmation flow.
  6. Observe that the flow appears to complete successfully.
  7. Return to the report and attempt to submit again.
  8. Observe that the duplicate violation is still present and Review duplicates is shown again.

Expected Result:

Resolving the duplicate should persist the resolution to the server and clear the duplicate violation. Once the violation is cleared, Submit should become available. If the duplicate cannot be resolved, the user should receive a clear error explaining why.

Actual Result:

The duplicate resolution flow appears to complete and navigates away as if the resolution succeeded, but no server request is sent to resolve the violation. The duplicate violation remains active, Submit stays blocked, and the user is repeatedly returned to Review duplicates.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome / Safari

Screenshots/Videos

The video for the issue is in Slack thread

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit

m-natarajan avatar Aug 26 '26 20:08 m-natarajan

This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989

exfy-zapier avatar Aug 26 '26 20:08 exfy-zapier

Proposal

ℹ️ Medium confidence. The client-side gap is concretely evidenced in the App repo, but the final step of the loop depends on Auth's RESOLVE_DUPLICATES behavior, which isn't visible from this repo and would need log/Auth confirmation.

What is the root cause of that problem?

When an admin who is not the report owner confirms in the Review duplicates flow, the app calls resolveDuplicates (not mergeDuplicates), then navigates away unconditionally without checking that the resolution actually took effect:

DynamicConfirmationPage.tsx:130-133 — Navigation.dismissToSuperWideRHP() runs right after resolveDuplicates(...) regardless of what it did, so the flow always looks successful.

The resolution itself is only one-sided. The DUPLICATED_TRANSACTION violation is bilateral (each duplicate's violation data.duplicates points at the others), but the set of transactions actually resolved gets narrowed down two ways:

  1. Settled/approved duplicates are filtered out at build time. buildMergeDuplicatesParams runs the duplicate set through removeSettledAndApprovedTransactions (TransactionUtils/index.ts:3102, helper at :2851), so a duplicate on an approved/reimbursed/closed report is dropped from transactionIDList.
  2. Duplicates whose report actions aren't loaded in Onyx are skipped at request time. resolveDuplicates rebuilds the list, skipping any transaction with no loaded IOU action (Duplicate.ts:508-521) — common when an admin reviews reports/threads they haven't opened.

Meanwhile the optimistic update clears the violation off every transaction using the full list (Duplicate.ts:481-490), so the UI immediately flips to Submit — but the server (Duplicate.ts:595-603) is only told about the kept transactionID with a reduced (possibly empty) transactionIDList, and there is no successData re-confirming the violation removal. The un-resolved counterpart still references the kept transaction, so when the server response (or a queued OpenReport) lands, the DUPLICATED_TRANSACTION violation returns on the kept transaction.

Because getReportPrimaryAction returns REVIEW_DUPLICATES before it ever checks SUBMIT, the reappearing violation flips the button back to Review duplicates — the loop the reporter describes. "No server request is sent" is the observable symptom; more precisely, the request sent is ineffective/one-sided.

Evidence & data flow

Flow: A has DUPLICATED_TRANSACTION with data.duplicates = [B, C]; B is on an open report, C on an approved/closed one → admin resolves → transactionIDList = [B] (C dropped) → optimistic clears A/B/C → RHP dismisses → server clears only A's side → C's dangling reference re-flags A → button flips back to Review duplicates → repeat (C is filtered out every time). The same happens on the owner/mergeDuplicates path.

What changes do you think we should make in order to solve the problem?

  1. Clear the counterpart side of the violation. In both resolveDuplicates and mergeDuplicates, reuse the existing removeTransactionFromDuplicateTransactionViolation pattern so that every transaction referencing the kept one (including settled/approved and not-loaded duplicates) has the kept transactionID removed from its data.duplicates, and re-apply the cleaned violations via successData so a queued OpenReport/server response can't reintroduce a one-sided violation.
  2. Don't navigate away as if it succeeded when nothing effective happened. In handleResolveDuplicates, only dismiss after confirming there's actually a resolvable set; if the narrowing (settled/approved filtering + missing report actions) leaves nothing to resolve, surface a clear error instead of silently dismissing — the same way the length === 0 guard already does.
  3. Confirm Auth's RESOLVE_DUPLICATES behavior via logs before finalizing (see below) — if Auth only clears the violation for the exact transactionIDList it's handed, fix #1 is required and sufficient; if Auth clears all referencing transactions, the primary gap is the App narrowing the list.

What alternative solutions did you explore? (Optional)

  • Stop excluding settled/approved duplicates from the violation-clearing set even though they're correctly excluded from the actual merge (they can't be merged, but their dangling violation still needs clearing).
  • Don't offer "Review duplicates" at all when the only remaining duplicates are on non-mergeable reports, since resolving can never fully clear them.
Why this wasn't verified in-app

Reproduction needs a specific multi-report/multi-user state (a non-owner admin, plus a duplicate sitting on an already-settled/approved report, or unloaded report actions), and the final loop step depends on Auth re-propagating the violation — which isn't observable from a single app session. This is why the issue is marked Needs Reproduction. A log-investigator pass on a real affected report would confirm whether the RESOLVE_DUPLICATES/OpenReport responses re-include DUPLICATED_TRANSACTION for the kept transaction.

Related issues

Quick scan surfaced Expensify/App#96967 (report incorrectly shows a policy violation/RBR after a split is reverted) — possibly related as another stale-violation-not-clearing case, though a different trigger.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/99595) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Aug 26 '26 20:08 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @gijoe0295 (External)

melvin-bot[bot] avatar Aug 26 '26 20:08 melvin-bot[bot]

Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

melvin-bot[bot] avatar Aug 26 '26 20:08 melvin-bot[bot]

@gijoe0295 Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Aug 31 '26 21:08 melvin-bot[bot]

@gijoe0295 Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Sep 02 '26 23:09 melvin-bot[bot]

@gijoe0295 Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Sep 03 '26 01:09 melvin-bot[bot]

@gijoe0295 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Sep 03 '26 03:09 melvin-bot[bot]

I don't have time for this yet. Will check back in 1-2 days.

gijoe0295 avatar Sep 04 '26 07:09 gijoe0295

@gijoe0295 Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Sep 07 '26 21:09 melvin-bot[bot]

@gijoe0295 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Sep 09 '26 21:09 melvin-bot[bot]

@gijoe0295 Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Sep 09 '26 21:09 melvin-bot[bot]

It's not overdue

gijoe0295 avatar Sep 10 '26 15:09 gijoe0295

I'm working on it

gijoe0295 avatar Sep 14 '26 16:09 gijoe0295

Proposal

Please re-state the problem that we are trying to solve in this issue.

An admin resolves a duplicate transaction group. The UI dismisses the "Review duplicates" screen and optimistically shows Submit - but within seconds (or on the next OpenReport network response), the button flips back to "Review duplicates". The loop repeats indefinitely because no server request is ever effective.

What is the root cause of that problem?

The root cause is a one-sided violation clear inside resolveDuplicates (src/libs/actions/IOU/Duplicate.ts).

Step-by-step breakdown:

  1. Suppose transaction A has DUPLICATED_TRANSACTION with data.duplicates = [B, C]. B is on an open report, C is on an already-settled/approved report.

  2. The for loop in resolveDuplicates (lines 511-564) builds resolvedTransactionIDList by iterating params.transactionIDList and skipping any transaction whose iouAction cannot be found (settled reports often have no loaded report actions). C is silently dropped. Only B ends up in resolvedTransactionIDList.

  3. optimisticTransactionViolations (lines 484-492) clears DUPLICATED_TRANSACTION for [B, A] only. C is untouched.

  4. C still holds data.duplicates = [A] in its Onyx violation entry.

  5. The API.write(RESOLVE_DUPLICATES) call sends transactionIDList = [B] to the server - correct for the merge side, but it means Auth only clears the violation for A and B server-side.

  6. When the next OpenReport fires (or when Onyx re-hydrates from a queued command), C's stale violation data.duplicates = [A] is re-applied to A, restoring DUPLICATED_TRANSACTION on the kept transaction.

  7. getReportPrimaryAction in ReportPrimaryActionUtils.ts (line 540) checks isReviewDuplicatesAction before it checks Submit or Approve. The moment A has the violation again, the button flips back. The loop is complete.

The decisive proof is that the fix already exists in the codebase and is simply not being called. removeTransactionFromDuplicateTransactionViolation (TransactionUtils/index.ts, line 2989) does exactly what is needed: it walks every counterpart in the duplicate graph (via getValidDuplicateTransactionIDs), strips the kept transactionID from each counterpart's data.duplicates, and - critically - pushes the cleaned violations into both optimisticData and successData (lines 3049-3066) so that a subsequent OpenReport or stale queued command cannot reintroduce the one-sided violation. resolveDuplicates never calls it.

What changes do you think we should make in order to solve the problem?

One targeted change in src/libs/actions/IOU/Duplicate.ts inside resolveDuplicates:

Before the API.write call on line 606, build an onyxData object and call removeTransactionFromDuplicateTransactionViolation on it with the kept params.transactionID:

// After building optimisticData and failureData, before API.write:
const onyxData: OnyxData<UpdateMoneyRequestDataKeys> = {
    optimisticData,
    successData: [],
    failureData,
};

removeTransactionFromDuplicateTransactionViolation(
    onyxData,
    params.transactionID,
    allTransactions,
    allTransactionViolations,
);

API.write(WRITE_COMMANDS.RESOLVE_DUPLICATES, parameters, onyxData);

This single call walks ALL counterpart transactions in the duplicate graph - including settled/approved ones that were correctly excluded from the merge but whose stale violation reference still needs clearing - and appends the proper optimisticData/successData entries so that no queued OpenReport can reintroduce them.

No server-side change is required. The RESOLVE_DUPLICATES command already clears violations for the transactions it is told about; the gap is purely that the client never told it about the settled/approved counterparts, and never cleaned their Onyx state locally.

What alternative solutions did you explore? (Optional)

Alternative 1 - Expand transactionIDList to include settled/approved transactions. This would require server-side changes to RESOLVE_DUPLICATES to handle transactions it currently skips (settled/approved). Higher risk, wider blast radius. Rejected in favor of the pure-client fix.

Alternative 2 - Add a successData entry that force-clears the violation on the kept transaction. This would mask the symptom (A stops showing the violation after the server responds) but C's stale data.duplicates = [A] entry would remain in Onyx, ready to reappear on the next OpenReport. Not a real fix.

Alternative 3 - Block REVIEW_DUPLICATES primary action when all remaining duplicates are on non-mergeable reports. Correct as a UX guard but does not fix the underlying data corruption. Should be added as a complementary defensive check, not as the primary fix.

Mister124x avatar Sep 14 '26 17:09 Mister124x

@gijoe0295 Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Sep 17 '26 21:09 melvin-bot[bot]

Not reproduce yet!

gijoe0295 avatar Sep 19 '26 16:09 gijoe0295

Oops this is a tough one. I tried many cases and here is what I found.

Reproducible steps (two cases):

Precondition:

  • User is part of a domain with "Strictly enforce workspace rules" settings enabled
  • Has an expense that was paid via Expensify (not just Mark as paid)

Case 1:

  1. Create a new expense whose amount, merchant and date match exactly as the expense in Precondition
  2. Press Review duplicates > Keep all
  3. DismissViolation fails with "401 Unauthorized"
  4. Submit is also blocked due to "Strictly enforce workspace rules" settings

Case 2 (matches what the recording in Slack showed):

  1. Clear cache and reset app
  2. Open the draft expense above. Do not open the settled expense
  3. Press Review duplicates
  4. Only the draft expense shows up here
  5. Press Keep selected then Confirm
  6. MergeDuplicates fails with "404 Merging expenses is only permitted for your own reports in an open state or awaiting first level approval, or reports submitted to you..."
  7. Submit is also blocked due to "Strictly enforce workspace rules" settings

We need backend fix for this.

🎀 👀 🎀 C+ reviewed

gijoe0295 avatar Sep 20 '26 21:09 gijoe0295

Triggered auto assignment to @mollfpr, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Sep 20 '26 21:09 melvin-bot[bot]

@mollfpr @gijoe0295 this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

melvin-bot[bot] avatar Sep 23 '26 21:09 melvin-bot[bot]