Skip to content

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

fix(assistantUiMessages): handle empty message list in provider

Steven Enamakel7c8eef0849f8
diff --git a/app/src/providers/__tests__/assistantUiMessages.test.ts b/app/src/providers/__tests__/assistantUiMessages.test.ts
index 7e16ca1257..7a557d522d 100644
--- a/app/src/providers/__tests__/assistantUiMessages.test.ts
+++ b/app/src/providers/__tests__/assistantUiMessages.test.ts
@@ -220,6 +220,30 @@ describe('buildRuntimeMessages', () => {
]);
});
+ it('never renders the answer twice when a transcript records it as narration', () => {
+ // An older core projects a prompt-guided turn's answer as an interim step
+ // with every call after it. The answer must still render once, last.
+ const answer = msg({
+ id: 'answer',
+ sender: 'agent',
+ content: 'The setting is on.',
+ extraMetadata: { requestId: 'req-p' },
+ });
+ const content = buildRuntimeMessages([answer], null, {
+ turnTimelines: { 'req-p': [tool({ id: 'call-1', status: 'success', result: 'ok' })] },
+ turnTranscripts: {
+ 'req-p': [
+ { kind: 'narration', round: 3, seq: 0, text: 'The setting is on.' },
+ { kind: 'toolCall', round: 3, seq: 1, callId: 'call-1' },
+ ],
+ },
+ })[0]?.content;
+ expect(Array.isArray(content) ? content.map(part => part.type) : content).toEqual([
+ 'tool-call',
+ 'text',
+ ]);
+ });
+
it('chronologically anchors persisted trails to async agent messages without request ids', () => {
const acknowledgement = msg({
id: 'ack',
diff --git a/app/src/providers/assistantUiMessages.ts b/app/src/providers/assistantUiMessages.ts
index 33b13cd126..24d473e7cb 100644
--- a/app/src/providers/assistantUiMessages.ts
+++ b/app/src/providers/assistantUiMessages.ts
@@ -365,6 +365,13 @@ function assistantParts(
answerEmitted = true;
continue;
}
+ // The answer is never narration, wherever a transcript puts it. A core
+ // that predates the prompt-guided projection fix records a text-mode
+ // turn's answer as an interim step (with the turn's calls after it); as
+ // narration it would render the answer twice.
+ if (mode === 'settled' && answerText.length > 0 && item.text.trim() === answerText.trim()) {
+ continue;
+ }
parts.push({ type: 'text', text: item.text });
continue;
}