Open matthew-white opened 4 days ago
@ktuite and I explored this issue a little while reviewing getodk/central-backend#1187. We ended up suspecting that there was an issue with these lines of code:
add(version) {
if (version.baseVersion === this.lastContiguousWithTrunk &&
version.version === version.baseVersion + 1)
this.lastContiguousWithTrunk = version.version;
}
When this method is called for v3 (the 1st update) in the scenario above, version.baseVersion
will be 1, which differs from this.lastContiguousWithTrunk
, which will be 2. In other words, add()
considers the branch to have been interrupted. What's actually happening is that all the updates are contiguous with the trunk version, but the updates have been applied out of order. In other words, in the normal case where updates are applied in order, add()
can tell whether a branch is interrupted, but in the case where an update is force-applied from the backlog, add()
breaks down.
add()
was originally written for Frontend and was adapted for Backend. If we patch it in Backend, we should probably also patch it in Frontend: there may be a problem there as well. In Frontend, I think lastContiguousWithTrunk
is just used to show the accuracy warning ("In this case, the author’s view may not be accurate.").
Right now, there are exactly three situations in which a new entity version is supposed to be marked as a conflict. Two of them are new as of v2024.3.
Note one important situation in which a new entity version is not marked as a conflict. If an offline update is force-applied from the backlog, that is not considered to be a conflict unless rule 3 applies. For example, let's say I create an entity, then make two offline updates to the entity. I submit both updates, but the first is delayed, so the second ends up being force-applied from the backlog and processed before the first. Assuming that there was no other update from another source, the second update should not be marked as a conflict. Its base version according to the server is v1, and it immediately follows it (1 ✅); it was not a create applied as an update (2 ✅); and it is contiguous with its trunk version (3 ✅). If the first update does eventually arrive, the first update will be marked as a conflict due to rule 1. However, the second update (the one processed first) is not considered to be a conflict.
This issue has to do with a related situation in which a new entity version is marked as a soft conflict when it is not intended to be. This situation came up as part of #698:
According to the three rules above, v4 should not be marked as a conflict. However, right now, it is being marked as a conflict. That can be seen in the Backend test here.