Skip to content

Add retry button and logic - #99902

Merged
mountiny merged 25 commits into
Expensify:mainfrom
callstack-internal:receipt-upload-retry-button
Sep 25, 2026
Merged

mountiny merged 25 commits into
Expensify:mainfrom
callstack-internal:receipt-upload-retry-button

Conversation

@rinej

@rinej rinej commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

When a receipt upload fails, SequentialQueue applies failureData and drops the request, so the expense is stranded with no way to resend it.

This PR adds a Try again action to the receipt error row. It rebuilds the original RequestMoney call from what the failure left in Onyx — the transaction, its report, and the file still on disk — and dispatches it again under the same transactionID, so a retry resends the same expense instead of creating a duplicate. On success the error is cleared and the row goes away.

Following the design feedback in this PR, the error row was also simplified:

  • It shows two actions, Try again and Save, each with an icon and using the same button style.
  • The error copy is shortened to Upload failed. Try again or save for later.
  • The row no longer renders its own red dot, since the Receipt · Issue found header above it already shows one.

Try again is native only (iOS and Android). It never appears on Web or mWeb. On native, the receipt is kept on the device in ReceiptStorage, so it can be resent even after a restart. On Web and mWeb, the receipt only exists as a blob URL in the open tab and is gone after a reload, so there is nothing to resend. isRetrySupported is false on web, so the row there always shows Save on its own.

On native, Try again is also rendered only when the upload can actually be replayed. canBuildRetryPayload returns false for distance, per diem, and time requests (they carry state the transaction alone does not store, such as waypoints, rates, and units), for track expenses and replaced receipts, for test receipts, and when the receipt source is no longer a local file.

Whenever the row shows Save on its own (always on Web/mWeb, and in the native cases above), the copy is Upload failed. Save your receipt to keep it., so the message never mentions a button that isn't there.

Fixed Issues

$ #100846
PROPOSAL:

Tests

On iOS:

  1. Go to Settings > Troubleshoot and turn on Simulate failing network requests.
  2. Create an expense from a receipt scan, on a workspace chat.
  3. Open the expense. Verify the receipt error row shows two actions: Try again and Save.
  4. Turn Simulate failing network requests in the troubleshoot menu, then return to the expense.
  5. Verify Try again is still there.
  6. Press Try again. Verify the expense completes and the error row goes away.
  7. Verify there is only one expense, so there is not duplication

Offline tests

QA Steps

Same as Tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

iOSWithNetworkFailing.mov
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/DotIndicatorMessage.tsx 85.45% <100.00%> (-0.76%) ⬇️
src/components/ErrorMessageRow.tsx 100.00% <100.00%> (ø)
src/components/MessagesRow.tsx 92.85% <100.00%> (ø)
src/components/OfflineWithFeedback.tsx 93.18% <ø> (ø)
...ceiptUploadRetryHandler/isRetrySupported.native.ts 100.00% <100.00%> (ø)
src/libs/actions/IOU/MoneyRequestBuilder.ts 90.52% <100.00%> (-0.12%) ⬇️
src/libs/actions/IOU/TrackExpense.ts 85.28% <ø> (+0.18%) ⬆️
...libs/ReceiptUploadRetryHandler/isRetrySupported.ts 0.00% <0.00%> (ø)
...bs/ReceiptUploadRetryHandler/resolveReceiptFile.ts 0.00% <0.00%> (ø)
...nents/ReportActionItem/MoneyRequestReceiptView.tsx 71.42% <63.63%> (-0.67%) ⬇️
... and 4 more
... and 927 files with indirect coverage changes

@rinej
rinej marked this pull request as ready for review September 14, 2026 14:13
@rinej
rinej requested review from a team as code owners September 14, 2026 14:13
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and brunovjk and removed request for a team September 14, 2026 14:13
@melvin-bot

melvin-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

@brunovjk Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

}

// These carry state the transaction does not store - GPS points, rates, units - so they are excluded rather
// than retried with those fields silently dropped.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-15 (docs)

This comment sets off a parenthetical with spaced hyphens used as em dashes (does not store - GPS points, rates, units - so they). Comments should read as plain sentences without dash-delimited asides.

Rewrite without the dashes, e.g.:

// A distance, per diem, or time request carries state the transaction alone does not store, such as GPS points,
// rates, and units, so it is excluded rather than retried with those fields silently dropped.

Reviewed at: f9367e2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/libs/ReceiptUploadRetryHandler/buildRetryPayload.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9367e2787

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/ReceiptUploadRetryHandler/buildRetryPayload.ts
Comment thread src/libs/ReceiptUploadRetryHandler/buildRetryPayload.ts
@rinej

rinej commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 668eeed463

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

},
policyParams,
transactionParams: {
amount: transaction.amount ?? 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Convert stored expense amounts back to request sign

For a nonzero workspace expense, the persisted transaction stores amount with the expense-report sign, while requestMoney() expects the original input sign and negates it again in MoneyRequestBuilder.ts:1545 before writing Onyx. Passing transaction.amount unchanged therefore sends a negative amount to RequestMoney and replaces the local transaction with a positive amount; an ALREADY_CREATED response only applies success data and does not restore that value, while repeated failed retries alternate the sign. Reverse the stored expense-report sign when rebuilding both amount and taxAmount.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by reading the transaction back through getTransactionDetails, which resolves the expense-report sign for both amount and taxAmount and is the same helper that duplicate uses to rebuild a request from an existing transaction

participant,
},
policyParams,
transactionParams: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the tracked-expense conversion on retry

When receipt upload fails while submitting an existing tracked expense, the failed operation is the action === SUBMIT branch that calls convertTrackedExpenseToRequest, but this payload omits action, linkedTrackedExpenseReportAction, and linkedTrackedExpenseReportID, so the retry enters the ordinary RequestMoney branch instead. Because the tracked transaction already exists under the reused ID, this can be treated as already created without ever converting/submitting it. Unlike the already-fixed TRACK_EXPENSE case, fresh evidence is that MoneyRequestBuilder.ts:1066 tags failures from this conversion path as MONEY_REQUEST, so the new render gate still offers the retry; preserve the conversion parameters or exclude this flow.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say its out of scope here - the gate already excludes any tracked expense whose receipt reached the server, since that leaves a remote receipt.source, so the remaining window is a tracked expense whose receipt never uploaded at all. The conversion path needs its own handling - we might work on follow up on that later

Comment thread src/components/DotIndicatorMessage.tsx
@BartekObudzinski

Copy link
Copy Markdown
Contributor

Translations updated, @brunovjk what's your status? thanks

@brunovjk

Copy link
Copy Markdown
Contributor

The "add payment card" modal is stuck; I click to dismiss it, but it keeps coming back:

Screen.Recording.2026-09-24.at.10.53.27.mov

The strange thing is that after pulling that PR and switching back to main, the bug persists. Does this happen to you too? Thanks.

@BartekObudzinski

Copy link
Copy Markdown
Contributor

@brunovjk I don’t see it on my side. This PR doesn’t touch any payment card or billing code. Have you tried a fresh account, or signing out and clearing the app cache?

}

retryReceiptUpload(receiptRetryContext, () =>
clearReceiptUploadError({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider clearing the receipt error only after requestMoney() succeeds? I'm wondering if clearing it in onBeforeDispatch could leave the user without the retry option if the dispatch fails synchronously. Is that a possible edge case here? Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Now the error is cleared only after requestMoney() is called. If building the request throws, the receipt error stays and the user still has Try again and Save. I added a test for that.

If the retry fails on the server, failureData writes a new receipt error, so Try again comes back anyway.

@brunovjk

Copy link
Copy Markdown
Contributor

One small style question: should src/libs/ReceiptUploadRetryHandler/buildRetryPayload.ts have the standard file header used for new non-trivial modules in this codebase?

@brunovjk

Copy link
Copy Markdown
Contributor

Have you tried a fresh account, or signing out and clearing the app cache?

Yes. I created another simulator, and it worked. It worked well in the initial tests; I'll test it on the other platforms later.

99902_android_native.mov

@BartekObudzinski

Copy link
Copy Markdown
Contributor

@brunovjk Good catch, I removed it by mistake. Added it back, and also the one in index.ts.

@brunovjk

brunovjk commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
99902_android_native.mov
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
99902_web_chrome.mov

@brunovjk brunovjk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

NAB: @BartekObudzinski @rinej, should we update the PR description to clarify that the Try again button should not appear on Web/mWeb? Thank you!

@melvin-bot
melvin-bot Bot requested a review from mountiny September 25, 2026 12:18
@BartekObudzinski

Copy link
Copy Markdown
Contributor

@MelvinBot please update the PR description to clarify that the Try again button should not appear on Web/mWeb

@MelvinBot

Copy link
Copy Markdown
Contributor

Updated the PR description. The Explanation of Change section now states that Try again is native only (iOS and Android) and never appears on Web or mWeb.

It also adds:

  • Why: on web, the receipt is only a blob URL in the open tab and is gone after a reload. isRetrySupported is false on web.
  • Web/mWeb copy: the row shows Save alone with Upload failed. Save your receipt to keep it.
  • Other native Save-only cases: track expenses and replaced receipts now appear next to distance, per diem, time, and test receipts.

I left the Tests and QA sections unchanged.


view run

@mountiny mountiny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this ahead, looks in a good shape now

@mountiny
mountiny merged commit bd73f8f into Expensify:main Sep 25, 2026
39 of 44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.95-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

MelvinBot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Yes, the help site needs one update. I opened a draft PR for it: Docs updates for E/A#99902 Update receipt upload failure FAQ for Try again

The "What should I do if my receipt upload fails?" FAQ in Attach-and-edit-receipts-on-expenses.md:173 still showed the old message and the Save receipt and Delete expense buttons. The update:

  • Native app: "Upload failed. Try again or save for later." with Try again and Save.
  • Web and mWeb: "Upload failed. Save your receipt to keep it." with Save only.
  • Lists when Try again is hidden: distance, per diem, and time expenses, track expenses, and replaced receipts.
  • Removes Delete expense.
Verification notes
  • I took the labels from the merged code: common.tryAgain, common.save, iou.error.receiptUploadFailedMessage, and iou.error.receiptUploadFailedSaveOnlyMessage.
  • A live web check confirmed the Simulate failing network requests toggle label. It could not show the error row because the test tool can't upload a receipt file. Please confirm the native row on a device.
  • No other article under docs/articles mentions this error row.

@rinej, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review


view run · view recording

@unzig21

unzig21 commented Sep 29, 2026

Copy link
Copy Markdown

Deploy Blocker #102494 was identified to be related to this PR.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.95-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 failure ❌

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.