Skip to content

[RCA #83896] Expense - Second expense shows error when duplicating report on instant submit workflow #86091

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create an expense.
  4. Open the report.
  5. Click More > Retract.
  6. Create another expense in the same report.
  7. Click More > Duplicate report.
  8. Open the duplicated report.
  9. 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.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @Krishna2323

Activity

  1. added
    DeployBlockerCash
    on Mar 23, 2026
  2. added
    Bug
    on Mar 23, 2026
  3. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83896

  4. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  5. github-actions commented on Mar 23, 2026

    @github-actions
    Contributor

    👋 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:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Mar 23, 2026

    @OSBotify
    Contributor

    🔍 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:

    1. New duplicateReport() function at lines 800-921
    2. Helper function createExpenseByType() at lines 562-635
    3. 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:

    1. 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)

    2. Transaction pending states: Transactions added to a retracted report may be in an inconsistent state when the parent report still has pendingFields.partial set

    3. 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.

  7. MelvinBot commented on Mar 23, 2026

    @MelvinBot
    Contributor

    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 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:

    1. duplicateReport → createNewReport() fires CREATE_APP_REPORT (empty OPEN report)
    2. Loop iteration 1: createExpenseByType → requestMoney → API.write(REQUEST_MONEY) → server processes it and auto-submits the report
    3. Loop iteration 2: requestMoney → API.write(REQUEST_MONEY) → server rejects because report is now SUBMITTED
    4. 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:

    1. 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.

    2. 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.

  8. Krishna2323 commented on Mar 23, 2026

    @Krishna2323
    Contributor

    Working on the PR...

  9. Krishna2323 commented on Mar 23, 2026

    @Krishna2323
    Contributor

    @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:

    1. 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)
    2. 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?

  10. Valforte commented on Mar 23, 2026

    @Valforte
    Contributor

    I'm investigating the approaches

  11. Valforte commented on Mar 23, 2026

    @Valforte
    Contributor

    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).

  12. Krishna2323 commented on Mar 23, 2026

    @Krishna2323
    Contributor

    can you add the parameter you suggested?

    Sure, should I add that in this PR? #86098

  13. 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
  14. removed
    DeployBlockerCash
    on Mar 23, 2026
  15. Valforte commented on Mar 23, 2026

    @Valforte
    Contributor

    Demoting from blocker, will ask for retest after the BE PRs are on staging

  16. m-natarajan commented on Mar 24, 2026

    @m-natarajan

    Can't reproduce, Win 11 / Chrome, v9.3.43-0

    bandicam.2026-03-24.17-36-13-538.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugEngineeringHourly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions