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-08-07] [$1000] Preferences- Notification toggle updating inconsistently on devices #19640

Closed
4 of 6 tasks
lanitochka17 opened this issue May 26, 2023 · 94 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Engineering External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented May 26, 2023

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


Action Performed:

Precondition - Login to the same account in Main device (Desktop) and secondary device (Web)

Offline test:

  1. Open Desktop app
  2. Open preferences (on Web & Desktop)
  3. Click "Force offline" (on Desktop)
  4. Click 3 times on Notifications toggle (On Desktop)
  5. Click on "Force offline" toggle to go online (On Desktop)

Online test:

  1. Open Desktop app
  2. Open preferences (on Web & Desktop)
  3. Click 2 times quickly on the Notifications toggle (On Desktop)
  4. See that it updated correctly on web, but the desktop is now wrong

Expected Result:

Notifications toggle is synced on main and secondary device.

Actual Result:

Notifications toggle differs on main and secondary device. When user goes online on main device - notification toggle blinks on the secondary device but then goes back to the previous state which differs from the main device state.

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.18-2

Reproducible in staging?: Yes

Reproducible in production?: Yes

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

https://platform.applause.com/services/links/v1/external/0875e549d85a3e7f06f3a10355369edfe2ef01dfd60007c73c53f56e5c845377

Screen.Recording.2023-05-29.at.3.33.21.AM.mov

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal
Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01240a84e969686e0b
  • Upwork Job ID: 1662121552691892224
  • Last Price Increase: 2023-06-09
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented May 26, 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

@lanitochka17 lanitochka17 changed the title Desktop - Notification toggle not updated on secondary device after go online Preferences- Notification toggle not updated on secondary device after go online May 26, 2023
@sakluger
Copy link
Contributor

I was able to reproduce this bug. One other note is that after following the reproduction steps, I refreshed the secondary device, and it synced the notification setting back off to match the primary device.

@sakluger sakluger added the External Added to denote the issue can be worked on by a contributor label May 26, 2023
@melvin-bot melvin-bot bot changed the title Preferences- Notification toggle not updated on secondary device after go online [$1000] Preferences- Notification toggle not updated on secondary device after go online May 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

Current assignee @sakluger is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

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

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

melvin-bot bot commented May 26, 2023

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

@namhihi237
Copy link
Contributor

namhihi237 commented May 27, 2023

Proposal

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

The notifications toggle is synced on a primary and secondary device.

What is the root cause of that problem?

####Offline test:
The issue here arises when the device is offline and requests are being queued into the persistedRequests array. When the device reestablishes an internet connection, these requests are retrieved and sent out in sequence. After each request is processed, it is removed from the array.

However, a problem occurs when the Notifications toggle is clicked three times, causing identical requests (number 1 and 3) to be queued into the persistedRequests array. Upon processing, the function PersistedRequests.remove(requestToProcess); is invoked, which results in the removal of both request 1 and 3 due to their similarity. Consequently, we lose one request in the process.

function remove(requestToRemove) {
persistedRequests = _.reject(persistedRequests, (persistedRequest) => _.isEqual(persistedRequest, requestToRemove));
Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests);
}

####Onlie test:
The issue happens when clicking a second time while the first API is not finished.
when briefly pressing the switch, the toggleAction method is called twice at almost the same time. toggleAction then calls props.onToggle, and the result is two API calls made at roughly the same time.
Then these two function calls are queued for execution. If the time between the two calls is too short, the second toggleAction may be executed before the props.onToggle from the first call completes.

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

####Offline test:
Instead of deleting all matching requests, you can modify your removal function to delete only the first matching request. This ensures that if there are duplicate requests in the persistedRequests array, only the one currently being processed gets deleted.

function remove(requestToRemove) {
   const requests = [...persistedRequest]
    const index = _.findIndex(persistedRequests, (requests) => _.isEqual(persistedRequest, requestToRemove));
    if (index !== -1) {
        requests.splice(index, 1);
    }
    persistedRequest = requests
    Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, requests);
}

Result:

Screen.Recording.2023-05-28.at.01.20.39.mp4

####Oneline test:
src/components/Switch.js

import { debounce } from 'lodash';
 // this.toggleAction = this.toggleAction.bind(this);
 this.toggleAction = debounce(this.toggleAction.bind(this), 500);

Result:

Screen.Recording.2023-05-30.at.00.38.12.mov

What alternative solutions did you explore? (Optional)

N/A

@allroundexperts
Copy link
Contributor

@danieldoglas For the offline case as mentioned in this issue, @namhihi237's proposal has the correct root cause and solves the problem in a decent manner as well. However, while testing, I found out that for online mode, if you click the toggle quickly twice, the toggle on the desktop (testing device) goes out of sync.

Screen.Recording.2023-05-29.at.3.33.21.AM.mov

Do we want to handle the above bug together with this one? If no, then @namhihi237's proposal works good.

@danieldoglas
Copy link
Contributor

That root cause makes sense to me, but I'm curious if this change won't break anything else - We probably remove all of them for a reason. cc @marcaaron, can you confirm?

If that's the case, we might need to create a new property in the queue object to confirm it is a unique request, and only delete the first if it is.

@danieldoglas
Copy link
Contributor

@allroundexperts for the error you found, can you confirm if it's a concurrency error? IMO the second device should have received all 3 pusher updates, but it might be out of order. If that's the case, I'm not sure we can fix it the way our pusher updates work today.

@allroundexperts
Copy link
Contributor

@allroundexperts for the error you found, can you confirm if it's a concurrency error? IMO the second device should have received all 3 pusher updates, but it might be out of order. If that's the case, I'm not sure we can fix it the way our pusher updates work today.

@danieldoglas The second device behaves correctly and all events are received in correct order there. It's just the main device on which the toggle gets set incorrectly.

@danieldoglas
Copy link
Contributor

Oh no, I thought you had clicked 3 times. Yeah, I think we should fix it here as well.

@allroundexperts
Copy link
Contributor

Oh no, I thought you had clicked 3 times. Yeah, I think we should fix it here as well.

Awesome. Can you update the reproduction steps to include this as well?

@danieldoglas danieldoglas changed the title [$1000] Preferences- Notification toggle not updated on secondary device after go online [$1000] Preferences- Notification toggle updating inconsistently on devices May 29, 2023
@danieldoglas
Copy link
Contributor

done.

@namhihi237
Copy link
Contributor

namhihi237 commented May 29, 2023

Hi @allroundexperts , I just checked the additional issue with the online, the issue happens when clicking a second time while the first API is not finished. I think we can use Debounce for this. What do you think?

@allroundexperts
Copy link
Contributor

Hi @allroundexperts , I just checked the additional issue with the online, the issue happens when clicking a second time while the first API is not finished. I think we can use Debounce for this. What do you think?

@namhihi237 Can you please update your proposal?

@namhihi237
Copy link
Contributor

Yes, @allroundexperts , I updated (#19640 (comment))

@melvin-bot melvin-bot bot added the Overdue label May 31, 2023
@sakluger
Copy link
Contributor

sakluger commented Jun 1, 2023

Hey @allroundexperts mind taking another look?

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 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:

  • [@allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
  • [@allroundexperts] 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:
  • [@allroundexperts] 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:
  • [@allroundexperts] Determine if we should create a regression test for this bug.
  • [@allroundexperts] 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.
  • [@puneetlath / @greg-schroeder] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot
Copy link

melvin-bot bot commented Jul 27, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @namhihi237 got assigned: 2023-07-11 18:35:13 Z
  • when the PR got merged: 2023-07-27 22:16:04 UTC
  • days elapsed: 12

On to the next one 🚀

@puneetlath
Copy link
Contributor

Reminder when paying: this issue had a regression.

@allroundexperts
Copy link
Contributor

The checklist for this bug is not needed here in my opinion. This was an issue since we implemented the http requests queue.

@greg-schroeder
Copy link
Contributor

Sounds good. Holding for payment and we can close, then.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Jul 31, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2023-08-02] [$1000] Preferences- Notification toggle updating inconsistently on devices [HOLD for payment 2023-08-07] [HOLD for payment 2023-08-02] [$1000] Preferences- Notification toggle updating inconsistently on devices Jul 31, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 31, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.47-6 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-08-07. 🎊

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:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Jul 31, 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:

  • [@allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
  • [@allroundexperts] 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:
  • [@allroundexperts] 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:
  • [@allroundexperts] Determine if we should create a regression test for this bug.
  • [@allroundexperts] 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.
  • [@puneetlath / @greg-schroeder] 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 Overdue and removed Weekly KSv2 labels Aug 1, 2023
@greg-schroeder
Copy link
Contributor

Not overdue

@melvin-bot melvin-bot bot removed the Overdue label Aug 4, 2023
@greg-schroeder greg-schroeder changed the title [HOLD for payment 2023-08-07] [HOLD for payment 2023-08-02] [$1000] Preferences- Notification toggle updating inconsistently on devices [HOLD for payment 2023-08-07] [$1000] Preferences- Notification toggle updating inconsistently on devices Aug 4, 2023
@melvin-bot melvin-bot bot added the Overdue label Aug 7, 2023
@greg-schroeder
Copy link
Contributor

Will process today as we've reached new payment date

@melvin-bot melvin-bot bot removed the Overdue label Aug 7, 2023
@greg-schroeder
Copy link
Contributor

The original upwork job is closed because it's so old, so I'll have to create a new one

@greg-schroeder
Copy link
Contributor

Issue Participants:

Issue reported by: Applause - Internal
Contributor: @namhihi237
C+: @allroundexperts

Was this issue merged in time to be eligible for the speed bonus? ❌
Were their any regressions? ✅

Payment summary:

Contributor: @namhihi237 - $500
C+: @allroundexperts - $500

@greg-schroeder
Copy link
Contributor

Payments made in Upwork. Just need @JmillsExpensify to confirm payment for C+ and then we can close as checklist isn't required.

@melvin-bot melvin-bot bot added the Overdue label Aug 10, 2023
@greg-schroeder greg-schroeder added Weekly KSv2 and removed Daily KSv2 labels Aug 11, 2023
@melvin-bot melvin-bot bot removed the Overdue label Aug 11, 2023
@greg-schroeder
Copy link
Contributor

Pending newdot payment

@greg-schroeder
Copy link
Contributor

Same as above

@JmillsExpensify
Copy link

Reviewed the details for @allroundexperts. Approved for payment in NewDot based on the BZ payment summary above.

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

No branches or pull requests