Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: stop a recovered chat crashing on a duplicate tool call key (#12442)
Daniel Han5d4bfb81751b
diff --git a/studio/frontend/src/features/chat/utils/generation-tool-recovery.ts b/studio/frontend/src/features/chat/utils/generation-tool-recovery.tsindex aa0c5ea5c17..807eda5f61e 100644--- a/studio/frontend/src/features/chat/utils/generation-tool-recovery.ts+++ b/studio/frontend/src/features/chat/utils/generation-tool-recovery.ts@@ -458,14 +458,18 @@ export function createGenerationToolRecovery(if (!toolName) {return;}+ // A save can hold this card past its cursor; minting it again duplicates the part key.+ const toolCallId = `${backendId || "tool"}:${runId}:${seq}`;+ entry ??= carried.find(({ part }) => {+ const card = record(part);+ return (+ card?.type === "tool-call" &&+ (card.toolCallId === toolCallId ||+ card.generationToolCallId === `${runId}:${seq}`)+ );+ });if (!entry) {- entry = {- at,- part: {- type: "tool-call",- toolCallId: `${backendId || "tool"}:${runId}:${seq}`,- },- };+ entry = { at, part: { type: "tool-call", toolCallId } };carried.push(entry);}const args = record(event.arguments) ?? {};diff --git a/studio/frontend/tests/generation-tool-recovery.test.ts b/studio/frontend/tests/generation-tool-recovery.test.tsindex dbfc069b040..bc57f13dcfa 100644--- a/studio/frontend/tests/generation-tool-recovery.test.ts+++ b/studio/frontend/tests/generation-tool-recovery.test.ts@@ -63,6 +63,42 @@ test("replay resumes an existing card without duplicating it", () => {assert.deepEqual(carried, [{ at: 12, part: { ...saved, result: "ok" } }]);});+test("a finished card saved past the cursor is not minted a second time", () => {+ const carried: Carried[] = [];+ let replay = createGenerationToolRecovery(carried, "run").apply;+ replay(start(), 12, 4897);+ replay(end(), 12, 4898);+ const finished = { ...(carried[0].part as Record<string, unknown>) };+ replay = createGenerationToolRecovery(carried, "run", 4800).apply;+ replay(start(), 12, 4897);+ replay(end(), 12, 4898);+ assert.deepEqual(+ carried.map((entry) => entry.part),+ [finished],+ );+});++test("a live card saved past the cursor is not recovered as a second card", () => {+ const live = {+ type: "tool-call",+ toolCallId: "call_0:live-uuid",+ backendToolCallId: "call_0",+ generationToolCallId: "run:4897",+ toolName: "edit_file",+ args: { path: "scene.glsl" },+ argsText: '{"path":"scene.glsl"}',+ result: "ok",+ };+ const carried: Carried[] = [{ at: 12, part: live }];+ const replay = createGenerationToolRecovery(carried, "run", 4800).apply;+ replay(start(), 12, 4897);+ replay(end(), 12, 4898);+ assert.deepEqual(+ carried.map((entry) => (entry.part as Record<string, unknown>).toolCallId),+ ["call_0:live-uuid"],+ );+});+test("reused backend ids get separate cards across rounds and reloads", () => {const carried: Carried[] = [];let replay = createGenerationToolRecovery(carried, "run").apply;