TypeScript
fix(web): a failed run shows Failed, not Completed (#20996)
Yannic Charlon25dff68e0122
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.tsindex 15acf606e8a..4883c690bb3 100644--- a/apps/web/src/components/Sidebar.logic.test.ts+++ b/apps/web/src/components/Sidebar.logic.test.ts@@ -1367,9 +1367,80 @@ describe("resolveThreadStatusPill", () => {}),).toMatchObject({ label: "Completed", pulse: false });});++ it("shows failed, not completed, when the unseen run failed", () => {+ expect(+ resolveThreadStatusPill({+ thread: {+ ...baseThread,+ interactionMode: "default",+ latestRun: { ...makeLatestRun(), status: "failed" },+ lastVisitedAt: "2026-03-09T10:04:00.000Z",+ runtime: {+ ...baseThread.runtime,+ status: "failed",+ activeRunId: null,+ lastError: "Provider turn failed.",+ },+ },+ }),+ ).toMatchObject({ label: "Failed", pulse: false });+ });++ it("shows failed for a thread nobody has opened yet", () => {+ expect(+ resolveThreadStatusPill({+ thread: {+ ...baseThread,+ interactionMode: "default",+ latestRun: { ...makeLatestRun(), status: "failed" },+ lastVisitedAt: null,+ runtime: { ...baseThread.runtime, status: "failed", activeRunId: null },+ },+ }),+ ).toMatchObject({ label: "Failed" });+ });++ it("shows failed, not plan ready, when a plan run proposed a plan and then failed", () => {+ expect(+ resolveThreadStatusPill({+ thread: {+ ...baseThread,+ hasActionableProposedPlan: true,+ latestRun: { ...makeLatestRun(), status: "failed" },+ lastVisitedAt: "2026-03-09T10:04:00.000Z",+ runtime: { ...baseThread.runtime, status: "failed", activeRunId: null },+ },+ }),+ ).toMatchObject({ label: "Failed" });+ });++ it("drops the failed pill once the failure has been seen", () => {+ expect(+ resolveThreadStatusPill({+ thread: {+ ...baseThread,+ interactionMode: "default",+ latestRun: { ...makeLatestRun(), status: "failed" },+ lastVisitedAt: "2026-03-09T10:06:00.000Z",+ runtime: { ...baseThread.runtime, status: "failed", activeRunId: null },+ },+ }),+ ).toBeNull();+ });});describe("resolveProjectStatusIndicator", () => {+ it("ranks a failure above work in progress and completions", () => {+ expect(+ resolveProjectStatusIndicator([+ { label: "Completed", colorClass: "", dotClass: "", pulse: false },+ { label: "Working", colorClass: "", dotClass: "", pulse: true },+ { label: "Failed", colorClass: "", dotClass: "", pulse: false },+ ]),+ ).toMatchObject({ label: "Failed" });+ });+it("returns null when no threads have a notable status", () => {expect(resolveProjectStatusIndicator([null, null])).toBeNull();});diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex d44bc6854e5..f10c58fa0de 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -573,6 +573,7 @@ export interface ThreadStatusPill {| "Working"| "Connecting"| "Completed"+ | "Failed"| "Pending Approval"| "Awaiting Input"| "Waiting"@@ -585,6 +586,7 @@ export interface ThreadStatusPill {const THREAD_STATUS_PRIORITY: Record<ThreadStatusPill["label"], number> = {"Pending Approval": 5,"Awaiting Input": 4,+ Failed: 3.5,Working: 3,Connecting: 3,Waiting: 2.5,@@ -720,6 +722,20 @@ export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {return completedAt > lastVisitedAt;}+/**+ * A failed latest run the person hasn't looked at since it ended. Unlike a+ * completion, a thread nobody has opened yet (an automation's, say) counts:+ * its failure still needs someone.+ */+function hasUnseenFailure(thread: ThreadStatusInput): boolean {+ if (thread.latestRun?.status !== "failed") return false;+ if (!thread.lastVisitedAt) return true;+ const completedAt = Date.parse(thread.latestRun.completedAt ?? "");+ const lastVisitedAt = Date.parse(thread.lastVisitedAt);+ if (Number.isNaN(completedAt) || Number.isNaN(lastVisitedAt)) return true;+ return completedAt > lastVisitedAt;+}+export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null): boolean {if (target === null) return true;return !target.closest(THREAD_SELECTION_SAFE_SELECTOR);@@ -1133,6 +1149,15 @@ export function resolveThreadStatusPill(input: {};}+ if (hasUnseenFailure(thread)) {+ return {+ label: "Failed",+ colorClass: "text-red-600 dark:text-red-300/90",+ dotClass: "bg-red-500 dark:bg-red-300/90",+ pulse: false,+ };+ }+const hasPlanReadyPrompt =!thread.hasPendingUserInput &&thread.interactionMode === "plan" &&