From 5d7fc35eda3c628bbebe1b07819b7591f4bc3e7c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 26 Aug 2026 09:39:01 +0000 Subject: [PATCH] fix: stop streaming responses breaking on a duplicate output key With reasoning-capable models the chat froze mid-stream: the first chunk of the answer appeared, nothing followed, and the whole message only showed up once generation finished. The browser console showed a Svelte each_key_duplicate error. When a stream event addresses an output slot past the end of the array, the missing slots were filled with the event's own item, id included, so a gap of two left two entries claiming the same id. The next chunk for that item was matched by id, landed in the first of the two, and the rendered list ended up with two items sharing a key, which Svelte refuses to update. Only the addressed slot now takes the event's item, and the slots before it are anonymous placeholders. Replayed the reported event sequence against the real code: keys are unique again and the chunks stay in order instead of being split across the copies. --- src/lib/components/chat/Messages/structuredOutput.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/Messages/structuredOutput.ts b/src/lib/components/chat/Messages/structuredOutput.ts index 96d5bd869f..d4ebe0493e 100644 --- a/src/lib/components/chat/Messages/structuredOutput.ts +++ b/src/lib/components/chat/Messages/structuredOutput.ts @@ -462,9 +462,12 @@ function ensureOutputItem( fallback?: OutputItem ): OutputItem { while (output.length <= outputIndex) { - output.push( - fallback ?? { type: 'message', status: 'in_progress', role: 'assistant', content: [] } - ); + // Only the addressed slot gets the event's item; filler slots must not reuse its id. + const item = + output.length === outputIndex && fallback + ? { ...fallback } + : { type: 'message', status: 'in_progress', role: 'assistant', content: [] }; + output.push(item); } output[outputIndex] = { ...output[outputIndex] }; return output[outputIndex];