Skip to content

[HOLD for payment 2024-04-15] [$500] Task - Chat messages are out of order after reassigning task, sometimes beginning of chat is duplicated #38439

Description

@kbecciv

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.53-2
Reproducible in staging?: y
Reproducible in production?: y
Issue reported by: Applause - Internal Team

Action Performed:

  1. Open the app and log into an account where you have multiple chats
  2. Navigate to a user from the recent contacts
  3. Tap the "+" > Assign task
  4. Enter the task name and proceed to the next screen
  5. Tap "Assignee" and search for a user you have not messaged yet
  6. Assign the task to that user
  7. Tap the "Assignee" again and reassign the task to the same user you are sharing it with
  8. Create the task

Expected Result:

The task is displayed as the last message in the report

Actual Result:

A duplicated beginning of the report is displayed, sometimes task is shown as the first message

Workaround:

n/a

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6415381_1710533895456.video_2024-03-15_16-16-07.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01479bcdfebb5e0089
  • Upwork Job ID: 1770147572055535616
  • Last Price Increase: 2024-03-26
  • Automatic offers:
    • hungvu193 | Reviewer | 0

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 16, 2024
  2. melvin-bot commented on Mar 16, 2024

    @melvin-bot

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

  3. kbecciv commented on Mar 16, 2024

    @kbecciv
    Author

    @sakluger I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors.

  4. kbecciv commented on Mar 16, 2024

    @kbecciv
    Author

    We think that this bug might be related to #vip-vsb

  5. ahmedGaber93 commented on Mar 17, 2024

    @ahmedGaber93
    Contributor

    Proposal

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

    Task - Beginning of chat shown after reassigning task from user you have no chat to recent user

    What is the root cause of that problem?

    when we select assignee we call setAssigneeChatReport.

    setAssigneeChatReport(chatReport);

    which merge the value with the old value.
    function setAssigneeChatReport(chatReport: OnyxTypes.Report) {
    Onyx.merge(ONYXKEYS.TASK, {assigneeChatReport: chatReport});
    }

    the root cause is the merge leed to merge ReportUtils.buildOptimisticChatReport for new user with ReportUtils.getChatByParticipants for user chated before and this add optimistic fields like isOptimisticReport to the old report

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

    we need to reset the old value of assigneeChatReport before merge the new value here.

    function setAssigneeChatReport(chatReport: OnyxTypes.Report) {
    Onyx.merge(ONYXKEYS.TASK, {assigneeChatReport: chatReport});
    }

    we can do that by merge it to null then merge it to the new value.

    Onyx.merge(ONYXKEYS.TASK, {assigneeChatReport: null}).then(() => Onyx.merge(ONYXKEYS.TASK, {assigneeChatReport: chatReport}));

    What alternative solutions did you explore? (Optional)

  6. nkdengineer commented on Mar 18, 2024

    @nkdengineer
    Contributor

    Proposal

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

    A duplicated beginning of the report is displayed, sometimes task is shown as the first message

    What is the root cause of that problem?

    When we select an assignee that is a new user, we create an optimistic report here and set it to assigneeChatReport. After we re-select a recent contact, another chat report is set to assigneeChatReport but other fields like isOptimisticReport, pendingFields are in-correct because we merge from old assignee report.

    setAssigneeChatReport(chatReport);

    And then a created action is created here.

    App/src/libs/ReportUtils.ts

    Lines 4813 to 4814 in c915e7f

    if (assigneeChatReport?.isOptimisticReport && assigneeChatReport.pendingFields?.createChat !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
    optimisticChatCreatedReportAction = buildOptimisticCreatedReportAction(assigneeChatReportID);

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

    Instead of storing assignReport in task data, we can store the assigneeChatReportID which is the ID of chat report and then get the correct data from Onyx to check here.

    App/src/libs/ReportUtils.ts

    Lines 4813 to 4814 in c915e7f

    if (assigneeChatReport?.isOptimisticReport && assigneeChatReport.pendingFields?.createChat !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
    optimisticChatCreatedReportAction = buildOptimisticCreatedReportAction(assigneeChatReportID);

    I checked all use of task.assigneeChatReport and saw that it's only used when we create the task. So we can only store the reportID of chat report and then get the report data from Onyx correctly.

    What alternative solutions did you explore? (Optional)

    Updated the chat report with updating the optimistic field correctly if the chatReport is an exist report

     setAssigneeChatReport({
        ...chatReport,
        isOptimisticReport: chatReport.isOptimisticReport,
        pendingField: chatReport.pendingField,
        pendingAction: chatReport.pendingAction
    }); 
    
    

    setAssigneeChatReport(chatReport);

  7. changed the title [-]Task - Beginning of chat shown after reassigning task from user you have no chat to recent user[/-] [+]Task - Chat messages are out of order after reassigning task[/+] on Mar 19, 2024
  8. sakluger commented on Mar 19, 2024

    @sakluger
    Contributor

    Updated the issue title and description for clarify.

  9. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 19, 2024
  10. changed the title [-]Task - Chat messages are out of order after reassigning task[/-] [+][$500] Task - Chat messages are out of order after reassigning task[/+] on Mar 19, 2024
  11. 38 remaining items

  12. changed the title [-][$500] Task - Chat messages are out of order after reassigning task, sometimes beginning of chat is duplicated[/-] [+][HOLD for payment 2024-04-15] [$500] Task - Chat messages are out of order after reassigning task, sometimes beginning of chat is duplicated[/+] on Apr 8, 2024
  13. melvin-bot commented on Apr 8, 2024

    @melvin-bot

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

  14. melvin-bot commented on Apr 8, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.60-13 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 2024-04-15. 🎊

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

  15. melvin-bot commented on Apr 8, 2024

    @melvin-bot

    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:

    • [@hungvu193] The PR that introduced the bug has been identified. Link to the PR:
    • [@hungvu193] 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:
    • [@hungvu193] 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:
    • [@hungvu193] Determine if we should create a regression test for this bug.
    • [@hungvu193] 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.
    • [@sakluger] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  16. sakluger commented on Apr 15, 2024

    @sakluger
    Contributor

    Summarizing payment on this issue:

    Contributor: @nkdengineer $500, sent offer via Upwork (https://www.upwork.com/nx/wm/offer/101873781)
    Contributor+: @hungvu193 $500, paid via Upwork

    @hungvu193 could you please complete the BZ checklist?

  17. sakluger commented on Apr 15, 2024

    @sakluger
    Contributor

    Paid @nkdengineer, just waiting on the checklist now.

  18. hungvu193 commented on Apr 16, 2024

    @hungvu193
    Contributor
    • The PR that introduced the bug has been identified. Link to the PR: Allow optimistic assignee chat reports #22778
    • 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: https://github.com/Expensify/App/pull/22778/files#r1566611957
    • 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: N/A
    • Determine if we should create a regression test for this bug: No

    This is an edge case, so I don't think we need regression test for this one.

  19. sakluger commented on Apr 16, 2024

    @sakluger
    Contributor

    Thanks!

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions