: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(posthog-ai): show gerund loader only while the agent is thinking (#66166)
Georgiy Tarasov01390a1185d0
diff --git a/products/posthog_ai/frontend/components/ThreadView.tsx b/products/posthog_ai/frontend/components/ThreadView.tsxindex 0481cc069f46..274001df5df6 100644--- a/products/posthog_ai/frontend/components/ThreadView.tsx+++ b/products/posthog_ai/frontend/components/ThreadView.tsx@@ -55,16 +55,13 @@ export function ThreadView({threadItems,toolInvocations,isThinking,- streamPhase,+ showThinkingIndicator,runArtifacts,turnComplete,currentRunStatus,contextUsage,} = useValues(runStreamLogic)const turnCancelled = currentRunStatus === 'cancelled'- const hasActiveProgressItem = threadItems.some(- (item) => item.type === 'progress' && item.progressSteps?.some((step) => step.status === 'in_progress')- )// Header/footer are kept as memoized leaf components with stable element identity so they don't rebuild// `VirtualizedThread`'s `renderRow` (and re-sweep visible rows) on every streamed frame. Each is wrapped@@ -80,7 +77,6 @@ export function ThreadView({[branch, baseBranch, repo])- const showThinking = streamPhase === 'thinking' && !hasActiveProgressItem// Post-turn only: a reconnect refetch can fold in a pr_url mid-run, so gate on !isThinking.const pullRequestUrl = !isThinking ? runArtifacts.prUrl : undefined// Context usage rides the thread footer, but only between turns (idle) — never while the agent is@@ -88,17 +84,17 @@ export function ThreadView({const showContextUsageFooter = showContextUsage && !isThinking && !!contextUsageconst footer = useMemo(() =>- showThinking || pullRequestUrl || showContextUsageFooter ? (+ showThinkingIndicator || pullRequestUrl || showContextUsageFooter ? (<VirtualizedThread.Row className={rowClassName}><ThreadFooter- showThinking={showThinking}+ showThinking={showThinkingIndicator}pullRequestUrl={pullRequestUrl}prBranch={branch}showContextUsage={showContextUsageFooter}/></VirtualizedThread.Row>) : undefined,- [showThinking, pullRequestUrl, branch, showContextUsageFooter]+ [showThinkingIndicator, pullRequestUrl, branch, showContextUsageFooter])const renderItem = useCallback(diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts b/products/posthog_ai/frontend/logics/runStreamLogic.test.tsindex d0ad4b9cc22e..8d7be3a44314 100644--- a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts+++ b/products/posthog_ai/frontend/logics/runStreamLogic.test.ts@@ -286,6 +286,48 @@ describe('runStreamLogic', () => {})})+ describe('showThinkingIndicator', () => {+ const runStartedFrame = notification('_posthog/run_started', {})+ const messageChunk = sessionUpdate({+ sessionUpdate: 'agent_message_chunk',+ messageId: 'm1',+ content: { text: 'Hi' },+ })+ const messageFinal = sessionUpdate({ sessionUpdate: 'agent_message', messageId: 'm1', content: { text: 'Hi' } })+ const toolStart = sessionUpdate({+ sessionUpdate: 'tool_call',+ toolCallId: 't1',+ serverName: 'posthog',+ toolName: 'exec',+ status: 'in_progress',+ })+ const toolDone = sessionUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 't1', status: 'completed' })+ const progressActive = notification('_posthog/progress', {+ group: 'g',+ step: 's',+ label: 'Working',+ status: 'in_progress',+ })+ const turnComplete = notification('_posthog/turn_complete', {})++ it.each<[string, StoredLogEntry[], boolean]>([+ ['idle gap after run start shows the loader', [runStartedFrame], true],+ ['a streaming answer hides the loader', [runStartedFrame, messageChunk], false],+ ['a finalized answer mid-turn shows the loader', [runStartedFrame, messageChunk, messageFinal], true],+ ['a running tool hides the loader', [runStartedFrame, toolStart], false],+ ['a completed tool shows the loader', [runStartedFrame, toolStart, toolDone], true],+ ['a running progress step hides the loader', [runStartedFrame, progressActive], false],+ ['no run in flight hides the loader', [], false],+ ['a completed turn hides the loader', [runStartedFrame, messageFinal, turnComplete], false],+ ])('%s', async (_name, frames, expected) => {+ await expectLogic(logic, () => {+ frames.forEach((frame) => logic.actions.ingestAcpFrame(frame))+ }).toFinishAllListeners()++ expect(logic.values.showThinkingIndicator).toEqual(expected)+ })+ })+describe('assistant message buffering without messageId', () => {it('keeps two consecutive turns without a messageId in separate thread items', async () => {const frames: StoredLogEntry[] = [diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.ts b/products/posthog_ai/frontend/logics/runStreamLogic.tsindex 72d9480b4274..872ae1df4f3c 100644--- a/products/posthog_ai/frontend/logics/runStreamLogic.ts+++ b/products/posthog_ai/frontend/logics/runStreamLogic.ts@@ -1540,6 +1540,46 @@ export const runStreamLogic = kea<runStreamLogicType>([return 'idle'},],+ /**+ * Whether the bottom-of-thread gerund loader ("Thinking…", "Pondering…") should show. The+ * loader is a *gap filler*: it stands in only while the agent is working a turn but nothing+ * visible is streaming at the tail — i.e. it is genuinely "thinking". It hides the moment the+ * tail produces visible output: a streaming assistant message, an in-flight tool call, or a+ * running structured-progress activity (each already conveys "the agent is busy"). Reasoning is+ * deliberately NOT a hide condition — the gerund is what fills the thinking/reasoning period+ * (and the explicit `agent_thought_chunk` thinking signal arrives during exactly these gaps).+ */+ showThinkingIndicator: [+ (s) => [s.streamPhase, s.threadItems, s.toolInvocations],+ (streamPhase, threadItems, toolInvocations): boolean => {+ if (streamPhase !== 'thinking') {+ return false+ }+ // Scan the current turn only (items after the last separator).+ const turnStart = threadItems.findLastIndex((item) => item.type === 'turn_separator') + 1+ for (let i = turnStart; i < threadItems.length; i++) {+ const item = threadItems[i]+ // A running structured-progress activity owns the "busy" line.+ if (item.type === 'progress' && item.progressSteps?.some((step) => step.status === 'in_progress')) {+ return false+ }+ // A tool actively running already shows its own spinner.+ if (+ item.type === 'tool_invocation' &&+ item.toolCallId &&+ ['pending', 'in_progress'].includes(toolInvocations.get(item.toolCallId)?.status ?? '')+ ) {+ return false+ }+ }+ // The visible tail is streaming answer text — that's writing, not thinking.+ const tail = threadItems[threadItems.length - 1]+ if (tail?.type === 'assistant_message' && tail.complete !== true) {+ return false+ }+ return true+ },+ ],/** Whether the run exposes any git artifact worth surfacing — gates the pre/post-turn coding UI. */hasGitArtifacts: [(s) => [s.runArtifacts],