diff --git a/jam-ui/src/store/features/sessionChatSlice.js b/jam-ui/src/store/features/sessionChatSlice.js index 2738aa903..a71142e11 100644 --- a/jam-ui/src/store/features/sessionChatSlice.js +++ b/jam-ui/src/store/features/sessionChatSlice.js @@ -468,9 +468,13 @@ const sessionChatSlice = createSlice({ // Use music_notation.id as part of message id to avoid collision with real msg_id const messageId = `attachment-${notation.id}`; - // Check for duplicates (in case WebSocket somehow delivers to sender) - const exists = state.messagesByChannel[channel].some(m => m.id === messageId); - if (!exists) { + // Check for duplicates by both message ID AND attachmentId + // WebSocket may deliver message before this handler runs with different ID format + const existsById = state.messagesByChannel[channel].some(m => m.id === messageId); + const existsByAttachmentId = state.messagesByChannel[channel].some( + m => m.attachmentId && m.attachmentId === notation.id + ); + if (!existsById && !existsByAttachmentId) { const purpose = attachmentType === 'audio' ? 'Audio File' : 'Notation File'; const message = { id: messageId,