TypeScript
fix(web): keep tool groups collapsed after a usage-limit pause (#24937)
shivamfe219c4de18f
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.tsindex 3ee079809f1..8f4b15cc11f 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts@@ -3841,9 +3841,15 @@ it("keeps the working header in place across worktree setup handoff", () => {});describe("failed turn transcript", () => {- it.each(["provider_error", "usage_limit"] as const)(- "keeps historical %s failures and preceding work visible without disclosures",- (failureClass) => {+ it.each([+ { position: "historical", failureClass: "provider_error" },+ { position: "historical", failureClass: "usage_limit" },+ { position: "latest", failureClass: "usage_limit" },+ ] as const)(+ "keeps $position $failureClass failures visible with preceding work grouped appropriately",+ ({ position, failureClass }) => {+ const isLatest = position === "latest";+ const commands = isLatest ? ["pwd", "ls", "false"] : ["pwd"];const runId = RunId.make("failed-run");const threadId = ThreadId.make("failed-thread");const at = DateTime.makeUnsafe("2026-09-20T12:00:00Z");@@ -3880,23 +3886,24 @@ describe("failed turn transcript", () => {attachments: [],},},- {- position: 1,+ ...commands.map((input, index): OrchestrationV2ProjectedTurnItem => ({+ position: index + 1,visibility: "local",sourceThreadId: threadId,- sourceItemId: TurnItemId.make("command"),+ sourceItemId: TurnItemId.make(index === 0 ? "command" : `command-${index}`),item: {...base,- id: TurnItemId.make("command"),+ id: TurnItemId.make(index === 0 ? "command" : `command-${index}`),+ ordinal: index + 1,type: "command_execution",status: "completed",- input: "pwd",+ input,output: "",exitCode: 0,},- },+ })),{- position: 2,+ position: commands.length + 1,visibility: "local",sourceThreadId: threadId,sourceItemId: TurnItemId.make("failure"),@@ -3918,20 +3925,24 @@ describe("failed turn transcript", () => {timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({visibleTurnItems: items,optimisticMessages: [],- }).map((entry) => ({- ...entry,- attempt: {- id: RunAttemptId.make("superseded-attempt"),- runId,- attemptOrdinal: 1,- rootNodeId: NodeId.make("superseded-root"),- status: "superseded" as const,- completedAt: null,- },- })),+ }).map((entry) =>+ isLatest+ ? entry+ : {+ ...entry,+ attempt: {+ id: RunAttemptId.make("superseded-attempt"),+ runId,+ attemptOrdinal: 1,+ rootNodeId: NodeId.make("superseded-root"),+ status: "superseded" as const,+ completedAt: null,+ },+ },+ ),latestRun: {- runId: RunId.make("newer-run"),- status: "completed",+ runId: isLatest ? runId : RunId.make("newer-run"),+ status: isLatest ? "failed" : "completed",startedAt: DateTime.formatIso(at),completedAt: DateTime.formatIso(at),},@@ -3939,16 +3950,19 @@ describe("failed turn transcript", () => {turnDiffSummaries: [],supportsConversationRollback: false,});- expect(- rows.some(- (row) =>- row.kind === "turn-fold" || row.kind === "attempt-fold" || row.kind === "work-toggle",- ),- ).toBe(false);+ expect(rows.some((row) => row.kind === "turn-fold" || row.kind === "attempt-fold")).toBe(+ false,+ );const work = rows.flatMap((row) => (row.kind === "work" ? row.groupedEntries : []));- expect(work.map((entry) => entry.id)).toEqual(["command", "failure"]);+ expect(rows.find((row) => row.kind === "work-toggle")).toEqual(+ isLatest ? expect.objectContaining({ hiddenCount: 3, expanded: false }) : undefined,+ );+ expect(work.map((entry) => entry.id)).toEqual(+ isLatest ? ["failure"] : ["command", "failure"],+ );expect(work.at(-1)?.detail).toBe("The provider stopped this turn.\nRetry later.");expect(work.at(-1)?.createdAt).toBe("2026-09-20T12:00:00.000Z");+ if (isLatest) return;const entriesWithoutTools = deriveTimelineEntriesFromVisibleTurnItems({visibleTurnItems: items.filter((row) => row.item.type !== "command_execution"),optimisticMessages: [],diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.tsindex f4b409f901b..c26bcf51a71 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts@@ -973,6 +973,24 @@ function failedTimelineRunIds(return failed;}+/** Usage-limit pauses keep their tool groups; any other failure itemizes the run's work. */+function itemizedFailedRunIds(+ entries: ReadonlyArray<TimelineEntry>,+ failedRunIds: ReadonlySet<RunId>,+) {+ const usageLimited = new Set<RunId>();+ const otherFailures = new Set<RunId>();+ for (const entry of entries) {+ const item = timelineEntryFailedItem(entry);+ if (item?.runId) {+ (item.failure.class === "usage_limit" ? usageLimited : otherFailures).add(item.runId);+ }+ }+ return new Set(+ [...failedRunIds].filter((runId) => !usageLimited.has(runId) || otherFailures.has(runId)),+ );+}+function deriveTurnFolds(input: {timelineEntries: ReadonlyArray<TimelineEntry>;terminalAssistantMessageIds: ReadonlySet<string>;@@ -1410,6 +1428,7 @@ export function deriveMessagesTimelineRows(input: {const nextRows: MessagesTimelineRow[] = [];const terminalAssistantMessageIds = deriveTerminalAssistantMessageIds(timelineEntries);const failedRunIds = failedTimelineRunIds(timelineEntries, input.latestRun ?? null);+ const itemizedRunIds = itemizedFailedRunIds(timelineEntries, failedRunIds);const liveSubagentEntryIds = liveSubagentCardEntryIds(timelineEntries);const completeSupersededReplyIds = completeSupersededReplyEntryIds(timelineEntries);const supersededFoldsByAnchorEntryId = deriveSupersededAttemptFolds(@@ -1772,7 +1791,7 @@ export function deriveMessagesTimelineRows(input: {if (timelineEntry.kind === "work") {if (isPendingApproval(timelineEntry.entry) ||- (timelineEntry.entry.runId != null && failedRunIds.has(timelineEntry.entry.runId)) ||+ (timelineEntry.entry.runId != null && itemizedRunIds.has(timelineEntry.entry.runId)) ||(timelineEntry.entry.itemType === "error" &&timelineEntry.entry.toolLifecycleStatus === "failed") ||timelineEntry.entry.tone === "error" ||@@ -1798,6 +1817,8 @@ export function deriveMessagesTimelineRows(input: {!nextEntry ||nextEntry.kind !== "work" ||nextEntry.entry.sourceActivityKind === "context-compaction" ||+ (nextEntry.entry.itemType === "error" &&+ nextEntry.entry.toolLifecycleStatus === "failed") ||nextEntry.entry.tone === "error" ||nextEntry.entry.sourceActivityKind === "runtime.error" ||nextEntry.entry.itemType === "system_notice" ||