[Payment due @cretadn22] Fix silent receipt drop when file is missing from cache#86581
Conversation
When a receipt image was written to an ephemeral iOS cache directory (e.g. Library/Caches/ImageManipulator/) and the SequentialQueue was delayed, iOS could purge the file before upload. prepareRequestPayload would silently omit the receipt from the FormData, creating an expense with no receipt attached and no error shown to the user. Changes: - Throw an error in prepareRequestPayload when a receipt file is missing instead of silently dropping it, so the request fails visibly - Add moveReceiptToDurableStorage utility that copies files from ephemeral cache to the durable Receipts-Upload directory - Use durable storage after crop/rotate in TransactionReceiptModalContent and IOURequestStepOdometerImage native flows - Add unit tests for prepareRequestPayload covering receipt file existence, missing files, and edge cases Made-with: Cursor
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Instead of throwing an error that could disrupt the SequentialQueue, log an alert with the command name, source path, and filename so the issue is surfaced without breaking the request flow. Made-with: Cursor
Verifies that receipts produced by crop/rotate operations are moved from the ephemeral ImageManipulator cache to the durable Receipts-Upload directory. These tests fail on main (where cache URIs pass through unchanged) and pass with the moveReceiptToDurableStorage fix. Made-with: Cursor
Comments referencing "fix branch" vs "main" become misleading once merged. Simplified to a direct requireActual import. Made-with: Cursor
The empty-source scenario is not a realistic receipt flow and the test was just verifying an implementation detail of the fallthrough logic. Made-with: Cursor
- Fix trailing blank line in prepareRequestPayloadNativeTest.ts - Replace deprecated StyleSheet.absoluteFillObject with absoluteFill Made-with: Cursor
…ilent-receipt-drop
| style={[StyleSheet.absoluteFillObject, styles.backgroundWhite, blinkStyle, styles.zIndex10]} | ||
| style={[StyleSheet.absoluteFill, styles.backgroundWhite, blinkStyle, styles.zIndex10]} |
There was a problem hiding this comment.
AI explains:
The ESLint rule @typescript-eslint/no-deprecated flagged StyleSheet.absoluteFillObject because React Native has deprecated it in favor of StyleSheet.absoluteFill.
They do the same thing -- both resolve to {position: 'absolute', left: 0, right: 0, top: 0, bottom: 0}. The only difference is that absoluteFill is typed as a registered style (number ID) which is slightly more optimized, while absoluteFillObject returns the plain object literal. React Native now recommends absoluteFill exclusively.
This was a pre-existing deprecation in IOURequestStepOdometerImage/index.native.tsx that CI flagged because our PR touched that file (adding the moveReceiptToDurableStorage import). The "changed files ESLint check" lints all files modified by the PR, so it caught this even though we didn't introduce it.
|
🚧 @neil-marcellini has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
@cretadn22 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] |
|
@cretadn22 would you please test on iOS for me? I'm currently unable to until our app deployer team re-generates some profiles. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d83e3d311a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@neil-marcellini yes |
|
🚧 @neil-marcellini has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
- Extract shared durable receipt logic into applyDurableReceipt helper to eliminate duplication between rotate and crop handlers (CONSISTENCY-3) - Pass original file to replaceReceipt instead of spreading, which preserves the File prototype and Blob data on web (Codex P1) - Add explanatory comment for eslint-disable in durable storage test (CONSISTENCY-5) Made-with: Cursor
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-04-02.at.23.57.23.movAndroid: mWeb ChromeScreen.Recording.2026-04-03.at.00.04.12.moviOS: HybridAppScreen.Recording.2026-04-02.at.23.51.39.moviOS: mWeb SafariScreen.Recording.2026-04-03.at.00.02.47.movMacOS: Chrome / SafariScreen.Recording.2026-04-03.at.00.00.07.mov |
Avoids the abbreviated txnID variable and the no-shadow conflict with the transactionID route param by reading transaction.transactionID directly after the null guard. Made-with: Cursor
Instead of checking existence before mkdir and separately after, always call mkdir (which is a no-op if it already exists) then verify it was created. Log an alert and bail if it still doesn't exist after the mkdir attempt. Made-with: Cursor
Two offline crop/rotate operations on different transactions could both produce a file named receipt.jpg, causing one to overwrite the other in Receipts-Upload. Generate a unique name using timestamp + random suffix while preserving the file extension. Also update the test mock from copyFile to moveFile and add a collision test. Made-with: Cursor
Replace the ad-hoc Date.now + Math.random approach with the codebase's existing rand64() utility from NumberUtils, which is the standard client-side ID generator used for transaction IDs and report IDs. Made-with: Cursor
Insert the rand64 suffix before the file extension instead of replacing the entire name, so receipt_4611686018427387903.jpg preserves the original name for debugging context. Made-with: Cursor
Resolve conflicts in TransactionReceiptModalContent.tsx: keep applyDurableReceipt helper, update setMoneyRequestOdometerImage to new signature (takes transaction object + isEditingConfirmation). Made-with: Cursor
|
Thanks for the review @cretadn22. It's updated and ready for another. |
|
🎯 @cretadn22, thanks for reviewing and testing this PR! 🎉 A payment issue will be created for your review once this PR is deployed to production. If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created. |
|
It's past working hours for @mollfpr so for the sake of urgency re-assigning internal review to @francoisl |
|
🚧 @francoisl has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/francoisl in version: 9.3.53-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are required for this PR. The changes are purely an internal bug fix for iOS file storage handling — moving receipt files from ephemeral cache directories to durable storage and adding alerting when files are missing. There are no changes to user-facing features, UI labels, settings, workflows, or button names. The existing help article |
|
🚀 Deployed to staging by https://github.com/francoisl in version: 9.3.53-0 🚀
Bundle Size Analysis (Sentry): |
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.53-7 🚀
|
Explanation of Change
When a receipt image was written to an ephemeral iOS cache directory (e.g.,
Library/Caches/ImageManipulator/) by the crop/rotate functionality and the SequentialQueue was delayed (due to network issues, other pending requests, etc.), iOS could purge the cached file before the upload completed. The nativeprepareRequestPayloadwould silently omit the receipt from the FormData, creating an expense with no receipt attached and no error shown to the user.This PR fixes the issue with two complementary approaches:
1. Safety net — alert on missing receipt files:
prepareRequestPayload/index.native.tsnow logs an alert whencheckFileExistsreturns false for a receipt, instead of silently dropping it. This ensures and engineer will investigate this case that should not occur.2. Prevention — move crop/rotate output to durable storage:
A new
moveReceiptToDurableStorageutility copies files from the ephemeral ImageManipulator cache to the durableReceipts-Uploaddirectory. This is used in:TransactionReceiptModalContentafter crop/rotate operationsIOURequestStepOdometerImagenative flow aftercropImageToAspectRatioFixed Issues
$ https://github.com/Expensify/Expensify/issues/615648
Tests
Offline tests
N/A
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
I'm unable to test on iOS currently, so asking if C+ can do it for me.
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Made with Cursor