Skip to content

Spend - After adding several existing expenses offline, previous report shows incorrect amount #89354

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.65-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: #85225
Email or phone of affected tester (no customers): ibellicotest+2250@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Motorola MotoG60 / Android 12 (Hybrid app) - Windows 11 / Chrome
App Component: Search

Action Performed:

Prerequisite: Account has at least one workspace.

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat.
  3. Create three manual expenses on the same report.
  4. Create an empty report.
  5. Navigate to "Spend" > "Reports"
  6. Turn off internet connection.
  7. Open the report created on step 4.
  8. Click on "Add Expense" > "Add existing expense"
  9. Select all the expenses from the remaining report and add them.
  10. Return to "Reports"
  11. Note that previous report, that is now empty, doesn´t show "0.00" as amount.
  12. Turn on internet connection.
  13. Note that now amount is correctly updated.

Expected Result:

After adding all the expenses from a report to another one while offline, first report should automatically display "0.00" as amount.

Actual Result:

After adding several existing expenses to a report while in offline mode, amount on previous report is not correctly updated.

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

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 1, 2026
  2. melvin-bot commented on May 1, 2026

    @melvin-bot

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

  3. melvin-bot commented on May 1, 2026

    @melvin-bot

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

  4. github-actions commented on May 1, 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.
  5. OSBotify commented on May 1, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #85225 - "Feat: Change Add unreported expense to Add existing expense in a report" by @nyomanjyotisa (High confidence)
    Related Issues: #84130

    Recommendation: REVERT

    PR #85225 expanded the "Add existing expense" flow to also surface expenses from open Draft reports (not just purely unreported/selfDM expenses). This exposed a bug in the changeTransactionsReport optimistic total calculation logic in src/libs/actions/Transaction.ts: when multiple expenses are moved from the same source Draft report, only the first transaction's amount is deducted from the source report's optimistic total, and subsequent deductions are silently dropped. The result is that the source report's displayed amount does not update to "0.00" after all expenses are moved away while offline. Before this PR, the flow only handled truly unreported transactions (no backing oldReport in Onyx), so the stale-total code path was never triggered for a real source report.

    Assigned: @nyomanjyotisa (PR author), @puneetlath and @sobitneupane (approving reviewers) from highest-confidence causing PR only
    Labels: DeployBlockerCash kept (frontend App PR is the cause). No label changes made.

    Detailed Analysis

    Evidence

    Verification

    Root Cause

    In changeTransactionsReport (Transaction.ts), the logic that accumulates the optimistic total for the source (old) report contains a bug at line 1216:

    updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : updatedReportTotal;
    

    updatedReportTotal at line 1207 is computed as oldReport.total ± transactionAmount, where oldReport.total is always the original report total from Onyx, not the running accumulated total. After the first transaction is processed for a given source report, updatedReportTotals[oldReportID] is set, so the ternary never updates it again for subsequent transactions from the same report. Only the first transaction's deduction is applied; all remaining deductions are lost.

    Before PR #85225, this code path was unreachable for a real source report because the "Add unreported expense" flow only picked up transactions with reportID === '' or CONST.REPORT.UNREPORTED_REPORT_ID. These transactions have no backing oldReport in Onyx, so the if (oldReport) block (line 1209) was skipped entirely and the total was simply marked stale. PR #85225 introduced openExpenseReportIDsSelector and used it in getEligibleTransactions to also surface expenses from open Draft reports, giving them a real oldReport. When a user selects all expenses from such a Draft report and adds them while offline, the accumulated total deduction is wrong and the source report does not display "0.00".

  6. MelvinBot commented on May 1, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When multiple transactions are moved from one report to another via "Add existing expense", the source report's optimistic total only accounts for the first transaction removed. The bug is in changeTransactionsReport — line 1216:

    updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : updatedReportTotal;

    This ternary sets the value on the first iteration, then preserves it for all subsequent transactions from the same source report. The second and third expense removals are silently dropped.

    By contrast, the target report correctly accumulates at line 1239:

    const currentTotal = updatedReportTotals[targetReportID] ?? targetReport?.total ?? 0;
    updatedReportTotals[targetReportID] = currentTotal - transactionAmount;

    The same accumulation bug also affects updatedReportTotal itself — it's recalculated from the original oldReport.total each iteration (line 1206–1207), not from the running accumulated value, so even if the ternary guard were removed, only the last transaction's adjustment would be applied rather than the sum of all.

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

    Replace line 1216 with the same accumulation pattern used for the target report:

    const currentOldTotal = updatedReportTotals[oldReportID] ?? oldReportTotal;
    updatedReportTotals[oldReportID] = transactionAmount < 0 ? currentOldTotal - transactionAmount : currentOldTotal + transactionAmount;

    This reads the previously accumulated value (or falls back to the original report total), then adjusts it for each transaction removed — matching the pattern at lines 1239–1240 and the existing nonReimbursableTotal accumulation at lines 1217–1219.

    What alternative solutions did you explore? (Optional)

    None — the fix is a straightforward alignment with the existing correct pattern already used for the target report totals.

    Investigation details

    Concrete example: Report A has 3 expenses ($20, $20, $10) → total = -5000 cents.

    Transaction moved oldReportTotal (from report) updatedReportTotal updatedReportTotals[oldReportID] stored
    1st ($20) -5000 -3000 -3000 ✓
    2nd ($20) -5000 (re-read from report, not accumulated) -3000 -3000 (truthy → kept) ✗ should be -1000
    3rd ($10) -5000 -4000 -3000 (truthy → kept) ✗ should be 0

    Result: source report shows $30 instead of $0.00 until the server corrects it.

    Evidence chain:

    Possibly related: #75134 (expense preview shows wrong amount after moving offline) — may share the same root cause.


    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.

  7. nyomanjyotisa commented on May 1, 2026

    @nyomanjyotisa
    Member

    I don't think this issue is caused by #85225, since the same issue occurs in production, just with a different reproduction steps

    MacOS-Chrome.mp4
  8. sobitneupane commented on May 1, 2026

    @sobitneupane
    Contributor

    It's not a regression. We have been working on this in another issue for quite some time.

  9. puneetlath commented on May 1, 2026

    @puneetlath
    Contributor

    Closing in favor of that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringHourlyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions