Skip to content

Do not block Search page payments on a missing chat report - #98760

Open
VickyStash wants to merge 8 commits into
Expensify:mainfrom
callstack-internal:VickyStash/bugfix/98444-bulk-pay-fallback-chat-report
Open

Do not block Search page payments on a missing chat report#98760
VickyStash wants to merge 8 commits into
Expensify:mainfrom
callstack-internal:VickyStash/bugfix/98444-bulk-pay-fallback-chat-report

Conversation

@VickyStash

@VickyStash VickyStash commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Bulk Mark as paid on the Search page requires each report's chat report object to be resolvable from the search snapshot or Onyx. The Search snapshot contains matched expense reports but not their parent policy-expense chats, so any chat not already cached in Onyx caused the report to be silently unpayable in bulk. The row-level Pay dropdown (PayActionCell) had the same unlogged early return. Paying worked only after opening the report (which loads the chat via OpenReport) — matching the "sometimes nothing, sometimes only one" reports from the affected user.

The chat report object is only used by payMoneyRequest to build optimistic chat updates (chat preview, iouReportID clearing, last message); the API call itself needs just the IDs. This PR stops treating the missing object as a blocker for money requests:

  • useSearchBulkActions.ts (onBulkPaySelected): when getChatReportForBulkPay finds nothing, derive chatReportID from item.chatReportID ?? iouReport.chatReportID ?? iouReport.parentReportID and pay with a fallback {reportID, policyID}. The policyID (same workspace as the expense report) keeps the billing-restriction check inside payMoneyRequest working. Invoices — or items with no derivable chatReportID — are still skipped, now with a [BulkPay] log.
  • PayActionCell.tsx (row Pay dropdown): chatReport removed from the top guard; money requests use the same fallbackChatReport pattern; invoices keep the strict check with a [SearchPay] log.

Fixed Issues

$ #98444
PROPOSAL: N/A

Tests

  • Verify that no errors appear in the JS console
  1. As a workspace admin on web, have 2+ Approved expense reports from another member (no VBBA connected, so Pay offers "Mark as paid").
  2. Remember chatReportID of the chat where expenses are posted.
  3. Go to Spend > Reports
  4. In the dev console, evict one report's chat from Onyx: Onyx.set('report_<chatReportID>', null).
  5. Select expense reports, click Pay > Mark as paid (bulk payment).
  6. Verify reports get paid (PayMoneyRequest sent for each, row label turns into paid).
  7. Repeat the same steps but pay with the ROW-level Pay dropdown > "Mark as paid". Verify it works.

Offline tests

Same, as in Tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

Same, as in 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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

MacOS: Chrome / Safari
web_bulk.mp4
pay_perRow.mp4

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...h/SearchList/ListItem/ActionCell/PayActionCell.tsx 96.15% <100.00%> (+2.82%) ⬆️
src/hooks/useSearchBulkActions.ts 70.96% <100.00%> (+9.14%) ⬆️
src/libs/actions/IOU/PayMoneyRequest.ts 81.09% <100.00%> (+0.28%) ⬆️
src/libs/actions/Search.ts 53.66% <28.57%> (+5.43%) ⬆️
... and 204 files with indirect coverage changes

@VickyStash

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: 4bd48b79a3

ℹ️ 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/hooks/useSearchBulkActions.ts Outdated
Comment thread src/components/Search/SearchList/ListItem/ActionCell/PayActionCell.tsx Outdated
@VickyStash
VickyStash marked this pull request as ready for review August 17, 2026 16:42
@VickyStash
VickyStash requested review from a team as code owners August 17, 2026 16:42
@melvin-bot
melvin-bot Bot requested review from daledah and removed request for a team August 17, 2026 16:42
@melvin-bot

melvin-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

@daledah 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]

Comment thread src/hooks/useSearchBulkActions.ts Outdated
Comment thread src/libs/actions/IOU/PayMoneyRequest.ts Outdated

@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: 925351a796

ℹ️ 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/actions/IOU/PayMoneyRequest.ts Outdated
@mountiny

Copy link
Copy Markdown
Contributor

@MelvinBot review

@daledah

daledah commented Aug 17, 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
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

Comment thread src/hooks/useSearchBulkActions.ts Outdated
Comment thread src/hooks/useSearchBulkActions.ts Outdated
@daledah

daledah commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@VickyStash could you please add some unit tests to this PR?

@VickyStash

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

Solid, well-reasoned fix. The core idea — treat a missing chat-report object as a blocker only for the optimistic chat updates, not for the API call itself (which only needs the IDs) — is correct, and the change is backward-compatible: isFallbackChatReport is optional and defaults falsy, so every other payMoneyRequest/getPayMoneyRequestParams caller is unaffected. I traced the fallback path end-to-end and found no blocking bugs. A few suggestions below.

Verified correct

  • The API gets the right chatReportID in the fallback path — PayMoneyRequest.ts:528 sends chatReport.reportID, which is the derived fallbackChatReportID.
  • The optimistic/failure chat-report writes are cleanly gated behind !isFallbackChatReport and the old trailing failureData revert was correctly folded into the same guard — PayMoneyRequest.ts:326-337. So on failure we no longer try to "revert" a chat report we never had.
  • The billing-restriction check still works because the fallback carries a policyID and chatReportPolicy resolves from the search snapshot — useSearchBulkActions.ts:1447, PayMoneyRequest.ts:814.
  • The row label flips to paid off the iouReport statusNum: REIMBURSED optimistic update, which is unchanged — so the UI still reflects payment even with no chat-report merge.
  • The {reportID, policyID} fallback literal typechecks against Report (reportID is the only required field).

Suggestions (non-blocking)

  1. Add a unit test for the fallback branch. This is the one thing I'd want before merge. The whole PR is a new behavioral branch (isFallbackChatReport → skip optimistic chat merge, still pay), and it's easy to silently regress. useSearchBulkActionsPayTest.ts currently only asserts the Pay option shows/hides — it never exercises payment execution. A test that evicts the chat report from Onyx and asserts (a) PayMoneyRequest is still dispatched with the derived chatReportID, and (b) no report_<chatReportID> optimistic key is written, would lock in this fix. The author checklist marks "I added unit tests" as done, but no test file is in the diff.

  2. Reuse isItemInvoice. useSearchBulkActions.ts:1434 still calls isInvoiceReport(item.reportID) inline even though isItemInvoice was just computed at line 1402. Minor tidy-up.

One thing worth confirming

The linked issue pins the root cause on a stale/revoked auth-token (407) window, whereas this PR fixes a distinct silent-failure path (missing chat-report object). Both produce the same "nothing happens / only one paid" symptom, and your reproduction (evict chat from Onyx) is a genuine bug, so this is a good defensive fix regardless. Just flagging that it may not fully cover the original 407 scenario described in the issue — worth confirming with the reporter that this maps to what they hit.

I did not run a live reproduction: it needs a specific data setup (2+ approved payable reports plus a chat evicted from Onyx) that isn't reproducible in an automated smoke test, and none of the changed lines affect initial render, so a page-load check wouldn't exercise them.

@VickyStash

Copy link
Copy Markdown
Contributor Author

@daledah Please, take another look!

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.

4 participants