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): keep unopened local tasks idle after restart (#98698)

Peter Kirkham79cecb8e8ba2
diff --git a/products/desktop/docs/ARCHITECTURE.md b/products/desktop/docs/ARCHITECTURE.md
index 72d27146bd99..8118fd6f9f63 100644
--- a/products/desktop/docs/ARCHITECTURE.md
+++ b/products/desktop/docs/ARCHITECTURE.md
@@ -80,6 +80,11 @@ has a prompt to send. A task description or an existing run does not imply that
prompt is pending. This lets an empty session open after a failed startup instead
of keeping it in the loading view. Opening it does not resend the description.
+A local task without a session is idle in the space sidebar after an app restart.
+The sidebar shows startup only when a startup marker or a live session reports it.
+The open chat can still show loading while it waits for its local connection.
+The shared lifecycle state must not treat an unopened task as an active startup.
+
New cloud runs seed the full user message before subscribing to setup progress.
The chat renders that message immediately, including its space context chip.
Reopened transcripts reconcile the plain initial prompt with its context-bearing
diff --git a/products/desktop/packages/core/src/sessions/sessionViewState.test.ts b/products/desktop/packages/core/src/sessions/sessionViewState.test.ts
index 4eef8142547b..ab0433a88ee7 100644
--- a/products/desktop/packages/core/src/sessions/sessionViewState.test.ts
+++ b/products/desktop/packages/core/src/sessions/sessionViewState.test.ts
@@ -1,7 +1,10 @@
import type { AgentSession } from "@posthog/shared";
import type { Task, TaskRunStatus } from "@posthog/shared/domain-types";
import { describe, expect, it } from "vitest";
-import { deriveSessionViewState } from "./sessionViewState";
+import {
+ deriveSessionLifecycleState,
+ deriveSessionViewState,
+} from "./sessionViewState";
function makeTask(runStatus: TaskRunStatus, runId = "run-1"): Task {
return {
@@ -193,16 +196,26 @@ describe("deriveSessionViewState", () => {
expect(state.isInitializing).toBe(false);
});
- it("shows loading while a local session reconnects after reload", () => {
- const task = makeTask("in_progress");
- if (task.latest_run) {
- task.latest_run.environment = "local";
- }
-
- expect(
- deriveSessionViewState(undefined, task, null, false).isInitializing,
- ).toBe(true);
- });
+ it.each(["queued", "in_progress", "completed"] as const)(
+ "keeps an unopened local %s run idle while its chat waits to reconnect",
+ (status) => {
+ const task = makeTask(status);
+ if (task.latest_run) {
+ task.latest_run.environment = "local";
+ }
+
+ expect(
+ deriveSessionLifecycleState(undefined, task, false).isInitializing,
+ ).toBe(false);
+ expect(
+ deriveSessionLifecycleState(undefined, task, false, true)
+ .isInitializing,
+ ).toBe(true);
+ expect(
+ deriveSessionViewState(undefined, task, null, false).isInitializing,
+ ).toBe(true);
+ },
+ );
it("keeps a local session loading until its first prompt", () => {
const task = makeTask("in_progress");
diff --git a/products/desktop/packages/core/src/sessions/sessionViewState.ts b/products/desktop/packages/core/src/sessions/sessionViewState.ts
index 244ad162baa1..1c75b402fdfb 100644
--- a/products/desktop/packages/core/src/sessions/sessionViewState.ts
+++ b/products/desktop/packages/core/src/sessions/sessionViewState.ts
@@ -65,10 +65,9 @@ export function deriveSessionLifecycleState(
isInitializing = effectiveIsCloud;
if (!effectiveIsCloud) {
isInitializing =
- !session ||
- (sessionMatchesActiveRun &&
- (session.status === "connecting" ||
- (session.status === "connected" && expectsInitialPrompt)));
+ sessionMatchesActiveRun &&
+ (session.status === "connecting" ||
+ (session.status === "connected" && expectsInitialPrompt));
}
}
@@ -127,7 +126,7 @@ export function deriveSessionViewState(
events,
isPromptPending,
promptStartedAt,
- isInitializing,
+ isInitializing: isInitializing || (!effectiveIsCloud && !session),
cloudBranch,
errorTitle: session?.errorTitle,
errorMessage:
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.stories.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.stories.tsx
index 7537f81957ef..16ea6ffad1f5 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.stories.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.stories.tsx
@@ -170,3 +170,17 @@ export const Crowded: Story = {
),
},
};
+
+export const LocalAfterRestart: Story = {
+ args: {
+ item: item(
+ run({
+ environment: "local",
+ status: "queued",
+ completed_at: null,
+ state: { mode: "background" },
+ }),
+ { environment: "local" },
+ ),
+ },
+};