From 88ca3c865d5aa719a394ade4b50f218bba2a84be Mon Sep 17 00:00:00 2001 From: ekko <152005280+EKKOLearnAI@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:18:12 +0800 Subject: [PATCH] fix(chat): prevent duplicate user messages in conversation history (#258) Build conversation_history before adding the new user message to the session, so the message is sent only via `input` and not duplicated in `conversation_history` as well. Closes #257 Co-authored-by: Claude Opus 4.6 --- packages/client/src/stores/hermes/chat.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/client/src/stores/hermes/chat.ts b/packages/client/src/stores/hermes/chat.ts index 965f578..6fc403e 100644 --- a/packages/client/src/stores/hermes/chat.ts +++ b/packages/client/src/stores/hermes/chat.ts @@ -777,6 +777,14 @@ export const useChatStore = defineStore('chat', () => { timestamp: Date.now(), attachments: attachments && attachments.length > 0 ? attachments : undefined, } + // Build conversation history BEFORE adding the new message, so the + // user's current message appears only in `input` — not duplicated in + // `conversation_history` as well. + const sessionMsgs = getSessionMsgs(sid) + const history: ChatMessage[] = sessionMsgs + .filter(m => (m.role === 'user' || m.role === 'assistant') && m.content.trim()) + .map(m => ({ role: m.role as 'user' | 'assistant' | 'system', content: m.content })) + addMessage(sid, userMsg) updateSessionTitle(sid) // Persist immediately so a refresh before the first SSE event (e.g. the @@ -788,11 +796,6 @@ export const useChatStore = defineStore('chat', () => { } try { - // Build conversation history from past messages - const sessionMsgs = getSessionMsgs(sid) - const history: ChatMessage[] = sessionMsgs - .filter(m => (m.role === 'user' || m.role === 'assistant') && m.content.trim()) - .map(m => ({ role: m.role as 'user' | 'assistant' | 'system', content: m.content })) // Upload attachments and build input with file paths let inputText = content.trim()