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" &&