Skip to content
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

[HOLD for payment 2023-11-21] [$500] LHN - Money Request removal offline doesn't update LHN correctly #28941

Closed
6 tasks done
kbecciv opened this issue Oct 5, 2023 · 52 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kbecciv
Copy link

kbecciv commented Oct 5, 2023

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


Action Performed:

  1. Open a chat with user B
  2. Request money
  3. Go offline
  4. Open the newly created money request report
  5. Delete the request

Expected Result:

In the LHN, the chat with user B should show the last visible message

Actual Result:

In the LHN, the chat with user B shows " owes " until going back online

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.78.0
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
Notes/Photos/Videos: Any additional supporting documentation

ios.1.mov
android.1.mov
desktop.2.mov
safari.MP4
chrome.MP4
272100142-18604d4d-3bc9-4507-893a-d5d2204648e3.mp4
Recording.4879.mp4

Expensify/Expensify Issue URL:
Issue reported by: @paultsimura
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1696501720522399

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e4ad059b092f74b3
  • Upwork Job ID: 1709994082221408256
  • Last Price Increase: 2023-10-12
  • Automatic offers:
    • tienifr | Contributor | 27265296
    • paultsimura | Reporter | 27265299
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 5, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot changed the title LHN - Money Request removal offline doesn't update LHN correctly [$500] LHN - Money Request removal offline doesn't update LHN correctly Oct 5, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 5, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

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

@paultsimura
Copy link
Contributor

paultsimura commented Oct 5, 2023

Proposal

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

Once IOU report is deleted, the parent report's last message is not updated in LHN

What is the root cause of that problem?

When deleting a Money Request, if it's the last request in the IOU report, we optimistically update the parent report:

App/src/libs/actions/IOU.js

Lines 1567 to 1580 in 1663440

...(shouldDeleteIOUReport
? [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
value: {
hasOutstandingIOU: false,
iouReportID: null,
lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).lastMessageText,
lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).created,
},
},
]
: []),

We explicitly tell the ReportActionsUtils.getLastVisibleMessage to ignore the "IOU Preview" action: {[parentReportAction.reportActionID]: null}
However, this null is ignored here, the change was introduced by #26447, the null scenario was not ignored before:

function getLastVisibleAction(reportID, actionsToMerge = {}) {
const updatedActionsToMerge = {};
if (actionsToMerge && Object.keys(actionsToMerge).length !== 0) {
Object.keys(actionsToMerge).forEach(
(actionToMergeID) => (updatedActionsToMerge[actionToMergeID] = {...allReportActions[reportID][actionToMergeID], ...actionsToMerge[actionToMergeID]}),
);
}

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

If the actionsToMerge contains explicit null, we should set the corresponding updatedActionsToMerge key to null instead of using the spread operator:

    if (actionsToMerge && Object.keys(actionsToMerge).length !== 0) {
        Object.keys(actionsToMerge).forEach(
-           (actionToMergeID) => (updatedActionsToMerge[actionToMergeID] = {...allReportActions[reportID][actionToMergeID], ...actionsToMerge[actionToMergeID]}),
+           (actionToMergeID) => (updatedActionsToMerge[actionToMergeID] = lodashIsNull(actionsToMerge[actionToMergeID]) ? null : {...allReportActions[reportID][actionToMergeID], ...actionsToMerge[actionToMergeID]}),
        );
    }

And also, for better code reuse, in IOU.deleteMoneyRequest we should consider passing {[reportPreviewAction.reportActionID]: updatedReportPreviewAction} (as a param to ReportActionsUtils.getLastVisibleMessage and ReportActionsUtils.getLastVisibleAction) instead of {[reportPreviewAction.reportActionID]: null}, as the updatedReportPreviewAction is already null in this scenario.

    // STEP 5: Build Onyx data
+   const optimisticChatReportActions = {[reportPreviewAction.reportActionID]: updatedReportPreviewAction};

    const optimisticData = [
        ......
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`,
-           value: {
-               [reportPreviewAction.reportActionID]: updatedReportPreviewAction,
-           },
+           value: optimisticChatReportActions,
        },
        ...(shouldDeleteIOUReport
            ? [
                  {
                      onyxMethod: Onyx.METHOD.MERGE,
                      key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
                      value: {
                          hasOutstandingIOU: false,
                          iouReportID: null,
-                         lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).lastMessageText,
-                         lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).created,
+                         lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, optimisticChatReportActions).lastMessageText,
+                         lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport.chatReportID, optimisticChatReportActions).created,
                      },
                  },
              ]
            : []),
    ];

Result:

iou-delete-offline.mov

What alternative solutions did you explore? (Optional)

We can alternatively leave the ReportActionsUtils.getLastVisibleAction logic untouched and pass some dummy "invisible" action instead of null. Like an action with message.html: '', but that's not a preferable approach.

@tienifr
Copy link
Contributor

tienifr commented Oct 6, 2023

Proposal

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

LHN - Money Request removal offline doesn't update LHN correctly

What is the root cause of that problem?

After deleting the request money action, we update the lastMessageText of parent report

lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).lastMessageText,

As we're passing {[reportPreviewAction.reportActionID]: null} to getLastVisibleMessage

In getLastVisibleMessage function, we merge the actionsToMerge with allReportActions[reportID]

function getLastVisibleAction(reportID, actionsToMerge = {}) {
const updatedActionsToMerge = {};
if (actionsToMerge && Object.keys(actionsToMerge).length !== 0) {
Object.keys(actionsToMerge).forEach(
(actionToMergeID) => (updatedActionsToMerge[actionToMergeID] = {...allReportActions[reportID][actionToMergeID], ...actionsToMerge[actionToMergeID]}),
);
}
const actions = Object.values({
...allReportActions[reportID],
...updatedActionsToMerge,
});

but actionsToMerge[actionToMergeID] is null -> it will be ignored

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

we need to merge 2 objects to achieve the final objects, so we should do the same as onyx

implement mergeObject like what we did in onyx so we can remove the redundant code avoid the future inconsistency bug

function getLastVisibleAction(reportID, actionsToMerge = {}) {
    const actions = Object.values(mergeObject(
        allReportActions[reportID],
        actionsToMerge,
    ));

Result

Screen.Recording.2023-10-06.at.15.25.47.mov

@melvin-bot melvin-bot bot added the Overdue label Oct 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

@burczu, @dylanexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

@dylanexpensify
Copy link
Contributor

@burczu can we review these soon? 🙇‍♂️

@melvin-bot melvin-bot bot removed the Overdue label Oct 9, 2023
@dylanexpensify
Copy link
Contributor

bump @burczu

@burczu
Copy link
Contributor

burczu commented Oct 11, 2023

@dylanexpensify Ahh, sorry - I've missed this one... I'll take a look today!

@burczu
Copy link
Contributor

burczu commented Oct 11, 2023

@paultsimura Just to note, posting code diffs in proposals is not allowed.

@paultsimura
Copy link
Contributor

@burczu it was discussed multiple times recently and the agreement was that the proposal must not consist only of code diffs, but the code diffs are welcomed as they help describing the changes:

Just keep it within reason. We made that guideline because:
people would post a whole PR in a comment 🤦
they would not post anything else but the code. everyone has to work harder to understand the changes.

https://expensify.slack.com/archives/C01GTK53T8Q/p1694106505333079

@burczu
Copy link
Contributor

burczu commented Oct 11, 2023

@paultsimura Alright! Thanks for pointing this out ;)

@burczu
Copy link
Contributor

burczu commented Oct 11, 2023

@paultsimura and @tienifr I've just tested your solutions and they both works until we go back online. Please see what happens after that:

Screen.Recording.2023-10-11.at.10.47.36.mov

I think this should be also handled in this issue.

@tienifr
Copy link
Contributor

tienifr commented Oct 11, 2023

@burczu After dig deeper on Onyx implementation, I found out that:

  1. Users action 2 request (RequestMoney and DeleteMoney) in offline mode
  2. When they go online BE will return the result in the right order, the first one (RequestMoney) contain the onyx merge data (new chat) and the second one contain the onyx set (set new chat to null)
  3. All these onyx actions are performed async here
  4. But the set action is faster than merge so the report is set to null before merge action is finished
    That why we still can see the new report

Here is the result if I perform the onyx actions sequentially

Screen.Recording.2023-10-11.at.18.45.36.mp4

I think it's out of this scope (The expectation is In the LHN, the chat with user B should show the last visible message) and even depend on the engineer design

@melvin-bot
Copy link

melvin-bot bot commented Oct 12, 2023

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Oct 13, 2023
@dylanexpensify
Copy link
Contributor

@burczu mind replying to the above? 🙇‍♂️

@melvin-bot melvin-bot bot removed the Overdue label Oct 16, 2023
@burczu
Copy link
Contributor

burczu commented Oct 17, 2023

@dylanexpensify I'm sorry, I was busy reviewing PR's - I'll get back to checking proposals soon.

Copy link

melvin-bot bot commented Nov 14, 2023

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

Copy link

melvin-bot bot commented Nov 14, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.98-5 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 2023-11-21. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

Copy link

melvin-bot bot commented Nov 14, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR:
  • [@burczu] 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:
  • [@burczu] A discussion in #expensify-bugs 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:
  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@dylanexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Nov 21, 2023
@dylanexpensify
Copy link
Contributor

Payment time! @burczu to complete checklist

@melvin-bot melvin-bot bot added the Overdue label Nov 24, 2023
@burczu
Copy link
Contributor

burczu commented Nov 27, 2023

@dylanexpensify Sorry for the delay - I'll get back to BZ Checklists soon, after I finish reviewing my PR's and proposals.

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Nov 27, 2023
@flodnv
Copy link
Contributor

flodnv commented Nov 30, 2023

Will you be able to do that before EOW @burczu ?

@melvin-bot melvin-bot bot removed the Overdue label Nov 30, 2023
@burczu
Copy link
Contributor

burczu commented Nov 30, 2023 via email

@burczu
Copy link
Contributor

burczu commented Dec 1, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR:

#26447

  • [@burczu] 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:

#26447 (comment)

  • [@burczu] A discussion in #expensify-bugs 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:

Didn't find any.

  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

Regression test proposal in a separate comment.

  • [@dylanexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@burczu
Copy link
Contributor

burczu commented Dec 1, 2023

Regression test proposal

  1. Login to the App
  2. Open chat with some user
  3. Type any message
  4. Request money in this chat
  5. Go offline
  6. Open money request report that's just created in step 4 and delete it
  7. Go back to LHN and verify that the chat shows the correct (last, added in step 3) message
  8. Do we agree 👍 or 👎

@flodnv
Copy link
Contributor

flodnv commented Dec 1, 2023

I don't know, feels a bit niche.

@melvin-bot melvin-bot bot added the Overdue label Dec 4, 2023
Copy link

melvin-bot bot commented Dec 4, 2023

@flodnv, @burczu, @dylanexpensify, @tienifr Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@burczu
Copy link
Contributor

burczu commented Dec 5, 2023

@flodnv I wonder if we have some regression tests for deleting money requests - maybe we just need to add some offline steps there? But I'm also ok with not adding regression test at all for this if you feel it's an overkill.

@melvin-bot melvin-bot bot removed the Overdue label Dec 5, 2023
@flodnv
Copy link
Contributor

flodnv commented Dec 5, 2023

Good call, let's ask that to Applause @dylanexpensify and close this issue

@paultsimura
Copy link
Contributor

Hey @dylanexpensify, could you please check the payment on this issue?
I've looked through my Upwork, and seems like my Reporter contract remains unpaid. Thanks.

@dylanexpensify
Copy link
Contributor

looking now!

@dylanexpensify
Copy link
Contributor

paid!

@tienifr
Copy link
Contributor

tienifr commented Jan 2, 2024

@dylanexpensify sorry, I also wasn't paid as Contributor yet, could you process the payment for me as well, thanks!

@tienifr
Copy link
Contributor

tienifr commented Jan 17, 2024

@dylanexpensify Gentle bump on this, thanks!

@dylanexpensify
Copy link
Contributor

omg sorry! Yes on it now!

@dylanexpensify
Copy link
Contributor

@tienifr done!

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. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

6 participants