Skip to content

Commit e65f5a3

Browse files
fix(web): clear failed badges when threads are opened
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 58a407c commit e65f5a3

3 files changed

Lines changed: 83 additions & 10 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
pinOrderKeyBetween,
1919
resolveProjectStatusIndicator,
2020
resolveSidebarSweepKeys,
21+
resolveSidebarRowStatus,
2122
resolveSidebarThreadStatus,
2223
resolveThreadStatusPill,
2324
resolveWorkingStartedAt,
@@ -348,6 +349,55 @@ describe("resolveSidebarThreadStatus", () => {
348349
});
349350
});
350351

352+
describe("resolveSidebarRowStatus", () => {
353+
const failedRuntime = {
354+
status: "failed" as const,
355+
activeRunId: null,
356+
providerInstanceId: ProviderInstanceId.make("codex"),
357+
providerName: "Codex",
358+
lastError: "Provider turn failed.",
359+
updatedAt: "2026-03-09T10:05:00.000Z",
360+
};
361+
const failed = {
362+
hasActionableProposedPlan: false,
363+
hasPendingApprovals: false,
364+
hasPendingUserInput: false,
365+
interactionMode: "default" as const,
366+
runtime: failedRuntime,
367+
latestRun: { ...makeLatestRun(), status: "failed" as const },
368+
};
369+
370+
it("clears a failure once opened, without showing Done, and shows the next failure", () => {
371+
expect(resolveSidebarRowStatus({ ...failed, lastVisitedAt: undefined })).toBe("failed");
372+
373+
const opened = { ...failed, lastVisitedAt: "2026-03-09T10:06:00.000Z" };
374+
expect(resolveSidebarRowStatus(opened)).toBe("ready");
375+
expect(hasUnseenCompletion(opened)).toBe(false);
376+
377+
const failedAgain = {
378+
...opened,
379+
latestRun: { ...opened.latestRun, completedAt: "2026-03-09T10:10:00.000Z" },
380+
};
381+
expect(resolveSidebarRowStatus(failedAgain)).toBe("failed");
382+
});
383+
384+
it("dates a failure without a completed run by the runtime update", () => {
385+
const visitedAfter = "2026-03-09T10:06:00.000Z";
386+
const visitedBefore = "2026-03-09T10:00:00.000Z";
387+
const noCompletedAt = {
388+
...failed,
389+
latestRun: { ...failed.latestRun, completedAt: null },
390+
};
391+
expect(resolveSidebarRowStatus({ ...noCompletedAt, lastVisitedAt: visitedAfter })).toBe(
392+
"ready",
393+
);
394+
395+
const noRun = { ...failed, latestRun: null };
396+
expect(resolveSidebarRowStatus({ ...noRun, lastVisitedAt: visitedBefore })).toBe("failed");
397+
expect(resolveSidebarRowStatus({ ...noRun, lastVisitedAt: visitedAfter })).toBe("ready");
398+
});
399+
});
400+
351401
describe("searchSidebarThreads", () => {
352402
const searchThread = (id: string, title: string, latestUserMessageAt: string) => ({
353403
environmentId: localEnvironmentId,
@@ -1732,6 +1782,12 @@ describe("resolveSidebarFolderDot", () => {
17321782
expect(resolveSidebarFolderDot([idle, working])).toBe("working");
17331783
expect(resolveSidebarFolderDot([working, unread])).toBe("unread");
17341784
expect(resolveSidebarFolderDot([unread, limited])).toBe("attention");
1785+
// A failure the user already opened clears, like its row.
1786+
const failed = { ...idle, runtime: { ...runtime, status: "failed" as const } };
1787+
expect(resolveSidebarFolderDot([failed])).toBeNull();
1788+
expect(
1789+
resolveSidebarFolderDot([{ ...failed, lastVisitedAt: "2026-03-09T09:00:00.000Z" }]),
1790+
).toBe("failed");
17351791
});
17361792
});
17371793

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,22 @@ export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {
775775
}
776776

777777
/** Unopened threads' failures still count as unseen, unlike completions. */
778-
function hasUnseenFailure(thread: ThreadStatusInput): boolean {
779-
if (thread.latestRun?.status !== "failed") return false;
778+
function hasUnseenFailure(
779+
thread: Pick<ThreadStatusInput, "latestRun" | "runtime" | "lastVisitedAt">,
780+
): boolean {
781+
// Failed runs can lack completedAt, and a session can fail before any run.
782+
const failedAt =
783+
thread.latestRun?.status === "failed"
784+
? (thread.latestRun.completedAt ?? thread.runtime?.updatedAt)
785+
: thread.runtime?.status === "failed"
786+
? thread.runtime.updatedAt
787+
: undefined;
788+
if (failedAt === undefined) return false;
780789
if (!thread.lastVisitedAt) return true;
781-
const completedAt = Date.parse(thread.latestRun.completedAt ?? "");
782-
const lastVisitedAt = Date.parse(thread.lastVisitedAt);
783-
if (Number.isNaN(completedAt) || Number.isNaN(lastVisitedAt)) return true;
784-
return completedAt > lastVisitedAt;
790+
const failedAtMs = Date.parse(failedAt ?? "");
791+
const lastVisitedAtMs = Date.parse(thread.lastVisitedAt);
792+
if (Number.isNaN(failedAtMs) || Number.isNaN(lastVisitedAtMs)) return true;
793+
return failedAtMs > lastVisitedAtMs;
785794
}
786795

787796
// Suppress trailing double-click navigation; keyboard and synthetic clicks use detail 0.
@@ -952,14 +961,22 @@ export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): Si
952961
return "ready";
953962
}
954963

964+
/** Sidebar row status: a failure the user has already opened settles to ready, like Done. */
965+
export function resolveSidebarRowStatus(
966+
thread: SidebarThreadStatusInput & Pick<ThreadStatusInput, "latestRun" | "lastVisitedAt">,
967+
): SidebarThreadStatus {
968+
const status = resolveSidebarThreadStatus(thread);
969+
return status === "failed" && !hasUnseenFailure(thread) ? "ready" : status;
970+
}
971+
955972
/**
956973
* The dot on a closed boring-sidebar folder: the most urgent state among its
957974
* hidden threads. Waiting threads stay quiet, like their rows.
958975
*/
959976
export function resolveSidebarFolderDot(
960977
threads: ReadonlyArray<ThreadStatusInput & SidebarThreadStatusInput>,
961978
): "attention" | "failed" | "unread" | "working" | null {
962-
const statuses = new Set(threads.map(resolveSidebarThreadStatus));
979+
const statuses = new Set(threads.map(resolveSidebarRowStatus));
963980
if (
964981
statuses.has("input") ||
965982
statuses.has("approval") ||
@@ -971,7 +988,7 @@ export function resolveSidebarFolderDot(
971988
if (statuses.has("failed")) return "failed";
972989
// Rows show Done only for ready threads, so the dot follows the same rule.
973990
const hasUnread = threads.some(
974-
(thread) => resolveSidebarThreadStatus(thread) === "ready" && hasUnseenCompletion(thread),
991+
(thread) => resolveSidebarRowStatus(thread) === "ready" && hasUnseenCompletion(thread),
975992
);
976993
if (hasUnread) return "unread";
977994
if (statuses.has("working")) return "working";

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {
7979
hasUnseenCompletion,
8080
resolveSidebarRowAccessibility,
8181
type SidebarDropVerb,
82-
resolveSidebarThreadStatus,
82+
resolveSidebarRowStatus,
8383
resolveThreadLastVisitedAt,
8484
shouldRecedeSidebarThread,
8585
resolveWorkingStartedAt,
@@ -707,7 +707,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
707707
: null;
708708

709709
const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });
710-
const status = resolveSidebarThreadStatus(thread);
710+
const status = resolveSidebarRowStatus({ ...thread, lastVisitedAt });
711711
const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
712712
const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
713713
const isWoke =

0 commit comments

Comments
 (0)