Is there an algorithm that is responsible for the grouping of messages in a conversation view?

Sometimes I notice that messages are mistakenly grouped in conversation view.

What does it depend?


Eg: