Chat: a message sent while the history is still loading disappears, and the reply overwrites a row
Product impact
- Primary loop layer: Retrieval-Action (chat)
- [x] Involves data loss, failed capture, or broken sync/trust
Describe the bug
Opening chat starts the history load ("Reading your memories…"). A message sent before that load returns is
dropped from the screen: the load replaces messages wholesale, and the streamed reply is then written to an
index computed before the replacement.
To reproduce
- New account (no cached messages), open chat.
- While "Reading your memories…" is showing, type a message and send.
- Wait for the reply.
Current behavior
The user's own message disappears and only Omi's reply is left (seen on device with a new account). Depending on
what the load returned, the reply lands on another row's index, or messages[aiIndex] is out of range.
Expected behavior
The sent message and its reply both stay, in order, whether or not the history load lands in between.
Evidence
lib/providers/message_provider.dart:512—getMessagesFromServerassignsmessages = List.from(mes), discarding anything added since the load began (the human message and the reply placeholder).lib/providers/message_provider.dart:806/lib/providers/message_provider.dart:864— the typed path capturesaiIndex = messages.length - 1before streaming and writesmessages[aiIndex] = messageondone.lib/providers/message_provider.dart:636/lib/providers/message_provider.dart:686— the voice path has the same stale index (andmessages.insert(aiIndex, …)formessagechunks).
Suggested fix
Merge the loaded history with messages created after the load started (skip a human message the server already returned), and replace the reply placeholder by identity instead of by index.
Fix available
Fixed with a regression test on the fork branch design/v2-step0-tokens (bc79f057cb). It will be linked from the draft PR.
Found while testing the Omi v2 Flutter restyle on an iPhone, then confirmed against main at 32c2ed22cf.