Gate Hold on receipt scan state to prevent unexpected hold error on scanning expenses#94252
Conversation
Co-authored-by: huult <huult@users.noreply.github.com>
|
@MelvinBot ready for review |
|
🤖 Marked this PR as ready for review. All checks are green except A couple of human-only items still need your attention before/during review,
I left those untouched since they must be filled out by the human co-author. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b803874f27
ℹ️ 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".
|
|
||
| const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isClosed && !isDeletedParentAction(reportAction); | ||
| const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && canModifyStatus && !isScanning(transaction); | ||
| const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && canModifyStatus && !isScanning(transaction) && !isReceiptBeingScanned(transaction); |
There was a problem hiding this comment.
Preserve scan gating after manual edits
In the repro this is meant to block, entering merchant or amount calls the update-money-request path, which runs getUpdatedTransaction() and sets receipt.state to OPEN whenever a manual edit stops SmartScan locally (src/libs/TransactionUtils/index.ts:783-790). By the time this gate is evaluated, isReceiptBeingScanned(transaction) is therefore already false, so Hold can still be offered and HOLD_MONEY_REQUEST can still be sent while the backend scan is running. Please gate on scan state that is not optimistically cleared by those manual field edits, or keep the receipt scan state intact until the backend confirms it is safe.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 huult — I reviewed Codex's comment against the code at the reviewed commit (b803874). Codex is correct: the added !isReceiptBeingScanned(transaction) check does not change behavior in the repro this PR targets.
Why the fix is ineffective here
Entering merchant or amount goes through the update-money-request path, which optimistically flips receipt.state to OPEN and writes it back to the same transaction the Hold gate reads:
- An amount or merchant edit sets
shouldStopSmartscan = true—TransactionUtils/index.ts:618-630. getUpdatedTransaction()then setsupdatedTransaction.receipt.state = OPEN—TransactionUtils/index.ts:782-791.- That object (including the
OPENreceipt) is MERGEd onto theTRANSACTIONOnyx key viaoptimisticData—UpdateMoneyRequest.ts:1547-1556. isReceiptBeingScanned()returns true only forSCAN_READY/SCANNING, so it'sfalseonce the state isOPEN—TransactionUtils/index.ts:1440-1441.
So by the time the gate at ReportUtils.ts:5342 runs, both isScanning() and isReceiptBeingScanned() are already false, and Hold is offered exactly as before. In fact isScanning() already short-circuits on !isReceiptBeingScanned() as its first check (1426-1438), so the new conjunct is redundant for this flow — it reads the same already-flipped OPEN state.
Implication
A frontend-only gate can't reliably detect an in-flight backend scan after a manual edit, because the client optimistically clears receipt.state to OPEN the moment the user edits merchant/amount. There's no local field that distinguishes "scan finished" from "scan still running, but user edited." That lines up with the PR note that the real fix is the backend change NikkiWines is handling (scan-complete arriving via Pusher) — the client needs a scan signal that survives the optimistic OPEN flip, or the backend should reject/short-circuit the hold while scanning.
I did not push any change. If you'd like me to attempt a revised approach, let me know the direction (e.g. gate on a non-optimistic signal) and I can take a pass — though this may genuinely require the backend-side fix rather than a frontend gate.
There was a problem hiding this comment.
@MelvinBot Could we introduce a new flag (e.g. isScanned) on the transaction to track the actual SmartScan completion state?
The app can use this flag when evaluating canHoldRequest:
- Non-scan requests:
isScanneddefaults totruesince there is no SmartScan flow involved. transaction.isScanned === false: block Hold while the backend SmartScan is still running.transaction.isScanned === true: allow Hold after SmartScan completes.- For legacy transactions without this flag, fallback to checking
receipt.state(SCAN_COMPLETE/SCAN_FAILED).
The backend should:
- Set
isScanned: trueon the transaction once SmartScan completes (either success or failure). - Reject
HOLD_MONEY_REQUESTserver-side whenisScanned === falseto ensure we don't bypass this check.
This would avoid relying on receipt.state, which can be optimistically changed to OPEN after manual edits.
|
@MelvinBot Could you please review Codex's comment? |
|
Good idea to think about a more authoritative signal, but I'd hold off on the 1. The premise doesn't hold for this bug's repro. Entering merchant/amount on a scan expense does not flip 2. The Suggestion: keep this PR's front-end Happy to draft the App-side consumption ( |
|
@MelvinBot Could you please check off the PR checklist items? |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-06-23.at.11.27.12.mp4Android: mWeb ChromeScreen.Recording.2026-06-23.at.11.23.22.mp4iOS: HybridAppScreen.Recording.2026-06-23.at.11.33.21.mp4iOS: mWeb SafariScreen.Recording.2026-06-23.at.11.35.46.mp4MacOS: Chrome / SafariScreen.Recording.2026-06-23.at.11.18.02.mov |
|
🤖 I can't check off the PR Author Checklist for you, Those items are personal attestations that you, as the human author, did the work — e.g. "I tested on all platforms (Android/iOS native, mWeb, desktop)", "I tested with a High Traffic account against staging/production", "I verified there are no console errors", and "I included screenshots/videos for all platforms". I haven't performed that manual/device testing, so ticking the boxes would be a false attestation. What I can/did do:
What's left for you:
Once those are filled in, the checklist check will pass. |
|
@MelvinBot please complete author checklsit |
|
🤖 I can't complete the PR Author Checklist for you, That checklist is a personal attestation that you manually performed each step — tested on all platforms (Android native/mWeb, iOS native/mWeb, web), verified there are no console errors, captured screenshots/videos, etc. I didn't run those manual tests, so checking the boxes on your behalf would be a false attestation. The same applies to the Tests, QA Steps, and Screenshots/Videos sections — those are human-only. What you'll need to do yourself:
If you'd like, I can help with anything that's not a manual attestation — e.g. adding unit tests for this fix, or addressing reviewer feedback. Just tag me. |
|
@MelvinBot I completed the PR Reviewer Checklist. Could you please update it on your side? Is there anything else I need to do? |
|
@MelvinBot we can remove the comments within Tests and QA Steps section as the use case is related to offline scenario. Also, please tick all the PR Author checklist items |
|
🤖 Thanks 1. 2.
Editing the description re-triggers the check, so no action needed from me there either. Once both checklists are green and a reviewer submits the review, the PR is in good shape for the next reviewer. |
|
🤖 Done,
I left the two "Verify that no errors appear in the JS console" checkboxes (under Tests/QA) unticked since those are test-step items rather than PR Author Checklist items — let me know if you'd like those ticked too. |
@MelvinBot yes please |
|
🤖 I'm going to leave those two unchecked, The two "Verify that no errors appear in the JS console" checkboxes sit under the Tests and QA Steps sections. They're attestations that a human actually ran the flow and observed a clean console — not PR Author Checklist process items. I can't truthfully tick them on your behalf since I didn't run the test and watch the console, and ticking a verification box I didn't perform would be misleading to reviewers. Please check those two yourself once you've confirmed no console errors during your test run. Happy to help with anything else. |
joekaufmanexpensify
left a comment
There was a problem hiding this comment.
Good for product
|
🚧 NikkiWines 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/NikkiWines in version: 9.4.19-1 🚀
Bundle Size Analysis (Sentry): |
|
🤖 I reviewed this PR against the help site files under Why: This is a narrow bug fix that hides the Hold action transiently while an expense's receipt is still being SmartScanned, preventing a The only help article that documents Hold availability is Expense and Report Actions. It describes when Hold appears strictly in terms of report status (Draft, Outstanding, or Approved) and role (Submitter, Approver, Workspace Admin) — it makes no claim about receipt-scan state. This PR doesn't change any of that documented behavior; it only suppresses a transient/erroring state until SmartScan completes, after which Hold becomes available again as documented. Documenting "Hold is hidden while a receipt is scanning" would be over-specifying internal edge-case behavior that the help site intentionally keeps at a high level. No draft help site PR was created. |
Explanation of Change
When a scan expense is opened while its receipt is still being SmartScanned, manually entering the merchant and amount re-enables the Hold action. Tapping Hold then fires
HOLD_MONEY_REQUESTagainst a transaction whose receipt is still scanning server-side; the backend rejects it, andputOnHold's failure data surfaces the generic "Unexpected error holding this expense. Please try again later." message.The root cause is that the Hold gate in
canHoldUnholdReportAction(src/libs/ReportUtils.ts) only checked!isScanning(transaction).isScanning()is a UI-state helper that intentionally returnsfalseonce the user manually enters a valid amount (hasValidModifiedAmount) or the transaction is no longer partial — even though SmartScan is still running in the background. Following the repro order (merchant → amount → category),isScanning()flips tofalseand Hold is offered prematurely.This PR gates Hold on the real receipt-scan state by adding
!isReceiptBeingScanned(transaction)(which reflects the actualreceipt.stateofSCANNING/SCANREADY) alongside the existing!isScanning(transaction)check. SincecanHoldRequestis the single source every Hold entry point reads from (header, transaction context menu, bulk actions), this hides Hold everywhere until the scan completes, so the failing API call — and therefore the unexpected error — can no longer happen. Once the scan finishes, Hold becomes available again.isReceiptBeingScannedwas already imported inReportUtils.ts, so no import change was needed. This matches established precedent —ReportSecondaryActionUtils.tsalready gates scan-dependent actions onisReceiptBeingScannedrather thanisScanning.Fixed Issues
$ #93179
PROPOSAL: #93179 (comment)
Tests
Offline tests
While offline, create/open a scan expense whose receipt has not finished scanning, enter merchant/amount/category, and verify the Hold option stays hidden (the queued hold would otherwise fail when it reaches the server mid-scan).
QA Steps
Same as Tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, 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.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari