:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): clear task unread dots when opened (#94067)
Adam Bowker65ade489538f
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsxindex 7680a4f9c8e8..cc46b72a0bd3 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx@@ -159,12 +159,11 @@ describe("ChannelItemRow", () => {],["a streaming agent", { isGenerating: true }, "Working"],[- // A background run is one-shot and unattended, so its in_progress really- // is a claim that the agent is still on it. Live, but nothing streaming —- // the still dot, not the spinner.- "a background run claiming progress with nothing in flight",+ // Persisted run status can outlive the work. Without a live stream it+ // must not look like unread attention that opening the session can clear.+ "a background run left in progress with nothing in flight",{ taskRunStatus: "in_progress" as const, runMode: "background" as const },- "Pending — no work in flight",+ "All caught up",],[// The backend leaves an interactive run in_progress after it succeeds, so@@ -190,7 +189,16 @@ describe("ChannelItemRow", () => {// here means "was launched at some point", not "is starting"."a local background run parked at queued",{ taskRunStatus: "queued" as const, runMode: "background" as const },- "Pending — no work in flight",+ "All caught up",+ ],+ [+ "unread output on a background run with stale status",+ {+ taskRunStatus: "in_progress" as const,+ runMode: "background" as const,+ isUnread: true,+ },+ "Unread — something to read",],[// A PR outranks a run that only claims to be working, but not one that isdiff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useRecentSpaceTasks.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useRecentSpaceTasks.tsindex c9fe49e8db01..d98a0a583a11 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useRecentSpaceTasks.ts+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useRecentSpaceTasks.ts@@ -109,15 +109,13 @@ interface CachedSpaceTasks {}/**- * What a session is asking of you: blocked on you, then merely unread or- * working, then quiet.+ * What a session is asking of you: blocked on you, then unread or working,+ * then quiet.** Blue is its own tier rather than part of the yellow one, because the two are- * cleared differently. `wantsAttention` is the space dot's yellow predicate, and- * reading a session clears it: open a blocked session and its row would fall- * past the unread rows above it while the prompt it is blocked on is still- * sitting there unanswered. A permission prompt only goes away when answered, so- * a blue row holds its place until it is.+ * cleared differently. `wantsAttention` is the space dot's yellow predicate.+ * Opening clears unread; live work stays yellow until it settles. A permission+ * prompt only goes away when answered, so a blue row holds its place until it is.*/const ATTENTION_TIERS = 3;diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useUnreadSessionCount.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useUnreadSessionCount.tsindex 3d3642d67d16..a4c08dac3492 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useUnreadSessionCount.ts+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useUnreadSessionCount.ts@@ -17,7 +17,7 @@ import { useMemo } from "react";* answers, asked of a task we only have the polled DTO for.** Grey is the vocabulary's "nothing owed", so anything else is a dot worth- * counting: blue is blocked on you, yellow is working, pending, or unread.+ * counting: blue is blocked on you, yellow is working or unread.* Running it through `taskDot` rather than re-deriving the rule is the point —* the space's dots have to mean what the session rows' dots mean, and there is* one function that decides that.diff --git a/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx b/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsxindex 32182e44915a..a2532f6bdff2 100644--- a/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx+++ b/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx@@ -35,7 +35,6 @@ import { useMarqueeSelection } from "@posthog/ui/features/sidebar/useMarqueeSeleimport { usePinnedTasks } from "@posthog/ui/features/sidebar/usePinnedTasks";import { useSidebarBulkActions } from "@posthog/ui/features/sidebar/useSidebarBulkActions";import { useSidebarData } from "@posthog/ui/features/sidebar/useSidebarData";-import { useTaskViewed } from "@posthog/ui/features/sidebar/useTaskViewed";import { HandoffTaskDialog } from "@posthog/ui/features/task-detail/components/HandoffTaskDialog";import { useTaskContextMenu } from "@posthog/ui/features/tasks/useTaskContextMenu";import { useRenameTask } from "@posthog/ui/features/tasks/useTaskMutations";@@ -82,8 +81,6 @@ function SidebarMenuComponent() {);const { data: workspaces = {} } = useWorkspaces();- const { markAsViewed } = useTaskViewed();-const { folders, removeFolder } = useFolders();const openExternalApp = useExternalAppAction();@@ -102,26 +99,6 @@ function SidebarMenuComponent() {const commandCenterCells = useCommandCenterStore((s) => s.cells);- const previousTaskIdRef = useRef<string | null>(null);-- useEffect(() => {- const currentTaskId =- view.type === "task-detail" && view.taskId ? view.taskId : null;-- if (- previousTaskIdRef.current &&- previousTaskIdRef.current !== currentTaskId- ) {- markAsViewed(previousTaskIdRef.current);- }-- if (currentTaskId) {- markAsViewed(currentTaskId);- }-- previousTaskIdRef.current = currentTaskId;- }, [view, markAsViewed]);-const queryClient = useQueryClient();const [archiveConfirm, setArchiveConfirm] = useState<{diff --git a/products/desktop/packages/ui/src/features/sidebar/components/items/taskStatusVocabulary.ts b/products/desktop/packages/ui/src/features/sidebar/components/items/taskStatusVocabulary.tsindex 81902ee43e64..1aff5fa7d715 100644--- a/products/desktop/packages/ui/src/features/sidebar/components/items/taskStatusVocabulary.ts+++ b/products/desktop/packages/ui/src/features/sidebar/components/items/taskStatusVocabulary.ts@@ -110,19 +110,12 @@ export interface TaskDot {** A cloud run's queued is folded into working for the same reason. "Waiting on a* sandbox" and "a sandbox is writing code" are one fact to the reader, that it's- * under way, so they share the spinner. Two states don't share it: a local run- * at `queued`, whose persisted status nothing ever advances, and a run at- * `in_progress` with nothing streaming. Both claims outlive the work, and a- * spinner that never stops is a lie about the machine.+ * under way, so they share the spinner. A local run at `queued`, or any run at+ * `in_progress` with nothing streaming, is not a live signal by itself: those+ * persisted states can outlive the work, so neither earns an attention dot.*- * And a run that has already opened a PR is not working, whatever its status- * says. The cloud workflow keeps the run `in_progress` while it babysits CI- * after opening the PR, and under a merge queue that wait ends only when someone- * enqueues the merge — so the run can claim to be working for hours after the- * agent stopped. The PR is the deliverable; once it exists the badge carries the- * story and the dot goes quiet. This beats a status that merely claims work, not- * one that is visibly starting: a re-queued cloud run keeps its spinner even- * with last run's PR still on the task.+ * A run that has already opened a PR follows the same rule. The PR badge carries+ * that story; only a visibly starting or streaming run lights the dot.*/export function taskDot(props: TaskStatusInput): TaskDot {if (props.needsPermission) {@@ -157,22 +150,6 @@ export function taskDot(props: TaskStatusInput): TaskDot {label: props.isGenerating && !isStarting ? "Working" : "Starting",};}- // Only a background run's status is a claim about work. An interactive run is- // left `in_progress` after it succeeds, deliberately — the session stays open- // for a follow-up, so the status says "followable", not "working". Reading it- // as a claim marked every finished session as pending, on a row nobody could- // clear: opening the session writes a viewed timestamp, not a status.- const runClaimsWork =- props.runMode === "background" &&- (props.taskRunStatus === "in_progress" || props.taskRunStatus === "queued");- if (runClaimsWork && !hasPullRequest(props)) {- return {- tone: "yellow",- style: "solid",- pulse: false,- label: "Pending — no work in flight",- };- }if (props.isUnread) {// Solid, not flashing: fresh output is worth a look but isn't blocking the// run the way a permission prompt is, and two moving states in one list@@ -201,14 +178,6 @@ export function taskDot(props: TaskStatusInput): TaskDot {};}-/**- * Whether a PR exists at all, by either route: the state from a GitHub lookup,- * or just the url the run wrote when it opened one.- */-function hasPullRequest(props: TaskStatusInput): boolean {- return props.prState != null || !!props.prUrl;-}-export interface TaskBadge {key: string;Icon: Icon;diff --git a/products/desktop/packages/ui/src/features/sidebar/useTaskViewed.test.tsx b/products/desktop/packages/ui/src/features/sidebar/useTaskViewed.test.tsxnew file mode 100644index 000000000000..cc472a94bd01--- /dev/null+++ b/products/desktop/packages/ui/src/features/sidebar/useTaskViewed.test.tsx@@ -0,0 +1,81 @@+import { isTaskUnread } from "@posthog/core/sidebar/buildSidebarData";+import type { RawTaskTimestamp } from "@posthog/core/sidebar/taskMeta";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { act, renderHook, waitFor } from "@testing-library/react";+import type { PropsWithChildren } from "react";+import { beforeEach, describe, expect, it, vi } from "vitest";++const TIMESTAMPS_QUERY_KEY = ["task-timestamps"];+const mocks = vi.hoisted(() => ({+ loadTimestamps: vi.fn(),+ markActivity: vi.fn(),+ markViewed: vi.fn(),+}));++vi.mock("@posthog/host-router/react", () => ({+ useHostTRPC: () => ({+ workspace: {+ getAllTaskTimestamps: {+ queryKey: () => TIMESTAMPS_QUERY_KEY,+ queryOptions: (+ _input: undefined,+ options: Record<string, unknown>,+ ) => ({+ queryKey: TIMESTAMPS_QUERY_KEY,+ queryFn: mocks.loadTimestamps,+ ...options,+ }),+ },+ },+ }),+ useHostTRPCClient: () => ({+ workspace: {+ markActivity: { mutate: mocks.markActivity },+ markViewed: { mutate: mocks.markViewed },+ },+ }),+}));++import { useTaskViewed } from "./useTaskViewed";++describe("useTaskViewed", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mocks.markViewed.mockResolvedValue(undefined);+ });++ it("clears unread immediately when a task is viewed", async () => {+ const queryClient = new QueryClient({+ defaultOptions: {+ queries: { retry: false },+ mutations: { retry: false },+ },+ });+ const wrapper = ({ children }: PropsWithChildren) => (+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ );+ const activityAt = new Date(Date.now() - 60_000).toISOString();+ queryClient.setQueryData<Record<string, RawTaskTimestamp>>(+ TIMESTAMPS_QUERY_KEY,+ {+ "task-1": {+ pinnedAt: null,+ lastViewedAt: "2026-01-01T00:00:00.000Z",+ lastActivityAt: null,+ },+ },+ );+ const { result } = renderHook(() => useTaskViewed(), { wrapper });++ act(() => result.current.markAsViewed("task-1"));++ await waitFor(() => {+ expect(+ isTaskUnread(activityAt, result.current.timestamps["task-1"]),+ ).toBe(false);+ });+ expect(mocks.markViewed).toHaveBeenCalledWith({+ taskId: "task-1",+ });+ });+});diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsxindex 4c8e9c4d5cac..32a91ad2e6a3 100644--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx@@ -27,6 +27,7 @@ import { useRenameTask } from "../../tasks/useTaskMutations";import { useWorkspace } from "../../workspace/useWorkspace";import { useWorkspaceEvents } from "../../workspace/useWorkspaceEvents";import { HeaderTitleEditor } from "../HeaderTitleEditor";+import { useMarkTaskViewed } from "../hooks/useMarkTaskViewed";import { useTaskData } from "../hooks/useTaskData";import { CustomImageBadge } from "./CustomImageBadge";import { TaskHeaderMark, TaskHeaderMarks } from "./TaskHeaderStatus";@@ -53,6 +54,7 @@ export function TaskDetail({}: TaskDetailProps) {const taskId = initialTask.id;const { task } = useTaskData({ taskId, initialTask });+ useMarkTaskViewed(taskId);const effectiveRepoPath = useCwd(taskId);diff --git a/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.test.tsx b/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.test.tsxnew file mode 100644index 000000000000..0e6860e87865--- /dev/null+++ b/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.test.tsx@@ -0,0 +1,29 @@+import { renderHook } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";++const markAsViewed = vi.hoisted(() => vi.fn());++vi.mock("@posthog/ui/features/sidebar/useTaskViewed", () => ({+ useTaskViewed: () => ({ markAsViewed }),+}));++import { useMarkTaskViewed } from "./useMarkTaskViewed";++describe("useMarkTaskViewed", () => {+ beforeEach(() => vi.clearAllMocks());++ it("marks each rendered task as viewed once", () => {+ const { rerender } = renderHook((taskId) => useMarkTaskViewed(taskId), {+ initialProps: "task-1",+ });++ expect(markAsViewed).toHaveBeenLastCalledWith("task-1");++ markAsViewed.mockClear();+ rerender("task-1");+ expect(markAsViewed).not.toHaveBeenCalled();++ rerender("task-2");+ expect(markAsViewed).toHaveBeenLastCalledWith("task-2");+ });+});diff --git a/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.ts b/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.tsnew file mode 100644index 000000000000..2d103792b82a--- /dev/null+++ b/products/desktop/packages/ui/src/features/task-detail/hooks/useMarkTaskViewed.ts@@ -0,0 +1,10 @@+import { useTaskViewed } from "@posthog/ui/features/sidebar/useTaskViewed";+import { useEffect } from "react";++export function useMarkTaskViewed(taskId: string): void {+ const { markAsViewed } = useTaskViewed();++ useEffect(() => {+ markAsViewed(taskId);+ }, [markAsViewed, taskId]);+}diff --git a/products/desktop/packages/ui/src/router/routes/_shell/spaces/$channelId/tasks/$taskId.tsx b/products/desktop/packages/ui/src/router/routes/_shell/spaces/$channelId/tasks/$taskId.tsxindex 07c6365b8231..040b8236eed8 100644--- a/products/desktop/packages/ui/src/router/routes/_shell/spaces/$channelId/tasks/$taskId.tsx+++ b/products/desktop/packages/ui/src/router/routes/_shell/spaces/$channelId/tasks/$taskId.tsx@@ -2,7 +2,6 @@ import type { Task } from "@posthog/shared/domain-types";import { ThreadSidebar } from "@posthog/ui/features/canvas/components/ThreadSidebar";import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";-import { useTaskViewed } from "@posthog/ui/features/sidebar/useTaskViewed";import { TaskDetail } from "@posthog/ui/features/task-detail/components/TaskDetail";import {getCachedTask,@@ -17,7 +16,6 @@ import { yieldToPaint } from "@posthog/ui/router/yieldToPaint";import { Button, Flex, Text } from "@radix-ui/themes";import { useQuery } from "@tanstack/react-query";import { createFileRoute, Navigate } from "@tanstack/react-router";-import { useEffect } from "react";export const Route = createFileRoute("/_shell/spaces/$channelId/tasks/$taskId")({@@ -47,15 +45,6 @@ function ChannelTaskDetailRoute() {const { channels } = useChannels();const channelName = channels.find((c) => c.id === channelId)?.name;- // The channels space doesn't mount SidebarMenu (which marks code-space tasks- // viewed on open), so mark it viewed here. Clears the task's unread state and- // lets a canvas's generation task drop out of the nested sidebar row once the- // user has actually looked at it.- const { markAsViewed } = useTaskViewed();- useEffect(() => {- markAsViewed(taskId);- }, [taskId, markAsViewed]);-const {data: fetched,error,