From 8b751785b74f1580f39585a89e11276a12396f7c Mon Sep 17 00:00:00 2001 From: cogwheel <172976095+cogwheel0@users.noreply.github.com> Date: Wed, 17 Dec 2025 18:57:03 +0530 Subject: [PATCH] feat(chat): improve assistant message pre-seeding and sync logic --- lib/features/chat/providers/chat_providers.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/features/chat/providers/chat_providers.dart b/lib/features/chat/providers/chat_providers.dart index 2c9d098..51d1462 100644 --- a/lib/features/chat/providers/chat_providers.dart +++ b/lib/features/chat/providers/chat_providers.dart @@ -883,7 +883,7 @@ class ChatMessagesNotifier extends Notifier> { } // Pre-seed an assistant skeleton message (with a given id or a new one), -// persist it to the server to keep the chain correct, and return the id. +// persist it to the server to establish the message structure, and return the id. Future _preseedAssistantAndPersist( dynamic ref, { String? existingAssistantId, @@ -926,7 +926,11 @@ Future _preseedAssistantAndPersist( } catch (_) {} } - // Sync conversation state to ensure WebUI can load conversation history + // Sync conversation state to establish the full message structure on the server. + // The server's upsert only sets parentId and model - we need to set role, + // timestamp, childrenIds, etc. for proper message rendering. + // Note: syncConversationMessages always sets done:true to prevent broken UI + // if streaming is interrupted (see api_service.dart). try { final api = ref.read(apiServiceProvider); final activeConv = ref.read(activeConversationProvider);