Skip to content

: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.

fix(desktop/sidebar): stop marking a finished session as pending (#80005)

Adam Leith2ed4f9f7847a
diff --git a/products/desktop/packages/core/src/sidebar/buildSidebarData.test.ts b/products/desktop/packages/core/src/sidebar/buildSidebarData.test.ts
index 705fab52511b..1e4ac2cb0db8 100644
--- a/products/desktop/packages/core/src/sidebar/buildSidebarData.test.ts
+++ b/products/desktop/packages/core/src/sidebar/buildSidebarData.test.ts
@@ -1,5 +1,9 @@
import { describe, expect, it } from "vitest";
-import { limitTasksPerGroup, sliceVisibleTasks } from "./buildSidebarData";
+import {
+ limitTasksPerGroup,
+ readRunMode,
+ sliceVisibleTasks,
+} from "./buildSidebarData";
import type { TaskData, TaskGroup } from "./sidebarData.types";
function makeTask(id: string): TaskData {
@@ -74,3 +78,19 @@ describe("limitTasksPerGroup", () => {
expect(hasMore).toBe(false);
});
});
+
+// The mode decides whether a run's `in_progress` is a claim that work is
+// happening. Defaulting the wrong way marks every finished interactive session
+// as pending, which is what this replaced.
+describe("readRunMode", () => {
+ it.each([
+ ["an interactive run", { mode: "interactive" }, "interactive"],
+ ["a background run", { mode: "background" }, "background"],
+ // The backend's own default for a run whose state never carried a mode.
+ ["a run with no mode", {}, "background"],
+ ["a run with no state at all", undefined, "background"],
+ ["a mode that is not a mode", { mode: 7 }, "background"],
+ ])("reads %s", (_case, state, expected) => {
+ expect(readRunMode(state)).toBe(expected);
+ });
+});
diff --git a/products/desktop/packages/core/src/sidebar/buildSidebarData.ts b/products/desktop/packages/core/src/sidebar/buildSidebarData.ts
index 2f1557301031..42469076c1e6 100644
--- a/products/desktop/packages/core/src/sidebar/buildSidebarData.ts
+++ b/products/desktop/packages/core/src/sidebar/buildSidebarData.ts
@@ -33,9 +33,32 @@ export interface SidebarTask {
status?: TaskRunStatus | null;
environment?: "local" | "cloud" | null;
output?: { pr_url?: unknown } | null;
+ /** "interactive" or "background"; see `readRunMode`. */
+ mode?: RunMode | null;
} | null;
}
+/**
+ * Whether anyone is expected to follow the run. The backend keeps an
+ * interactive run `in_progress` after it succeeds, on purpose — the session
+ * stays open for a follow-up, so that status is not a claim that work is
+ * happening. Only a background run is one-shot, and only its `in_progress`
+ * means the agent is still on it.
+ */
+export type RunMode = "interactive" | "background";
+
+/**
+ * The run's mode, off the untyped `state` bag the backend stores it in. It
+ * defaults to background there, so an absent value defaults the same way here.
+ */
+export function readRunMode(state: unknown): RunMode {
+ const mode =
+ state && typeof state === "object"
+ ? (state as { mode?: unknown }).mode
+ : undefined;
+ return mode === "interactive" ? "interactive" : "background";
+}
+
// Accepts both the local `FullTask` shape and the canonical `Task` from
// `@posthog/shared` so callers holding a real `Task` can narrow it directly,
// without an `as unknown as FullTask` escape hatch.
@@ -52,6 +75,7 @@ export function narrowFullTask(task: FullTask | Task): SidebarTask {
status: task.latest_run.status,
environment: task.latest_run.environment ?? null,
output: task.latest_run.output ?? null,
+ mode: readRunMode(task.latest_run.state),
}
: null,
origin_product: task.origin_product,
@@ -176,6 +200,7 @@ export function deriveTaskData(
folderId: workspace?.folderId || undefined,
taskRunStatus: session?.cloudStatus ?? task.latest_run?.status ?? undefined,
taskRunEnvironment: task.latest_run?.environment ?? undefined,
+ runMode: task.latest_run?.mode ?? undefined,
// The `latest_run` fallback only matters in the `showAllUsers` view: the
// default view's `filterVisibleTasks` already restricts to tasks with a
// local `workspace`, so a pure-cloud task without one only shows up there.
diff --git a/products/desktop/packages/core/src/sidebar/sidebarData.types.ts b/products/desktop/packages/core/src/sidebar/sidebarData.types.ts
index 706c139150d2..21c0f2cf7f14 100644
--- a/products/desktop/packages/core/src/sidebar/sidebarData.types.ts
+++ b/products/desktop/packages/core/src/sidebar/sidebarData.types.ts
@@ -1,5 +1,6 @@
import type { WorkspaceMode } from "@posthog/shared";
import type { TaskRunStatus } from "@posthog/shared/domain-types";
+import type { RunMode } from "./buildSidebarData";
import type {
TaskGroup as GenericTaskGroup,
TaskRepositoryInfo,
@@ -19,6 +20,7 @@ export interface TaskData {
folderId?: string;
taskRunStatus?: TaskRunStatus;
taskRunEnvironment?: "local" | "cloud";
+ runMode?: RunMode;
workspaceMode?: WorkspaceMode;
originProduct?: string;
slackThreadUrl?: string;
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/TaskTabIcon.tsx b/products/desktop/packages/ui/src/features/browser-tabs/TaskTabIcon.tsx
index f0476e771064..27e7a7e3ddb5 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/TaskTabIcon.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/TaskTabIcon.tsx
@@ -41,6 +41,7 @@ export function TaskTabIcon({
isSuspended={taskData.isSuspended}
needsPermission={taskData.needsPermission}
taskRunStatus={taskData.taskRunStatus}
+ runMode={taskData.runMode}
originProduct={taskData.originProduct}
slackThreadUrl={taskData.slackThreadUrl}
prState={prState}
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.tsx
index 0f464b413a4f..be776c0ba1d1 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
@@ -78,13 +78,25 @@ describe("ChannelItemRow", () => {
],
["a streaming agent", { isGenerating: true }, "Working"],
[
- // The run says in_progress, but nothing is streaming: a local run never
- // gets a terminal status written, and the cloud one holds in_progress past
- // the agent. Live, but not moving — the still dot, not the spinner.
- "a run claiming progress with nothing in flight",
- { taskRunStatus: "in_progress" as const },
+ // 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",
+ { taskRunStatus: "in_progress" as const, runMode: "background" as const },
"Pending — no work in flight",
],
+ [
+ // The backend leaves an interactive run in_progress after it succeeds, so
+ // the session stays open for a follow-up. Reading that as a claim marked
+ // every finished session pending, forever, on a row opening it could not
+ // clear.
+ "an interactive run left in_progress after it finished",
+ {
+ taskRunStatus: "in_progress" as const,
+ runMode: "interactive" as const,
+ },
+ "All caught up",
+ ],
[
// Launching: a sandbox is being claimed and the backend leaves this state
// on its own, so the motion is honest.
@@ -93,10 +105,10 @@ describe("ChannelItemRow", () => {
"Starting",
],
[
- // A local run's status is never advanced, so queued here means "was
- // launched at some point", not "is starting". Seen parked for hours.
- "a local run parked at queued",
- { taskRunStatus: "queued" as const },
+ // A background run's status is never advanced once it parks, so queued
+ // 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",
],
[
@@ -123,13 +135,18 @@ describe("ChannelItemRow", () => {
// opening the PR; under a merge queue that wait can outlast the agent by
// hours, so the PR's existence has to win over the run's claim.
"a run still babysitting CI behind an open PR",
- { taskRunStatus: "in_progress" as const, prState: "open" as const },
+ {
+ taskRunStatus: "in_progress" as const,
+ runMode: "background" as const,
+ prState: "open" as const,
+ },
"All caught up",
],
[
"a run whose PR url is known but state isn't",
{
taskRunStatus: "in_progress" as const,
+ runMode: "background" as const,
prUrl: "https://github.com/PostHog/code/pull/1",
},
"All caught up",
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelTaskStatus.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelTaskStatus.ts
index 41f577cabb75..cdabb5bb864a 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelTaskStatus.ts
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelTaskStatus.ts
@@ -49,6 +49,7 @@ export function useChannelTaskStatus(
isSuspended: taskData.isSuspended,
needsPermission: taskData.needsPermission,
taskRunStatus: taskData.taskRunStatus,
+ runMode: taskData.runMode,
originProduct: taskData.originProduct,
slackThreadUrl: taskData.slackThreadUrl,
prState,
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/TaskListView.tsx b/products/desktop/packages/ui/src/features/sidebar/components/TaskListView.tsx
index e3cf45a6c111..08ea61594f66 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/TaskListView.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/TaskListView.tsx
@@ -117,6 +117,7 @@ function TaskRow({
isPinned={task.isPinned}
needsPermission={task.needsPermission}
taskRunStatus={task.taskRunStatus}
+ runMode={task.runMode}
originProduct={task.originProduct}
slackThreadUrl={task.slackThreadUrl}
prState={prState}
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/items/TaskIcon.tsx b/products/desktop/packages/ui/src/features/sidebar/components/items/TaskIcon.tsx
index a978b17725c9..864dabc3ee67 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/items/TaskIcon.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/items/TaskIcon.tsx
@@ -17,6 +17,7 @@ import {
SlackLogo,
WarningCircle,
} from "@phosphor-icons/react";
+import type { RunMode } from "@posthog/core/sidebar/buildSidebarData";
import type { WorkspaceMode } from "@posthog/shared";
import {
isTerminalStatus,
@@ -274,6 +275,8 @@ export interface TaskIconProps {
isSuspended?: boolean;
needsPermission?: boolean;
taskRunStatus?: TaskRunStatus;
+ /** Whether anyone follows this run. Only a background run's status claims work. */
+ runMode?: RunMode;
originProduct?: string;
/** Pre-built URL to the originating Slack thread (read from
* `task.latest_run.state.slack_thread_url`). When set, the Slack icon
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/items/TaskItem.tsx b/products/desktop/packages/ui/src/features/sidebar/components/items/TaskItem.tsx
index da8383f24aae..a7d4053f4a1d 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/items/TaskItem.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/items/TaskItem.tsx
@@ -1,4 +1,5 @@
import { Archive, GitPullRequest, PushPin } from "@phosphor-icons/react";
+import type { RunMode } from "@posthog/core/sidebar/buildSidebarData";
import { parseGithubUrl } from "@posthog/git/utils";
import type { WorkspaceMode } from "@posthog/shared";
import { formatRelativeTimeShort } from "@posthog/shared";
@@ -45,6 +46,7 @@ interface TaskItemProps {
isSuspended?: boolean;
needsPermission?: boolean;
taskRunStatus?: TaskRunStatus;
+ runMode?: RunMode;
originProduct?: string;
slackThreadUrl?: string;
prState?: SidebarPrState;
@@ -117,6 +119,7 @@ export function TaskItem({
isPinned = false,
needsPermission = false,
taskRunStatus,
+ runMode,
originProduct,
slackThreadUrl,
prState,
@@ -143,6 +146,7 @@ export function TaskItem({
isSuspended={isSuspended}
needsPermission={needsPermission}
taskRunStatus={taskRunStatus}
+ runMode={runMode}
originProduct={originProduct}
slackThreadUrl={slackThreadUrl}
prState={prState}
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.ts
index 4d340c79a4f0..e2afb9b45ebf 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
@@ -148,12 +148,14 @@ export function taskDot(props: TaskStatusInput): TaskDot {
label: props.isGenerating ? "Working" : "Starting",
};
}
- // The statuses that lie. Nothing writes a terminal status when a local agent
- // goes idle, and the cloud workflow holds in_progress while it babysits CI, so
- // the claim outlives the work, sometimes for the row's whole life. Live, but
- // nothing moving: the still dot.
+ // 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.taskRunStatus === "in_progress" || props.taskRunStatus === "queued";
+ props.runMode === "background" &&
+ (props.taskRunStatus === "in_progress" || props.taskRunStatus === "queued");
if (runClaimsWork && !hasPullRequest(props)) {
return {
tone: "yellow",