Skip to content

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

fix(assistantUiMessages): correct message ordering in provider

Steven Enamakel832ac35646f6
diff --git a/app/src/providers/assistantUiMessages.ts b/app/src/providers/assistantUiMessages.ts
index 07f7d6ba3b..b2a837174e 100644
--- a/app/src/providers/assistantUiMessages.ts
+++ b/app/src/providers/assistantUiMessages.ts
@@ -103,6 +103,18 @@ function toolPart(entry: ToolTimelineEntry): ThreadAssistantMessagePart {
};
}
+/**
+ * Project one assistant message into assistant-ui parts.
+ *
+ * **Every tool part must have a distinct `toolCallId`.** assistant-ui keys them
+ * as `toolCallId-${id}` and *throws* on a repeat ("Duplicate key … in
+ * useResources"), which takes the whole thread render down rather than dropping
+ * a row — so this is a hard invariant, not a tidiness rule, and it is enforced
+ * here at the boundary as well as at each producer. `emittedToolIds` guards
+ * both passes below; the sources upstream (the live Redux slice and the derived
+ * transcript mapper) also mint unique ids, but threads persisted before those
+ * fixes still carry colliding ones.
+ */
function assistantParts(
text: string,
timeline: readonly ToolTimelineEntry[],
@@ -119,9 +131,13 @@ function assistantParts(
}
if (item.kind === 'toolCall') {
const entry = timelineById.get(item.callId);
- if (entry) {
- parts.push(toolPart(entry));
+ // Guarded here too, not only in the timeline pass below: two transcript
+ // pointers can name the same `callId` (a provider that emits tool calls
+ // without ids writes the empty string for all of them), and both resolve
+ // to the same timeline row.
+ if (entry && !emittedToolIds.has(entry.id)) {
emittedToolIds.add(entry.id);
+ parts.push(toolPart(entry));
}
}
// Narration is process commentary, not the final assistant answer. The
@@ -130,12 +146,6 @@ function assistantParts(
}
for (const entry of [...timeline].sort((a, b) => a.seq - b.seq)) {
- // The `has` check also stands in for id uniqueness across the timeline
- // itself, not just against the transcript pass above. assistant-ui keys
- // tool parts as `toolCallId-${id}` and *throws* on a repeat ("Duplicate key
- // … in useResources"), taking the thread render down — so a duplicate has
- // to be dropped here rather than trusted not to occur. The slice no longer
- // mints colliding ids, but threads persisted before that fix still can.
if (emittedToolIds.has(entry.id)) continue;
emittedToolIds.add(entry.id);
parts.push(toolPart(entry));