Skip to content

Reuse the existing chat for a second expense to a login created offline - #103195

Merged
carlosmiceli merged 19 commits into
mainfrom
claude-resolveStaleP2PParticipantAccountID
Nov 2, 2026
Merged

carlosmiceli merged 19 commits into
mainfrom
claude-resolveStaleP2PParticipantAccountID

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

When you send an expense offline to a brand-new login, the app gives that login a temporary accountID. Once the request syncs, the temporary accountID is removed from personal details. A second expense draft that was started before the sync still holds the old ID. The confirmation page then couldn't match the existing chat, so it treated the recipient as brand new and reused the existing chat's ID as a "new" chat. The new chat is written with Onyx.SET, which wiped the real chat locally and left a loading chat.

This PR:

  1. getParticipantsOption: when a participant's accountID is no longer in personal details, look the participant up by login and use the real account. The confirmation page and the submission hooks then find the existing chat, and the expense is added to it.
  2. getMoneyRequestDraftParticipantsFromReport: when a draft gets its recipient from a chat, store the recipient's login along with their accountID. For a recipient created offline, also store the reportID of their 1:1 chat, the same way a recipient picked from the participant list already has it. This covers setMoneyRequestParticipantsFromReport, setMultipleMoneyRequestParticipantsFromReport (multi-scan) and useDefaultParticipants, which fills in the recipient when you use the FAB quick action. Those drafts used to hold only the accountID, so the lookups in items 1 and 3 had nothing to use and the existing chat was still overwritten.
  3. getSyncedParticipantAccountIDs / setMoneyRequestParticipantsSyncedAccountIDs: the confirmation page now moves the draft itself to the real accountID once the recipient syncs, together with the recipient's split share. It finds the real account by login, or through the 1:1 chat when the server returns an existing Expensify user without a login. The chat is only used when the draft saved it as the recipient's chat, so a newly picked recipient is never swapped. Everything it needs is saved in the draft, so it also works when the sync finished before the confirmation page opened. Before this, the split share stayed saved under the old accountID and went blank, and an existing user's second expense still overwrote the chat.
  4. Adds unit tests for these changes.

Fixed Issues

$ #102476
PROPOSAL: #102476 (comment)

Tests

  1. While offline, use the main FAB to submit an expense to a new login that you have not previously chatted with.

  2. Using the same login, start again from the main FAB and navigate to the confirmation page. Then, reconnect to the internet.

  3. Submit a second expense.

  4. Verify that the second expense is submitted to the same, correct chat report that was created for that login in Step 1, once the report has been created and synced.

  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as Tests.

  • 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

…offline expense reuses the existing chat

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 6, 2026 14:04
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-resolveStaleP2PParticipantAccountID
git checkout -b claude-resolveStaleP2PParticipantAccountID upstream/claude-resolveStaleP2PParticipantAccountID
git push -u origin claude-resolveStaleP2PParticipantAccountID

Then you can close this PR and open a new one from your fork.

@MelvinBot

MelvinBot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ❌ fail

The second offline expense to a new login did not reuse the existing chat after the first expense synced. It created a separate chat with a "Hidden" participant and the errors "Unexpected error creating this chat" and "Unexpected error submitting this expense." The PR's Tests section is still a TODO, so I ran the reproduction steps from the linked issue on the PR head (c731bd2).
Original chat still showing only the first $12 expense

Step Status
Offline, use the main FAB to submit an expense to a new loginIn airplane mode, submitted a $12 manual expense to melvinbottest+offline379344@gmail.com. The chat appeared with "owes $12.00", "Outstanding", "1 expense."
First offline expense created, chat with new login shows owes $12.00
✅
Start a second expense to the same login from the main FAB, reach the confirmation page, then go onlineStill offline, used the FAB quick action for the same login, entered $20, and reached the confirmation page with the participant preselected. Turned airplane mode off on that page and waited about 8 seconds for the first expense to sync.
Second expense confirmation page, offline, amount $20, same recipient
✅
Submit the second expense; it lands in the same chat as the firstThe $20 expense went to a new, separate chat. That chat shows a "Hidden" participant with a red Fix badge, plus "Unexpected error creating this chat" and "Unexpected error submitting this expense." The original chat was not wiped, but it still shows only the $12 expense.
Inbox showing two separate chats: Hidden chat and original login chat
Hidden chat with chat-creation and expense-submission error banners
Original chat still showing only the first $12 expense
❌

view run · view recording

@MelvinBot

MelvinBot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

I could not run the key condition on web: the second expense draft must stay open on its confirmation page while the app goes back online. The web test tooling cannot keep that draft open while switching back online, so I submitted a new draft started after going online instead. That second expense joined the existing chat, but a draft started online already has the real accountID, so this result does not prove the fix. The PR's Tests section is still a TODO, so I used the linked issue's steps on the PR head (c731bd2).
Single chat showing owes $32.00 with 2 expenses

Step Status
Offline, use the main FAB to submit an expense to a new loginWith Force offline on, submitted $12 to melvinbottest+offlineweb48213@gmail.com. The chat appeared with "owes $12.00" and the offline banner.
First offline expense created for the new login
Chat with new login shows owes $12.00 while offline
✅
Start a second expense to the same login from the main FAB, reach the confirmation page, then go onlineReached the $20 draft for the same login while offline. The only way to turn Force offline off was to open Account > Troubleshoot, which closes the draft. Ctrl+D, which opens Test Tools on top of the current page, could not be sent with the tooling. After going online, the first expense synced, and I filled the second draft again online.
Second expense draft for $20 reached offline
Force offline turned off in Troubleshoot
First expense synced after going online
Second expense confirmation page refilled online
⚠️
Submit the second expense; it lands in the same chat as the firstThe second expense, from the draft started online, landed in the existing chat: "owes $32.00, 2 expenses," with one inbox entry and no loading or Hidden chat. The draft was not started offline, so the stale-accountID case this PR fixes was not covered.
Single chat showing owes $32.00 with 2 expenses
⚠️

view run · view recording

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot, replace the PR Author checklist with the verified one below:

PR author checklist

<!-- If necessary, assign reviewers that know the area or changes well. Feel free to tag any additional reviewers you see fit. -->

### Explanation of Change
<!-- Explain what your change does and how it addresses the linked issue -->
When you send an expense offline to a brand-new login, the app gives that login a temporary accountID. Once the request syncs, the temporary accountID is removed from personal details. A second expense draft that was started before the sync still holds the old ID. The confirmation page then couldn't match the existing chat, so it treated the recipient as brand new and reused the existing chat's ID as a "new" chat. The new chat is written with `Onyx.SET`, which wiped the real chat locally and left a loading chat.

This PR:
1. **`getParticipantsOption`**: when a participant's accountID is no longer in personal details, look the participant up by login and use the real account. The confirmation page and the submission hooks then find the existing chat, and the expense is added to it.
2. **`resolveOptimisticChatReportID`**: never reuse a caller-reserved optimistic chat ID that already belongs to a stored report. A fresh ID is generated instead, so an existing chat can't be overwritten even if participant matching fails for another reason.
3. Adds unit tests for both changes.

### Fixed Issues
<!---
1. Please postfix `$` with a URL link to the GitHub issue this Pull Request is fixing. For example, `$ https://github.com/Expensify/App/issues/<issueID>`.
2. Please postfix  `PROPOSAL:` with a URL link to your GitHub comment, which contains the approved proposal (i.e. the proposal that was approved by Expensify).  For example, `PROPOSAL: https://github.com/Expensify/App/issues/<issueID>#issuecomment-1369752925`

Do NOT add the special GH keywords like `fixed` etc, we have our own process of managing the flow.
It MUST be an entire link to the github issue and your comment proposal ; otherwise, the linking and its automation will not work as expected.

Make sure this section looks similar to this (you can link multiple issues using the same formatting, just add a new line):

$ https://github.com/Expensify/App/issues/<issueID>
$ https://github.com/Expensify/App/issues/<issueID(comment)>

Do NOT only link the issue number like this: $ #<issueID>
--->
$ https://github.com/Expensify/App/issues/102476
PROPOSAL: https://github.com/Expensify/App/issues/102476#issuecomment-5880210990


<!--- 
If you want to trigger adhoc build of hybrid app from specific Mobile-Expensify PR please link it like this:

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/<PR-number>

--->

### Tests
<!---
Add a numbered list of manual tests you performed that validates your changes work on all platforms, and that there are no regressions present.
Add any additional test steps if test steps are unique to a particular platform.
Manual test steps should be written so that your reviewer can repeat and verify one or more expected outcomes in the development environment.

For example:
1. Click on the text input to bring it into focus
2. Upload an image via copy paste
3. Verify a modal appears displaying a preview of that image
--->

1. While offline, use the main FAB to submit an expense to a new login that you have not previously chatted with.

2. Using the same login, start again from the main FAB and navigate to the confirmation page. Then, reconnect to the internet.

3. Submit a second expense.

4. Verify that the second expense is submitted to the same, correct chat report that was created for that login in Step 1, once the report has been created and synced.


- [x] Verify that no errors appear in the JS console

### Offline tests
<!---
Add any relevant steps that validate your changes work as expected in a variety of network states e.g. "offline", "spotty connection", "slow internet", etc. Manual test steps should be written so that your reviewer and QA testers can repeat and verify one or more expected outcomes. If you are unsure how the behavior should work ask for advice in the `#expensify-open-source` Slack channel.
--->

N/A

### QA Steps
<!---
Add a numbered list of manual tests that can be performed by our QA engineers on the staging environment to validate that your changes work on all platforms, and that there are no regressions present.
Add any additional QA steps if test steps are unique to a particular platform.
Manual test steps should be written so that the QA engineer can repeat and verify one or more expected outcomes in the staging environment.

For example:
1. Click on the text input to bring it into focus
2. Upload an image via copy paste
3. Verify a modal appears displaying a preview of that image

It's acceptable to write "Same as tests" if the QA team is able to run the tests in the above "Tests" section.
--->

Same as Tests.

- [x] Verify that no errors appear in the JS console

### PR Author Checklist
<!--
This is a checklist for PR authors. Please make sure to complete all tasks and check them off once you do, or else your PR will not be merged!
-->

- [x] I linked the correct issue in the `### Fixed Issues` section above
- [x] I wrote clear testing steps that cover the changes made in this PR
    - [x] I added steps for local testing in the `Tests` section
    - [x] I added steps for the expected offline behavior in the `Offline steps` section
    - [x] I added steps for Staging and/or Production testing in the `QA steps` section
    - [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    - [x] 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)
    - [x] I tested this PR with a [High Traffic account](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#high-traffic-accounts) against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
- [x] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms)
- [x] I ran the tests on **all platforms** & verified they passed on:
    - [x] Android: Native
    - [x] Android: mWeb Chrome
    - [x] iOS: Native
    - [x] iOS: mWeb Safari
    - [x] MacOS: Chrome / Safari
- [x] 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)
- [x] I followed proper code patterns (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code))
    - [x] I verified that comments were added to code that is not self explanatory
    - [x] 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.
    - [x] 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)
- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [x] I followed the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md)
- [x] 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)
- [x] If a new CSS style is added I verified that:
    - [x] A similar style doesn't already exist
    - [x] The style can't be created with an existing [StyleUtils](https://github.com/Expensify/App/blob/main/src/styles/utils/index.ts) function (i.e. `StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)`)
- [x] If new assets were added or existing ones were modified, I verified that:
    - [x] The assets are optimized and compressed (for SVG files, run `npm run compress-svg`)
    - [x] The assets load correctly across all supported platforms.
- [x] 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.
- [x] 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)
- [x] 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.
- [x] 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.
- [x] 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:
    - [x] I verified that all the inputs inside a form are aligned with each other.
    - [x] I added `Design` label and/or tagged `@Expensify/design` so the design team can review the changes.
- [x] If the PR adds or modifies the UI:
    - [x] I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    - [x] I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    - [x] I verified all new/changed elements have meaningful accessible names and roles.
    - [x] I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
- [x] I added [unit tests](https://github.com/Expensify/App/blob/main/tests/README.md) for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
- [x] 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
<details>
<summary>Android: Native</summary>

<!-- add screenshots or videos here -->

</details>

<details>
<summary>Android: mWeb Chrome</summary>

<!-- add screenshots or videos here -->

</details>

<details>
<summary>iOS: Native</summary>

<!-- add screenshots or videos here -->

</details>

<details>
<summary>iOS: mWeb Safari</summary>

<!-- add screenshots or videos here -->

</details>

<details>
<summary>MacOS: Chrome / Safari</summary>

<!-- add screenshots or videos here -->

</details>



@MelvinBot

Copy link
Copy Markdown
Contributor Author

I replaced the PR description with the verified version you shared. The Tests, Offline tests, QA Steps, and PR Author Checklist sections are now filled in and checked.

Your version did not include the ### AI Tests section, so it is no longer in the description. Let me know if you want it added back.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

BUG: Sending a expense for a phoneNumber login shows unexpected error

RF-1.mp4

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot check this bug #103195 (comment)

@MelvinBot

MelvinBot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR likely causes the phone-number error. The new lookup by login misses phone recipients, because their login is saved without the @expensify.sms suffix. That sends the draft down the new "fresh chat ID" path, which creates a second chat for a pair that already has one. The server can then reject it with "Unexpected error creating this chat."

Suggested fix: add the SMS suffix before the lookup in getParticipantsOption. addSMSDomainIfPhoneNumber is already imported in that file.

getPersonalDetailByEmail(addSMSDomainIfPhoneNumber(participant.login ?? ''))

Add a unit test: a stale accountID with login +15551234567 should resolve to a personal detail whose login is +15551234567@expensify.sms.

How it breaks
  1. When you type a phone number, getSearchValueForPhoneOrEmail returns +15551234567 with no SMS suffix. The offline expense saves the temporary personal detail with that login.
  2. After sync, the real account's login is +15551234567@expensify.sms.
  3. The new lookup in getParticipantsOption uses an exact lowercase match (PersonalDetailsStore.ts:51-56). It finds nothing, so the draft keeps the stale accountID. Email logins match exactly, which is why only phone numbers break.
  4. With the stale accountID, no existing chat is found. The existing chat's ID is already stored, so resolveOptimisticChatReportID creates a new ID. The request then builds a second chat with the same user, and the participant shows as "Hidden."

Second gap: the FAB quick-action path builds participants with an accountID but no login. The lookup can't match those drafts for email or phone recipients, and the fresh-ID path fails the same way. This matches the earlier Android failure on this PR. Normalizing phone logins doesn't fix this path. Before merging, decide whether to find the real participant from the existing stored chat, or to rethink the fresh-ID change.

Confidence: high on the client-side mechanism. I inferred the exact server rejection from an App code comment and the earlier Android run. I haven't confirmed it from the server.

Web test on PR head (c731bd2)

I couldn't view your video. My web test didn't show the "Unexpected error" text, but it did reproduce the "Hidden" recipient. The web test can't keep a draft open on the confirmation page while going back online. So I couldn't run the exact two-draft flow.

Step Status
Online: create an expense to a new phone number and reach the confirmation pageThe confirmation page showed (415) 555-0142 and $25.00.
Confirmation with new phone recipient
✅
Online: submit and check for errors"Expense added" appeared with no error. The chat and profile showed the phone number. All API calls returned HTTP 200.
Online phone expense with no error
✅
Offline: submit to a second new phone number, then go back onlineNo error message appeared. After sync, the recipient showed as "Hidden" in the report, the chat header, and the profile, and the profile had no phone number.
Offline confirmation with second phone recipient
After sync the recipient shows as Hidden
Profile shows Hidden with no phone number
❌

I didn't test whether main shows the same "Hidden" result after a single offline phone expense. It may be a separate issue that already exists.


view run · view recording

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot fix it.

A phone number typed into the participant search is stored without the @expensify.sms domain, but the canonical account's login has it, so the lookup missed phone recipients and the draft kept its stale accountID.

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I pushed a fix for the phone-number error in e0816b9. getParticipantsOption now adds the @expensify.sms domain to a phone login before it looks up the real account. A draft with a stale accountID now finds the existing chat for phone recipients too.

I also added a unit test for a phone login without the SMS domain.

Still open: the FAB quick-action path. Those drafts have an accountID but no login, so this lookup can't fix them. Please decide how you want to handle that before merging.

Checks
  • Passed: 568 tests in OptionsListUtilsTest, IOUUtilsTest, resolveChatTargetTest, useExpenseSubmission.test, and IOURequestStepConfirmationPageTest.
  • Passed: npm run typecheck, and npm run lint on both changed files.
  • Not run: npm run lint-changed failed on the shallow clone (git merge-base failed), so I ran npm run lint on the files instead. I couldn't run oxfmt or cspell here. The new ternary is wrapped because it's 201 characters on one line, which is over the 190 limit.
  • I didn't run a manual web test. The last web run couldn't keep a draft on the confirmation page while going back online.

view run

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed the failing Oxfmt check. It flagged the canonicalDetail ternary in src/libs/OptionsListUtils/index.ts:152-153. It fits within the 190-character limit, so Oxfmt wants it on one line. I pushed that change in 1c53004, and Oxfmt check now passes.

Check independent approval still fails. It clears when a reviewer approves the PR.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot the app crash on Android Native after the user signs up.

RF.mov

@MelvinBot

MelvinBot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ✅ pass

I couldn't reproduce the crash on an Android dev build of this PR (head 1c530046). A new account signed up, finished onboarding, and created an expense to a new recipient without crashing. Neither changed function runs during sign-up or onboarding, so this PR is unlikely to be the cause. I couldn't load your video. Could you share the logcat FATAL EXCEPTION stack or the Sentry event, and confirm whether the crash happens on main too?
Inbox chat with new recipient

Step Status
Sign out, sign up with a new email, finish onboarding, and wait 30 seconds on the first screen without a crashSigned up as a new user and finished onboarding. The app stayed in the foreground for 30 seconds afterwards, with no restart and no red box.
Home screen after sign-up and onboarding
✅
FAB > Create expense > amount > new email recipient > confirm without a crashCreated a $25.00 expense to a new email recipient. The new 1:1 chat showed "owes $25.00" in Inbox. No crash.
New 25 dollar expense created
Inbox chat with new recipient
✅

view run · view recording

@marufsharifi

Copy link
Copy Markdown
Contributor

Bug:

When a user sends an expense to an existing Expensify user and begins creating a second expense, the data syncs and the chat title loads, highlighting the corresponding chat in the LHN (Left-Hand Navigation). However, when the user sends the second expense, it is successfully sent to the correct chat, but the chat unexpectedly loses its highlighted (focused) state in the LHN.

RF-1.webm

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot check this bug: #103195 (comment)

@MelvinBot

MelvinBot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

I couldn't tie this bug to the PR's changes. Neither change affects which chat the LHN highlights or where the app navigates after you submit. I also couldn't reproduce it, because the automated web session got stuck on a blank page before it could start.

The LHN highlights a chat when that chat is the report open in the main pane (OptionRowLHNData.tsx:54, useCurrentReportID.tsx:76). If the highlight disappears, the main pane switched to a different report after you submitted. On this branch, the stale draft resolves to the step 1 chat, and the app navigates to that chat and adds the expense there.

There are two possible causes. Neither is confirmed:

  1. The app navigated to the expense report instead of the chat. If the confirmation page's report is the step 1 expense report, the app goes to that expense report (IOURequestStepConfirmation.tsx:731-737). P2P expense reports have no row in the LHN. This logic predates the PR. The PR only makes this flow reach it.
  2. The server swapped the step 1 chat for an existing one. Your recipient is an existing Expensify user, so the server may have returned a preexistingReportID. The main pane only moves to the new chat if /r/<chatID> is the active route (replaceOptimisticReportWithActualReport.ts:170-188). While the confirmation page is open, the active route is the confirmation page instead.

Two things would settle it:

  • Does this also happen on main? To check, start the second expense online from the same open chat. If it does, the bug predates the PR and is out of scope here.
  • What is the main-pane URL before and after the second submit? A /r/<id> that matches the chat points to cause 2. An ID that matches the expense report points to cause 1.

view run · no recording available

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot, but it works on latest main.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

You're right. I was wrong that this PR can't affect navigation. The second change (the "taken ID" check) can send the expense to a new chat ID while the app still opens the old one, so the highlight is lost.

Likely cause: the app picks two chat IDs separately from the same reserved ID (transaction.reportID):

The server then merges the fresh chat into the real chat, so the expense lands in the right place. But the app only moves the main pane to the real chat if the merged chat is the one on screen (replaceOptimisticReportWithActualReport.ts:170). The fresh chat was never on screen, so the pane stays on the old ID, which has no LHN row.

On main, both IDs are the same, so the redirect works and the highlight follows.

Proposed fix: run the "taken ID" check once, on the confirmation page. If the reserved ID is taken and no chat matches, save a fresh ID to transaction.reportID. Navigation and the write then use the same ID. I'd also add a test that checks the two IDs match.

Confidence and open questions

Medium confidence. This comes from reading the code. I didn't reproduce it. Two things are still unconfirmed:

  • Why the chat lookup still misses after the first change resolves the real accountID.
  • Why the old chat ID still has a report row when you submit.

The main-pane URL before and after the second submit would confirm it. If this is the cause, it should stay on the old chat's /r/<id> while the LHN row shows a different ID.


Reply with @MelvinBot implement the fix and I'll push it to this PR.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot fix it.

…ortID

When the reserved chat ID already belonged to a stored report, the submission hooks built the new chat under a fresh ID while the confirmation screen still opened the reserved ID. The preexisting-chat redirect only follows the chat that is on screen, so the user stayed on a report with no LHN row and the chat lost its highlight. The stale-accountID fix in getParticipantsOption already lets the existing chat be found, so the reserved ID is reused again, matching main.

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I pushed a fix in fbb892fc. It removes the PR's second change, the "taken ID" check in resolveOptimisticChatReportID. That check moved the expense to a fresh chat ID while the screen stayed on the old one, so the chat lost its LHN highlight. This code path now matches main, where you saw it work.

The first change (resolving the stale accountID by login) stays. It's the part that lets the existing chat be found.

Please retest the highlight case and the original test steps.

Why I didn't use the fix I proposed

I first tried what I proposed earlier: swapping in a fresh ID on the confirmation page. It broke two existing tests in IOURequestStepConfirmationPageTest.tsx, because changing the draft's ID also changes which report the expense goes to. Removing the check is smaller and safer.

The trade-off: the PR no longer has the extra guard against overwriting an existing chat if participant matching fails for some other reason. I also updated the PR description so it no longer mentions that change.

Checks: IOUUtilsTest, resolveChatTargetTest, useExpenseSubmission.test, and IOURequestStepConfirmationPageTest pass (212 tests), and typecheck and lint pass. I didn't run the flow in the app.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot the original flow doesn't work now. carefully update to not break everything.

1.mov

…o a stale optimistic accountID can be resolved

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Merge the main.

…PParticipantAccountID

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Merged the latest main into this branch and pushed it (80836f0). There were no conflicts. The PR diff is unchanged: 10 files, all from this PR.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot resolve the conflicts.

…PParticipantAccountID

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>

# Conflicts:
#	src/hooks/useDefaultParticipants.ts
@MelvinBot
MelvinBot dismissed stale reviews from carlosmiceli and garrettmknight via 1a19fce October 27, 2026 06:05
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I merged main into this branch and resolved the conflicts in 1a19fce.

The only conflict was in src/hooks/useDefaultParticipants.ts:

  • I kept main's version without useMemo, since React Compiler now handles memoization.
  • I kept this PR's change, which reads source-report participants with getMoneyRequestDraftParticipantsFromReport.

Git merged the other files on its own. The useResetIOUType and OptionsListUtils unit tests pass (381 of 381). Typecheck shows no errors in this PR's files. I couldn't run lint here because it timed out in this environment, so CI will run it.

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Merge the main.

…PParticipantAccountID

Co-authored-by: Maruf Sharifi <marufsharifi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I merged main into this branch and pushed it in 70870a5. The merge had no conflicts.


view run

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Resolve the conflicts

…PParticipantAccountID

# Conflicts:
#	src/libs/actions/IOU/MoneyRequest.ts
#	src/pages/iou/request/step/IOURequestStepConfirmation/index.tsx
#	tests/actions/IOU/MoneyRequestSettersTest.ts
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflicts with main in b4d21f2. The PR is now mergeable.

All three conflicts were import lists where both sides added names. I kept both sides:

main's changes to these files (copying scan results to a moved expense draft, and the pre-mount check for Pay) don't touch the PR's participant-sync logic. I couldn't run lint, typecheck, or Jest in this environment, so CI will confirm them.

@marufsharifi

Copy link
Copy Markdown
Contributor

doing another round of test.

@carlosmiceli

Copy link
Copy Markdown
Contributor

@garrettmknight all yours

@marufsharifi

Copy link
Copy Markdown
Contributor

LGTM

@marufsharifi

Copy link
Copy Markdown
Contributor

@garrettmknight, could you please take a look at this pr when you get a chance. thanks.

@garrettmknight

Copy link
Copy Markdown
Contributor

Still looks good, merge away!

@carlosmiceli
carlosmiceli merged commit acef1c1 into main Nov 2, 2026
45 of 46 checks passed
@carlosmiceli
carlosmiceli deleted the claude-resolveStaleP2PParticipantAccountID branch November 2, 2026 21:48
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@OSBotify OSBotify mentioned this pull request Nov 3, 2026
99 tasks done
@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.5.31-0 🚀

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

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.5.31-0 🚀

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

@MelvinBot

MelvinBot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

No help site update needed — this PR restores expected expense and recipient behavior after offline syncing without changing documented workflows.

@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀

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

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants