Skip to content

[$175] A failed move to another report is undone silently and leaves an empty $0 report #106962

Todo

Description

@mountiny

Part of #106153 (receipt retention). Found by @adhorodyski.

Problem

When a move of an expense to another report fails, the expense goes back to its old report. The app shows no error, and an empty $0 report stays behind.

Impact

  • Severity: P2
  • About 170 failed moves a day.

Code

Related pull requests

Expected behavior

A failed move shows an error on the expense. The app removes the empty report it created.

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

Activity

  1. added
    Daily
    Bug
    on Nov 16, 2026
  2. added
    External
    on Nov 16, 2026
  3. expensify-chore-bot commented on Nov 16, 2026

    @expensify-chore-bot

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

  4. changed the title [-]A failed move to another report is undone silently and leaves an empty $0 report[/-] [+][$175] A failed move to another report is undone silently and leaves an empty $0 report[/+] on Nov 16, 2026
  5. expensify-chore-bot commented on Nov 16, 2026

    @expensify-chore-bot
  6. MelvinBot commented on Nov 16, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Medium confidence: Failed moves restore the expense without adding a fallback error. Separately, creating the destination and moving the expense are independent requests, so a failed move does not undo successful report creation.

    Code evidence and limitations

    Alternative checked: Server responses can supply their own errors through onyxData; therefore, not every rejection is necessarily silent (OnyxUpdates.ts:74–111).

    These findings explain the reported symptoms when creation succeeds and the subsequent move fails without a server-supplied error. They do not establish why the move was rejected. Production logs were unavailable, the reported ~170 failures/day was not independently verified, and no browser reproduction was performed.

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

    Escalate the complete fix to an internal engineer for server-side lifecycle review. The required behavior is a visible failure on the restored expense plus safe, persistent cleanup of a destination created exclusively for that failed move.

    An App-only removal from local state would hide, not delete, a persisted report. Existing report deletion can also unreport transactions, and its inspected request has no “only if still empty” guard (Report/index.ts:7548–7561, 7939–7946). Guaranteed cleanup therefore needs backend coordination, not an unverified App-only deletion.

    Validation should cover successful creation followed by failed movement, existing destinations, concurrent additions, successful retry, and persistence after reload.

    What alternative solutions did you explore? (Optional)

    Deleting every empty destination is unsafe: it may predate the move or have acquired other content. A visible error alone addresses the silent rollback but leaves the empty-report symptom unresolved.

    Related work


    Next Steps for Contributor+ team:
    Internal engineering review is required before accepting implementation.
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/106962) to create a draft PR once an App-scoped plan is confirmed.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  7. kevinjosh10 commented on Nov 16, 2026

    @kevinjosh10

    Proposal

    What is the root cause of that problem?

    There are two distinct root causes contributing to this behavior:

    1. Silent transaction move failure:
      In src/libs/actions/Transaction.ts (changeTransactionsReport, lines 1212–1225), when the ChangeTransactionsReport API command fails, failureData reverts the transaction's reportID, comment, and currency/amount values back to their pre-move state:
    failureData.push({
        onyxMethod: Onyx.METHOD.MERGE,
        key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
        value: {
            reportID: transaction.reportID,
            comment: transaction.comment,
            originalAmount: transaction.originalAmount,
            originalCurrency: transaction.originalCurrency,
            ...(shouldClearAmount && {pendingAction: transaction.pendingAction ?? null}),
            ...(shouldClearAmount && {convertedAmount: transaction.convertedAmount}),
            ...(shouldClearAmount && {convertedTaxAmount: transaction.convertedTaxAmount}),
        },
    });

    Unlike other money request mutations (e.g. changeTransactionsToAutomaticReport in Transaction.ts:2290 or UpdateMoneyRequest.ts), failureData does not set errors on the transaction object. Therefore, when the server rejects the move request, the expense is moved back to the original report with zero visual feedback or Red Brick Road (RBR) indicator.

    1. Empty destination report lingering after rollback:
      When moving an expense via the "Create report" option (createReportForPolicy in src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:220–239), an optimistic report is created via createNewReport (WRITE_COMMANDS.CREATE_APP_REPORT), followed immediately by changeTransactionsReport (WRITE_COMMANDS.CHANGE_TRANSACTIONS_REPORT).
      In Transaction.ts:1870–1916, failureData reverts the destination report's total, unheldTotal, and transactionCount. However, because the destination report itself was optimistically generated for this move, rolling back the totals leaves an empty, unlinked report with $0 total in Onyx (ONYXKEYS.COLLECTION.REPORT) and the LHN/search views, instead of cleaning it up as done for selfDMReport in Transaction.ts:1038–1055.

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

    1. Surface error on the transaction upon move failure:
      In src/libs/actions/Transaction.ts inside changeTransactionsReport:
    • In optimisticData, set errors: null on each moving transaction to clear any previous transient errors.
    • In failureData (line 1215), populate errors on each transaction using ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage') (or a specific translation key for move failure). This ensures that if the move request fails, an error banner is displayed directly on the restored expense card.
    1. Clean up newly created destination reports on move failure:
    • Accept an optional isNewReport?: boolean parameter in ChangeTransactionsReportProps (or inspect newReport?.pendingFields?.createReport === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD).
    • When useReportPickerActions.ts creates a report via createReportForPolicy and delegates to handleRegularReportSelection, pass isNewReport: true.
    • In changeTransactionsReport, when isNewReport is true, add rollback entries to failureData to remove the empty destination report:
    if (isNewReport) {
        failureData.push(
            {
                onyxMethod: Onyx.METHOD.SET,
                key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
                value: null,
            },
            {
                onyxMethod: Onyx.METHOD.SET,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
                value: null,
            },
            {
                onyxMethod: Onyx.METHOD.SET,
                key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
                value: null,
            },
        );
        if (newReport?.parentReportID && newReport?.parentReportActionID) {
            failureData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReport.parentReportID}`,
                value: {
                    [newReport.parentReportActionID]: null,
                },
            });
        }
    }

    This mirrors the existing optimistic cleanup pattern in Transaction.ts:1038–1055 and DeleteReport.ts, cleanly removing the $0 empty report from local state if the move cannot be completed.

    What alternative solutions did you explore? (Optional)

    • We explored calling deleteAppReport unconditionally for any empty destination report on failure. However, an existing user report may legitimately have had 0 transactions prior to the move attempt; deleting it would destroy pre-existing user data. Restricting report removal specifically to isNewReport (reports instantiated during that move session) guarantees safe cleanup without side effects.

    Contributor Details:

  8. cocvn157 commented on Nov 16, 2026

    @cocvn157

    Proposal

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

    When moving an expense to another report (ChangeTransactionsReport) fails:

    1. failureData silently moves the expense back to its original report without setting any error on the transaction, so the user sees no error banner or Red Brick Road (RBR) indicator explaining why the move was undone.
    2. When the user chose "Create report" to move the expense into a newly created report, createNewReport (WRITE_COMMANDS.CREATE_APP_REPORT) succeeds on the server first, and when the subsequent ChangeTransactionsReport request fails, rolling back the transaction leaves an empty $0 report behind in Onyx (REPORT, REPORT_ACTIONS, parent REPORT_ACTIONS preview, and SNAPSHOT) and on the server.
    3. Furthermore, getChangeTransactionsReportOnyxData never pushes searchUpdate.failureData (at src/libs/actions/Transaction.ts:1831-1836), so Search snapshot rows remain out of sync when a move fails.

    What is the root cause of that problem?

    1. failureData in getChangeTransactionsReportOnyxData (src/libs/actions/Transaction.ts:1212-1224) does not set errors or errorFields on the transaction, and omits searchUpdate.failureData:
      • At src/libs/actions/Transaction.ts#L1212-L1224, failureData restores reportID: transaction.reportID, comment: transaction.comment, etc., without setting errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage') (unlike autoReportTransactions at lines 2287-2291 which explicitly sets errors on each transaction in failureData).
      • In addition, at src/libs/actions/Transaction.ts#L1831-L1836, searchUpdate.optimisticData and searchUpdate.successData are appended, but searchUpdate.failureData is never pushed to failureData.
    2. createReportForPolicy creates the report via a separate CREATE_APP_REPORT write (src/libs/actions/Report/index.ts:5131), and ChangeTransactionsReport only rolls back total / transactionCount to 0 instead of removing the newly created report:
      • In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts#L226-L238 (and SearchTransactionsChangeReport.tsx), createNewReport(...) writes:
        • ${ONYXKEYS.COLLECTION.REPORT}${reportID}
        • ${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}
        • ${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportID}
        • ${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID} ([reportPreviewReportActionID]: optimisticReportPreview)
        • ${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}
      • Then changeTransactionsReport is queued as a second request. When changeTransactionsReport fails (e.g. 456 because the expense creation was dropped, or a server/network error), Transaction.ts:1871-1917 and 2128-2135 merge {total: 0, transactionCount: 0, nextStep: ...} into ${ONYXKEYS.COLLECTION.REPORT}${reportID}. Even if a SET: null were pushed earlier in failureData, those later Onyx.METHOD.MERGE entries in steps 8 and 9 of getChangeTransactionsReportOnyxData would re-create a partial report object in Onyx unless reportID is excluded from steps 8 & 9 when removing the newly created report!

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

    1. Set errors on the transaction in failureData (and clear errors: null in optimisticData / successData) and include searchUpdate.failureData:

      • In src/libs/actions/Transaction.ts:
        • At lines 1188-1201 (optimisticData), include errors: null on ${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}.
        • At lines 1212-1224 (failureData), add errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'):
          failureData.push({
              onyxMethod: Onyx.METHOD.MERGE,
              key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
              value: {
                  reportID: transaction.reportID,
                  comment: transaction.comment,
                  originalAmount: transaction.originalAmount,
                  originalCurrency: transaction.originalCurrency,
                  ...(shouldClearAmount && {pendingAction: transaction.pendingAction ?? null}),
                  ...(shouldClearAmount && {convertedAmount: transaction.convertedAmount}),
                  ...(shouldClearAmount && {convertedTaxAmount: transaction.convertedTaxAmount}),
                  errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'),
              },
          });
        • At lines 1831-1836, also push searchUpdate.failureData:
          if (searchUpdate?.failureData) {
              failureData.push(...searchUpdate.failureData);
          }
    2. Remove the newly created empty report on move failure without re-merging it in steps 8 & 9:

      • Pass isNewReport?: boolean (or reportPreviewReportActionID?: string returned by createNewReport, which already returns {...optimisticReportData, reportPreviewReportActionID} at src/libs/actions/Report/index.ts:5150) from createReportForPolicy in useReportPickerActions.ts (and SearchTransactionsChangeReport.tsx) into handleRegularReportSelection $\rightarrow$ changeTransactionsReport (ChangeTransactionsReportProps).
      • In getChangeTransactionsReportOnyxData (src/libs/actions/Transaction.ts):
        • When isNewReport && newReport?.reportID, in failureData:
          • Skip newReport.reportID in the failureData loops of Step 8 (updatedReportTotals, updatedReportUnheldTotals, updatedReportTransactionCounts, updatedReportNonReimbursableTotals, updatedReportStateNums, updatedReportReimbursableTotals) and Step 9 (affectedReportIDs) so later Onyx.METHOD.MERGE updates do not resurrect a partial report entry after SET: null.
          • Push cleanup updates to failureData to remove the empty report, its actions, its loading state, its parent chat REPORT_PREVIEW action, and its Search snapshot entry:
            const previewActionID = newReport.reportPreviewReportActionID ?? newReport.parentReportActionID;
            failureData.push(
                {
                    onyxMethod: Onyx.METHOD.SET,
                    key: `${ONYXKEYS.COLLECTION.REPORT}${newReport.reportID}`,
                    value: null,
                },
                {
                    onyxMethod: Onyx.METHOD.SET,
                    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReport.reportID}`,
                    value: null,
                },
                {
                    onyxMethod: Onyx.METHOD.SET,
                    key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${newReport.reportID}`,
                    value: null,
                },
                {
                    onyxMethod: Onyx.METHOD.SET,
                    key: `${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${newReport.reportID}`,
                    value: null,
                },
            );
            if (newReport.parentReportID && previewActionID) {
                failureData.push({
                    onyxMethod: Onyx.METHOD.MERGE,
                    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReport.parentReportID}`,
                    value: {
                        [previewActionID]: null,
                    },
                });
            }
      • Add unit tests in tests/unit/TransactionTest.ts verifying that when changeTransactionsReport fails:
        1. The transaction is restored to its original report with errors populated.
        2. When moving to a newly created report (isNewReport: true), ${ONYXKEYS.COLLECTION.REPORT}${newReport.reportID} is completely removed (null in Onyx, not left behind as a partial or $0 report) and its parent REPORT_PREVIEW action is cleaned up.

    What alternative solutions did you explore? (Optional)

    • Appending SET: null for ${ONYXKEYS.COLLECTION.REPORT}${reportID} at the start of getChangeTransactionsReportOnyxData without excluding reportID from steps 8 and 9: rejected because steps 8 and 9 (lines 1881-2135) push subsequent Onyx.METHOD.MERGE updates for reportID into failureData, which would execute after the SET: null and leave a broken partial report object {total: 0, transactionCount: 0, nextStep: ...} in Onyx.
  9. dankezo commented on Nov 16, 2026

    @dankezo

    Contributor details
    Your Expensify account email: dannyphan190@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab

    Proposal

    Problem

    When moving expenses to another report fails, the move is undone silently -
    the expenses reappear in the old report with no error - and if the move
    created a new destination report, that report is left behind, empty, with a
    $0 total.

    Root cause

    Both defects are in the failure data of changeTransactionsReport
    (src/libs/actions/Transaction.ts):

    1. No error is set. The transaction failure entry (lines 1214-1225)
      restores reportID, comment, originalAmount and originalCurrency,
      but contains no errors field. The user sees the expense back where it
      started and is told nothing.

    2. A destination report created by this flow is never cleaned up. The
      same function already knows how to do this: its selfDM branch appends
      failure entries that remove the report it created - Onyx.METHOD.MERGE
      with value: null for the REPORT, REPORT_METADATA and REPORT_ACTIONS
      keys (lines 1038-1055). The newReport branch has no equivalent, so a
      failed "move to new report" leaves the empty report behind.

      The flow can tell whether it created the destination: callers pass
      newReport as either an existing report
      (DynamicIOURequestEditReport.tsx) or a freshly created optimistic one
      (SearchTransactionsChangeReport.tsx passes optimisticReport). A
      just-created report carries the marker pendingFields.createReport
      (set at creation, src/libs/ReportUtils.ts:8570); an existing report
      does not.

    The report totals/counts rollback already exists (lines 1870-1916) - only
    the error surface and the created-report cleanup are missing.

    Changes

    1. Set an error on every moved transaction. Add errors to the
      transaction failure entry, using the generic failure pattern this file
      already uses for the same purpose (Transaction.ts:2290 sets
      errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage')).
      The expense returns to its original report WITH the failure shown, so the
      user knows the move did not happen and can retry.

    2. Delete a destination report this flow created. When
      newReport?.pendingFields?.createReport is set, append failure entries
      mirroring the selfDM cleanup in the same function - Onyx.METHOD.MERGE
      with value: null for:

      • ${ONYXKEYS.COLLECTION.REPORT}${newReport.reportID}
      • ${ONYXKEYS.COLLECTION.REPORT_METADATA}${newReport.reportID}
      • ${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReport.reportID}

      METHOD.MERGE with null, not METHOD.SET: MERGE-with-null is the pattern
      this codebase uses to remove a created report's keys (the selfDM branch
      directly above), and it does not clobber sibling state the way a SET of
      the whole key would. When newReport is a pre-existing report (no
      createReport pending field), nothing is deleted - the destination
      report stays, exactly as today.

    Not changed: the optimistic move, the success data, the totals/counts
    rollback, the selfDM branch, and moves to pre-existing reports (other than
    now showing the error).

    Tests

    In tests/unit/TransactionTest.ts and tests/actions/TransactionTest.ts
    (both already cover changeTransactionsReport):

    • A failed move sets errors on each moved transaction and restores its
      original reportID.
    • A failed move to a NEW report (created by the flow) removes the
      destination report, its metadata and its report actions - no empty $0
      report remains.
    • A failed move to a PRE-EXISTING report leaves that report in place
      (regression control for the createReport marker check).
    • A successful move to a new report keeps the report and clears the pending
      state as today.

    Alternatives considered

    • METHOD.SET with null for the report cleanup (as in one existing
      proposal). Rejected: it contradicts the cleanup pattern used in this very
      function for the selfDM report; consistency here is not cosmetic, SET and
      MERGE behave differently for keys other writers have touched.
    • A new isNewReport parameter threaded from the callers. Rejected as
      unnecessary: pendingFields.createReport already records exactly this
      fact on the report object the function receives, and threading a param
      means touching all six call sites for information that is already there.
    • Delete empty $0 reports lazily on next app load. Rejected: the empty
      report is visible in the meantime, and a lazy sweep races with a user
      retrying the move into the same report.
  10. melvin-bot commented on Nov 16, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  11. 15 remaining items

  12. dankezo commented on Nov 17, 2026

    @dankezo

    @mountiny Apologies for that. I posted proposals on a few External issues before the Help Wanted label was added, and I understand now that proposals are only accepted once an issue carries that label. From here on I will only post proposals on Help Wanted labelled issues. Sorry for the noise.

  13. RajGahoi commented on Nov 18, 2026

    @RajGahoi

    Hi! I'm interested in working on this issue. I have a complete fix already coded and tested locally. Could I be assigned? I can submit the PR immediately once assigned. Stack: React Native + TypeScript. All communication is async/written — no calls needed.

  14. RajGahoi commented on Nov 18, 2026

    @RajGahoi

    Proposal

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

    When moving expenses to a destination report fails mid-way, an empty $0 report artifact is left behind in the reports list, polluting the UI with a ghost report the user cannot interact with meaningfully.

    What is the root cause of that problem?

    The "move expenses" action creates the destination report first, then moves expenses. If the move fails after the report creation, there is no cleanup step to delete the now-empty destination report.

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

    File — the report move/merge action (wherever moveExpensesToReport or equivalent is implemented):

    • Wrap the move operation in a try/catch.
    • On failure, check if the destination report now has 0 expenses (i.e. the move did not succeed for any expense).
    • If empty, call the report deletion API to purge the orphaned destination report.
    • Restore the original expenses to their source report if any were partially moved.
    • Surface a user-visible error message.

    What specific scenarios should we test?

    1. Move succeeds → destination report has expenses, source has none. No orphan.
    2. Move fails before first expense moved → destination report deleted, source unchanged.
    3. Move fails midway (partial) → remaining expenses restored to source, empty destination deleted.
    4. Network offline during move → same cleanup behavior on next online sync.
  15. mountiny commented on Nov 19, 2026

    @mountiny
    ContributorAuthor

    This is not open to proposals, please only post proposals on Help Wanted issues otherwise you will be removed from the repo for spamming

  16. expensify-chore-bot commented on Nov 19, 2026

    @expensify-chore-bot

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

  17. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot

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

  18. Ollyws commented on Nov 25, 2026

    @Ollyws
    Contributor

    I think as Melvin says this will require some backend work.

  19. expensify-chore-bot commented on Nov 25, 2026

    @expensify-chore-bot

    @adhorodyski Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  20. expensify-chore-bot commented on Nov 27, 2026

    @expensify-chore-bot

    @adhorodyski 10 days overdue. Is anyone even seeing these? Hello?

  21. mountiny commented on Nov 28, 2026

    @mountiny
    ContributorAuthor

    @adhorodyski Should we look for someone with backend access to tackle this one or did you have a specific plan for it?

  22. elirangoshen commented on Nov 30, 2026

    @elirangoshen
    Contributor

    Hi Im investigating this issue - I would if and what we can do in the client side.
    I already have some findings , so you can assign me as well

  23. expensify-chore-bot commented on Nov 30, 2026

    @expensify-chore-bot

    @Ollyws @mountiny @adhorodyski 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!

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

Metadata

Metadata

Labels

BugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions