Skip to content

[Due for payment 2025-05-22] [$250] When starting a new chat via global create, we are calling OpenReport twice. #61285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 of 16 tasks
m-natarajan opened this issue May 2, 2025 · 17 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@m-natarajan
Copy link

m-natarajan commented May 2, 2025

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.1.38-3
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @iwiznia
Slack conversation (hyperlinked to channel name): #Quality

Action Performed:

  1. Open network tab
  2. Click big + button
  3. Start chat
  4. Select any user from the list (does not matter if you have a chat already with them or not)

Expected Result:

Only one Open report call

Actual Result:

There are 2 OpenReport calls (the parameters are different, but the reportID is the same and we should not need 2 calls)

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Recording.1175.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021918305693515707842
  • Upwork Job ID: 1918305693515707842
  • Last Price Increase: 2025-05-02
  • Automatic offers:
    • ikevin127 | Reviewer | 107183589
Issue OwnerCurrent Issue Owner: @trjExpensify
@m-natarajan m-natarajan added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels May 2, 2025
Copy link

melvin-bot bot commented May 2, 2025

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@bernhardoj
Copy link
Contributor

bernhardoj commented May 2, 2025

🚨 Edited by proposal-police: This proposal was edited at 2025-05-03 04:01:13 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

When starting a new chat from new chat page, OpenReport is called twice.

What is the root cause of that problem?

When we select a user from the new chat page, we call the openReport.

openReport(report?.reportID, '', userLogins, newChat, undefined, undefined, undefined, avatarFile);

Then, another openReport is called when the report screen is mounted.

useEffect(() => {
// This function is triggered when a user clicks on a link to navigate to a report.
// For each link click, we retrieve the report data again, even though it may already be cached.
// There should be only one openReport execution per page start or navigating
fetchReport();
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [route, isLinkedMessagePageReady, reportActionIDFromRoute]);

What changes do you think we should make in order to solve the problem?

First, in navigateToAndOpenReport, we should only call the openReport if we are creating a new chat. So, we need to move the openReport to inside the if block.

App/src/libs/actions/Report.ts

Lines 1327 to 1341 in 62a49d2

if (isEmptyObject(chat)) {
if (isGroupChat) {
// If we are creating a group chat then participantAccountIDs is expected to contain currentUserAccountID
newChat = buildOptimisticGroupChatReport(participantAccountIDs, reportName ?? '', avatarUri ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
} else {
newChat = buildOptimisticChatReport({
participantList: [...participantAccountIDs, currentUserAccountID],
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
});
}
}
const report = isEmptyObject(chat) ? newChat : chat;
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(report?.reportID, '', userLogins, newChat, undefined, undefined, undefined, avatarFile);

This aligns the logic with opening a thread.

App/src/libs/actions/Report.ts

Lines 1384 to 1415 in 62a49d2

function navigateToAndOpenChildReport(childReportID: string | undefined, parentReportAction: Partial<ReportAction> = {}, parentReportID?: string) {
const childReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${childReportID}`];
if (childReport?.reportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID));
} else {
const participantAccountIDs = [...new Set([currentUserAccountID, Number(parentReportAction.actorAccountID)])];
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`];
// Threads from DMs and selfDMs don't have a chatType. All other threads inherit the chatType from their parent
const childReportChatType = parentReport && isSelfDM(parentReport) ? undefined : parentReport?.chatType;
const newChat = buildOptimisticChatReport({
participantList: participantAccountIDs,
reportName: ReportActionsUtils.getReportActionText(parentReportAction),
chatType: childReportChatType,
policyID: parentReport?.policyID ?? CONST.POLICY.OWNER_EMAIL_FAKE,
ownerAccountID: CONST.POLICY.OWNER_ACCOUNT_ID_FAKE,
oldPolicyName: parentReport?.policyName ?? '',
notificationPreference: getChildReportNotificationPreference(parentReportAction),
parentReportActionID: parentReportAction.reportActionID,
parentReportID,
optimisticReportID: childReportID,
});
if (!childReportID) {
const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(Object.keys(newChat.participants ?? {}).map(Number));
openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID);
} else {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${childReportID}`, newChat);
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(newChat.reportID));
}
}

(we can apply the same fix to navigateToAndOpenReportWithAccountIDs if needed)

Opening an existing chat will now trigger 1 openReport from ReportScreen. But for new chat, openReport is still called twice, and the fix is the same as in my proposal here.

We can prevent that by skipping the openReport in ReportScreen when the report is optimistic.

const fetchReport = useCallback(() => {
const moneyRequestReportActionID: string | undefined = route.params?.moneyRequestReportActionID;
const transactionID: string | undefined = route.params?.transactionID;
// When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the transaction thread created yet
// so we have to call OpenReport in a way that the transaction thread will be created and attached to the parentReportAction
if (transactionID && currentUserEmail) {
openReport(reportIDFromRoute, '', [currentUserEmail], undefined, moneyRequestReportActionID, false, [], undefined, undefined, transactionID);
return;
}
openReport(reportIDFromRoute, reportActionIDFromRoute);
}, [route.params?.moneyRequestReportActionID, route.params?.transactionID, reportIDFromRoute, reportActionIDFromRoute, currentUserEmail]);

if (reportMetadata.isOptimisticReport) {
    return;
}

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

We can test calling navigateToAndOpenReport with a case where the report exists and doesn't exist, and assert that the openReport is only called when it's a new report.

@trjExpensify
Copy link
Contributor

Report so good @iwiznia, we open it twice.

@trjExpensify trjExpensify added the External Added to denote the issue can be worked on by a contributor label May 2, 2025
@melvin-bot melvin-bot bot changed the title When starting a new chat via global create, we are calling OpenReport twice. [$250] When starting a new chat via global create, we are calling OpenReport twice. May 2, 2025
Copy link

melvin-bot bot commented May 2, 2025

Job added to Upwork: https://www.upwork.com/jobs/~021918305693515707842

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label May 2, 2025
Copy link

melvin-bot bot commented May 2, 2025

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (External)

@ikevin127
Copy link
Contributor

ikevin127 commented May 2, 2025

@bernhardoj Thanks for the proposal. While RCA makes sense, unfortunately the solution is incomplete, calling OpenReport once only for existing chats which does not fulfil our issue's Expected result which states that the OpenReport should only be called once for new chats as well as existing chats (I assume).

We can either add shouldFetchReport back, check only for reportMetadata.isOptimisticReport, or add a new field to reportMetadata to skip the open report. I prefer the 3rd one.

⚠️ This is pretty vague ☝ resulting in not being able to figure out / put together the suggested solution changes for navigateToAndOpenReportWithAccountIDs which you proposed in another issue. Please provide a complete solution for this issue which I'll be able to implement, test and validate whether it fixes this issue 👍

@bernhardoj
Copy link
Contributor

Updated my proposal.

@ikevin127
Copy link
Contributor

Thanks for the update!

@bernhardoj's updated proposed solution works now, eliminates second OpenReport call when opening both existing chats and new chats.

⚠️ The only issue I experienced while testing on develop (doesn't happen on staging / production) is that sometimes, in the New chat field, when we add an email of an existing account (Hidden), the profile is not fetched (default avatar) and when we open a new chat with that account, there seems to be a second OpenReport call.

Develop issue
Screen.Recording.2025-05-03.at.12.54.08.mov

☝ Given that this is a rare occurance and the existing account not being fetched seems to only happen on develop, I'd say let's move forward with the fix and perform further testing during PR phase.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented May 3, 2025

Triggered auto assignment to @Julesssss, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@Julesssss
Copy link
Contributor

The develop issues sounds a bit worrying. We'll need to fully understand that before merging. But lets move forward with the proposed fix.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label May 5, 2025
Copy link

melvin-bot bot commented May 5, 2025

📣 @ikevin127 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@bernhardoj
Copy link
Contributor

PR is ready

cc: @ikevin127

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels May 6, 2025
@Julesssss
Copy link
Contributor

PR merged, awaiting deployment

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels May 15, 2025
@melvin-bot melvin-bot bot changed the title [$250] When starting a new chat via global create, we are calling OpenReport twice. [Due for payment 2025-05-22] [$250] When starting a new chat via global create, we are calling OpenReport twice. May 15, 2025
Copy link

melvin-bot bot commented May 15, 2025

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 15, 2025
Copy link

melvin-bot bot commented May 15, 2025

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.45-21 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-05-22. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented May 15, 2025

@ikevin127 @trjExpensify @ikevin127 The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@ikevin127
Copy link
Contributor

ikevin127 commented May 16, 2025

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
  • 2b. Reported on staging (eg. found during regression or PR testing)
  • 2d. Reported on a PR
  • 2z. Other:

Who reported the bug:

  • 3a. Expensify user
  • 3b. Expensify employee
  • 3c. Contributor
  • 3d. QA
  • 3z. Other:
  • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

    Link to comment: Wasn't able to identify offending PR.

  • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

    Link to discussion: N/A

  • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

  • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

    Link to issue:

Regression Test Proposal

  1. Open the inspect element and switch to the Network tab.
  2. Press FAB > Start chat.
  3. Select an existing chat.
  4. Verify that only 1 OpenReport is called in the Network tab.
  5. Press FAB > Start chat.
  6. Search for a new user and select it.
  7. Verify that only 1 OpenReport is called in the Network tab.

Do we agree 👍 or 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
Status: LOW
Development

No branches or pull requests

5 participants