From c441400f36e709beab170f338d93f26427601a9c Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 2 Dec 2026 16:48:13 +0000 Subject: [PATCH] Chat: an unchecked earlier send no longer flashes 'Not sent' on open A message a previous visit sent but never saw acknowledged was restored as 'Not sent' and flipped to sent a moment later, once the history read showed the server had it. It now stays 'sending' until that read, and only becomes 'Not sent' if the server really does not have it. Co-Authored-By: Claude Opus 5.5 --- .../chat/conversation/chat_deliveries.dart | 10 +++++- .../chat_deliveries_restore_test.dart | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/test/features/chat/conversation/chat_deliveries_restore_test.dart diff --git a/app/lib/features/chat/conversation/chat_deliveries.dart b/app/lib/features/chat/conversation/chat_deliveries.dart index b04eb826..5eeaf22f 100644 --- a/app/lib/features/chat/conversation/chat_deliveries.dart +++ b/app/lib/features/chat/conversation/chat_deliveries.dart @@ -243,7 +243,10 @@ class ChatDeliveries extends ChangeNotifier { for (final intent in intents) { if (_states.containsKey(intent.operationId)) continue; _remember(intent); - _states[intent.operationId] = ChatDelivery.failed; + // Unchecked, not failed: it shows as sending until [reconcile] has read + // the transcript, so a message the server did record never flashes + // "Not sent" while the chat opens. + _states[intent.operationId] = ChatDelivery.sending; _unverified.add(intent); changed = true; } @@ -264,6 +267,11 @@ class ChatDeliveries extends ChangeNotifier { for (final intent in confirmed) { _states[intent.operationId] = ChatDelivery.sent; } + for (final intent in _unverified) { + if (!confirmed.contains(intent)) { + _states[intent.operationId] = ChatDelivery.failed; + } + } _unsent.removeWhere(confirmed.contains); _unverified.removeWhere(confirmed.contains); _unsent.addAll(_unverified); diff --git a/app/test/features/chat/conversation/chat_deliveries_restore_test.dart b/app/test/features/chat/conversation/chat_deliveries_restore_test.dart new file mode 100644 index 00000000..17660a07 --- /dev/null +++ b/app/test/features/chat/conversation/chat_deliveries_restore_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_composer_send.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_deliveries.dart'; + +const _send = ChatComposerSend( + sessionId: 's', + text: 'Did it land?', + operationId: 'op-1', + nativeMessageId: 'msg_op-1', +); + +final _message = {'role': 'user', 'id': 'msg_op-1', 'operation_id': 'op-1'}; + +void main() { + test('a restored unchecked send never shows "Not sent" before the history ' + 'read; the server having it makes it sent', () { + final deliveries = ChatDeliveries()..restore([_send]); + expect(deliveries.stateFor(_message), ChatDelivery.sending); + deliveries.reconcile([_message]); + // Settled as sent: an older accepted send is drawn quietly. + expect(deliveries.stateFor(_message), isNull); + expect(deliveries.unsent, isEmpty); + deliveries.dispose(); + }); + + test('a restored send the history does not have becomes "Not sent"', () { + final deliveries = ChatDeliveries()..restore([_send]); + deliveries.reconcile(const []); + expect(deliveries.stateFor(_message), ChatDelivery.failed); + expect(deliveries.unsent, [_send]); + deliveries.dispose(); + }); +}