From 1f4b976495ea5a9901ae4e60b0d1fb279b585672 Mon Sep 17 00:00:00 2001 From: jamesx0416 Date: Sun, 8 Mar 2026 11:20:23 +1100 Subject: [PATCH] fix: avoid duplicating streamed assistant completion text --- .../orchestration/Layers/ProviderRuntimeIngestion.test.ts | 1 + .../src/orchestration/Layers/ProviderRuntimeIngestion.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts index 96242b846c..24409655eb 100644 --- a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts +++ b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts @@ -834,6 +834,7 @@ describe("ProviderRuntimeIngestion", () => { payload: { itemType: "assistant_message", status: "completed", + detail: "hello live", }, }); diff --git a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts index 022a196674..5a6f71d5e6 100644 --- a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts +++ b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts @@ -951,6 +951,10 @@ const make = Effect.gen(function* () { if (assistantCompletion) { const assistantMessageId = assistantCompletion.messageId; const turnId = toTurnId(event.turnId); + const existingAssistantMessage = thread.messages.find((entry) => entry.id === assistantMessageId); + const shouldApplyFallbackCompletionText = + !existingAssistantMessage || + existingAssistantMessage.text.length === 0; if (turnId) { yield* rememberAssistantMessageId(thread.id, turnId, assistantMessageId); } @@ -963,7 +967,7 @@ const make = Effect.gen(function* () { createdAt: now, commandTag: "assistant-complete", finalDeltaCommandTag: "assistant-delta-finalize", - ...(assistantCompletion.fallbackText !== undefined + ...(assistantCompletion.fallbackText !== undefined && shouldApplyFallbackCompletionText ? { fallbackText: assistantCompletion.fallbackText } : {}), });