Repository navigation
Supersedes #22051: fix(app): preserve messages sent during history load and replace reply placeholder by identity - #25157
omiagent[bot] wants to merge 1 commit into
Conversation
…y placeholder by identity (#19232)
Git-on-my-level
left a comment
There was a problem hiding this comment.
The two fixes here are correct and well-targeted; one mechanical blocker keeps CI red: the new test file fails the repo formatter.
- app/lib/providers/chat_history_state.dart —
_withSentWhileLoadingmerges locally-added/streamed messages (createdAt >= loadStarted) back into the loaded page, dedupes by id and by human-text match, and thedropdownSelectedguard preserves the intentional full refresh on app switch. Legacy-cache writes now usefilteredbefore merge-back, so ephemeral local messages don't pollute the disk cache. Correct. - app/lib/providers/message_provider.dart —
_replaceMessage/_insertBeforepin the streamed placeholder by object identity instead of the capturedaiIndex, in both the voice and text streaming paths. That's the right fix for the wrong-row overwrite when rows shift mid-stream; the no-op fallback when the placeholder is no longer in the list is safe. - app/test/providers/message_provider_chat_reliability_test.dart — the two new tests are exactly the coverage I'd want (message sent during load preserved without duplication; identity replacement under mid-stream reorder), and the Dart test lane is green — but this file is unformatted: the Formatting job logs
Changed app/test/providers/message_provider_chat_reliability_test.dart(dart format, line length 120). - app/changelog/unreleased/20261112-chat-sent-while-loading-and-reply-identity.json — accurate user-facing fragment, matches repo convention.
Non-blocking nit: the text-based human dedupe in _withSentWhileLoading can drop a locally-sent message if the same text already appears in the loaded page (e.g. "ok" sent twice in quick succession) — acceptable heuristic, a brief comment would help.
USER IMPACT: messages sent while chat history is still loading no longer vanish from the view, and finished replies land in their own row instead of overwriting a neighboring message.
Action needed: run dart format --line-length 120 on app/test/providers/message_provider_chat_reliability_test.dart (only that file) and push — everything else here looks ready.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Thanks for carrying #22051 forward and for the review @Git-on-my-level! Since --- a/app/test/providers/message_provider_chat_reliability_test.dart
+++ b/app/test/providers/message_provider_chat_reliability_test.dart
@@ -97,7 +97,8 @@ void main() {
expect(provider.messages.any((m) => m.id == 'late-history'), isFalse);
});
- test('a local message added while history is loading is preserved without duplication when the load completes', () async {
+ test('a local message added while history is loading is preserved without duplication when the load completes',
+ () async {
final pending = Completer<List<ServerMessage>>();
final greeting = ServerMessage(
'greeting',Verified |
|
Verified — your fix commit is correct; it just needs to land on the PR branch. The formatting blocker from my earlier review is still present on this head ( I applied Since USER IMPACT: once merged, messages sent while chat history is loading no longer disappear, and finished replies replace their own placeholder instead of overwriting a neighboring row. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Supersedes #22051 (stalled since 2026-10-17 on a merge conflict; carried forward with the author's credit).
What this does, in plain terms
Two chat bugs stop losing or corrupting messages on mobile:
No product behavior changes beyond the bug fixes: dedupe of already-delivered user messages keeps the list honest, and app switching keeps its current full-refresh behavior. This closes #19232.
Credit
All of the code in this PR is @ocakciomursel-pixel's — cherry-picked with the original git authorship intact (committer is only the carrying agent). The original PR (#22051,
fix/chat-sent-while-loading-and-placeholder-identity) contains the identical authorial change; Member review on it (2026-10-17) verified both halves as "a well-scoped, correct fix for two real message-loss bugs" with only non-blocking notes.What changed and why (carried from #22051, by @ocakciomursel-pixel)
app/lib/providers/chat_history_state.dart):refreshMessagesnow recordsloadStartedand merges any messages added after the load began via_withSentWhileLoading(when not switching apps viadropdownSelected), deduplicating any human message the server already returned with the same text. Previously, a message added viaaddMessageLocally(or a voice turn insendVoiceMessageStreamToServer) before a pending history load completed was overwritten whenmessageswas replaced wholesale.app/lib/providers/message_provider.dart): BothsendVoiceMessageStreamToServerand_streamReplypreviously capturedfinal aiIndex = messages.length - 1before streaming and wrotemessages[aiIndex] = messageonMessageChunkType.done(andvoiceMessages.insert(aiIndex, ...)onMessageChunkType.message). Ifmessageswas merged or reordered while the stream was in flight, the final reply overwrote the wrong row. Added_replaceMessageand_insertBeforehelpers usingidentical(m, placeholder).Carry-forward resolution
The original diff applied cleanly to
chat_history_state.dart(untouched on main since 2026-10-17) and to the test file.message_provider.dartconflicted because main gained the stop/replace-reply feature (095b2864e5), thinking-buffer flushing and voice-playback machinery inside the same functions since the original PR. Resolution kept main's current declarations in full and layered the author's change on top: the twoaiIndexdeclarations and both index-based writes become the author's identity-based_replaceMessage/_insertBefore; main's currentquestioncapture, stop-path and playback code are untouched. The carried diff is otherwise byte-identical in intent to #22051 (+101/−12 across the same 3 files).Product invariants affected
none
How it was verified (this branch, current main @ ac02feb)
git grepon plainorigin/mainconfirms the unguarded pattern this PR fixes still exists on main (voiceMessages[aiIndex] = message,messages[aiIndex] = message,voiceMessages.insert(aiIndex, ...)) — the bug is not yet fixed on main, and linked issue Chat: a message sent while the history is still loading disappears, and the reply overwrites a row #19232 is open.flutter test test/providers/message_provider_chat_reliability_test.dartunder Flutter stable 3.44.5 (the CI pin) on macOS/arm64 — 30/30 passed, including the author's two new tests (a local message added while history is loading is preserved without duplication when the load completes,a streamed reply replaces its placeholder by identity even when messages are reordered mid-stream), in all three timezone runs: plain,TZ=Pacific/Kiritimati,TZ=Pacific/Pago_Pago.dart run build_runner build --delete-conflicting-outputsclean (7 outputs).bash scripts/analyze_ratchet.sh— passed, zero regressions (no rule above baseline; several improved: avoid_print 13/19, unnecessary_import 11/12, etc.).--suggest): passed — speaker-identity-interpolation-ratchet, diff-hygiene, product-invariants, new-file-headers, mobile-changelog-entry (added unreleased fragmentapp/changelog/unreleased/20261112-chat-sent-while-loading-and-reply-identity.json, this is a user-facing fix), dead-code-ratchet, check-manifest-contract, plan-catalog-contract, and the rest.Tests
app/test/providers/message_provider_chat_reliability_test.dartUI 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