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): recognize cloud tasks without a workspace row (#82981)

Charles Vien97dd7dd13581
diff --git a/products/desktop/apps/code/src/shared/constants.ts b/products/desktop/apps/code/src/shared/constants.ts
index 413f8d381a59..cf3e7cc15f17 100644
--- a/products/desktop/apps/code/src/shared/constants.ts
+++ b/products/desktop/apps/code/src/shared/constants.ts
@@ -3,7 +3,6 @@ export const EXPERIMENT_SUGGESTIONS_FLAG =
"posthog-code-experiment-suggestions";
export const SELF_DRIVING_SETUP_TASK_FLAG =
"posthog-code-self-driving-setup-task";
-export const SYNC_CLOUD_TASKS_FLAG = "posthog-code-sync-cloud-tasks";
export const DISCOVERY_RUN_FLAG = "posthog-code-discovery-run";
export const BRANCH_PREFIX = "posthog/";
export const APP_WINDOW_ARG = "--posthog-app-window";
diff --git a/products/desktop/apps/web/README.md b/products/desktop/apps/web/README.md
index 325baa3707fb..c23059cfd200 100644
--- a/products/desktop/apps/web/README.md
+++ b/products/desktop/apps/web/README.md
@@ -85,7 +85,7 @@ All are Vite build-time vars (`import.meta.env.*`), baked in at build time.
| Var | Required | Purpose |
| --- | --- | --- |
-| `VITE_POSTHOG_API_KEY` | Recommended | Real `phc_…` project key. Enables posthog-js analytics, error/rejection capture, session recording, and real feature flags. The guard in `main.tsx` requires the `phc_` prefix; without it posthog stays uninitialized and the tracker/analytics service no-op, leaving only the host-forced `SYNC_CLOUD_TASKS_FLAG` on (every other flag reads `false`). |
+| `VITE_POSTHOG_API_KEY` | Recommended | Real `phc_…` project key. Enables posthog-js analytics, error/rejection capture, session recording, and real feature flags. The guard in `main.tsx` requires the `phc_` prefix; without it posthog stays uninitialized, the tracker/analytics service no-op and every flag reads `false`. |
| `VITE_POSTHOG_API_HOST` | No | posthog-js ingestion host. Default `https://internal-c.posthog.com`. |
| `VITE_POSTHOG_UI_HOST` | No | posthog-js UI host. Default `https://us.i.posthog.com`. |
| `VITE_POSTHOG_ACCESS_TOKEN_OVERRIDE` | No | Dev/test only: a static access token that bypasses the OAuth flow (`AUTH_TOKEN_OVERRIDE`). Leave unset in production. |
diff --git a/products/desktop/apps/web/src/web-container.ts b/products/desktop/apps/web/src/web-container.ts
index 23cf5821417b..58e2da805a15 100644
--- a/products/desktop/apps/web/src/web-container.ts
+++ b/products/desktop/apps/web/src/web-container.ts
@@ -193,7 +193,7 @@ import {
type IPowerManager,
POWER_MANAGER_SERVICE,
} from "@posthog/platform/power-manager";
-import { type Adapter, SYNC_CLOUD_TASKS_FLAG } from "@posthog/shared";
+import type { Adapter } from "@posthog/shared";
import { sandboxProxyHtml } from "@posthog/shared/mcp-sandbox-proxy";
import { authUiModule } from "@posthog/ui/features/auth/auth.module";
import {
@@ -501,19 +501,10 @@ container
.toDynamicValue(() => getSessionService())
.inSingletonScope();
-// ── Feature flags (real posthog-js, with one host-forced flag) ──
-container.bind(FEATURE_FLAGS).toConstantValue({
- // Cloud-task sync is a hard requirement of the cloud-only host — __root's
- // reconcile effect derives the (localStorage-backed) sidebar task list from it
- // — so force it on regardless of the remote flag, then defer every other flag
- // to posthog-js. When posthog isn't initialized (no real VITE_POSTHOG_API_KEY),
- // isEnabled returns false for everything else, so only the forced flag is on —
- // same behavior as the old stub, but real flags light up once a key is set.
- isEnabled: (flagKey: string) =>
- flagKey === SYNC_CLOUD_TASKS_FLAG || posthogFeatureFlags.isEnabled(flagKey),
- getPayload: posthogFeatureFlags.getPayload,
- onFlagsLoaded: posthogFeatureFlags.onFlagsLoaded,
-});
+// ── Feature flags (real posthog-js) ──
+// When posthog isn't initialized (no real VITE_POSTHOG_API_KEY), isEnabled
+// returns false for everything; real flags light up once a key is set.
+container.bind(FEATURE_FLAGS).toConstantValue(posthogFeatureFlags);
// ── Analytics + error tracking (real posthog-js) ──
// Both ports share the single posthog-js instance initialized in main.tsx (see
diff --git a/products/desktop/packages/shared/src/constants.ts b/products/desktop/packages/shared/src/constants.ts
index 0e3f6e615c92..f34e86c35d9f 100644
--- a/products/desktop/packages/shared/src/constants.ts
+++ b/products/desktop/packages/shared/src/constants.ts
@@ -2,7 +2,6 @@ export {
BILLING_FLAG,
DISCOVERY_RUN_FLAG,
EXPERIMENT_SUGGESTIONS_FLAG,
- SYNC_CLOUD_TASKS_FLAG,
} from "./flags";
export const SELF_DRIVING_SETUP_TASK_FLAG =
diff --git a/products/desktop/packages/shared/src/flags.ts b/products/desktop/packages/shared/src/flags.ts
index 6ef368e14659..d881c2587293 100644
--- a/products/desktop/packages/shared/src/flags.ts
+++ b/products/desktop/packages/shared/src/flags.ts
@@ -4,7 +4,6 @@ export const CLOUD_COMPUTE_BILLING_FLAG =
export const SPEND_ANALYSIS_FLAG = "posthog-code-spend-analysis";
export const EXPERIMENT_SUGGESTIONS_FLAG =
"posthog-code-experiment-suggestions";
-export const SYNC_CLOUD_TASKS_FLAG = "posthog-code-sync-cloud-tasks";
/** Autoresearch (metric-optimization loop). Staff-gated while it bakes. */
export const AUTORESEARCH_FLAG = "posthog-code-autoresearch";
export const DISCOVERY_RUN_FLAG = "posthog-code-discovery-run";
diff --git a/products/desktop/packages/ui/src/features/panels/components/LeafNodeRenderer.tsx b/products/desktop/packages/ui/src/features/panels/components/LeafNodeRenderer.tsx
index 50c42f887ce9..c9b9983fd429 100644
--- a/products/desktop/packages/ui/src/features/panels/components/LeafNodeRenderer.tsx
+++ b/products/desktop/packages/ui/src/features/panels/components/LeafNodeRenderer.tsx
@@ -10,7 +10,7 @@ import type { Task } from "@posthog/shared/domain-types";
import type React from "react";
import { useMemo } from "react";
import { useHostCapabilities } from "../../../shell/useHostCapabilities";
-import { useIsWorkspaceCloudRun } from "../../workspace/useWorkspace";
+import { useIsCloudTask } from "../../workspace/useWorkspace";
import { useTabInjection } from "../hooks/usePanelLayoutHooks";
import type { SplitDirection } from "../panelLayoutStore";
import type { LeafPanel } from "../panelTypes";
@@ -47,7 +47,7 @@ export const LeafNodeRenderer: React.FC<LeafNodeRendererProps> = ({
onAddTerminal,
onSplitPanel,
}) => {
- const isCloud = useIsWorkspaceCloudRun(taskId);
+ const isCloud = useIsCloudTask(task);
const { localWorkspaces } = useHostCapabilities();
// Hide the terminal for cloud runs, and on cloud-only hosts (web).
const hideTerminal = isCloud || !localWorkspaces;
diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.test.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.test.tsx
index fa2b56f3384f..13298ccc8e5f 100644
--- a/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.test.tsx
+++ b/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.test.tsx
@@ -19,7 +19,7 @@ vi.mock("../../sessions/components/ArtifactPreview", () => ({
ArtifactPreview: (): null => null,
}));
vi.mock("../../workspace/useWorkspace", () => ({
- useIsWorkspaceCloudRun: () => false,
+ useIsCloudTask: () => false,
}));
vi.mock("./ActionPanel", () => ({ ActionPanel: (): null => null }));
vi.mock("./CanvasInstructionsTab", () => ({
diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.tsx
index 269ebcd46ce7..59a3eb0d07b6 100644
--- a/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.tsx
+++ b/products/desktop/packages/ui/src/features/task-detail/components/TabContentRenderer.tsx
@@ -8,7 +8,7 @@ import {
import type { Tab } from "../../panels/panelTypes";
import { PiSessionView } from "../../pi-sessions/PiSessionView";
import { ArtifactPreview } from "../../sessions/components/ArtifactPreview";
-import { useIsWorkspaceCloudRun } from "../../workspace/useWorkspace";
+import { useIsCloudTask } from "../../workspace/useWorkspace";
import { ActionPanel } from "./ActionPanel";
import { CanvasInstructionsTab } from "./CanvasInstructionsTab";
import { ChangesPanel } from "./ChangesPanel";
@@ -28,8 +28,7 @@ export function TabContentRenderer({
taskId,
task,
}: TabContentRendererProps) {
- const isCloud =
- useIsWorkspaceCloudRun(taskId) || task.latest_run?.environment === "cloud";
+ const isCloud = useIsCloudTask(task);
const { data } = tab;
switch (data.type) {
diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.test.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.test.tsx
index 9e438ed75521..eedaf2b15ca2 100644
--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.test.tsx
+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.test.tsx
@@ -9,10 +9,21 @@ const { useWorkspace, useWorkspaceLoaded } = vi.hoisted(() => ({
useWorkspaceLoaded: vi.fn(),
}));
-vi.mock("@posthog/ui/features/workspace/useWorkspace", () => ({
- useWorkspace,
- useWorkspaceLoaded,
-}));
+vi.mock(
+ "@posthog/ui/features/workspace/useWorkspace",
+ async (importOriginal) => {
+ const actual =
+ await importOriginal<
+ typeof import("@posthog/ui/features/workspace/useWorkspace")
+ >();
+ return {
+ useWorkspace,
+ useWorkspaceLoaded,
+ useIsCloudTask: (task: Task) =>
+ actual.isCloudTask(task, useWorkspace(task.id)),
+ };
+ },
+);
vi.mock("@posthog/ui/features/auth/store", () => ({
useAuthStateValue: (selector: (state: { status: string }) => unknown) =>
selector({ status: "authenticated" }),
@@ -76,9 +87,9 @@ vi.mock("@posthog/ui/primitives/Tooltip", () => ({
import { TaskHeaderActions } from "./TaskHeaderActions";
-const task = { id: "task-1", title: "Fix the bug" } as Task;
-
-function renderActions() {
+function renderActions(
+ task: Task = { id: "task-1", title: "Fix the bug" } as Task,
+) {
render(
<Theme>
<TaskHeaderActions task={task} />
@@ -108,4 +119,19 @@ describe("TaskHeaderActions", () => {
expect(screen.getByText("task menu")).toBeInTheDocument();
expect(screen.queryByText("Continue in cloud")).not.toBeInTheDocument();
});
+
+ it("shows cloud controls for a cloud run without a local workspace row", () => {
+ useWorkspace.mockReturnValue(null);
+ useWorkspaceLoaded.mockReturnValue(true);
+
+ renderActions({
+ id: "task-1",
+ title: "Fix the bug",
+ latest_run: { environment: "cloud" },
+ } as Task);
+
+ expect(screen.getByText("stop cloud run")).toBeInTheDocument();
+ expect(screen.getByText("cloud actions")).toBeInTheDocument();
+ expect(screen.queryByText("Continue in cloud")).not.toBeInTheDocument();
+ });
});
diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.tsx
index b3e931afd6d7..b34463369d34 100644
--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.tsx
+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskHeaderActions.tsx
@@ -19,6 +19,7 @@ import { useHandoffDialogStore } from "@posthog/ui/features/sessions/handoffDial
import { useSessionCallbacks } from "@posthog/ui/features/sessions/hooks/useSessionCallbacks";
import { useSessionForTask } from "@posthog/ui/features/sessions/useSession";
import {
+ useIsCloudTask,
useWorkspace,
useWorkspaceLoaded,
} from "@posthog/ui/features/workspace/useWorkspace";
@@ -130,7 +131,7 @@ function TaskDiffStatsBadge({ task }: { task: Task }) {
export function TaskHeaderActions({ task }: { task: Task }) {
const workspace = useWorkspace(task.id);
const workspaceLoaded = useWorkspaceLoaded();
- const isCloudTask = workspace?.mode === "cloud";
+ const isCloudTask = useIsCloudTask(task);
return (
<Flex
diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskShellPanel.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskShellPanel.tsx
index 421683194cb5..0b9ab3c1265b 100644
--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskShellPanel.tsx
+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskShellPanel.tsx
@@ -1,12 +1,24 @@
+import { Cloud as CloudIcon, FolderDashed } from "@phosphor-icons/react";
+import {
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+ Spinner,
+} from "@posthog/quill";
import type { Task } from "@posthog/shared/domain-types";
-import { Box } from "@radix-ui/themes";
-import { useEffect } from "react";
+import { type ReactNode, useEffect } from "react";
import { usePanelLayoutStore } from "../../panels/panelLayoutStore";
import { useSessionSelector } from "../../sessions/sessionStore";
import { ShellTerminal } from "../../terminal/ShellTerminal";
import { useTerminalStore } from "../../terminal/terminalStore";
import { useShellProcessPoller } from "../../terminal/useShellProcessPoller";
-import { useWorkspace } from "../../workspace/useWorkspace";
+import {
+ useIsCloudTask,
+ useWorkspace,
+ useWorkspaceLoaded,
+} from "../../workspace/useWorkspace";
interface TaskShellPanelProps {
taskId: string;
@@ -14,18 +26,34 @@ interface TaskShellPanelProps {
shellId?: string;
}
-export function TaskShellPanel({
- taskId,
- task: _task,
- shellId,
-}: TaskShellPanelProps) {
+function TerminalUnavailable({
+ icon,
+ description,
+}: {
+ icon: ReactNode;
+ description: string;
+}) {
+ return (
+ <Empty className="h-full border-0">
+ <EmptyHeader>
+ <EmptyMedia variant="icon">{icon}</EmptyMedia>
+ <EmptyTitle>Terminal isn't available</EmptyTitle>
+ <EmptyDescription>{description}</EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ );
+}
+
+export function TaskShellPanel({ taskId, task, shellId }: TaskShellPanelProps) {
const stateKey = shellId ? `${taskId}-${shellId}` : taskId;
const tabId = shellId || "shell";
// Only the connection status gates rendering here; reading it narrowly keeps
// the terminal panel from re-rendering on every streamed token.
const sessionStatus = useSessionSelector(taskId, (s) => s?.status);
+ const isCloud = useIsCloudTask(task);
const workspace = useWorkspace(taskId);
+ const workspaceLoaded = useWorkspaceLoaded();
const workspacePath = workspace?.worktreePath ?? workspace?.folderPath;
const processName = useTerminalStore(
@@ -41,13 +69,35 @@ export function TaskShellPanel({
}
}, [processName, taskId, tabId, updateTabLabel]);
+ if (isCloud) {
+ return (
+ <TerminalUnavailable
+ icon={<CloudIcon size={24} className="text-gray-10" />}
+ description="This session runs in the cloud, not on this machine."
+ />
+ );
+ }
+
+ if (workspaceLoaded && !workspacePath) {
+ return (
+ <TerminalUnavailable
+ icon={<FolderDashed size={24} className="text-gray-10" />}
+ description="This task doesn't have a local workspace on this machine."
+ />
+ );
+ }
+
if (!workspacePath || !sessionStatus || sessionStatus === "connecting") {
- return null;
+ return (
+ <div className="flex h-full items-center justify-center">
+ <Spinner className="size-5 text-(--gray-9)" />
+ </div>
+ );
}
return (
- <Box height="100%">
+ <div className="h-full">
<ShellTerminal cwd={workspacePath} stateKey={stateKey} taskId={taskId} />
- </Box>
+ </div>
);
}
diff --git a/products/desktop/packages/ui/src/features/workspace/useWorkspace.test.ts b/products/desktop/packages/ui/src/features/workspace/useWorkspace.test.ts
new file mode 100644
index 000000000000..3b35c184a348
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/workspace/useWorkspace.test.ts
@@ -0,0 +1,58 @@
+import type { Workspace } from "@posthog/shared";
+import type { Task, TaskRunEnvironment } from "@posthog/shared/domain-types";
+import { describe, expect, it } from "vitest";
+import { isCloudTask } from "./useWorkspace";
+
+function task(environment?: TaskRunEnvironment): Task {
+ return {
+ id: "task-1",
+ ...(environment ? { latest_run: { environment } } : {}),
+ } as Task;
+}
+
+function workspace(mode: Workspace["mode"]): Workspace {
+ return { mode } as Workspace;
+}
+
+describe("isCloudTask", () => {
+ it.each([
+ {
+ name: "no workspace row, cloud run",
+ task: task("cloud"),
+ workspace: null,
+ expected: true,
+ },
+ {
+ name: "no workspace row, local run",
+ task: task("local"),
+ workspace: null,
+ expected: false,
+ },
+ {
+ name: "no workspace row, no run",
+ task: task(),
+ workspace: null,
+ expected: false,
+ },
+ {
+ name: "cloud workspace row",
+ task: task(),
+ workspace: workspace("cloud"),
+ expected: true,
+ },
+ {
+ name: "local workspace row wins over cloud run",
+ task: task("cloud"),
+ workspace: workspace("local"),
+ expected: false,
+ },
+ {
+ name: "worktree workspace row wins over cloud run",
+ task: task("cloud"),
+ workspace: workspace("worktree"),
+ expected: false,
+ },
+ ])("$name -> $expected", ({ task, workspace, expected }) => {
+ expect(isCloudTask(task, workspace)).toBe(expected);
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/workspace/useWorkspace.ts b/products/desktop/packages/ui/src/features/workspace/useWorkspace.ts
index 00483dcd41ec..131c1b98ba2d 100644
--- a/products/desktop/packages/ui/src/features/workspace/useWorkspace.ts
+++ b/products/desktop/packages/ui/src/features/workspace/useWorkspace.ts
@@ -1,5 +1,6 @@
import { useHostTRPC } from "@posthog/host-router/react";
import type { Workspace } from "@posthog/shared";
+import type { Task } from "@posthog/shared/domain-types";
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
@@ -33,6 +34,19 @@ export function useIsWorkspaceCloudRun(taskId: string | undefined): boolean {
return workspace?.mode === "cloud";
}
+// The workspace row wins when present: handoff updates it before latest_run refreshes.
+export function isCloudTask(task: Task, workspace: Workspace | null): boolean {
+ if (workspace) {
+ return workspace.mode === "cloud";
+ }
+ return task.latest_run?.environment === "cloud";
+}
+
+export function useIsCloudTask(task: Task): boolean {
+ const workspace = useWorkspace(task.id);
+ return isCloudTask(task, workspace);
+}
+
export function useWorkspaceLoaded(): boolean {
const { isFetched } = useWorkspacesQuery();
return isFetched;
diff --git a/products/desktop/packages/ui/src/router/routes/__root.tsx b/products/desktop/packages/ui/src/router/routes/__root.tsx
index 773009e4c116..c2c514cb3d11 100644
--- a/products/desktop/packages/ui/src/router/routes/__root.tsx
+++ b/products/desktop/packages/ui/src/router/routes/__root.tsx
@@ -5,11 +5,7 @@ import {
} from "@phosphor-icons/react";
import { useHostTRPC, useHostTRPCClient } from "@posthog/host-router/react";
import { Button, ButtonGroup } from "@posthog/quill";
-import {
- BILLING_FLAG,
- PROJECT_BLUEBIRD_FLAG,
- SYNC_CLOUD_TASKS_FLAG,
-} from "@posthog/shared";
+import { BILLING_FLAG, PROJECT_BLUEBIRD_FLAG } from "@posthog/shared";
import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
import { isContentlessTask } from "@posthog/shared/domain-types";
import { DeepLinkApprovalModal } from "@posthog/ui/features/agent-applications/components/DeepLinkApprovalModal";
@@ -204,7 +200,6 @@ function RootLayout() {
const queryClient = useQueryClient();
const reconcilingTaskIds = useRef<Set<string>>(new Set());
const billingEnabled = useFeatureFlag(BILLING_FLAG);
- const syncCloudTasksEnabled = useFeatureFlag(SYNC_CLOUD_TASKS_FLAG);
// "PostHog Web" is a channels-world affordance — show it only while the user
// is actually seeing channels (toggle on, which itself requires the flag).
const bluebirdEnabled = useFeatureFlag(
@@ -249,7 +244,6 @@ function RootLayout() {
// task cache populates the route automatically.
useEffect(() => {
- if (!syncCloudTasksEnabled) return;
if (!tasks || !workspaces || !workspacesFetched) return;
const missing = tasks.filter(
(t) =>
@@ -277,15 +271,7 @@ function RootLayout() {
for (const id of missingIds) reconcilingTaskIds.current.delete(id);
log.warn("Failed to reconcile cloud workspaces", err);
});
- }, [
- syncCloudTasksEnabled,
- tasks,
- workspaces,
- workspacesFetched,
- queryClient,
- hostClient,
- trpc,
- ]);
+ }, [tasks, workspaces, workspacesFetched, queryClient, hostClient, trpc]);
// Flags resolve asynchronously — flag-gated routes below wait for this
// before redirecting away from a restored route the user can't access.