Skip to content

Fix/96257 relaid optimistic scan failed move - #99328

Merged
deetergp merged 16 commits into
Expensify:mainfrom
yusufdeveloper2903:fix/96257-relaid-optimistic-scan-failed-move
Sep 4, 2026
Merged

deetergp merged 16 commits into
Expensify:mainfrom
yusufdeveloper2903:fix/96257-relaid-optimistic-scan-failed-move

Conversation

@yusufdeveloper2903

@yusufdeveloper2903 yusufdeveloper2903 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Re-lands the optimistic scan-failed expense move from #97084, which was reverted in #98914 because it nulled the optimistic report in successData while the user could still be looking at it, leaving them on the "Hmm... it's not here" page.

Instead of dropping that report blindly, HandleMovedScanFailedExpenses reads the backend's report out of the PayMoneyRequest response and points every route showing the optimistic report at it — its reportID param and any encoded backTo — before removing it, re-parenting each moved expense's transaction thread on the way.

The cleanup is appended to the request's successData rather than the response, so it lands after the pending-state cleanup already there instead of being merged back onto the actions it just removed. If the response does not name exactly one backend report, nothing happens at all — a guessed destination renders an expense report screen with no expenses.

Fixed Issues

$ #96257
$ #98821

Tests

Precondition: a workspace chat where you can submit, approve and pay.

  1. Create a manual expense, then a scan expense with a receipt that fails SmartScan.
  2. Open the report, click Submit, then Approve.
  3. Go offline and click Mark as paid. Verify the scan-failed expense moves to a new Draft report right away.
  4. Open that new report, then go online. Verify it keeps showing the expense, the URL switches to the backend's report, and no "Hmm... it's not here" page appears.
  5. Repeat, but open the report details RHP before going online. Verify the same, and that dismissing the RHP lands on the backend report.
  6. Repeat, but reload the app while offline before reconnecting. Verify the reconciliation still happens.
  7. Verify the expense's transaction thread still opens after reconnect.
  • Verify that no errors appear in the JS console

Offline tests

  1. Steps 1–3 above.
  2. Verify the new report and its expense are visible offline, and the paid report no longer lists the scan-failed expense.
  3. Go online and verify step 4 above.

QA Steps

  1. In a workspace chat, create a manual expense, then a scan expense with an invalid receipt and wait for the scan to fail.
  2. Open the report, click Submit, then Approve.
  3. Go offline and click Mark as paid. Verify the scan-failed expense moves to a new report.
  4. Open the new report, then go online.
  5. Verify the report keeps showing the expense and no "Hmm... it's not here" page appears.
  • Verify that no errors appear in the JS console

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 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.
  • 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

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari After fix:
REC-20260824172438.mp4

@yusufdeveloper2903
yusufdeveloper2903 requested review from a team as code owners August 24, 2026 12:33
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and brunovjk and removed request for a team August 24, 2026 12:34
@melvin-bot

melvin-bot Bot commented Aug 24, 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]

@melvin-bot
melvin-bot Bot removed the request for review from a team August 24, 2026 12:34
@codecov

codecov Bot commented Aug 24, 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/libs/Middleware/register.ts 100.00% <100.00%> (ø)
src/libs/TransactionUtils/index.ts 92.39% <100.00%> (+0.06%) ⬆️
src/libs/actions/IOU/PayMoneyRequest.ts 82.07% <100.00%> (+0.08%) ⬆️
src/libs/actions/IOU/Hold.ts 93.39% <87.50%> (-0.17%) ⬇️
...libs/actions/IOU/reconcileMovedScanFailedReport.ts 94.28% <94.28%> (ø)
...c/libs/Middleware/HandleMovedScanFailedExpenses.ts 92.40% <92.40%> (ø)
... and 10 files with indirect coverage changes

@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: a5ab214e55

ℹ️ 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".

@brunovjk

Copy link
Copy Markdown
Contributor

@yusufdeveloper2903wWe have some comments from Melvin here; could you please take a look at them?

Do you think these additional findings make sense?

  • pointRoutesToReport() may update the navigation before the backend report and the reconciliation updates are committed to Onyx, potentially showing the “not here” page temporarily.
  • For sparse responses, the optimistic report is removed without explicitly updating the moved transactions’ reportID to the backend report ID.
  • If the payment fails, failureData removes the optimistic report but may not restore the transaction threads’ original parentReportID, parentReportActionID, and chatReportID.

Thanks a lot.

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

Thanks @brunovjk, these were good finds. Two of them were real and I fixed them.

1. pointRoutesToReport() running before the Onyx updates — I looked into this one but left it as is. The route switches to the backend report a moment before its data lands, but the report screen doesn't show the not-found page in that moment: ReportNotFoundGuard starts fresh whenever the route's reportID changes and won't call a report missing until it has actually seen it load, and an open RHP shows the loading indicator for a report ID it doesn't know yet. So the worst you get is a frame of loading.

The other order is worse, and it's the one that got #97084 reverted: if we removed the optimistic report first and moved the routes after, the user would be sitting on a report that no longer exists.

2. Moved transactions keeping the optimistic reportID — you were right, fixed. Expenses are looked up by transaction.reportID, so when the response didn't carry them the user landed on the backend report and the expense wasn't in it. They're now moved over as well, unless the response already places them somewhere itself.

3. failureData not restoring the transaction threads — also right, fixed. On a failed payment the threads now get their original parentReportID, parentReportActionID and chatReportID back. This was missing for the hold split too, so both cases are covered now.

I also fixed the Codex P1 (the chat's iouReportID was left pointing at the removed report) and the coding-standards comments.

Added tests for all of it.

@yusufdeveloper2903

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: c52169f58f

ℹ️ 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".

@brunovjk

Copy link
Copy Markdown
Contributor

@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: 8a75e9d3b1

ℹ️ 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 on lines +505 to +506
if (!full || shouldMoveScanFailedTransactions) {
const holdReportOnyxData = getReportFromHoldRequestsOnyxData({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Wait for expense actions before creating the split

When the transaction collection is populated but this report's actions have not been loaded or were evicted, shouldMoveScanFailedTransactions is true, yet getHoldReportActionsAndTransactions() finds no actions and therefore no transactions. This branch still creates an optimistic report, points the workspace chat at it, and sends empty optimisticHoldReportExpenseActionIDs, leaving an offline user with an empty report while the scan-failed expense remains on the paid report. Only create the optimistic split when all moved transactions can be paired with their actions, or build the split from the known transactions. CLAUDE.mdL82-L86

Useful? React with 👍 / 👎.

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.

What do you think of this comment, @yusufdeveloper2903? Thanks.

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

@brunovjk I don't think we should act on this one.

The condition is new, but the behaviour isn't — getReportFromHoldRequestsOnyxData has always built the report from actions while the caller decides from transactions, same as the !full path on main. And it's unreachable: it needs transactions loaded without report actions, which neither the report/preview flow (OpenReport loads both) nor Search (reads snapshot_, so the branch never runs) can produce. Happy to add a guard if you'd still prefer one.

@melvin-bot
melvin-bot Bot requested a review from deetergp September 1, 2026 16:11
@deetergp

deetergp commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-02T01:16:37.104012Z 62cdc50 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 62cdc50042

ℹ️ 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".

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

LGTM; we just need to resolve the conflicts and check if the tests pass and there are no warnings. @yusufdeveloper2903, can you resolve the conflicts? Thanks.

@brunovjk conflicts are resolved and main is merged ready for review

@deetergp

deetergp commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@yusufdeveloper2903 You've got failing Jest tests that appear to be unrelated. Can you pull main into your branch?

@yusufdeveloper2903

yusufdeveloper2903 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @deetergp merged main in and the test failure is gone. Ready for review

@deetergp

deetergp commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Jeez… This nonsense again:

Screenshot 2026-09-03 at 3 08 57 PM

@yusufdeveloper2903

yusufdeveloper2903 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@deetergp Just merged main again to resolve the conflicts. main keeps getting changes in the same files this PR touches, so conflicts come up pretty often. The branch is up to date now.

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

Hi @deetergp 👋 — friendly bump on this one.

@deetergp
deetergp merged commit f7571cf into Expensify:main Sep 4, 2026
34 of 35 checks passed
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Sep 4, 2026

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

OSBotify commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/deetergp in version: 9.4.73-0 🚀

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

@MelvinBot

MelvinBot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Docs impact review: no help site changes required. I did not create a draft PR.

Why: this PR is an internal state-reconciliation fix, not a behavior or copy change. It re-lands the optimistic move of scan-failed expenses off a report at payment time, and adds middleware that repoints routes from the optimistic report to the backend's real report so users no longer land on the "Hmm... it's not here" page after reconnecting.

The user-facing outcome after this fix is the already expected behavior described in both linked issues (Expensify/App#96257, Expensify/App#98821) — the scan-failed expense moves to a new report, and that report keeps working. Before the fix, users saw a bug. Help articles document expected behavior, so there is nothing to update.

What I checked

PR contents — all 13 changed files are middleware, IOU actions, TransactionUtils, and tests:

No src/languages/*.ts changes, so no new or reworded UI strings. No new screens, settings, tabs, or buttons. Nothing in the diff introduces a workflow a member would need instructions for.

Docs I reviewed for possible impact:

One adjacent gap, out of scope for this PR: the help site does not document the underlying behavior anywhere — that paying a report moves any scan-failed expense onto a new report so the rest can be paid. That behavior shipped earlier in #95682, not here, so I left it alone rather than widening this review. Say the word and I'll open a draft PR adding a short FAQ entry to Pay-Expenses.md and a cross-reference from Troubleshoot-SmartScan-Issues.md.

@yusufdeveloper2903, since no docs changes are needed there is no help site PR to link or mark Ready for review. Please confirm you agree with this read — or tell me to cover the adjacent gap above and I'll create the draft PR, label it HelpDot, and assign it to you.


view run · view recording

@OSBotify

OSBotify commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.73-3 🚀

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

Bundle Size Analysis (Sentry):

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.

6 participants