You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RCA #83896] Expense - Second expense shows error when duplicating report on instant submit workflow #86091
Version Number: 9.3.42-0 Reproducible in staging?: Yes Reproducible in production?: N/A - new feature, doesn't exist in prod If this was caught during regression testing, add the test name, ID and link from BrowserStack:#83896 Email or phone of affected tester (no customers):sdsodsoijnosjdio@gmail.com Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 26.2 / Chrome App Component: Money Requests
Action Performed:
Precondition:
Set Submissions to Instantly.
Disable Approvals and Payments.
Go to staging.new.expensify.com
Go to workspace chat.
Create an expense.
Open the report.
Click More > Retract.
Create another expense in the same report.
Click More > Duplicate report.
Open the duplicated report.
Open the expense with error.
Expected Result:
The report will be duplicated without issue when there are two expenses in one report on instant submission.
Actual Result:
The second expense in the report shows error and it cannot be duplicated. Only the first expense in the report can be duplicated.
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
The issue is specific to the interaction between the new duplicate report feature and retracted reports in instant submit workflows. A targeted fix to handle reports with pending states during duplication would be less disruptive than reverting the entire feature PR, which introduces significant new functionality that is working correctly in other scenarios.
Labels: Keeping DeployBlockerCash (App deploy is blocked by this frontend bug)
Helper function createExpenseByType() at lines 562-635
Transaction filtering logic at lines 832-850
The affected file implements the core duplicate report logic that is failing in this scenario.
Root Cause
The duplicateReport() function filters out certain transaction types (credit card imports, scanning transactions, etc.) but does NOT check for:
Report pending states: When a report is retracted on instant submit, it sets pendingFields.partial to UPDATE (see src/libs/actions/IOU/index.ts:10511-10513)
Transaction pending states: Transactions added to a retracted report may be in an inconsistent state when the parent report still has pendingFields.partial set
Transaction thread generation: The function sets shouldGenerateTransactionThreadReport: true for all duplicated transactions (line 887), which may cause issues when duplicating transactions from a report with pending state changes
Specific Issue Flow:
1. Create expense A → Instant submit creates & submits report
2. Retract report → Sets report.pendingFields.partial = UPDATE
3. Create expense B in same report → Expense B added to report with pending partial state
4. Duplicate report → Both expenses duplicated, but expense B has errors due to source report partial state
The filtering logic in duplicateReport() at lines 832-850 filters based on transaction properties but not on the source report's pending state or the transaction's relationship to that pending state.
Please re-state the problem that we are trying to solve in this issue.
When a user on an instant-submit workspace duplicates a report that contains two expenses (created after a retract + new expense flow), the second expense in the duplicated report shows an error. Only the first expense is duplicated successfully.
What is the root cause of that problem?
The duplicateReport function in src/libs/actions/IOU/Duplicate.ts (lines 800-921) creates a new empty report via CREATE_APP_REPORT, then fires a separate REQUEST_MONEY API call for each transaction in a synchronous loop. On an instant-submit policy, the server auto-submits the report after processing the first REQUEST_MONEY, moving it from OPEN to SUBMITTED (or CLOSED for submit-and-close). When the second REQUEST_MONEY arrives, the server rejects it because the report is no longer in a state that accepts new transactions — the backend equivalent of canAddOrDeleteTransactions (src/libs/ReportUtils.ts:2830-2849) returns false for SUBMITTED/CLOSED reports.
The retract step in the reproduction is what creates the 2-expense scenario on instant submit. Normally on instant-submit, each expense auto-creates its own report. But after retracting (which sets the report back to OPEN per retractReport at src/libs/actions/IOU/index.ts:10452), a second expense can be added to the same report. When this 2-expense report is then duplicated, the race condition between sequential API calls manifests.
Key code path:
duplicateReport → createNewReport() fires CREATE_APP_REPORT (empty OPEN report)
Loop iteration 1: createExpenseByType → requestMoney → API.write(REQUEST_MONEY) → server processes it and auto-submits the report
Loop iteration 2: requestMoney → API.write(REQUEST_MONEY) → server rejects because report is now SUBMITTED
Failure data from buildOnyxDataForMoneyRequest (src/libs/actions/IOU/index.ts:2413) sets errors on the second transaction via getReceiptError(), which shows as 'iou.error.genericCreateFailureMessage'
What changes do you think we should make in order to solve the problem?
The duplicateReport function should batch all transactions into a single API call rather than firing separate REQUEST_MONEY calls in a loop. Specifically:
Create a new write command (e.g., DUPLICATE_REPORT) that accepts the source report's transaction data and creates the new report with all expenses in a single server-side operation, preventing the auto-submit from firing between individual expense creations.
Alternatively, if a new command is too large a change, modify the duplicateReport loop to pass a parameter (e.g., shouldDeferAutoSubmit: true) in the REQUEST_MONEY calls, and have the server defer auto-submission until all transactions for the batch are processed. The last REQUEST_MONEY call would omit this flag, triggering the auto-submit after all expenses are added.
The fix should be in src/libs/actions/IOU/Duplicate.ts and potentially src/libs/API/parameters/ for the new params.
What alternative solutions did you explore?
Client-side workaround: Making the optimistic report state OPEN regardless of instant-submit to match client expectations. This would hide the error optimistically but wouldn't prevent the server-side rejection.
Filtering transactions: Limiting duplicateReport to only duplicate one transaction at a time on instant-submit policies. This avoids the race condition but changes the feature behavior.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
@Valforte The duplicateReport function fires a separate REQUEST_MONEY API call per transaction in a loop. On instant-submit policies, the server auto-submits the report after processing the first REQUEST_MONEY, so subsequent expenses are rejected because the report is now SUBMITTED.
This cannot be fixed purely on the frontend — the server-side auto-submit behavior is what causes the race. Two options:
Add a shouldDeferAutoSubmit parameter to REQUEST_MONEY — pass true for all but the last expense during duplication, so the server only auto-submits after the final expense is added. (Small backend change)
Create a new DUPLICATE_REPORT backend command — accepts the source report ID and handles all transaction creation atomically server-side. (Larger but more correct)
Which approach would you prefer, or is there an existing backend mechanism we can leverage to defer auto-submission during batch expense creation? Should we demote this from blocker?
Ok the change is quite minimal on the backend, I'll work on it asap. @Krishna2323 can you add the parameter you suggested? I'll be expecting shouldDeferAutoSubmit.
Only one edge case to consider: If the last expense call fails, the report would remain open with expenses but never auto-submitted. The FE would need error handling for that scenario (e.g., retry or manually trigger submit).
changed the title [-]Expense - Second expense shows error when duplicating report on instant submit workflow[/-][+][RCA #83896] Expense - Second expense shows error when duplicating report on instant submit workflow[/+]on Mar 23, 2026
Activity
melvin-bot commentedon Mar 23, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #83896
melvin-bot commentedon Mar 23, 2026
💬 A slack conversation has been started in #expensify-open-source
github-actions commentedon Mar 23, 2026
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
OSBotify commentedon Mar 23, 2026
🔍 Investigation Summary
Classification: Frontend bug
Causing PR: #83896 - "Implement core "Duplicate report" action logic." by @Krishna2323 (High confidence)
Related Issues: None identified
Recommendation: ROLL FORWARD
The issue is specific to the interaction between the new duplicate report feature and retracted reports in instant submit workflows. A targeted fix to handle reports with pending states during duplication would be less disruptive than reverting the entire feature PR, which introduces significant new functionality that is working correctly in other scenarios.
Labels: Keeping
DeployBlockerCash(App deploy is blocked by this frontend bug)📋 Detailed Analysis
Evidence
Verification
The PR modifies the following key file:
src/libs/actions/IOU/Duplicate.ts(299 additions, 87 deletions)Key changes include:
duplicateReport()function at lines 800-921createExpenseByType()at lines 562-635The affected file implements the core duplicate report logic that is failing in this scenario.
Root Cause
The
duplicateReport()function filters out certain transaction types (credit card imports, scanning transactions, etc.) but does NOT check for:Report pending states: When a report is retracted on instant submit, it sets
pendingFields.partialtoUPDATE(seesrc/libs/actions/IOU/index.ts:10511-10513)Transaction pending states: Transactions added to a retracted report may be in an inconsistent state when the parent report still has
pendingFields.partialsetTransaction thread generation: The function sets
shouldGenerateTransactionThreadReport: truefor all duplicated transactions (line 887), which may cause issues when duplicating transactions from a report with pending state changesSpecific Issue Flow:
The filtering logic in
duplicateReport()at lines 832-850 filters based on transaction properties but not on the source report's pending state or the transaction's relationship to that pending state.MelvinBot commentedon Mar 23, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user on an instant-submit workspace duplicates a report that contains two expenses (created after a retract + new expense flow), the second expense in the duplicated report shows an error. Only the first expense is duplicated successfully.
What is the root cause of that problem?
The
duplicateReportfunction insrc/libs/actions/IOU/Duplicate.ts(lines 800-921) creates a new empty report viaCREATE_APP_REPORT, then fires a separateREQUEST_MONEYAPI call for each transaction in a synchronous loop. On an instant-submit policy, the server auto-submits the report after processing the firstREQUEST_MONEY, moving it from OPEN to SUBMITTED (or CLOSED for submit-and-close). When the secondREQUEST_MONEYarrives, the server rejects it because the report is no longer in a state that accepts new transactions — the backend equivalent ofcanAddOrDeleteTransactions(src/libs/ReportUtils.ts:2830-2849) returns false for SUBMITTED/CLOSED reports.The retract step in the reproduction is what creates the 2-expense scenario on instant submit. Normally on instant-submit, each expense auto-creates its own report. But after retracting (which sets the report back to OPEN per
retractReportatsrc/libs/actions/IOU/index.ts:10452), a second expense can be added to the same report. When this 2-expense report is then duplicated, the race condition between sequential API calls manifests.Key code path:
duplicateReport→createNewReport()firesCREATE_APP_REPORT(empty OPEN report)createExpenseByType→requestMoney→API.write(REQUEST_MONEY)→ server processes it and auto-submits the reportrequestMoney→API.write(REQUEST_MONEY)→ server rejects because report is now SUBMITTEDbuildOnyxDataForMoneyRequest(src/libs/actions/IOU/index.ts:2413) setserrorson the second transaction viagetReceiptError(), which shows as'iou.error.genericCreateFailureMessage'What changes do you think we should make in order to solve the problem?
The
duplicateReportfunction should batch all transactions into a single API call rather than firing separateREQUEST_MONEYcalls in a loop. Specifically:Create a new write command (e.g.,
DUPLICATE_REPORT) that accepts the source report's transaction data and creates the new report with all expenses in a single server-side operation, preventing the auto-submit from firing between individual expense creations.Alternatively, if a new command is too large a change, modify the
duplicateReportloop to pass a parameter (e.g.,shouldDeferAutoSubmit: true) in theREQUEST_MONEYcalls, and have the server defer auto-submission until all transactions for the batch are processed. The lastREQUEST_MONEYcall would omit this flag, triggering the auto-submit after all expenses are added.The fix should be in
src/libs/actions/IOU/Duplicate.tsand potentiallysrc/libs/API/parameters/for the new params.What alternative solutions did you explore?
duplicateReportto only duplicate one transaction at a time on instant-submit policies. This avoids the race condition but changes the feature behavior.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.Krishna2323 commentedon Mar 23, 2026
Working on the PR...
Krishna2323 commentedon Mar 23, 2026
@Valforte The duplicateReport function fires a separate
REQUEST_MONEYAPI call per transaction in a loop. On instant-submit policies, the server auto-submits the report after processing the firstREQUEST_MONEY, so subsequent expenses are rejected because the report is now SUBMITTED.This cannot be fixed purely on the frontend — the server-side auto-submit behavior is what causes the race. Two options:
shouldDeferAutoSubmitparameter toREQUEST_MONEY— pass true for all but the last expense during duplication, so the server only auto-submits after the final expense is added. (Small backend change)DUPLICATE_REPORTbackend command — accepts the source report ID and handles all transaction creation atomically server-side. (Larger but more correct)Which approach would you prefer, or is there an existing backend mechanism we can leverage to defer auto-submission during batch expense creation? Should we demote this from blocker?
Valforte commentedon Mar 23, 2026
I'm investigating the approaches
Valforte commentedon Mar 23, 2026
Ok the change is quite minimal on the backend, I'll work on it asap. @Krishna2323 can you add the parameter you suggested? I'll be expecting
shouldDeferAutoSubmit.Only one edge case to consider: If the last expense call fails, the report would remain open with expenses but never auto-submitted. The FE would need error handling for that scenario (e.g., retry or manually trigger submit).
Krishna2323 commentedon Mar 23, 2026
Sure, should I add that in this PR? #86098
[-]Expense - Second expense shows error when duplicating report on instant submit workflow[/-][+][RCA #83896] Expense - Second expense shows error when duplicating report on instant submit workflow[/+]Valforte commentedon Mar 23, 2026
Demoting from blocker, will ask for retest after the BE PRs are on staging
m-natarajan commentedon Mar 24, 2026
Can't reproduce, Win 11 / Chrome, v9.3.43-0
bandicam.2026-03-24.17-36-13-538.mp4