Skip to content

Commit 88d6b57

Browse files
authored
fix(ui): keep tool failure state on individual calls (#122681)
1 parent 0c824f0 commit 88d6b57

17 files changed

Lines changed: 153 additions & 482 deletions

‎ui/src/e2e/chat-tool-turn-outcome.e2e.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,21 @@ suite.define(() => {
8989
await expandCompletedWorkGroups(page);
9090

9191
expect(await page.locator(".chat-tool-msg-summary__label").allTextContents()).toEqual([
92-
"Tool error",
92+
"Tool output",
9393
"Tool output",
9494
]);
95-
// The earlier failure must stay visibly marked as an error even though a
96-
// later turn recovered; the recovered row must render neutral.
95+
// Each failure keeps only its per-call badge even when its turn later
96+
// recovers; both row summaries otherwise render neutral.
9797
const summaryClasses = await page
9898
.locator(".chat-tool-msg-summary")
9999
.evaluateAll((nodes) => nodes.map((node) => node.className));
100100
expect(summaryClasses).toHaveLength(2);
101-
expect(summaryClasses[0]).toContain("chat-tool-msg-summary--error");
101+
expect(summaryClasses[0]).not.toContain("chat-tool-msg-summary--error");
102102
expect(summaryClasses[1]).not.toContain("chat-tool-msg-summary--error");
103+
expect(await page.locator(".chat-tool-row__badge").allTextContents()).toEqual([
104+
"failed",
105+
"failed",
106+
]);
103107
await context.close();
104108
});
105109

‎ui/src/i18n/locales/en.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5373,17 +5373,11 @@ export const en: TranslationMap = {
53735373
otherMany: "used {count} tools",
53745374
emptyOne: "Ran a tool call",
53755375
emptyMany: "Ran {count} tool calls",
5376-
failedOne: "{count} failed",
5377-
failedMany: "{count} failed",
5378-
activityErrorOne: "Activity: {count} tool, includes errors.",
5379-
activityErrorMany: "Activity: {count} tools, includes errors.",
53805376
},
53815377
},
53825378
workRun: {
53835379
workedFor: "Worked for {duration}",
53845380
worked: "Worked",
5385-
workedForError: "Worked for {duration}, includes errors.",
5386-
workedError: "Worked, includes errors.",
53875381
},
53885382
backgroundTasks: {
53895383
label: "Background tasks",

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export type MessageGroup = {
143143
messages: Array<{ message: unknown; key: string; duplicateCount?: number }>;
144144
timestamp: number;
145145
isStreaming: boolean;
146-
turnSucceeded?: boolean;
147146
};
148147

149148
/** Content item types in a normalized message */

‎ui/src/lib/chat/tool-call-grouping.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
type ToolGroupSummaryInput = {
1515
name: string;
1616
args?: unknown;
17-
isError?: boolean;
1817
};
1918

2019
type FileActivity = "read" | "edit" | "write" | "delete";
@@ -31,7 +30,6 @@ type GroupCounts = {
3130
fetches: number;
3231
otherNames: Set<string>;
3332
others: number;
34-
failed: number;
3533
};
3634

3735
function countFiles(counts: GroupCounts, activity: FileActivity, paths: readonly string[]): void {
@@ -78,9 +76,6 @@ function countCard(counts: GroupCounts, card: ToolGroupSummaryInput): void {
7876
counts.otherNames.add(card.name);
7977
}
8078
}
81-
if (card.isError) {
82-
counts.failed += 1;
83-
}
8479
}
8580

8681
function countLabel(count: number, oneKey: string, manyKey: string): string {
@@ -108,7 +103,6 @@ export function summarizeToolGroup(cards: readonly ToolGroupSummaryInput[]): str
108103
fetches: 0,
109104
otherNames: new Set(),
110105
others: 0,
111-
failed: 0,
112106
};
113107
for (const card of cards) {
114108
countCard(counts, card);
@@ -186,14 +180,5 @@ export function summarizeToolGroup(cards: readonly ToolGroupSummaryInput[]): str
186180
);
187181
}
188182
const label = segments.join(", ");
189-
const capitalized = label.charAt(0).toUpperCase() + label.slice(1);
190-
if (counts.failed === 0) {
191-
return capitalized;
192-
}
193-
const failureLabel = countLabel(
194-
counts.failed,
195-
"chat.toolCards.group.failedOne",
196-
"chat.toolCards.group.failedMany",
197-
);
198-
return `${capitalized} · ${failureLabel}`;
183+
return label.charAt(0).toUpperCase() + label.slice(1);
199184
}

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function activityAlignmentHtml() {
194194
<div class="chat-avatar tool">A</div>
195195
<div class="chat-group-messages">
196196
<div class="chat-activity-group is-open">
197-
<button class="chat-activity-group__summary chat-activity-group__summary--error" type="button">
197+
<button class="chat-activity-group__summary" type="button">
198198
<span class="chat-activity-group__icon">${iconSvg()}</span>
199199
<span class="chat-activity-group__label">Activity: 2 tools</span>
200200
</button>
@@ -212,10 +212,11 @@ function activityAlignmentHtml() {
212212
</div>
213213
<div class="chat-bubble chat-bubble--tool-shell">
214214
<div class="chat-tool-msg-collapse">
215-
<button class="chat-tool-msg-summary chat-tool-msg-summary--error" type="button">
215+
<button class="chat-tool-msg-summary" data-failed-call-row type="button">
216216
<span class="chat-tool-msg-summary__icon">${iconSvg()}</span>
217-
<span class="chat-tool-msg-summary__label">Tool error</span>
217+
<span class="chat-tool-msg-summary__label">Bash</span>
218218
<span class="chat-tool-msg-summary__names">Bash</span>
219+
<span class="chat-tool-row__badge">failed</span>
219220
</button>
220221
</div>
221222
</div>
@@ -1232,9 +1233,9 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
12321233

12331234
await expectNoHorizontalOverflow(page);
12341235
const callRow = await getRect(page, "[data-activity-call-row]");
1235-
const errorSummary = await getRect(page, ".chat-tool-msg-summary--error");
1236-
expect(Math.abs(callRow.right - errorSummary.right)).toBeLessThanOrEqual(1);
1237-
expect(Math.abs(callRow.height - errorSummary.height)).toBeLessThanOrEqual(1);
1236+
const failedSummary = await getRect(page, "[data-failed-call-row]");
1237+
expect(Math.abs(callRow.right - failedSummary.right)).toBeLessThanOrEqual(1);
1238+
expect(Math.abs(callRow.height - failedSummary.height)).toBeLessThanOrEqual(1);
12381239
const styles = await page.evaluate(() => {
12391240
const call = document.querySelector<HTMLElement>("[data-activity-call-row]")!;
12401241
return {

‎ui/src/pages/chat/chat-thread-build.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
shouldRenderQueuedSendInThread,
3030
} from "./chat-progress.ts";
3131
import {
32-
annotateToolTurnOutcome,
3332
coalesceToolActivityMessages,
3433
groupMessages,
3534
isKeyedAssistantStreamFallbackMessage,
@@ -615,7 +614,5 @@ export function buildChatItems(props: BuildChatItemsProps): Array<ChatItem | Mes
615614
appendQueuedSend(queued);
616615
}
617616

618-
return annotateToolTurnOutcome(
619-
groupMessages(collapseSequentialDuplicateMessages(coalesceToolActivityMessages(items))),
620-
);
617+
return groupMessages(collapseSequentialDuplicateMessages(coalesceToolActivityMessages(items)));
621618
}

‎ui/src/pages/chat/chat-thread-grouping.ts‎

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { ChatItem, MessageGroup, ToolCard } from "../../lib/chat/chat-types
88
import { extractTextCached } from "../../lib/chat/message-extract.ts";
99
import { normalizeMessage, normalizeRoleForGrouping } from "../../lib/chat/message-normalizer.ts";
1010
import { senderIdentityKey } from "../../lib/chat/sender-label.ts";
11-
import { extractToolCardsCached, isToolCardError } from "../../lib/chat/tool-cards.ts";
11+
import { extractToolCardsCached } from "../../lib/chat/tool-cards.ts";
1212
import { resolveMessageToolUseId, resolveToolBlockId } from "./chat-thread-items.ts";
1313
import {
1414
assistantGroupIsForwardedBoundary,
@@ -460,52 +460,6 @@ export function coalesceToolActivityMessages(items: ChatItem[]): ChatItem[] {
460460
return coalesced.filter((_, index) => !suppressedIndexes.has(index));
461461
}
462462

463-
function assistantGroupHasReplyText(group: MessageGroup): boolean {
464-
return group.messages.some(({ message }) => {
465-
if (extractTextCached(message)?.trim()) {
466-
return true;
467-
}
468-
return safeNormalizeMessage(message)?.content.some((block) => block.type === "canvas") ?? false;
469-
});
470-
}
471-
472-
export function annotateToolTurnOutcome(
473-
items: Array<ChatItem | MessageGroup>,
474-
): Array<ChatItem | MessageGroup> {
475-
let sawAssistantReply = false;
476-
for (let index = items.length - 1; index >= 0; index -= 1) {
477-
const item = items[index];
478-
if (!item || item.kind !== "group") {
479-
if (item && chatItemStartsUserTurn(item)) {
480-
sawAssistantReply = false;
481-
}
482-
continue;
483-
}
484-
const role = item.role.toLowerCase();
485-
const forwardedBoundary = role === "assistant" && assistantGroupIsForwardedBoundary(item);
486-
const startsTurn = chatItemStartsUserTurn(item);
487-
if (role === "user") {
488-
sawAssistantReply = false;
489-
} else if (role === "assistant") {
490-
if (forwardedBoundary) {
491-
// Gateway preserves sessions_send provenance when projecting inputs as assistant groups.
492-
// Those groups start a new autonomous turn; they are not replies to an earlier tool.
493-
sawAssistantReply = false;
494-
} else if (assistantGroupHasReplyText(item)) {
495-
sawAssistantReply = true;
496-
}
497-
} else if (role === "tool") {
498-
item.turnSucceeded = sawAssistantReply;
499-
}
500-
if (role !== "user" && !forwardedBoundary && startsTurn) {
501-
// This group belongs to the new hidden-input turn. Reset only after
502-
// processing it so replies from this turn cannot classify older tools.
503-
sawAssistantReply = false;
504-
}
505-
}
506-
return items;
507-
}
508-
509463
type RenderChatItem = ChatItem | MessageGroup;
510464
type StreamRunRenderItem = {
511465
kind: "stream-run";
@@ -549,7 +503,6 @@ type WorkGroupRenderItem = {
549503
key: string;
550504
groups: MessageGroup[];
551505
durationMs: number | null;
552-
hasError: boolean;
553506
};
554507

555508
type ActivityRunRenderItem = {
@@ -607,17 +560,6 @@ function isFinalReplyGroup(item: TurnRenderItem): boolean {
607560
);
608561
}
609562

610-
function workGroupHasError(groups: MessageGroup[]): boolean {
611-
return groups.some(
612-
(group) =>
613-
group.role.toLowerCase() === "tool" &&
614-
group.turnSucceeded !== true &&
615-
group.messages.some((entry) =>
616-
extractToolCardsCached(entry.message, entry.key).some(isToolCardError),
617-
),
618-
);
619-
}
620-
621563
/**
622564
* Once a turn is done, its intermediate work (tool groups and assistant
623565
* commentary before the final reply) collapses behind one "Worked for X"
@@ -717,7 +659,6 @@ export function collapseCompletedTurnWork(
717659
key: `work:${finalReply.key}`,
718660
groups,
719661
durationMs,
720-
hasError: workGroupHasError(groups),
721662
});
722663
result.push(...turn.slice(segmentEnd + 1));
723664
}

0 commit comments

Comments
 (0)