Skip to content

Commit ae7d9f0

Browse files
authored
fix(session-ui): preserve configured groups on tool failure (#46998)
1 parent 9acdb0b commit ae7d9f0

4 files changed

Lines changed: 59 additions & 34 deletions

File tree

‎packages/app/e2e/regression/session-timeline-reducer-projection.spec.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ test("combines follow-up patches into one three-file stack inside Used", async (
138138
await expect(group.locator('[data-slot="apply-patch-filename"]')).toHaveText(["a.ts", "b.ts", "c.ts"])
139139
})
140140

141-
test("keeps failed search calls and their error cards outside the collapsed stack", async ({ page }) => {
141+
test("keeps failed search calls and their error cards inside the collapsed stack", async ({ page }) => {
142142
const parts = [
143143
toolPart(
144144
"prt_error_glob",
@@ -161,9 +161,14 @@ test("keeps failed search calls and their error cards outside the collapsed stac
161161
]
162162
await setupTimeline(page, { messages: [userMessage(), assistantMessage(parts)] })
163163

164-
await expect(page.locator('[data-component="collapsed-tool-group"]')).toHaveCount(0)
165-
await expect(page.locator('[data-kind="tool-error-card"]')).toHaveCount(2)
166-
const glob = page.locator('[data-timeline-part-id="prt_error_glob"]')
164+
const group = page.locator('[data-component="collapsed-tool-group"]')
165+
const summary = group.getByRole("button", { name: "Used 1 Glob, 1 Grep", exact: true })
166+
await expect(summary).toHaveAttribute("aria-expanded", "false")
167+
await summary.click()
168+
await expect(group.locator('[data-kind="tool-error-card"]')).toHaveCount(2)
169+
const glob = group.locator('[data-timeline-part-id="prt_error_glob"]')
170+
await expect(glob.getByRole("button")).toHaveAttribute("aria-expanded", "false")
171+
await glob.getByRole("button").click()
167172
await expect(glob).toContainText("Invalid tool input")
168173
await expect(glob.locator('[data-component="tool-error-card-icon"]')).toBeVisible()
169174
await expect(glob.locator('[data-component="tool-error-card-icon"] use')).toHaveAttribute(
@@ -177,7 +182,8 @@ test("keeps failed search calls and their error cards outside the collapsed stac
177182
.evaluate((element) => getComputedStyle(element, "::before").display),
178183
)
179184
.toBe("none")
180-
await expect(page.locator('[data-timeline-part-id="prt_error_grep"]')).toContainText(
185+
await group.locator('[data-timeline-part-id="prt_error_grep"]').getByRole("button").click()
186+
await expect(group.locator('[data-timeline-part-id="prt_error_grep"]')).toContainText(
181187
"Search timed out after 30 seconds",
182188
)
183189
})

‎packages/app/e2e/regression/session-timeline-tool-projection.spec.ts‎

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import {
88
userMessage,
99
} from "../performance/timeline-stability/fixture"
1010

11-
test("transitions shell and question through running error outcomes", async ({ page }) => {
11+
test("keeps shell and question failures in their Used group", async ({ page }) => {
1212
const shellID = "prt_transition_error_shell"
1313
const questionID = "prt_transition_error_question"
1414
const timeline = await setupTimeline(page, {
15-
settings: {
16-
timelineDetail: { ...timelinePresets[2].value, shell: { placement: "separate", details: "expanded" } },
17-
},
15+
settings: { timelineDetail: timelinePresets[2].value },
1816
messages: [
1917
userMessage(),
2018
assistantMessage(
@@ -26,31 +24,46 @@ test("transitions shell and question through running error outcomes", async ({ p
2624
),
2725
],
2826
})
27+
const group = page.locator('[data-component="collapsed-tool-group"]')
28+
const used = group.locator(':scope > [data-component="collapsible"] > [data-slot="collapsible-trigger"]')
29+
await used.click()
2930
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toHaveCount(0)
3031
await timeline.send(partUpdated(toolPart(shellID, "shell", "running", { command: "exit 1" })))
3132
await expect(page.locator(`[data-timeline-part-id="${shellID}"]`)).toContainText("exit 1")
3233
await timeline.send(partUpdated(toolPart(questionID, "question", "running", questionInput())))
3334
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toHaveCount(0)
3435
await timeline.send(
35-
partUpdated(toolPart(shellID, "shell", "error", { command: "exit 1" }, { error: "Command exited 1" })),
36+
partUpdated(
37+
toolPart(
38+
shellID,
39+
"shell",
40+
"completed",
41+
{ command: "exit 1" },
42+
{ output: "Command exited 1", metadata: { exit: 1 } },
43+
),
44+
),
3645
)
3746
await timeline.send(
3847
partUpdated(
3948
toolPart(questionID, "question", "error", questionInput(), { error: "The user dismissed this question" }),
4049
),
4150
)
4251

43-
await expect(page.locator(`[data-timeline-part-id="${shellID}"] [data-kind="tool-error-card"]`)).toBeVisible()
44-
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toContainText(/dismissed/i)
52+
await expect(group).toHaveAttribute("data-timeline-part-ids", `${shellID},${questionID}`)
53+
await expect(used).toHaveAttribute("aria-expanded", "true")
54+
const shell = group.locator(`[data-timeline-part-id="${shellID}"]`)
55+
await expect(shell.locator('[data-slot="collapsible-trigger"]')).toHaveAttribute("aria-expanded", "false")
56+
await shell.locator('[data-slot="collapsible-trigger"]').click()
57+
await expect(shell).toContainText("Command exited 1")
58+
const question = group.locator(`[data-timeline-part-id="${questionID}"]`)
59+
await expect(question).toContainText(/dismissed/i)
4560
})
4661

47-
test("preserves surviving grouped patch state when its first patch fails", async ({ page }) => {
62+
test("keeps a failed patch in Used without losing the surviving file choice", async ({ page }) => {
4863
const failed = "prt_grouped_patch_failed"
4964
const surviving = "prt_grouped_patch_surviving"
5065
const timeline = await setupTimeline(page, {
51-
settings: {
52-
timelineDetail: { ...timelinePresets[2].value, edit: { placement: "separate", details: "collapsed" } },
53-
},
66+
settings: { timelineDetail: timelinePresets[2].value },
5467
messages: [
5568
userMessage(),
5669
assistantMessage(
@@ -81,7 +94,9 @@ test("preserves surviving grouped patch state when its first patch fails", async
8194
],
8295
})
8396

84-
const group = page.locator(`[data-timeline-part-ids="${failed},${surviving}"]`)
97+
const group = page.locator('[data-component="collapsed-tool-group"]')
98+
const used = group.locator(':scope > [data-component="collapsible"] > [data-slot="collapsible-trigger"]')
99+
await used.click()
85100
const file = group.locator('[data-scope="apply-patch"] button')
86101
await expect(file).toBeVisible()
87102
await expect(file).toHaveAttribute("aria-expanded", "false")
@@ -104,18 +119,14 @@ test("preserves surviving grouped patch state when its first patch fails", async
104119
const survivingRow = page.locator("[data-timeline-key]", {
105120
has: page.locator(`[data-timeline-part-id="${surviving}"]`),
106121
})
107-
await expect(failedRow).toHaveAttribute("data-timeline-key", /^assistant-part:part:/)
108-
await expect(survivingRow).toHaveAttribute("data-timeline-key", /^assistant-part:file:/)
122+
await expect(group).toHaveAttribute("data-timeline-part-ids", `${failed},${surviving}`)
123+
await expect(used).toHaveAttribute("aria-expanded", "true")
124+
await expect(failedRow).toHaveAttribute("data-timeline-key", /^assistant-part:context:/)
125+
await expect(survivingRow).toHaveAttribute("data-timeline-key", /^assistant-part:context:/)
126+
await group.locator(`[data-timeline-part-id="${failed}"] [data-slot="collapsible-trigger"]`).click()
109127
await expect(failedRow.getByText("Patch failed visibly")).toBeVisible()
110128
await expect(survivingRow).toHaveAttribute("data-group-identity", "preserved")
111129
await expect(survivingRow.locator('[data-scope="apply-patch"] button')).toHaveAttribute("aria-expanded", "true")
112-
await expect
113-
.poll(async () => {
114-
const previous = await failedRow.boundingBox()
115-
const next = await survivingRow.boundingBox()
116-
return previous && next ? next.y - (previous.y + previous.height) : Number.NEGATIVE_INFINITY
117-
})
118-
.toBeGreaterThanOrEqual(-0.5)
119130
})
120131

121132
test("groups instruction files loaded by the same read", async ({ page }) => {

‎packages/session-ui/src/timeline/projection.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ export namespace Timeline {
271271
detail,
272272
new Set(
273273
messages
274-
.filter(
275-
(message) => timelineNoticeRequired(message) || (message.type === "shell" && shellFailed(message)),
276-
)
274+
.filter((message) => message.type === "compaction" && timelineNoticeRequired(message))
277275
.map((message) => message.id),
278276
),
279277
)
@@ -321,7 +319,8 @@ export namespace Timeline {
321319
const refs = messages.flatMap((message, messageIndex) =>
322320
contentEntries(message)
323321
.filter(
324-
(entry) => isRenderable(entry.content, showReasoning, detail) && !(thinking && entry.content === lastContent),
322+
(entry) =>
323+
isRenderable(entry.content, showReasoning, detail) && !(thinking && entry.content === lastContent),
325324
)
326325
.map((entry) => ({ messageID: message.id, messageIndex, partID: entry.id, content: entry.content })),
327326
)
@@ -662,9 +661,10 @@ function toolGroupType(
662661
detail?: TimelineDetail,
663662
) {
664663
if (detail) {
665-
if (currentToolFailed(content) || content.name === "question") return undefined
664+
if (content.name === "question" && !currentToolFailed(content)) return undefined
666665
const category = timelineCategory(content)!
667666
if (detail[category].placement === "grouped") return "context"
667+
if (currentToolFailed(content)) return undefined
668668
if (content.name === "patch") return "patch"
669669
if (content.name === "edit") return "edit"
670670
return undefined

‎packages/session-ui/src/timeline/session-timeline-row.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export function createSessionTimelineRowRenderer(input: {
7171
input.projection.rows().forEach((row) => {
7272
if (row._tag !== "AssistantPart" || row.group.type !== "context") return
7373
row.group.refs.forEach((ref) => {
74+
const content = Timeline.resolveContent(input.projection.messageByID().get(ref.messageID), ref.partID)
75+
if (content?.type !== "tool" || content.name !== "patch" || content.state.status === "error") return
7476
const part = `${ref.messageID}:${ref.partID}`
7577
const key = patchGroupKeys.get(part)
7678
if (key && !owners.has(key)) owners.set(key, part)
@@ -273,8 +275,14 @@ export function createSessionTimelineRowRenderer(input: {
273275

274276
function contentDefaultOpen(item: SessionMessageAssistant["content"][number]) {
275277
if (input.timelineDetail) {
276-
if (item.type === "tool" && currentToolFailed(item)) return true
277278
const category = timelineCategory(item)
279+
if (
280+
category &&
281+
input.timelineDetail()[category].placement === "hidden" &&
282+
item.type === "tool" &&
283+
currentToolFailed(item)
284+
)
285+
return true
278286
if (category === "shell" || category === "edit" || category === "thinking")
279287
return input.timelineDetail()[category].details === "expanded"
280288
}
@@ -488,8 +496,8 @@ export function createSessionTimelineRowRenderer(input: {
488496
const value = message()
489497
return (
490498
input.timelineDetail().shell.details === "expanded" ||
491-
value?.status === "timeout" ||
492-
(value?.status === "exited" && value.exit !== undefined && value.exit !== 0)
499+
(input.timelineDetail().shell.placement === "hidden" &&
500+
(value?.status === "timeout" || (value?.status === "exited" && value.exit !== undefined && value.exit !== 0)))
493501
)
494502
})
495503
return (

0 commit comments

Comments
 (0)