Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions site/src/api/queries/chats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,78 @@ describe("mergeWatchedChatSummary", () => {
}).has_unread,
).toBe(false);
});

it("does not mark inactive chats unread when transitioning to running", () => {
const cachedChat = makeChat("chat-1", {
has_unread: false,
updated_at: "2025-01-01T00:00:00.000Z",
});
const watchedChat = makeChat("chat-1", {
status: "running",
updated_at: "2025-01-01T00:05:00.000Z",
});

expect(
mergeWatchedChatSummary(cachedChat, watchedChat, {
eventKind: "status_change",
activeChatId: "chat-2",
}).has_unread,
).toBe(false);
});

it("does not mark inactive chats unread when transitioning to pending", () => {
const cachedChat = makeChat("chat-1", {
has_unread: false,
updated_at: "2025-01-01T00:00:00.000Z",
});
const watchedChat = makeChat("chat-1", {
status: "pending",
updated_at: "2025-01-01T00:05:00.000Z",
});

expect(
mergeWatchedChatSummary(cachedChat, watchedChat, {
eventKind: "status_change",
activeChatId: "chat-2",
}).has_unread,
).toBe(false);
});

it("preserves existing has_unread when transitioning to a streaming status", () => {
const cachedChat = makeChat("chat-1", {
has_unread: true,
updated_at: "2025-01-01T00:00:00.000Z",
});
const watchedChat = makeChat("chat-1", {
status: "running",
updated_at: "2025-01-01T00:05:00.000Z",
});

expect(
mergeWatchedChatSummary(cachedChat, watchedChat, {
eventKind: "status_change",
activeChatId: "chat-2",
}).has_unread,
).toBe(true);
});

it("marks inactive chats unread when transitioning to waiting", () => {
const cachedChat = makeChat("chat-1", {
has_unread: false,
updated_at: "2025-01-01T00:00:00.000Z",
});
const watchedChat = makeChat("chat-1", {
status: "waiting",
updated_at: "2025-01-01T00:05:00.000Z",
});

expect(
mergeWatchedChatSummary(cachedChat, watchedChat, {
eventKind: "status_change",
activeChatId: "chat-2",
}).has_unread,
).toBe(true);
});
});

describe("mergeWatchedChatIntoCaches", () => {
Expand Down
13 changes: 12 additions & 1 deletion site/src/api/queries/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,19 @@ export const mergeWatchedChatSummary = (
isFreshEnough || isSummaryEvent
? watchedChat.last_turn_summary
: cachedChat.last_turn_summary;
// Only flip has_unread to true on a status_change when the new status is
// not actively streaming. While a chat is `running` or `pending` the user
// has nothing to act on (the spinner already conveys progress), and an
// unread dot in that state is just noise. Intermediate status_change
// events during a turn would also race the authoritative server value,
// producing a visible flicker where the dot appears then vanishes.
const isStreamingStatus =
watchedChat.status === "running" || watchedChat.status === "pending";
const nextHasUnread =
isFreshEnough && isStatusEvent && watchedChat.id !== activeChatId
isFreshEnough &&
isStatusEvent &&
watchedChat.id !== activeChatId &&
!isStreamingStatus
? true
: cachedChat.has_unread;
const nextUpdatedAt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ const ChatTreeNode: FC<ChatTreeNodeProps> = ({ chat, isChildNode }) => {
>
{chat.title}
</span>
{chat.has_unread && !isActiveChat && (
{chat.has_unread && !isActiveChat && !isStreaming && (
<span className="sr-only">(unread)</span>
)}
{isRegeneratingThisChat && (
Expand Down Expand Up @@ -762,7 +762,7 @@ const ChatTreeNode: FC<ChatTreeNodeProps> = ({ chat, isChildNode }) => {
) : (
<>
<span className="flex items-center justify-end text-xs text-content-secondary/50 tabular-nums [@media(hover:hover)]:group-hover:hidden group-has-[[data-state=open]]:hidden">
{chat.has_unread && !isActiveChat ? (
{chat.has_unread && !isActiveChat && !isStreaming ? (
<span
className="h-2 w-2 shrink-0 rounded-full bg-content-link"
data-testid={`unread-indicator-${chat.id}`}
Expand Down
Loading