Skip to content

fix(app): preserve messages sent during history load and replace reply placeholder by identity - #22051

Closed
ocakciomursel-pixel wants to merge 1 commit into
BasedHardware:mainfrom
ocakciomursel-pixel:fix/chat-sent-while-loading-and-placeholder-identity
Closed

ocakciomursel-pixel wants to merge 1 commit into
BasedHardware:mainfrom
ocakciomursel-pixel:fix/chat-sent-while-loading-and-placeholder-identity

Conversation

@ocakciomursel-pixel

@ocakciomursel-pixel ocakciomursel-pixel commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Closes #19232.

  • Merge locally added / in-flight messages on history load (app/lib/providers/chat_history_state.dart): refreshMessages now records loadStarted and merges any messages added after the load began via _withSentWhileLoading (when not switching apps via dropdownSelected), deduplicating any human message the server already returned with the same text. Previously, a message added via addMessageLocally (or a voice turn in sendVoiceMessageStreamToServer) before a pending history load completed was overwritten when messages was replaced wholesale.
  • Replace and insert streaming reply placeholders by object identity (app/lib/providers/message_provider.dart): Both sendVoiceMessageStreamToServer and _streamReply previously captured final aiIndex = messages.length - 1 before streaming and wrote messages[aiIndex] = message on MessageChunkType.done (and voiceMessages.insert(aiIndex, ...) on MessageChunkType.message). If messages was merged or reordered while the stream was in flight, the final reply overwrote the wrong row. Added _replaceMessage and _insertBefore helpers using identical(m, placeholder).

Product invariants affected

none

How it was verified

Added regression unit tests in app/test/providers/message_provider_chat_reliability_test.dart verifying both _withSentWhileLoading preservation/deduplication and identity-based placeholder replacement when messages is modified mid-stream.

Tests

  • app/test/providers/message_provider_chat_reliability_test.dart

UI evidence

UI-Evidence: none -- state-management / provider-only fix with unit test coverage; no widget layout or visual styling changes.

Failure class (fixes)

Failure-Class: none

View guided diff

@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: this is a well-scoped, correct fix for two real message-loss bugs — happy to see it; a few non-blocking notes below, leaving the merge call to a human maintainer.

What I verified:

  • app/lib/providers/chat_history_state.dart — refreshMessages used to replace messages wholesale when a history load landed, wiping anything sent while it was in flight. _withSentWhileLoading(loaded, loadStarted) (line ~296) now re-appends messages whose ids are absent from the loaded page and whose createdAt is not before loadStarted, with a text-based dedupe for human messages the server already returned. Correctly applied in both the session branch (line ~265) and the legacy branch (line ~288), and correctly skipped when dropdownSelected (app switch), where full replacement is intended. The existing epoch guard still fences stale loads, and identity of preserved messages is kept (same instances), which is what makes the second fix below work across merges.
  • app/lib/providers/message_provider.dart — the old aiIndex index arithmetic in sendVoiceMessageStreamToServer and _streamReply could overwrite the wrong row if the list was merged/reordered mid-stream. _replaceMessage/_insertBefore resolve the placeholder by identical() instead. I checked the ordering semantics for consecutive MessageChunkType.message chunks: each inserts directly before the placeholder anchor, so chunks still render in arrival order — behavior preserved.
  • app/test/providers/message_provider_chat_reliability_test.dart — both regression tests exercise the real code paths via the existing legacyMessagesLoader / replyStreamOverride injection hooks; assertions check ordering and non-duplication, not just absence of crashes.

Non-blocking notes:

  1. The dedupe matches human messages by text only (_withSentWhileLoading). If a user sends the same text twice in quick succession and the server page contains just one instance, both local copies collapse into one. The window is narrow and the pre-fix behavior lost the message entirely, so this is still an improvement — but an id- or time-proximity-based dedupe would be tighter.
  2. _replaceMessage silently drops the completed reply if the placeholder is gone. That is strictly safer than overwriting an arbitrary row, but a debug log at that branch would make production diagnosis easier.
  3. The only reported check on this PR is the AI code reviewer — the Flutter test suite has not been observed green in CI on this head. Please make sure flutter test test/providers/message_provider_chat_reliability_test.dart (or the app test job) runs before merge.

UX: users will notice messages they sent during history load no longer vanish when loading completes, and a finished AI reply can no longer replace the wrong bubble when the list shifts mid-stream. Blast radius is confined to chat state management; no persistence, network, or schema changes.

USER IMPACT: messages you send while chat history is still loading no longer disappear once loading finishes, and a completed AI reply can no longer overwrite the wrong bubble if the list moved mid-stream.

This feedback is AI-generated maintainer assistance on behalf of the Omi maintainers; a human maintainer should make the final merge call.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution flutter flutter work labels Oct 17, 2026
@ocakciomursel-pixel

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and verification, @Git-on-my-level!

Noted on the non-blocking items:

  1. A tighter proximity/id-based dedupe will be a great follow-up once server message IDs or client-assigned transient UUIDs are threaded through the transport layer.
  2. Placeholder absence is safely guarded to prevent corrupted overwrites; diagnostic logging can be added in the next telemetry pass.
  3. The targeted unit tests ( est/providers/message_provider_chat_reliability_test.dart) run clean against this head.

Ready for human maintainer review and merge.

@omiagent

omiagent Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix, @ocakciomursel-pixel! Your commits are being carried forward in #25157 (cherry-picked with your original authorship intact) so they can land with the current CI and repo conventions. Closing this in favor of that branch — your contribution is credited there and in the git history.

@omiagent omiagent Bot closed this Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @ocakciomursel-pixel 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat: a message sent while the history is still loading disappears, and the reply overwrites a row

2 participants