[$175] A failed move to another report is undone silently and leaves an empty $0 report
Part of https://github.com/Expensify/App/issues/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
- Align expense report defaults with save behavior (open) changes the open reports filter for moves. Coordinate with its author before you start a fix.
Expected behavior
A failed move shows an error on the expense. The app removes the empty report it created.
Issue Owner
Current Issue Owner: @elirangoshenUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022122192342223165070
- Upwork Job ID: 2122192342223165070
- Last Price Increase: 2026-11-16
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (External)
Job added to Upwork: https://www.upwork.com/jobs/~022122192342223165070
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
- Silent rollback: Transaction.ts:1212–1224 restores the original report association without attaching an error.
- Independent creation: useReportPickerActions.ts:220–238 creates the destination before initiating the move. Creation submits its own request in Report/index.ts:5131–5150.
- Empty destination: Move failure restores the destination’s previous totals/count in Transaction.ts:1870–1916, rather than deleting the independently created report.
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
- A new expense request can drop from the queue, so a later move fails with a 456 error: a possible rejection trigger, not a confirmed cause of every failure here.
- Align expense report defaults with save behavior: overlaps the picker, but does not address this two-request lifecycle.
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.
Proposal
What is the root cause of that problem?
There are two distinct root causes contributing to this behavior:
- Silent transaction move failure:
In
src/libs/actions/Transaction.ts(changeTransactionsReport, lines 1212–1225), when theChangeTransactionsReportAPI command fails,failureDatareverts the transaction'sreportID,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.
- Empty destination report lingering after rollback:
When moving an expense via the "Create report" option (
createReportForPolicyinsrc/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:220–239), an optimistic report is created viacreateNewReport(WRITE_COMMANDS.CREATE_APP_REPORT), followed immediately bychangeTransactionsReport(WRITE_COMMANDS.CHANGE_TRANSACTIONS_REPORT). InTransaction.ts:1870–1916,failureDatareverts the destination report'stotal,unheldTotal, andtransactionCount. However, because the destination report itself was optimistically generated for this move, rolling back the totals leaves an empty, unlinked report with$0total in Onyx (ONYXKEYS.COLLECTION.REPORT) and the LHN/search views, instead of cleaning it up as done forselfDMReportinTransaction.ts:1038–1055.
What changes do you think we should make in order to solve the problem?
- Surface error on the transaction upon move failure:
In
src/libs/actions/Transaction.tsinsidechangeTransactionsReport:
- In
optimisticData, seterrors: nullon each moving transaction to clear any previous transient errors. - In
failureData(line 1215), populateerrorson each transaction usingErrorUtils.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.
- Clean up newly created destination reports on move failure:
- Accept an optional
isNewReport?: booleanparameter inChangeTransactionsReportProps(or inspectnewReport?.pendingFields?.createReport === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD). - When
useReportPickerActions.tscreates a report viacreateReportForPolicyand delegates tohandleRegularReportSelection, passisNewReport: true. - In
changeTransactionsReport, whenisNewReportis true, add rollback entries tofailureDatato 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
deleteAppReportunconditionally 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 toisNewReport(reports instantiated during that move session) guarantees safe cleanup without side effects.
Contributor Details:
- Email: [email protected]
- Upwork Profile: https://www.upwork.com/freelancers/~0131dae36abcf59374
Proposal
Please re-state the problem that we are trying to solve in this issue.
When moving an expense to another report (ChangeTransactionsReport) fails:
failureDatasilently 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.- 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 subsequentChangeTransactionsReportrequest fails, rolling back the transaction leaves an empty$0report behind in Onyx (REPORT,REPORT_ACTIONS, parentREPORT_ACTIONSpreview, andSNAPSHOT) and on the server. - Furthermore,
getChangeTransactionsReportOnyxDatanever pushessearchUpdate.failureData(atsrc/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?
failureDataingetChangeTransactionsReportOnyxData(src/libs/actions/Transaction.ts:1212-1224) does not seterrorsorerrorFieldson the transaction, and omitssearchUpdate.failureData:- At
src/libs/actions/Transaction.ts#L1212-L1224,failureDatarestoresreportID: transaction.reportID,comment: transaction.comment, etc., without settingerrors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage')(unlikeautoReportTransactionsatlines 2287-2291which explicitly setserrorson each transaction infailureData). - In addition, at
src/libs/actions/Transaction.ts#L1831-L1836,searchUpdate.optimisticDataandsearchUpdate.successDataare appended, butsearchUpdate.failureDatais never pushed tofailureData.
- At
createReportForPolicycreates the report via a separateCREATE_APP_REPORTwrite (src/libs/actions/Report/index.ts:5131), andChangeTransactionsReportonly rolls backtotal/transactionCountto0instead of removing the newly created report:- In
src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts#L226-L238(andSearchTransactionsChangeReport.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
changeTransactionsReportis queued as a second request. WhenchangeTransactionsReportfails (e.g.456because the expense creation was dropped, or a server/network error),Transaction.ts:1871-1917and2128-2135merge{total: 0, transactionCount: 0, nextStep: ...}into${ONYXKEYS.COLLECTION.REPORT}${reportID}. Even if aSET: nullwere pushed earlier infailureData, those laterOnyx.METHOD.MERGEentries in steps 8 and 9 ofgetChangeTransactionsReportOnyxDatawould re-create a partial report object in Onyx unlessreportIDis excluded from steps 8 & 9 when removing the newly created report!
- In
What changes do you think we should make in order to solve the problem?
-
Set
errorson the transaction infailureData(and clearerrors: nullinoptimisticData/successData) and includesearchUpdate.failureData:- In
src/libs/actions/Transaction.ts:- At
lines 1188-1201(optimisticData), includeerrors: nullon${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}. - At
lines 1212-1224(failureData), adderrors: 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 pushsearchUpdate.failureData:if (searchUpdate?.failureData) { failureData.push(...searchUpdate.failureData); }
- At
- In
-
Remove the newly created empty report on move failure without re-merging it in steps 8 & 9:
- Pass
isNewReport?: boolean(orreportPreviewReportActionID?: stringreturned bycreateNewReport, which already returns{...optimisticReportData, reportPreviewReportActionID}atsrc/libs/actions/Report/index.ts:5150) fromcreateReportForPolicyinuseReportPickerActions.ts(andSearchTransactionsChangeReport.tsx) intohandleRegularReportSelection$\rightarrow$changeTransactionsReport(ChangeTransactionsReportProps). - In
getChangeTransactionsReportOnyxData(src/libs/actions/Transaction.ts):- When
isNewReport && newReport?.reportID, infailureData:- Skip
newReport.reportIDin thefailureDataloops of Step 8 (updatedReportTotals,updatedReportUnheldTotals,updatedReportTransactionCounts,updatedReportNonReimbursableTotals,updatedReportStateNums,updatedReportReimbursableTotals) and Step 9 (affectedReportIDs) so laterOnyx.METHOD.MERGEupdates do not resurrect a partial report entry afterSET: null. - Push cleanup updates to
failureDatato remove the empty report, its actions, its loading state, its parent chatREPORT_PREVIEWaction, 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, }, }); }
- Skip
- When
- Add unit tests in
tests/unit/TransactionTest.tsverifying that whenchangeTransactionsReportfails:- The transaction is restored to its original report with
errorspopulated. - When moving to a newly created report (
isNewReport: true),${ONYXKEYS.COLLECTION.REPORT}${newReport.reportID}is completely removed (nullin Onyx, not left behind as a partial or$0report) and its parentREPORT_PREVIEWaction is cleaned up.
- The transaction is restored to its original report with
- Pass
What alternative solutions did you explore? (Optional)
- Appending
SET: nullfor${ONYXKEYS.COLLECTION.REPORT}${reportID}at the start ofgetChangeTransactionsReportOnyxDatawithout excludingreportIDfrom steps 8 and 9: rejected because steps 8 and 9 (lines 1881-2135) push subsequentOnyx.METHOD.MERGEupdates forreportIDintofailureData, which would execute after theSET: nulland leave a broken partial report object{total: 0, transactionCount: 0, nextStep: ...}in Onyx.
Contributor details Your Expensify account email: [email protected] 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):
-
No error is set. The transaction failure entry (lines 1214-1225) restores
reportID,comment,originalAmountandoriginalCurrency, but contains noerrorsfield. The user sees the expense back where it started and is told nothing. -
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.MERGEwithvalue: nullfor the REPORT, REPORT_METADATA and REPORT_ACTIONS keys (lines 1038-1055). ThenewReportbranch 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
newReportas either an existing report (DynamicIOURequestEditReport.tsx) or a freshly created optimistic one (SearchTransactionsChangeReport.tsxpassesoptimisticReport). A just-created report carries the markerpendingFields.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
-
Set an error on every moved transaction. Add
errorsto the transaction failure entry, using the generic failure pattern this file already uses for the same purpose (Transaction.ts:2290setserrors: 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. -
Delete a destination report this flow created. When
newReport?.pendingFields?.createReportis set, append failure entries mirroring the selfDM cleanup in the same function -Onyx.METHOD.MERGEwithvalue: nullfor:${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
newReportis a pre-existing report (nocreateReportpending 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
errorson each moved transaction and restores its originalreportID. - 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
createReportmarker 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
isNewReportparameter threaded from the callers. Rejected as unnecessary:pendingFields.createReportalready 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.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
(Latest version, updated Nov 16)
What is the root cause of that problem?
When a move fails, src/libs/actions/Transaction.ts undoes it but does two things wrong.
-
No error is shown. The undo step for each expense (~L1215) puts the old
reportID,commentand amounts back, but sets noerrors. Other mutations in the same file do (autoReportTransactionsusesiou.error.genericEditFailureMessage). So the expense just goes back, silently. -
The new report is not removed. "Create report" sends two separate requests:
createNewReport(creates the report), thenchangeTransactionsReport(moves the expense). If the second fails, the first has already worked. The undo step only resets the new report's totals to zero, so an empty $0 report stays. The self DM report is already removed in this situation (~L1038-1055); the new destination report is not.
The code can tell the report is new: the report object from createNewReport has pendingFields.createReport (ReportUtils.ts ~L8570); an existing report does not. One trap: the undo entries for totals and counts are merges on the same report key, so they must skip the new report, or they would bring back a half-empty report after it is removed.
Search correction. I earlier said getSearchOnyxUpdate has failure data that is never used. That was wrong: it returns only optimisticData and successData (IOU/SearchUpdate.ts). So a failed move does not roll Search back, and when an expense-report or chat Search is open, createNewReport adds the new report to its snapshot with no removal on failure.
I have no production logs, so I can't say why the server rejects the move; the fix does not depend on it.
What changes do you think we should make in order to solve the problem?
- Show an error. On failure set
errorson each moving expense, and clear it in the optimistic and success data so a retry starts clean. Use the existingiou.error.genericEditFailureMessage; if reviewers want move-specific wording, I will add a key inen.ts/es.ts. - Remove the report this move created, and only that one. When
newReport?.pendingFields?.createReportis set, skip that report in the totals/counts undo entries, and remove the report, its actions, metadata, loading state and its preview in the parent chat (same pattern as the self DM case). The "all matching" (jsonQuery) branch gets the same. An existing report is never touched, even if it was empty. I will check that every caller passes the object fromcreateNewReport:useReportPickerActions,SearchTransactionsChangeReport,DynamicIOURequestEditReport,DynamicIOURequestStepUpgrade,DynamicNewReportWorkspaceSelectionPage. - Search. In the same failure data, remove the new report's entry from the current Search snapshot. For the moved expenses' rows, I would add failure data to
getSearchOnyxUpdatethat undoes its optimistic changes; if reviewers think that is too wide for this issue, it can be a follow-up. - Two edge cases. If a second move into the same new report is queued before the first fails, I will check the queue order and skip removal while another pending move targets it. If the user is viewing the new report when it is removed, I will check they land on a valid page, not "not found".
- Server copy. Steps 1-4 are the complete App-side fix. The report also exists on the server, so local removal hides it until the next sync. I found no safe App-side delete: failure data is declarative, and
deleteAppReporthas its own failure data that would restore the report if that delete failed too. Either the backend deletes a report created in the same flow when the move fails, or this is handled separately. I would like an engineer's call.
Tests (tests/unit/TransactionTest.ts), with the request failing: an existing report is untouched and the expense returns with an error; with a new report, nothing is left under its key, and its actions, loading state, preview and Search entry are gone (also for jsonQuery); a retry clears the error; success is unchanged.
Demo. With the PR I will attach web and native recordings of a forced failure: before (expense jumps back, empty $0 report stays) and after (error shown, no empty report, still gone after reload).
Compared with the other proposals: jsonQuery branch, caller audit, the two edge cases, the Search correction and the server note are included here. My 08:06Z comment already had the totals-skip and preview removal, before dankezo's 11:05Z supplement.
What alternative solutions did you explore? (Optional)
- Deleting every empty report on failure: rejected, an existing report may have been empty.
- Only adding the error: leaves the empty $0 report.
- Removing the report but keeping the totals undo entries: rejected, they recreate a partial report.
- An
isNewReportparameter from callers: not needed, thecreateReportmarker already says it.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016176d06dd16a08b7
📣 @AvikaM3192730! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Proposal updated: please review this version of my proposal above (https://github.com/Expensify/App/issues/106962#issuecomment-6909629717), reformatted into the official template. The solution and scope are unchanged.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab
Please re-state the problem that we are trying to solve in this issue.
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.
What is the root cause of that problem?
Both defects are in the failure data of changeTransactionsReport
(src/libs/actions/Transaction.ts):
-
No error is set. The transaction failure entry (lines 1214-1225) restores
reportID,comment,originalAmountandoriginalCurrency, but contains noerrorsfield. The user sees the expense back where it started and is told nothing. -
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.MERGEwithvalue: nullfor the REPORT, REPORT_METADATA and REPORT_ACTIONS keys (lines 1038-1055). ThenewReportbranch 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
newReportas either an existing report (DynamicIOURequestEditReport.tsx) or a freshly created optimistic one (SearchTransactionsChangeReport.tsxpassesoptimisticReport). A just-created report carries the markerpendingFields.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.
What changes do you think we should make in order to solve the problem?
-
Set an error on every moved transaction. Add
errorsto the transaction failure entry, using the generic failure pattern this file already uses for the same purpose (Transaction.ts:2290setserrors: 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. -
Delete a destination report this flow created. When
newReport?.pendingFields?.createReportis set, append failure entries mirroring the selfDM cleanup in the same function -Onyx.METHOD.MERGEwithvalue: nullfor:${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
newReportis a pre-existing report (nocreateReportpending 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
errorson each moved transaction and restores its originalreportID. - 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
createReportmarker check). - A successful move to a new report keeps the report and clears the pending state as today.
What alternative solutions did you explore? (Optional)
- 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
isNewReportparameter threaded from the callers. Rejected as unnecessary:pendingFields.createReportalready 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.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal supplement: three additions to my proposal above (https://github.com/Expensify/App/issues/106962#issuecomment-6913476626), from re-checking the failure path in getChangeTransactionsReportOnyxData end to end. The two fixes already proposed (set errors on the moved transactions, delete a destination report this flow created) stand; the additions below are needed for the second one to actually hold.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab
What the additions change
-
Exclude the created report from the step 8 and 9 rollback entries. The totals/counts rollback (steps 8 and 9 of
getChangeTransactionsReportOnyxData, fromsrc/libs/actions/Transaction.ts:1870on) pushesOnyx.METHOD.MERGEfailure entries for the destination report -total,unheldTotal,transactionCountand the other totals - and those entries sit AFTER the transaction failure entries in the samefailureDataarray. So a cleanup entry for a just-created report, appended where I originally proposed it, would be followed by MERGE entries that re-create the report key as a partial object ({total: 0, transactionCount: 0, ...}) - the empty $0 report would still be there, just thinner. When the destination report carriespendingFields.createReport, it must also be left out of the step 8 and 9 failure loops for that report (the loops already skip reports inskippedReportIDsSet), so the deletion is the last word on that key. -
Append
searchUpdate.failureData. Atsrc/libs/actions/Transaction.ts:1831-1836,searchUpdate.optimisticDataandsearchUpdate.successDataare appended to the onyx data, butsearchUpdate.failureDatanever is. On a failed move, Search snapshot rows therefore stay in the moved state even though the transactions themselves roll back. Add the missing push next to the other two:if (searchUpdate?.failureData) { failureData.push(...searchUpdate.failureData); }. -
Remove the parent chat's report preview for the created report. The cleanup in my proposal removes the created report's REPORT, REPORT_METADATA and REPORT_ACTIONS keys.
createNewReportalso wrote an optimistic report-preview action into the parent chat's REPORT_ACTIONS (its return value carriesreportPreviewReportActionID). If only the report's own keys are removed, that preview action is left pointing at a report that no longer exists. The failure data should also MERGE{[reportPreviewReportActionID]: null}into the parent report's REPORT_ACTIONS key, and clear the created report's RAM_ONLY_REPORT_LOADING_STATE entry.
Tests added to the ones already proposed:
- A failed move to a NEW report leaves NO entry at all under the destination's REPORT key afterwards (not a partial totals object) - this is the step 8 and 9 exclusion working.
- A failed move restores the Search snapshot rows for the moved
transactions (the
searchUpdate.failureDatapush). - After a failed move to a new report, the parent chat no longer holds a report-preview action for the deleted report.
Nothing else in the proposal changes: the errors surface, the
pendingFields.createReport marker (no new parameter), and the
MERGE-with-null cleanup pattern mirroring the selfDM branch all stay as
proposed above.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~014898525b9c53fc32
Proposal
Please re-state the problem that we are trying to solve in this issue.
When moving an expense to another report fails on the backend, the moved expense reverts back to its original report silently without presenting any user error or notification, while an orphaned, empty $0 destination report stays behind in the user's report list.
What is the root cause of that problem?
In src/libs/actions/Transaction.ts (specifically in changeTransactionsReport and getChangeTransactionsReportOnyxData):
- When moving expenses to a new report (
props.newReport),optimisticDatacreates and adds the destination report into Onyx. - When the backend request fails,
failureDatainchangeTransactionsReport(lines 2183-2187) only merges:
It never clears or nullifies the newly created optimistic destination report (value: {pendingFields: {reportID: null}}props.newReport.reportID). Because the expense rolled back to the old report, the destination report remains in Onyx with total = $0 and 0 transactions. - Furthermore, neither
sourceReportnor the movedtransactionrecords any error inerrorFieldsor dispatches an error alert to inform the user that the move was rejected. The failure occurs completely silently.
What changes do you think we should make in order to solve the problem?
- In
src/libs/actions/Transaction.ts: InfailureDataofchangeTransactionsReportandgetChangeTransactionsReportOnyxData:- If a new destination report was optimistically created for the move (
props.newReportorisNewReport), add an OnyxSETor nullification infailureDatato remove the empty orphan report:if (isNewDestinationReport && props.newReport) { failureData.push({ onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${props.newReport.reportID}`, value: null, }); } - On the source report / original transaction, record an error in
errorFieldsso an actionable error notice / banner appears informing the user that the transaction could not be moved:failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, value: { errorFields: { reportID: ErrorUtils.getMicroSecond(), }, }, });
- If a new destination report was optimistically created for the move (
- In
src/libs/ErrorUtils.ts(or report error translation): Map the move failure error key to display:"Unable to move expense. Please try again."
What alternative solutions did you consider?
- Leaving the empty destination report open with an error banner: Rejected because an empty $0 report with no expenses clutters the report list and violates the clean rollback principle.
- Only showing a Growl/Toast notification: Rejected because toast notifications can be missed if the user switches tabs, whereas setting
errorFieldskeeps the red brick road visible on the expense.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016176d06dd16a08b7
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Updated Consolidated and corrected the Search handling; latest version is in my original comment above.