Ordering issues

Sometimes a recently sent message gets “split” in the UI with copies with different statuses? With a received in between.

Sometimes we see the same messages twice in the bottom page of a chat?

Sometimes I’ve sent a message and they reply from the other party ends up with a lower sort id than my send message. How is that even possible? Wasn’t even a MUC.

Found at least one bug: we set initial sortId to syncPoint on load, but what if we have send messages with no sync point after them? duplicate sort ids, strange results

I haven’t seen the old issues since the fixes, but I have a couple of times seen messages out of order at least on iOS, but then refreshing from DB got the right order so maybe that’s a different kind of issue.

I think maybe if a push notification comes after the real message (rare) this can cause it too

One user reports seeing out of order messages routinely in the public MUC. They claim the messages all came in during on sync? Maybe overlapping syncs are causing strange issues if they happen?

maybe related: Do not overwrite a sync'd message with one from push notification - Issues - Sopranica

this is likely part of it 8f4f9b2954842ffaebb76c522463db9de0c93cc4

Joined the public MUC from a clean profile and opened the chat and thrashed a lot during initial sync and when done everything seemed reasonable

Ok, I’ve identified at least one of the sorting issues (maybe there’s more, maybe not), and it has to do with edited messages. A mam sync can send us messages we already have. So when we get a duplicate message we delete the one in our database and store the new one, which means we will get the sortId that is assigned via the mam sync path.

However we only do this if the message doesn’t have versions. So if we know about a corrected message, we fall through to the correct message path, which preserves the sortId from the original message (which we want in a normal correction case).

So this can cause edited messages to show up in the wrong order after a sync.

Confirmed by running a manual sync in a channel and observing that edited messages did not have their sortIds changed but unedited ones did.

https://lists.sr.ht/~singpolyma/dev/patches/71705 this fixes the above issue

Had one report that seemed like this today, but it turned out the messages are in the right order and maybe a timestamp was off?

Eric also reported seeing something strange the other day. May have been mid sync and seemed fine after.