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): say how long a running turn has been silent (#83557)

Charles Vien91e36ff6a34e
diff --git a/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx b/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx
index 3897491f4060..68d5311a70a8 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/ConversationView.tsx
@@ -148,6 +148,7 @@ export function ConversationView({
isCompacting,
isClearing,
completedToolCallCount,
+ lastActivityAt,
} = useConversationItems(events, isPromptPending, {
showDebugLogs,
});
@@ -495,6 +496,7 @@ export function ConversationView({
isCompacting={isCompacting}
isClearing={isClearing}
completedToolCallCount={completedToolCallCount}
+ lastActivityAt={lastActivityAt}
/>
</div>
);
diff --git a/products/desktop/packages/ui/src/features/sessions/components/GeneratingIndicator.tsx b/products/desktop/packages/ui/src/features/sessions/components/GeneratingIndicator.tsx
index 47343950d1fc..ba7b32287411 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/GeneratingIndicator.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/GeneratingIndicator.tsx
@@ -3,7 +3,7 @@ import {
pickNextThinkingActivity,
pickThinkingActivity,
} from "@posthog/core/sessions/thinkingActivities";
-import { Flex, Text } from "@radix-ui/themes";
+import { Text } from "@posthog/quill";
import { useEffect, useRef, useState } from "react";
function getRandomThinkingMessage(): string {
@@ -16,6 +16,11 @@ function getNextThinkingMessage(current: string): string {
return pickNextThinkingActivity(current, Math.random());
}
+/** How long the thread has to stay silent before the hint says so. Long enough
+ * that a normally chatty turn never trips it, short enough to land well inside
+ * a slow tool call. */
+const QUIET_AFTER_MS = 10_000;
+
export function formatDuration(ms: number, fractionDigits = 2): string {
const totalSeconds = Math.floor(ms / 1000);
const mins = Math.floor(totalSeconds / 60);
@@ -44,23 +49,36 @@ interface GeneratingIndicatorProps {
* each time this changes, so it tracks real work completing rather than a
* timer — a stalled agent keeps the same word. */
activityKey?: number;
+ /** Timestamp (ms) of the newest event in the thread. Once it falls far enough
+ * behind, the hint adds a ticking "quiet for Ns" so a turn that renders
+ * nothing for minutes still reads as running rather than hung. */
+ lastActivityAt?: number | null;
}
export function GeneratingIndicator({
startedAt,
pausedDurationMs,
activityKey,
+ lastActivityAt,
}: GeneratingIndicatorProps) {
const [elapsed, setElapsed] = useState(0);
+ const [quietFor, setQuietFor] = useState(0);
const [activity, setActivity] = useState(getRandomThinkingMessage);
const pausedRef = useRef(pausedDurationMs ?? 0);
pausedRef.current = pausedDurationMs ?? 0;
+ const lastActivityRef = useRef(lastActivityAt ?? null);
+ lastActivityRef.current = lastActivityAt ?? null;
useEffect(() => {
const startTime = startedAt ?? Date.now();
const interval = setInterval(() => {
- setElapsed(Math.max(0, Date.now() - startTime - pausedRef.current));
+ const now = Date.now();
+ setElapsed(Math.max(0, now - startTime - pausedRef.current));
+ // Measured from the last event rather than the turn's start, so a turn
+ // that streamed for a minute and then went silent still reads as quiet.
+ const since = lastActivityRef.current;
+ setQuietFor(since === null ? 0 : Math.max(0, now - since));
}, 100);
return () => clearInterval(interval);
@@ -76,27 +94,43 @@ export function GeneratingIndicator({
setActivity((current) => getNextThinkingMessage(current));
}
+ const dot = (
+ <Circle
+ size={4}
+ weight="fill"
+ className="mx-1 inline-block align-middle text-gray-9"
+ />
+ );
+
return (
- <Flex
- align="center"
- gap="2"
- className="min-w-0 select-none"
+ <div
+ className="flex min-w-0 select-none items-center gap-2"
style={{ WebkitUserSelect: "none" }}
>
<Brain size={12} className="ph-pulse shrink-0" />
- <Text className="truncate text-[13px] text-accent-11">{activity}...</Text>
+ <Text render={<span />} className="truncate text-[13px] text-accent-11">
+ {activity}...
+ </Text>
{/* The hint shrinks (and truncates) well before the activity word does. */}
- <Text color="gray" className="shrink-[8] truncate text-[13px]">
+ <Text
+ render={<span />}
+ className="shrink-[8] truncate text-(--gray-11) text-[13px]"
+ >
(Esc to stop
- <Circle
- size={4}
- weight="fill"
- className="mx-1 inline-block align-middle text-gray-9"
- />
+ {dot}
<span style={{ fontVariantNumeric: "tabular-nums" }}>
- {formatDuration(elapsed, 1)})
+ {formatDuration(elapsed, 1)}
</span>
+ {quietFor >= QUIET_AFTER_MS && (
+ <>
+ {dot}
+ <span style={{ fontVariantNumeric: "tabular-nums" }}>
+ quiet for {formatDuration(quietFor, 0)}
+ </span>
+ </>
+ )}
+ )
</Text>
- </Flex>
+ </div>
);
}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.stories.tsx b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.stories.tsx
index 3949348d0d70..1c05da8b7af0 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.stories.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.stories.tsx
@@ -52,6 +52,17 @@ export const GeneratingAtNarrowWidths: Story = {
render: (args) => <AtWidths args={args} />,
};
+/** A turn that has rendered nothing for a while — one long tool call, or a
+ * thinking block the model kept to itself. */
+export const GeneratingWhileQuietAtNarrowWidths: Story = {
+ args: {
+ ...generatingArgs,
+ promptStartedAt: Date.now() - 128_000,
+ lastActivityAt: Date.now() - 47_000,
+ },
+ render: (args) => <AtWidths args={args} />,
+};
+
export const GeneratingWithQueueAtNarrowWidths: Story = {
args: { ...generatingArgs, queuedCount: 2 },
render: (args) => <AtWidths args={args} />,
diff --git a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx
index 8e0e72b58e19..f18cfc88f827 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/SessionFooter.tsx
@@ -25,6 +25,9 @@ interface SessionFooterProps {
/** Number of tool calls finished so far; the generating indicator advances
* its status word each time this changes. */
completedToolCallCount?: number;
+ /** Timestamp (ms) of the newest event in the thread; the generating indicator
+ * says how long it has been since one arrived. */
+ lastActivityAt?: number | null;
}
export function SessionFooter({
@@ -39,6 +42,7 @@ export function SessionFooter({
isCompacting = false,
isClearing = false,
completedToolCallCount,
+ lastActivityAt,
}: SessionFooterProps) {
const rightSide = (
<Flex align="center" gap="3" className="ml-auto shrink-0">
@@ -78,6 +82,7 @@ export function SessionFooter({
startedAt={promptStartedAt}
pausedDurationMs={pausedDurationMs}
activityKey={completedToolCallCount}
+ lastActivityAt={lastActivityAt}
/>
{queuedCount > 0 && (
<Text className="truncate text-[13px] text-muted-foreground">
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.ts
index bbe73397b713..a30dec595b65 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
@@ -920,6 +920,23 @@ describe("buildConversationItems", () => {
});
});
+ describe("lastActivityAt", () => {
+ it("is null when the thread has no events", () => {
+ expect(buildConversationItems([], null).lastActivityAt).toBeNull();
+ });
+
+ // The footer measures silence against this, so a late-arriving event must
+ // not be able to drag it backwards and report a turn as quieter than it is.
+ it("reports the newest timestamp even when an event arrives late", () => {
+ const events = [
+ userPromptMsg(10, 1, "hello"),
+ consoleMsg(30, "second"),
+ consoleMsg(20, "late arrival"),
+ ];
+ expect(buildConversationItems(events, true).lastActivityAt).toBe(30);
+ });
+ });
+
describe("session_update timestamps", () => {
const toolCallMsg = (ts: number, toolCallId: string): AcpMessage => ({
type: "acp_message",
diff --git a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
index 8ecbeb1e4153..70b15dcee623 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
@@ -85,6 +85,11 @@ export interface BuildResult {
/** Number of tool calls settled into a terminal status so far. Monotonic
* within a thread; consumers treat a change as "a tool/MCP call finished". */
completedToolCallCount: number;
+ /** Timestamp (ms) of the most recent event applied to the thread, or null
+ * when none have been. Lets the footer say how long the agent has been
+ * 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;
}
interface ProgressCardState {
@@ -142,6 +147,9 @@ export interface ItemBuilder {
* Drives the generating indicator's status word so it advances on real work
* finishing rather than on a timer. */
completedToolCallCount: number;
+ /** Timestamp (ms) of the newest event fed to this builder. See the field of
+ * the same name on `BuildResult`. */
+ lastActivityAt: number | null;
/** 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>;
@@ -161,10 +169,19 @@ export function createItemBuilder(): ItemBuilder {
progressCards: new Map(),
lowestTouchedProgressIndex: Number.POSITIVE_INFINITY,
completedToolCallCount: 0,
+ lastActivityAt: null,
runStartedRunIds: new Set(),
};
}
+/** Record that an event landed at `ts`. Events are usually fed in order, but a
+ * rebuild sorts them and an append can carry a stale ts, so keep the max. */
+function noteActivity(b: ItemBuilder, ts: number) {
+ if (b.lastActivityAt === null || ts > b.lastActivityAt) {
+ b.lastActivityAt = ts;
+ }
+}
+
const TERMINAL_TOOL_STATUSES = new Set(["completed", "failed", "cancelled"]);
function isTerminalToolStatus(status: string | null | undefined): boolean {
@@ -278,6 +295,7 @@ export function buildConversationItems(
isCompacting: b.isCompacting,
isClearing: b.isClearing,
completedToolCallCount: b.completedToolCallCount,
+ lastActivityAt: b.lastActivityAt,
};
}
@@ -292,6 +310,7 @@ export function processEvent(
options?: BuildConversationOptions,
) {
const msg = event.message;
+ noteActivity(b, event.ts);
if (isJsonRpcNotification(msg)) {
handleNotification(b, msg, event.ts, options);
@@ -333,6 +352,7 @@ export function buildAgentConversationItems(
isCompacting: b.isCompacting,
isClearing: b.isClearing,
completedToolCallCount: b.completedToolCallCount,
+ lastActivityAt: b.lastActivityAt,
};
}
@@ -340,6 +360,8 @@ export function processAgentConversationEvent(
b: ItemBuilder,
event: AgentConversationEvent,
): void {
+ noteActivity(b, event.timestamp);
+
if (event.type === "user_message") {
handlePromptRequest(
b,
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.tsx
index 4e4736e5ec74..77971fa6f2ab 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
@@ -51,6 +51,8 @@ export function ChatThreadFooter({
const completedToolCallCount =
footerState?.completedToolCallCount ??
eventFooterState.completedToolCallCount;
+ const lastActivityAt =
+ footerState?.lastActivityAt ?? eventFooterState.lastActivityAt;
const pendingPermissions = usePendingPermissionsForTask(taskId ?? "");
const pendingPermissionVisible = resolvePendingPermissionVisibility(
hasPendingPermission,
@@ -78,6 +80,7 @@ export function ChatThreadFooter({
isCompacting={isCompacting}
isClearing={isClearing}
completedToolCallCount={completedToolCallCount}
+ lastActivityAt={lastActivityAt}
/>
</div>
);
diff --git a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.test.ts b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.test.ts
index 330830ff7bb8..a93814b7ac8a 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.test.ts
@@ -198,6 +198,7 @@ function normalize(result: BuildResult) {
lastTurnInfo: result.lastTurnInfo,
isCompacting: result.isCompacting,
completedToolCallCount: result.completedToolCallCount,
+ lastActivityAt: result.lastActivityAt,
};
}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts
index 08fc46b11870..ec0f951287fc 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/incrementalConversationItems.ts
@@ -100,6 +100,7 @@ export function createIncrementalConversationBuilder() {
isCompacting: builder.isCompacting,
isClearing: builder.isClearing,
completedToolCallCount: builder.completedToolCallCount,
+ lastActivityAt: builder.lastActivityAt,
};
// A finalized builder can't be safely continued; the next streaming
// call rebuilds fresh.
@@ -181,6 +182,7 @@ export function createIncrementalConversationBuilder() {
isCompacting: builder.isCompacting,
isClearing: builder.isClearing,
completedToolCallCount: builder.completedToolCallCount,
+ lastActivityAt: builder.lastActivityAt,
};
}