From 4e56e548872a162129efee1b09987af7893b0e0c Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 25 Aug 2026 23:54:36 +0900 Subject: fix(tabs): never crash on duplicate toolCallIds in tool batches --- src/core/chunks/groups.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/core/chunks/groups.ts') diff --git a/src/core/chunks/groups.ts b/src/core/chunks/groups.ts index 53a2873..c1c80c9 100644 --- a/src/core/chunks/groups.ts +++ b/src/core/chunks/groups.ts @@ -72,9 +72,17 @@ export function groupRenderedChunks(rendered: readonly RenderedChunk[]): readonl emittedSteps.add(stepId); const entries: ToolBatchEntry[] = []; + // Dedupe by toolCallId within the batch: a provider double-emission (or any + // corrupted transcript) can carry the SAME call id on multiple tool-call + // chunks in one step. The first occurrence (stream order) wins; later ones + // are skipped so the keyed `{#each}` in the UI never sees duplicate keys + // (Svelte `each_key_duplicate` aborts the reactive flush — tab appears dead). + const seenCallIds = new Set(); let provisional = false; for (const inner of rendered) { if (inner.chunk.type === "tool-call" && inner.chunk.stepId === stepId) { + if (seenCallIds.has(inner.chunk.toolCallId)) continue; + seenCallIds.add(inner.chunk.toolCallId); const result = resultByCallId.get(inner.chunk.toolCallId) ?? null; entries.push({ call: inner.chunk, result }); if (inner.provisional) provisional = true; -- cgit v1.2.3