Skip to content

Conversation

@rayane-d
Copy link
Contributor

@rayane-d rayane-d commented Nov 13, 2025

Explanation of Change

Auth PR:

Fixed Issues

$ #74846
PROPOSAL:

Tests

Test 1 — Optimistically created transaction thread with a one-expense parent report

Goal:

Verify that when the parent IOU report contains only one transaction, any optimistically created transaction thread is discarded when the transaction thread already exists and the user is redirected back to the parent one-expense report.


Steps
  1. Create an account and a workspace.

  2. Open the workspace chat.

  3. Create an expense.

  4. Enable debug mode.

  5. Open the expense.

  6. Tap the header → open the debug menu.

  7. Tap Actions.

  8. Open the IOU action.

  9. Copy the reportActionID.

  10. Copy the reportID.

  11. Copy the childReportID (the existing transaction thread).

  12. Go offline.

  13. Run the following snippet after replacing the IDs:

    Onyx.merge('reportActions_<reportID from step 10>', {
        "<reportActionID from step 9>": {
            childReportID: null
        }
    });
  14. Open the workspace chat.

  15. Open the expense report.

  16. Open the debug menu again (header → debug).

  17. Tap Actions.

  18. Open the IOU action.

  19. Copy the newly created optimistic childReportID.

  20. Replace the URL's report ID with the ID from step 21.

  21. Confirm that a new transaction thread opens (may be greyed out) that has a report ID different than the report ID from step 11.

  22. Type some text in the composer without sending it (draft message).

  23. Run the following snippet to simulate OpenReport response:

      Onyx.update([
          {
              onyxMethod: "merge",
              key: "report_<reportID from step 21>",
              value: {
                  "reportID": "<reportID from step 21>",
                  "preexistingReportID": "<reportID from step 11>"
              }
          }
      ]);
  24. Confirm that you are automatically redirected to the parent one-expense report (reportID from step 10).

  25. Confirm the draft message from step 24 is moved to the parent one-expense report.

  26. Confirm that the Onyx data of the optimistic report from step 21 is deleted

  27. Confirm that the childReportID of the IOU report action points to the correct report ID (reportID from step 10)

  28. Go back online

  29. Confirm that OpenReport is called again for the parent report (the one expense report) (reportID from step 10).

Screen.Recording.2025-12-17.at.1.18.14.PM.mov
ios.mov

Test 2 — Optimistically created transaction thread in a multi-expense parent report, with existing transaction thread

Goal:

Verify that when the IOU report has multiple expenses, and the App try to create an optimistic transaction thread for an existing transaction thread, the user is redirected to the correct existing transaction thread, and the draft message is preserved.


Steps
  1. Create an account and a workspace.

  2. Open the workspace chat.

  3. Create two expenses.

  4. Enable debug mode.

  5. Open the IOU report.

  6. Copy the reportID

  7. Open each of the two expenses so that a transaction thread report is created

  8. Open the IOU report.

  9. Tap the header → open debug menu.

  10. Tap Actions.

  11. Open one of the IOU actions (choose one expense).

  12. Copy the reportActionID.

  13. Copy the childReportID (existing transaction thread).

  14. Go offline.

  15. Open the browser console.

  16. Run:

    Onyx.merge('reportActions_<reportID from step 6>', {
        "<reportActionID from step 12>": {
            childReportID: null
        }
    });
  17. Open the workspace chat.

  18. Open the IOU report.

  19. Open the expense selected in step 11.

  20. Confirm that a new optimistic transaction thread (may be greyed out) is created that has a report ID different than the report ID from step 13.

  21. Copy the optimistic transaction thread's report ID.

  22. Type some text in the composer without sending it (draft message).

  23. Run the following snippet to simulate OpenReport response:

      Onyx.update([
            {
                onyxMethod: "merge",
                key: "report_<reportID from step 23>",
                value: {
                    "reportID": "<reportID from step 23>",
                    "preexistingReportID": "<report ID from step 13>"
                }
            }
        ]);
  24. Confirm automatic redirection to the correct transaction thread (ID = step 13).

  25. Confirm the draft message from step 24 appears in the correct thread (ID = step 13).

  26. Confirm that the Onyx data of the optimistic report (report ID from step 23) is deleted

  27. Confirm that the childReportID of the IOU report action points to the correct report ID (reportID from step 13)

  28. Go back online

  29. Confirm that OpenReport is called again for preExistingReportID (report ID from step 13).

Screen.Recording.2025-11-20.at.12.32.46.AM.mov
Screen.Recording.2025-12-17.at.12.08.28.PM.mov

Test 3 — Optimistically created thread under a comment, but an existing thread exists

Goal:

Verify that when the App tries to create an optimistic thread report under a comment, and a thread report already exists, the App redirects to the correct thread and transfers the draft message.


Steps
  1. Create an account and a workspace.

  2. Open the workspace chat.

  3. Send a message.

  4. Right-click the message → Reply in thread.

  5. Send a message in the thread.

  6. Enable debug mode.

  7. Return to the workspace chat.

  8. Copy the workspace chat reportID

  9. Tap header → debug menu.

  10. Tap Actions.

  11. Open the ADDCOMMENT action for the message from step 3.

  12. Copy the reportActionID.

  13. Copy the childReportID (existing thread).

  14. Go offline.

  15. Run:

    Onyx.merge('reportActions_<reportID from step 8>', {
        "<reportActionID from step 12>": {
            childReportID: null
        }
    });
  16. Open the workspace chat.

  17. Click the original message (step 3) to open the thread.

  18. Confirm that a new optimistic transaction thread (may be greyed out) is created that has a report ID different than the report ID from step 13.

  19. Copy the optimistic thread's report ID.

  20. Type a draft message in the composer without sending it.

  21. Run the following snippet to simulate OpenReport response:

        Onyx.update([
              {
                  onyxMethod: "merge",
                  key: "report_<reportID from step 19>",
                  value: {
                      "reportID": "<reportID from step 19>",
                      "preexistingReportID": "<report ID from step 13>"
                  }
              }
          ]);
  22. Confirm automatic redirection to the correct thread (reportID form step 13).

  23. Confirm the draft message from step 20 is restored in the correct thread (reportID from step 13).

  24. Confirm that the Onyx data of the optimistic report from step 19 is deleted

  25. Confirm that the childReportID of the IOU report action from step 11 points to the correct report ID (reportID from step 13)

  26. Go back online

  27. Confirm that OpenReport is called again for preExistingReportID (reportID from step 13).

Untitled1.mov
Screen.Recording.2025-12-17.at.11.58.04.AM.mov
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as the tests, but QA should only test on the web platform. QA will only be able to properly test this on mobile platforms after the Auth PR has been merged and deployed.

  • 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
    • MacOS: Desktop
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

Tested with backend changes:

Screen.Recording.2025-11-14.at.10.01.42.PM.mov
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

@codecov
Copy link

codecov bot commented Nov 13, 2025

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/ReportUtils.ts 72.13% <ø> (-0.07%) ⬇️
src/libs/actions/Report/index.ts 58.00% <ø> (-0.13%) ⬇️
...actions/replaceOptimisticReportWithActualReport.ts 100.00% <100.00%> (+33.89%) ⬆️
...ReportActionCompose/SilentCommentUpdater/index.tsx 87.50% <100.00%> (+1.78%) ⬆️
...omposerWithSuggestions/ComposerWithSuggestions.tsx 58.78% <50.00%> (-0.12%) ⬇️
... and 9 files with indirect coverage changes

@rayane-d rayane-d requested a review from mountiny November 14, 2025 15:06
@rayane-d
Copy link
Contributor Author

Asking about the test failure here:
https://expensify.slack.com/archives/C08CZDJFJ77/p1763135674647879

@rayane-d rayane-d changed the title Handle the preExistingReportID for transaction threads and single expense reports Handle the preExistingReportID for transaction threads, messages threads, and single expense reports Nov 14, 2025
@rayane-d rayane-d changed the title Handle the preExistingReportID for transaction threads, messages threads, and single expense reports Handle the preExistingReportID for transaction threads, message threads, and single expense reports Nov 14, 2025
@rayane-d rayane-d changed the title Handle the preExistingReportID for transaction threads, message threads, and single expense reports [Hold Auth #18234] Handle the preExistingReportID for transaction threads, message threads, and single expense reports Nov 14, 2025
@rayane-d rayane-d marked this pull request as draft January 28, 2026 13:43
@rayane-d
Copy link
Contributor Author

@rayane-d This is becoming harder to reproduce due to new data being added to OpenApp. So first in Auth, comment the line that adds collectSearchTodosData. Revert App fix then do the following:

  1. Create empty report
  2. Add expense
  3. Open expense and copy its report id
  4. Clear cache
  5. Open https://dev.new.expensify.com:8082/r/IDHERE

Screen.Recording.2026-01-23.at.4.11.38.PM.mov

The problem with pendingAction and isOptimisticAction is that we typically clear them after the request is done (in successData) so that info is lost. For this one, maybe we could set isOptimisticAction and just don't unset it, adding a comment explaining why, still feels hacky though. We could add another field e.g. isCreatedOptimistically but that seems to be an overkill.

@s77rt - could you please check this Auth side fix for clearing the optimistic IOU report action: https://github.com/Expensify/Auth/pull/19610? What do you think about this BE solution? Can we rely on it instead of the logic added in the App PR #79356?

@s77rt
Copy link
Member

s77rt commented Jan 29, 2026

@rayane-d I feel like the preexistingReportID logic should be enough and we should fix this in the frontend still. I prefer that we rely on the isOptimisticAction in frontend to decide whether we should update report action or delete it, rather then moving this the backend, mainly because it's not the responsibility of the backend, data that is created in frontend only should be cleared by the frontend.

@rayane-d
Copy link
Contributor Author

rayane-d commented Jan 29, 2026

@s77rt I've used isOptimisticAction attribute to track the optimistic IOU report action and clear it in the preExistingReportID logic. I've also added automated tests. Could you please take a look and confirm whether this still covers the bug fixed in this PR? Thanks!

@rayane-d rayane-d marked this pull request as ready for review January 29, 2026 23:20
@rayane-d
Copy link
Contributor Author

could you please add test cases for these cases:

  1. should transfer draft comment to preexisting report when the user is not on the report
  2. should transfer draft comment to parent report for one-transaction report
  3. should clear optimistic report draft comment after transfer
  4. should handle preexistingReportID for DM/group-DM (no parent action) and preserve participants
  5. should merge preexisting report data correctly

I've added these test cases.

@mountiny
Copy link
Contributor

@codex review

@rayane-d rayane-d requested a review from mountiny January 29, 2026 23:25
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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

ℹ️ 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 +109 to +112
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${preexistingReportID}`, {
...report,
reportID: preexistingReportID,
preexistingReportID: null,

Choose a reason for hiding this comment

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

P2 Badge Preserve existing thread report fields when replacing optimistic

When a preexisting thread is detected, this branch replaces the existing report with the optimistic report object via Onyx.set. Optimistic thread reports are created with only a minimal field set (see setOptimisticTransactionThread in src/libs/actions/Report/index.ts), so overwriting here drops existing fields like participants, reportName, and other metadata on the preexisting thread. In the preexisting-thread scenario this can leave the UI missing avatars/header info after the switch. Consider merging into the existing report or preserving its fields (similar to the DM path) instead of replacing it.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rayane-d What do you think of this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mountiny - I don't agree with the bot comment. When the backend returns preexistingReportID, we usually don't have Onyx data for the preexisting report yet, so there's nothing to merge into. In this case, we should create the report using Onyx.set with the optimistic report data. After that, OpenReport will be called again with the preexisting report ID, and the backend will return the full report data to update it.

@s77rt
Copy link
Member

s77rt commented Jan 30, 2026

@rayane-d I was not able to reproduce using last repro steps but since the logic to clear the optimistic iOU action is there then we should be fine.

@rayane-d
Copy link
Contributor Author

@s77rt Thanks for confirming!

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ 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".

@mountiny
Copy link
Contributor

mountiny commented Feb 2, 2026

Code Review Observations

Thanks for the detailed PR! I've reviewed the changes and have a few observations:


1. Potential Race Condition in SilentCommentUpdater

File: src/pages/inbox/report/ReportActionCompose/SilentCommentUpdater/index.tsx

The isTransitioningToPreExistingReport ref is checked in the effect with the condition:

if (isTransitioningToPreExistingReport.current && reportID !== prevReportId) {
    onTransitionToPreExistingReportComplete();
    return;
}

This condition only triggers when the reportID prop changes. However, during the transition sequence:

  1. isTransitioningToPreExistingReport.current is set to true in ComposerWithSuggestions
  2. The draft is saved to the new report
  3. The callback clears the optimistic report
  4. The component may re-render before reportID prop actually changes

Suggestion: Consider adding a test case that verifies the timing of isTransitioningToPreExistingReport.current being set and cleared relative to the Onyx updates, to ensure no edge case can cause the draft to be overwritten.


2. Explicit Null Check for parentReportActionID

File: src/libs/actions/replaceOptimisticReportWithActualReport.ts

The current code around line 108 checks parentReportID but relies on optional chaining for parentReportActionID:

const parentReportAction = parentReportID ? allReportActions?.[parentReportID]?.[parentReportActionID] : null;

For improved clarity and safety, consider making both checks explicit:

const parentReportAction = (parentReportID && parentReportActionID) 
    ? allReportActions?.[parentReportID]?.[parentReportActionID] 
    : null;

This makes the intent clearer and ensures both IDs are present before attempting the lookup.


3. Verify isOptimisticAction Flag Cleanup in Success Handlers

File: src/libs/actions/Report/index.ts

The new code adds isOptimisticAction: true to the optimistic IOU action:

...optimisticIOUAction,
childReportID: reportID,
isOptimisticAction: true,

I see that in other parts of the codebase, success handlers clear this flag:

successReportActions[actionKey] = {pendingAction: null, isOptimisticAction: null};

Question: Could you verify that the success handler for this specific action path (when OpenReport succeeds after creating the transaction thread) also clears the isOptimisticAction flag? If the flag persists after a successful API response, it could affect logic that checks for optimistic actions (e.g., in PureReportActionItem.tsx where action.isOptimisticAction affects pending state display).


Overall the PR looks solid with great test coverage! These are just some observations for consideration.

@mountiny
Copy link
Contributor

mountiny commented Feb 2, 2026

Some nice opus observations @rayane-d

@grgia grgia merged commit 32687ce into Expensify:main Feb 2, 2026
36 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Feb 2, 2026

✋ 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
Copy link
Contributor

OSBotify commented Feb 3, 2026

🚀 Deployed to staging by https://github.com/grgia in version: 9.3.11-19 🚀

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants