fix(16): fix attachment deduplication in uploadAttachment.fulfilled
The previous fix only added deduplication by attachmentId in addMessageFromWebSocket and fetchChatHistory.fulfilled, but missed the uploadAttachment.fulfilled handler. Race condition: WebSocket message can arrive BEFORE the upload API returns. When this happens: 1. WebSocket delivers message with id='456', attachmentId=123 2. addMessageFromWebSocket adds it to state 3. Upload API returns 4. uploadAttachment.fulfilled only checked for id='attachment-123' → not found 5. Duplicate message added Fix: Also check by attachmentId in uploadAttachment.fulfilled handler. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c1ed8470ae
commit
20d0259433
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue