From f30c0a48dd45f49359dfea18883242399d9d4d86 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Thu, 28 May 2026 15:33:17 +0400 Subject: [PATCH] Studio: don't duplicate composer chip when re-uploading an indexed doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The backend dedups re-uploads and the sidepanel shows the doc once, but the composer's pending-doc chips are created per addDoc call, so each re-upload of an already-indexed file appended another 'Ready' chip for the same document. In the already_indexed branch, if a chip with the returned documentId already exists, drop the chip we just added instead of marking it ready — so the composer shows each document only once. --- .../chat/hooks/use-thread-doc-uploads.ts | 19 ++++++++++++++----- .../src/features/chat/shared-composer.tsx | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/studio/frontend/src/features/chat/hooks/use-thread-doc-uploads.ts b/studio/frontend/src/features/chat/hooks/use-thread-doc-uploads.ts index aa3dc9b71f..0b83662459 100644 --- a/studio/frontend/src/features/chat/hooks/use-thread-doc-uploads.ts +++ b/studio/frontend/src/features/chat/hooks/use-thread-doc-uploads.ts @@ -128,14 +128,23 @@ export function useThreadDocUploads(): UseThreadDocUploadsResult { file, ); if (alreadyIndexed) { - // Identical file already in this scope — no re-index. - setPendingDocs((prev) => - prev.map((d) => + // Identical file already in this scope — no re-index. If a + // chip for this document already exists, drop the one we just + // added so the composer doesn't show the same doc twice; + // otherwise mark this chip ready. + setPendingDocs((prev) => { + const dupExists = prev.some( + (d) => d.id !== localChipId && d.documentId === documentId, + ); + if (dupExists) { + return prev.filter((d) => d.id !== localChipId); + } + return prev.map((d) => d.id === localChipId ? { ...d, status: "ready", documentId } : d, - ), - ); + ); + }); toast.info(`${file.name} is already indexed`); if ( scope?.kind === "thread" && diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsx index c44f312ae2..abd06624c8 100644 --- a/studio/frontend/src/features/chat/shared-composer.tsx +++ b/studio/frontend/src/features/chat/shared-composer.tsx @@ -617,13 +617,21 @@ export function SharedComposer({ file, ); if (alreadyIndexed) { - setPendingDocs((prev) => - prev.map((d) => + // Drop the just-added chip if this doc is already represented + // so the composer never shows the same document twice. + setPendingDocs((prev) => { + const dupExists = prev.some( + (d) => d.id !== localChipId && d.documentId === documentId, + ); + if (dupExists) { + return prev.filter((d) => d.id !== localChipId); + } + return prev.map((d) => d.id === localChipId ? { ...d, status: "ready", documentId } : d, - ), - ); + ); + }); toast.info(`${file.name} is already indexed`); if ( scope?.kind === "thread" &&