@@ -73,8 +73,13 @@ export class WebBridge {
7373 private onChatListChange : ChatListChangeCallback | null = null ;
7474
7575 /**
76- * IDs of chats whose messages have already been fetched and dispatched.
77- * Used to avoid redundant loads when switching back to a previously viewed chat.
76+ * IDs of chats whose full message history has been fetched from the REST API
77+ * and dispatched to the webview. Used to avoid redundant loads when switching
78+ * back to a previously viewed chat.
79+ *
80+ * Note: chats that only received live SSE events (e.g. a running chat that
81+ * started streaming before the user opened it) are NOT in this set — they
82+ * need a full REST fetch to load the earlier messages.
7883 */
7984 private loadedChatIds = new Set < string > ( ) ;
8085
@@ -477,8 +482,10 @@ export class WebBridge {
477482
478483 // Track new chats and title updates for the sidebar.
479484 // Skip subagent chats — they render inside the parent chat's tool call.
485+ // Note: we do NOT add to loadedChatIds here — live SSE events only
486+ // carry new content, not the full history. A full REST fetch is needed
487+ // when the user selects this chat to load earlier messages.
480488 if ( data . chatId && ! this . subagentChatIds . has ( data . chatId ) ) {
481- this . loadedChatIds . add ( data . chatId ) ;
482489 this . upsertChatEntry ( data . chatId , { } ) ;
483490 if ( data . content ?. type === 'metadata' && data . content ?. title ) {
484491 this . upsertChatEntry ( data . chatId , { title : data . content . title } ) ;
@@ -692,6 +699,11 @@ export class WebBridge {
692699 const chat = await this . api . getChat ( chatId ) ;
693700 this . loadedChatIds . add ( chatId ) ;
694701
702+ // Clear any partial content the webview may already have from live SSE
703+ // events (e.g. a running chat that streamed new content before the user
704+ // clicked on it). This prevents duplicates when we replay the full history.
705+ this . dispatch ( 'chat/cleared' , { chatId, messages : true } ) ;
706+
695707 const events = chatToRestoreEvents ( chat ) ;
696708
697709 // Always dispatch at least one event so the webview's Redux store
0 commit comments