: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): keep generating footer visible (#86095)
Charles Vienf4b76fd0fc10
diff --git a/products/desktop/packages/agent/src/acp-extensions.ts b/products/desktop/packages/agent/src/acp-extensions.tsindex aa21667b5b54..0b4c7c40807f 100644--- a/products/desktop/packages/agent/src/acp-extensions.ts+++ b/products/desktop/packages/agent/src/acp-extensions.ts@@ -30,6 +30,9 @@ export const POSTHOG_NOTIFICATIONS = {* the tracked prompt lifecycle that TURN_COMPLETE drives on the agent side. */BACKGROUND_TURN_COMPLETE: "_posthog/background_turn_complete",+ /** Background/task-notification-triggered reply started without a prompt RPC. */+ BACKGROUND_TURN_STARTED: "_posthog/background_turn_started",+/** Error occurred during task execution */ERROR: "_posthog/error",diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.tsindex 616ff19efc49..1b8c222f7234 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts@@ -695,6 +695,33 @@ describe("CodexAppServerAgent", () => {});});+ it("reports the lifecycle of a native goal turn as background generation", async () => {+ const stub = makeStubRpc({+ "thread/start": { thread: { id: "thr_1" } },+ });+ const { client, extNotifications } = makeFakeClient();+ const agent = new CodexAppServerAgent(client, {+ processOptions: { binaryPath: "/bundle/codex" },+ rpcFactory: stub.factory,+ });+ await agent.newSession({ cwd: "/repo" } as unknown as NewSessionRequest);++ stub.emit("turn/started", { turn: { id: "goal_tick_1" } });+ stub.emit("turn/completed", {+ turn: { id: "goal_tick_1", status: "completed" },+ });+ await Promise.resolve();++ expect(extNotifications).toContainEqual({+ method: "_posthog/background_turn_started",+ params: { sessionId: "thr_1" },+ });+ expect(extNotifications).toContainEqual({+ method: "_posthog/background_turn_complete",+ params: { sessionId: "thr_1", stopReason: "end_turn" },+ });+ });+it("interrupts a native goal turn that started before it was paused", async () => {const stub = makeStubRpc({"thread/start": { thread: { id: "thr_1" } },diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.tsindex 6255dd9b9e7d..ecb119505629 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts@@ -1542,6 +1542,16 @@ export class CodexAppServerAgent extends BaseAcpAgent {const turnId = (params as { turn?: { id?: string } })?.turn?.id;if (!this.turns.isPending && turnId) {this.nativeGoalTurnId = turnId;+ void this.client+ .extNotification(POSTHOG_NOTIFICATIONS.BACKGROUND_TURN_STARTED, {+ sessionId: this.sessionId,+ })+ .catch((error) =>+ this.logger.warn(+ "Background turn start notification failed",+ error,+ ),+ );}this.turns.onStarted(turnId);this.interruptQueuedGoalTurn(turnId);@@ -1587,8 +1597,20 @@ export class CodexAppServerAgent extends BaseAcpAgent {this.commandOutputs.clear();const turn = (params as { turn?: { id?: string; status?: string } })?.turn;- if (turn?.id === this.nativeGoalTurnId) {+ const completedNativeGoalTurn = turn?.id === this.nativeGoalTurnId;+ if (completedNativeGoalTurn) {this.nativeGoalTurnId = undefined;+ void this.client+ .extNotification(POSTHOG_NOTIFICATIONS.BACKGROUND_TURN_COMPLETE, {+ sessionId: this.sessionId,+ stopReason: mapTurnStopReason(turn?.status),+ })+ .catch((error) =>+ this.logger.warn(+ "Background turn completion notification failed",+ error,+ ),+ );}// Drop the late completion of an already-interrupted turn (else it cancels the follow-up).if (this.turns.shouldDropCompletion(turn?.id)) return;diff --git a/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx b/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsxindex d2f74705ddb9..37f97ab923de 100644--- a/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx@@ -149,6 +149,7 @@ export function ConversationView({lastTurnInfo,isCompacting,isClearing,+ isBackgroundTurnActive,completedToolCallCount,lastActivityAt,} = useConversationItems(events, isPromptPending, {@@ -497,6 +498,7 @@ export function ConversationView({pausedDurationMs={pausedDurationMs}isCompacting={isCompacting}isClearing={isClearing}+ isBackgroundTurnActive={isBackgroundTurnActive}completedToolCallCount={completedToolCallCount}lastActivityAt={lastActivityAt}/>diff --git a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.test.tsxnew file mode 100644index 000000000000..d96f122c2112--- /dev/null+++ b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.test.tsx@@ -0,0 +1,39 @@+import { Theme } from "@radix-ui/themes";+import { render, screen } from "@testing-library/react";+import { describe, expect, it } from "vitest";+import { SessionFooter } from "./SessionFooter";++describe("SessionFooter", () => {+ it.each([+ ["compaction", { isCompacting: true }],+ ["conversation clearing", { isClearing: true }],+ ])("hides the generating footer during %s", (_label, state) => {+ render(+ <Theme>+ <SessionFooter+ isPromptPending+ promptStartedAt={Date.now()}+ lastGenerationDuration={null}+ {...state}+ />+ </Theme>,+ );++ expect(screen.queryByText(/Esc to stop/)).not.toBeInTheDocument();+ });++ it("shows the generating footer for a background Codex turn", () => {+ render(+ <Theme>+ <SessionFooter+ isPromptPending={false}+ isBackgroundTurnActive+ promptStartedAt={Date.now()}+ lastGenerationDuration={null}+ />+ </Theme>,+ );++ expect(screen.getByText(/Esc to stop/)).toBeInTheDocument();+ });+});diff --git a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsxindex f18cfc88f827..a31be949d014 100644--- a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx@@ -19,9 +19,11 @@ interface SessionFooterProps {hasPendingPermission?: boolean;pausedDurationMs?: number;isCompacting?: boolean;- /** A /clear is in flight; its dedicated "Clearing…" row replaces the- * generic generating indicator, same as compaction. */+ /** A /clear is in flight. */isClearing?: boolean;+ /** A turn the agent started on its own, with no prompt RPC behind it, so+ * `isPromptPending` stays false while it generates. */+ isBackgroundTurnActive?: boolean;/** Number of tool calls finished so far; the generating indicator advances* its status word each time this changes. */completedToolCallCount?: number;@@ -41,6 +43,7 @@ export function SessionFooter({pausedDurationMs,isCompacting = false,isClearing = false,+ isBackgroundTurnActive = false,completedToolCallCount,lastActivityAt,}: SessionFooterProps) {@@ -52,7 +55,11 @@ export function SessionFooter({{task && <DiffStatsChip task={task} />}</Flex>);- if (isPromptPending && !isCompacting && !isClearing) {+ if (+ (isPromptPending || isBackgroundTurnActive) &&+ !isCompacting &&+ !isClearing+ ) {if (hasPendingPermission) {return (<Box className="pt-3 pb-1 opacity-50 transition-opacity group-hover/thread:opacity-100">@@ -89,7 +96,9 @@ export function SessionFooter({({queuedCount} queued)</Text>)}- <SlotMachineLever spinning={Boolean(isPromptPending)} />+ <SlotMachineLever+ spinning={Boolean(isPromptPending || isBackgroundTurnActive)}+ /></Flex>{rightSide}</Flex>diff --git a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.test.ts b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.test.tsindex be3387b905d5..3261a4a16c3b 100644--- a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.test.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.test.ts@@ -89,6 +89,18 @@ function backgroundTurnCompleteMsg(};}+function backgroundTurnStartedMsg(ts: number): AcpMessage {+ return {+ type: "acp_message",+ ts,+ message: {+ jsonrpc: "2.0",+ method: "_posthog/background_turn_started",+ params: { sessionId: "session-1" },+ },+ };+}+function agentMessageMsg(ts: number, text: string): AcpMessage {return {type: "acp_message",@@ -1124,6 +1136,24 @@ describe("buildConversationItems", () => {expect(lastTurnInfo?.durationMs).toBeGreaterThan(0);});+ it("tracks an active background turn until its completion arrives", () => {+ const active = buildConversationItems(+ [backgroundTurnStartedMsg(10), agentMessageMsg(11, "Working")],+ false,+ );+ const completed = buildConversationItems(+ [+ backgroundTurnStartedMsg(10),+ agentMessageMsg(11, "Working"),+ backgroundTurnCompleteMsg(12),+ ],+ false,+ );++ expect(active.isBackgroundTurnActive).toBe(true);+ expect(completed.isBackgroundTurnActive).toBe(false);+ });+it("does not spawn a phantom turn for a silent trailing update like usage_update", () => {// A usage_update (or any other content-less session/update) commonly// trails the final background reply. It must not reopen a turn on itsdiff --git a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.tsindex 940a23de43a9..678dfff780e0 100644--- a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts@@ -90,6 +90,8 @@ export interface BuildResult {* silent: a turn can sit minutes inside one tool call or thinking block* with nothing new to render, and a frozen status word reads as a hang. */lastActivityAt: number | null;+ /** A background turn started without a prompt RPC and has not completed. */+ isBackgroundTurnActive: boolean;}interface ProgressCardState {@@ -151,6 +153,7 @@ export interface ItemBuilder {/** Timestamp (ms) of the newest event fed to this builder. See the field of* the same name on `BuildResult`. */lastActivityAt: number | null;+ isBackgroundTurnActive: boolean;/** Runs that emitted `_posthog/run_started`; until then the setup card's* "agent" step stays in_progress rather than completing at HTTP-boot time. */runStartedRunIds: Set<string>;@@ -169,6 +172,7 @@ export function createItemBuilder(): ItemBuilder {lowestTouchedProgressIndex: Number.POSITIVE_INFINITY,completedToolCallCount: 0,lastActivityAt: null,+ isBackgroundTurnActive: false,runStartedRunIds: new Set(),};}@@ -295,6 +299,7 @@ export function buildConversationItems(isClearing: b.isClearing,completedToolCallCount: b.completedToolCallCount,lastActivityAt: b.lastActivityAt,+ isBackgroundTurnActive: b.isBackgroundTurnActive,};}@@ -352,6 +357,7 @@ export function buildAgentConversationItems(isClearing: b.isClearing,completedToolCallCount: b.completedToolCallCount,lastActivityAt: b.lastActivityAt,+ isBackgroundTurnActive: b.isBackgroundTurnActive,};}@@ -686,10 +692,18 @@ function handleNotification(// products are surfaced as a persistent, de-duplicated bar above the composer// (see accumulateSessionResources / SessionResourcesBar).+ if (+ isNotification(msg.method, POSTHOG_NOTIFICATIONS.BACKGROUND_TURN_STARTED)+ ) {+ b.isBackgroundTurnActive = true;+ return;+ }+if (isNotification(msg.method, POSTHOG_NOTIFICATIONS.TURN_COMPLETE) ||isNotification(msg.method, POSTHOG_NOTIFICATIONS.BACKGROUND_TURN_COMPLETE)) {+ b.isBackgroundTurnActive = false;const params = msg.params as { stopReason?: string } | undefined;if (!b.currentTurn) return;completePromptTurn(b, b.currentTurn, ts, {diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThreadFooter.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThreadFooter.tsxindex 77971fa6f2ab..f73d0e732c1c 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThreadFooter.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThreadFooter.tsx@@ -53,6 +53,9 @@ export function ChatThreadFooter({eventFooterState.completedToolCallCount;const lastActivityAt =footerState?.lastActivityAt ?? eventFooterState.lastActivityAt;+ const isBackgroundTurnActive =+ footerState?.isBackgroundTurnActive ??+ eventFooterState.isBackgroundTurnActive;const pendingPermissions = usePendingPermissionsForTask(taskId ?? "");const pendingPermissionVisible = resolvePendingPermissionVisibility(hasPendingPermission,@@ -79,6 +82,7 @@ export function ChatThreadFooter({pausedDurationMs={pausedDurationMs}isCompacting={isCompacting}isClearing={isClearing}+ isBackgroundTurnActive={isBackgroundTurnActive}completedToolCallCount={completedToolCallCount}lastActivityAt={lastActivityAt}/>diff --git a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.tsindex ec0f951287fc..3a91784eeb96 100644--- a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts@@ -101,6 +101,7 @@ export function createIncrementalConversationBuilder() {isClearing: builder.isClearing,completedToolCallCount: builder.completedToolCallCount,lastActivityAt: builder.lastActivityAt,+ isBackgroundTurnActive: builder.isBackgroundTurnActive,};// A finalized builder can't be safely continued; the next streaming// call rebuilds fresh.@@ -183,6 +184,7 @@ export function createIncrementalConversationBuilder() {isClearing: builder.isClearing,completedToolCallCount: builder.completedToolCallCount,lastActivityAt: builder.lastActivityAt,+ isBackgroundTurnActive: builder.isBackgroundTurnActive,};}