From c39b9a3ca3ff52bf669c39ded024e305fc2243eb Mon Sep 17 00:00:00 2001 From: spencrmartin Date: Wed, 3 Dec 2025 16:48:04 -0500 Subject: [PATCH] Fix Matrix room history message type detection - Ensure user messages from self are properly categorized as 'user' type - Only categorize messages as 'assistant' if they have explicit Goose markers or are from other users - This fixes the issue where user's own messages weren't appearing in conversation history - Improved message type detection logic to be more precise and reliable --- ui/desktop/src/services/MatrixService.ts | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ui/desktop/src/services/MatrixService.ts b/ui/desktop/src/services/MatrixService.ts index 718191baf1..9a8c61e86e 100644 --- a/ui/desktop/src/services/MatrixService.ts +++ b/ui/desktop/src/services/MatrixService.ts @@ -2372,7 +2372,7 @@ export class MatrixService extends EventEmitter { sessionData = JSON.parse(sessionJson); actualContent = sessionData.content || actualContent; - // FIXED: Better role detection for session messages + // Better role detection for session messages if (sessionData.role === 'assistant' || sessionData.role === 'ai' || sessionData.role === 'goose') { messageType = 'assistant'; } else if (sessionData.role === 'system') { @@ -2386,19 +2386,33 @@ export class MatrixService extends EventEmitter { console.warn('Failed to parse session message:', error); } } - // Check if this is a regular Goose/AI message - else if (content['goose.message.type'] || content['goose.type'] || - this.isGooseInstance(sender, senderInfo.displayName) || - this.looksLikeGooseMessage(actualContent)) { + // Check if this is a regular Goose/AI message (but NOT from self unless it has explicit Goose markers) + else if (content['goose.message.type'] || content['goose.type']) { + // Explicit Goose message markers - always treat as assistant messageType = 'assistant'; - } else if (content.msgtype === 'm.notice' || sender.includes('bot')) { + } + // Check if message is from a known Goose instance (not self) + else if (!isFromSelf && this.isGooseInstance(sender, senderInfo.displayName)) { + messageType = 'assistant'; + } + // Check if message content looks like a Goose message (not self) + else if (!isFromSelf && this.looksLikeGooseMessage(actualContent)) { + messageType = 'assistant'; + } + // System messages + else if (content.msgtype === 'm.notice' || sender.includes('bot')) { messageType = 'system'; } - - // ADDITIONAL FIX: Check if message is from self but contains AI response patterns - else if (isFromSelf && this.looksLikeGooseMessage(actualContent)) { - // This handles cases where the user's own messages contain AI responses - messageType = 'assistant'; + // CRITICAL FIX: Messages from self that don't have explicit Goose markers should be 'user' + // This ensures user's own messages are properly categorized as 'user' type + else { + // Default to 'user' for all other messages, including messages from self + messageType = 'user'; + + // Log for debugging + if (isFromSelf) { + console.log('📜 Message from self categorized as user:', actualContent.substring(0, 50) + '...'); + } } return {