Cht-core: If multiple task documents are created with the same emission id only one of them is ever updated

Created on 1 May 2020  路  13Comments  路  Source: medic/cht-core

Describe the bug
In the MSF-Niger production instance, two task documents have been created from the same report and share the same emission._id attribute. It is unknown what circumstances lead up to this exactly -- but it is possible for this to result if multiple sessions login on different devices.

  1. This "same task" appears multiple times in the task list
  2. When the user completes the steps to resolve the task -- only one of the multiple tasks disappears

To Reproduce
I'm not sure of the steps that lead to multiple task documents being created in this case.

  • task~org.couchdb.user:riposte1~665c19fe-3c27-4209-950e-a070a4e5bf36~0~samu_yields_ripostefollowup_red~1588242822845
  • task~org.couchdb.user:riposte1~665c19fe-3c27-4209-950e-a070a4e5bf36~0~samu_yields_ripostefollowup_red~1588242869125

Expected behavior

  • The same task emission should never result in multiple tasks in the UI
  • Either duplicate task documents need to be deduplicated via cancellation, or all task documents should recieve updates when emission details change.

Environment

COVID-19 1 - High Bug

Most helpful comment

To reproduce this bug, pick any user and connect with the same credentials on 2 separate devices ( potentially separate browser should be okay but not tested).

We assume that the user will replicate the source doc from the server ( submitted by another user)

  1. On Device 1 Sync one time, and check in the task tab that a task was triggered
  2. On Device 2 Sync one time, and check in the task tab that a task was triggered

It's important to do 1 & 2 at the same time, after both are done we suppose that a task document has been created on pouch in both Device 1 and Device 2 but none of these task documents have synced to the server yet.

  1. Sync on Device 1
  2. Sync on Device 2

do 3&4 in the same time and go check in medic db by using the task id, you will notice that 2 different documents have been created for the same task with different authoredOn timestamp.

  1. Submit one of the task , it will not disappear and you will see in couch that one of the document was updated with the completed status, and the other one will be not.

EDIT :
This was reproduced using https://msf-niger.app.medicmobile.org/

  • Connect as the user samu: medic.1234 to create the source form
    You form have to be covid related, so check yes in the first question
  • Connect as the user dosso: medic.1234 on 2 separate devices to generate the tasks.

All 13 comments

Drawing attention to this code here where the task emission is mapped to a single task document for updates. This does not account for the scenario where multiple task documents have been created for the same emission.

We have worked around this issue for MSF-Niger by issuing guidance to not login to the same account on multiple devices, and by creating new user accounts for affected users.

To reproduce this bug, pick any user and connect with the same credentials on 2 separate devices ( potentially separate browser should be okay but not tested).

We assume that the user will replicate the source doc from the server ( submitted by another user)

  1. On Device 1 Sync one time, and check in the task tab that a task was triggered
  2. On Device 2 Sync one time, and check in the task tab that a task was triggered

It's important to do 1 & 2 at the same time, after both are done we suppose that a task document has been created on pouch in both Device 1 and Device 2 but none of these task documents have synced to the server yet.

  1. Sync on Device 1
  2. Sync on Device 2

do 3&4 in the same time and go check in medic db by using the task id, you will notice that 2 different documents have been created for the same task with different authoredOn timestamp.

  1. Submit one of the task , it will not disappear and you will see in couch that one of the document was updated with the completed status, and the other one will be not.

EDIT :
This was reproduced using https://msf-niger.app.medicmobile.org/

  • Connect as the user samu: medic.1234 to create the source form
    You form have to be covid related, so check yes in the first question
  • Connect as the user dosso: medic.1234 on 2 separate devices to generate the tasks.

I think this is worth fixing in 3.9.0 as it'll frustrate the users and presumably lead to duplicate reporting as they try and clear the task.

The same task emission should never result in multiple tasks in the UI
Either duplicate task documents need to be deduplicated via cancellation, or all task documents should recieve updates when emission details change.

As I understood it, we're appending a timestamp (representing the date the task was calculated at) at the end of the task document _id _because_ we were not sure whether some configurations emit unique emission ids.
If we choose now to dedupe or cancel these duplicated tasks, are we not essentially undoing what the _id timestamp suffix was trying to achieve = allow for multiple task documents for the same emission ID ?

Read for AT in 6389-dedupe-tasks. Test #6417 at the same time.

This is going to be a lot harder to replicate because we now sync immediately when local changes happen.

I can no longer reproduce the issue described above. Disabling the network and try also to no avail. I'm seeing tasks cleared when the sync occurs on both browsers. Tasks are clearing appropriately as well. I don't see duplicates in the couchdb either. I think we can close and merge both related tasks @dianabarsan

@newtewt I can prepare 2 custom builds for you, a master version that removes the instant sync and my proposed version that removes the instant sync, if you'd like to compare the two.

I think disabling the network in your branch is enough to disable instant sync right? By not being able to reproduce the issue. I was able to before applying your branch and after I could no longer(fixed). My initial comment wasn't very clear.

I just thought of another way of simulating. Change your users so they can't edit (set the can_edit permission to false, to stop the upwards sync), create the report on the server, sync down on 2 clients. they will both generate tasks, just not upload them. Change permission so they can_edit and have them both sync twice. Maybe that will get both of them to upload and generate tasks and then the duplicate "clear" should be visible.

Ah cool! :D I completely misunderstood. If the tasks got duplicated. there should be duplicates in CouchDB though.

Merged.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alxndrsn picture alxndrsn  路  6Comments

SCdF picture SCdF  路  5Comments

estellecomment picture estellecomment  路  5Comments

alxndrsn picture alxndrsn  路  4Comments

ghost picture ghost  路  4Comments