Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): render final assistant result once\n\n

Steven Enamakel05d3f16315ba
diff --git a/app/src/providers/__tests__/assistantUiMessages.test.ts b/app/src/providers/__tests__/assistantUiMessages.test.ts
index ce4313ecaf..3f318f356d 100644
--- a/app/src/providers/__tests__/assistantUiMessages.test.ts
+++ b/app/src/providers/__tests__/assistantUiMessages.test.ts
@@ -209,6 +209,19 @@ describe('buildRuntimeMessages', () => {
]);
});
+ it('renders final streamed narration only once', () => {
+ const finalText = 'hey! what is up?';
+ const answer = msg({ id: 'answer', sender: 'agent', content: finalText });
+ const content = buildRuntimeMessages([answer], null, {
+ turnTranscripts: {
+ request: [{ kind: 'narration', round: 1, seq: 0, text: finalText }],
+ },
+ turnTimelines: { request: [] },
+ })[0]?.content;
+
+ expect(content).toEqual([{ type: 'text', text: finalText }]);
+ });
+
/**
* The crash this guards: assistant-ui keys tool parts as `toolCallId-${id}`
* and throws "Duplicate key … in useResources" on a repeat, taking the whole
diff --git a/app/src/providers/assistantUiMessages.ts b/app/src/providers/assistantUiMessages.ts
index 884fb49e08..117f1f46b0 100644
--- a/app/src/providers/assistantUiMessages.ts
+++ b/app/src/providers/assistantUiMessages.ts
@@ -140,11 +140,15 @@ function assistantParts(
parts.push(toolPart(entry));
}
}
- if (item.kind === 'narration' && item.text.trim().length > 0) {
+ if (
+ item.kind === 'narration' &&
+ item.text.trim().length > 0 &&
+ item.text.trim() !== text.trim()
+ ) {
// Narration emitted before a tool call is assistant content in its own
// right. Keep it inline in assistant-ui's ordered part stream; the final
- // answer is appended separately below, so this preserves the real turn
- // sequence without relying on the removed legacy processing pane.
+ // answer is appended separately below. A final-round narration is the
+ // same streamed bytes as that answer and must not render twice.
parts.push({ type: 'text', text: item.text });
}
}
diff --git a/app/test/playwright/specs/chat-tool-call-flow.spec.ts b/app/test/playwright/specs/chat-tool-call-flow.spec.ts
index f30cd802f0..5642446b50 100644
--- a/app/test/playwright/specs/chat-tool-call-flow.spec.ts
+++ b/app/test/playwright/specs/chat-tool-call-flow.spec.ts
@@ -171,6 +171,7 @@ test.describe('Chat Tool Call Flow', () => {
await sendMessage(page, PROMPT);
await expect(agentMessageText(page, CANARY_FINAL)).toBeVisible({ timeout: 40_000 });
+ await expect(page.getByText(`Here is the fetched content: ${CANARY_FINAL}`, { exact: true })).toHaveCount(1);
// Regression: completed tool/reasoning arrays remain in Redux briefly, but
// they must not create a synthetic running tail after the final answer.