: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): render pi threads without the rollout flag (#125360)
Georgiy Tarasovb0507af08378
diff --git a/docs/published/handbook/engineering/ai/sandboxed-agents.md b/docs/published/handbook/engineering/ai/sandboxed-agents.mdindex 60a521253e22..450ef4a59252 100644--- a/docs/published/handbook/engineering/ai/sandboxed-agents.md+++ b/docs/published/handbook/engineering/ai/sandboxed-agents.md@@ -35,6 +35,7 @@ The full task composer remains available during startup.Follow-up messages collect in "Up next" and send after the first response finishes.Once the agent starts, Steer can send them before the current turn ends.The thread hides empty and whitespace-only assistant messages during streaming and history replay.+The PostHog AI thread and embedded run views render Pi session logs independently of the `pi-acp` rollout flag.An idle sandbox resume does not run an agent turn, so it does not send a finished notification or mark the run's activity completed.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 1c96e7d57f5d..4bf56017a44e 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -15851,9 +15851,9 @@ snapshots:scenes-app-tasks--new-task-with-repository--light:hash: v1.k794b7964.9d642604e30074883b4ed69e9c5965fd12780d9d481a97363f15a46af0d54b38.e_DQSN2xqXAPcmJeyrASvlyjQp5FcLAVFXha99Fe6Qoscenes-app-tasks--pi-task-selected--dark:- hash: v1.k794b7964.af9b88ddbc10b17dc0ccda95758fbf1ae9d103bcd0e511ec0352f76a1d0c2b80.kCLLV2HlqIkS_cCK8f1QsGpT7aNOgRJ6i7SRLgSzRv8+ hash: v1.k794b7964.8ce7c9a702d22a9348263ff924b26cdde84d0f8bbd4f1b62f72146828805fc4c.1YBH4GTr4e2CX7QUd8IdmzWCPQEa2OUestD4BTEmVGwscenes-app-tasks--pi-task-selected--light:- hash: v1.k794b7964.dc94140b8460e76c6e8b81adb9c46997c89a5634f20fac20ddada1f1ffd12223.4KOsU0tDj1zB26GFLV3daFR9ypOtXtETf08ZsGEMZt4+ hash: v1.k794b7964.2f858d3c0b563a56499b06f81d517a5db0d2d4b5e37d3ac2fbe59830f8348e0e.K_NazwRlvi_f1XYrlWJmHomMsM4bX7A6m608HD45fKAscenes-app-tasks--task-detail-loading--dark:hash: v1.k794b7964.a34fe05f1131d0368d2d803f27320c93f7a9bd5bcebc31d2459be0ed16e059c5.uSNsO42bTdJ1tYa-Bmz4uTocYRX1SIbo2vaa9IKq1AMscenes-app-tasks--task-detail-loading--light:diff --git a/frontend/src/scenes/max/Thread.tsx b/frontend/src/scenes/max/Thread.tsxindex 79326ac8eb00..86045d776bec 100644--- a/frontend/src/scenes/max/Thread.tsx+++ b/frontend/src/scenes/max/Thread.tsx@@ -3,7 +3,7 @@ import { BindLogic, useValues } from 'kea'import React, { useCallback, useMemo, useState } from 'react'import { IconChevronRight, IconWarning, IconWrench } from '@posthog/icons'-import { LemonBanner, LemonButton, LemonDivider, LemonSkeleton, Tooltip } from '@posthog/lemon-ui'+import { LemonButton, LemonDivider, LemonSkeleton, Tooltip } from '@posthog/lemon-ui'import {ChatBubble,ChatBubbleContent,@@ -55,7 +55,6 @@ import {useQuillThread,} from 'products/posthog_ai/frontend/api/primitives'import { LogEntry } from 'products/posthog_ai/frontend/lib/parse-logs'-import { isPiTaskRuntime } from 'products/posthog_ai/frontend/types/taskTypes'import { ReplayVisionScanWidget } from 'products/replay_vision/frontend/posthogAi/ReplayVisionScanWidget'import { LangGraphActivity } from './components/Activity'@@ -125,7 +124,6 @@ export function Thread({ compact = false }: { compact?: boolean }): JSX.Elementconst threadSkin = useThreadSkin()const quill = threadSkin === 'quill'const isSandboxRuntime = conversation?.agent_runtime === 'sandbox'- const isPiTask = isPiTaskRuntime(conversation?.task?.runtime)// Register the sandbox stream rendered in the side panel as the foreground stream (tool apply-back// reacts only to it). Only the side-panel instance qualifies — the full-page /ai scene (any other@@ -159,10 +157,6 @@ export function Thread({ compact = false }: { compact?: boolean }): JSX.Element[feedbackTaskId, feedbackRun])- if (isPiTask) {- return <LemonBanner type="info">Pi session logs aren't available in PostHog yet.</LemonBanner>- }-// Born-sandbox conversation (no legacy history): render only the sandbox thread.if (isSandboxRuntime && !isConvertedConversation) {if (!sandboxConversationKey) {diff --git a/frontend/src/scenes/max/maxThreadLogic.test.ts b/frontend/src/scenes/max/maxThreadLogic.test.tsindex c9199ee27c88..69609938f5a9 100644--- a/frontend/src/scenes/max/maxThreadLogic.test.ts+++ b/frontend/src/scenes/max/maxThreadLogic.test.ts@@ -1765,64 +1765,69 @@ describe('maxThreadLogic', () => {}}- it('replays logs/ then opens SSE for a non-terminal sandbox run, never reconnecting LangGraph', async () => {- logic.unmount()- jest.spyOn(api.conversations, 'get').mockResolvedValue(sandboxConversation(SANDBOX_RUN_ID))- const logsSpy = jest.spyOn(api.tasks.runs, 'getLogPage').mockResolvedValue({- entries: [],- offset: 0,- count: 0,- preamble: 0,- turnsBefore: 0,- origin: '',- indexed: false,- })- const runSpy = jest- .spyOn(tasksApi, 'tasksRunsRetrieve')- .mockResolvedValue({ status: 'in_progress' } as TaskRunDetailDTOApi)- const streamSpy = mockStream()-- logic = maxThreadLogic({- conversationId: MOCK_CONVERSATION_ID,- panelId: 'test',- conversation: sandboxConversation(SANDBOX_RUN_ID),- })- logic.mount()- // Drain the async afterMount (loadConversation → bootstrapRun → logs/ replay → run refetch).- await new Promise((resolve) => setTimeout(resolve, 0))- await new Promise((resolve) => setTimeout(resolve, 0))-- // bootstrapRun replayed logs/ and refetched the run, then opened SSE — and the LangGraph- // stream was never touched (coexistence).- expect(logsSpy).toHaveBeenCalledWith(- SANDBOX_TASK_ID,- SANDBOX_RUN_ID,- expect.objectContaining({ signal: expect.any(AbortSignal), projectId: 997 })- )- expect(runSpy).toHaveBeenCalledWith('997', SANDBOX_TASK_ID, SANDBOX_RUN_ID, {- signal: expect.any(AbortSignal),- })- expect(streamSpy).not.toHaveBeenCalled()- })-- it('does not bootstrap a Pi task run', async () => {- logic.unmount()- const conversation = sandboxConversation(SANDBOX_RUN_ID, TaskRuntimeEnumApi.Pi)- jest.spyOn(api.conversations, 'get').mockResolvedValue(conversation)- const logsSpy = jest.spyOn(api.tasks.runs, 'getLogPage')- const streamSpy = mockStream()-- logic = maxThreadLogic({- conversationId: MOCK_CONVERSATION_ID,- panelId: 'test',- conversation,- })- logic.mount()- await new Promise((resolve) => setTimeout(resolve, 0))+ it.each([TaskRuntimeEnumApi.Acp, TaskRuntimeEnumApi.Pi])(+ 'replays logs/ then opens SSE for a non-terminal %s run, never reconnecting LangGraph',+ async (runtime) => {+ logic.unmount()+ jest.spyOn(api.conversations, 'get').mockResolvedValue(sandboxConversation(SANDBOX_RUN_ID, runtime))+ const logsSpy = jest.spyOn(api.tasks.runs, 'getLogPage').mockResolvedValue({+ entries: [+ {+ type: 'notification',+ notification: {+ method: 'session/update',+ params: {+ update: {+ sessionUpdate: 'agent_message',+ messageId: 'saved-output',+ content: { type: 'text', text: 'Saved run output' },+ },+ },+ },+ },+ ],+ offset: 0,+ count: 1,+ preamble: 0,+ turnsBefore: 0,+ origin: '',+ indexed: false,+ })+ const runSpy = jest+ .spyOn(tasksApi, 'tasksRunsRetrieve')+ .mockResolvedValue({ status: 'in_progress' } as TaskRunDetailDTOApi)+ const streamSpy = mockStream()- expect(logsSpy).not.toHaveBeenCalled()- expect(streamSpy).not.toHaveBeenCalled()- })+ logic = maxThreadLogic({+ conversationId: MOCK_CONVERSATION_ID,+ panelId: 'test',+ conversation: sandboxConversation(SANDBOX_RUN_ID, runtime),+ })+ logic.mount()+ // Drain the async afterMount (loadConversation → bootstrapRun → logs/ replay → run refetch).+ await new Promise((resolve) => setTimeout(resolve, 0))+ await new Promise((resolve) => setTimeout(resolve, 0))++ // bootstrapRun replayed logs/ and refetched the run, then opened SSE — and the LangGraph+ // stream was never touched (coexistence).+ expect(logsSpy).toHaveBeenCalledWith(+ SANDBOX_TASK_ID,+ SANDBOX_RUN_ID,+ expect.objectContaining({ signal: expect.any(AbortSignal), projectId: 997 })+ )+ expect(runSpy).toHaveBeenCalledWith('997', SANDBOX_TASK_ID, SANDBOX_RUN_ID, {+ signal: expect.any(AbortSignal),+ })+ expect(streamSpy).not.toHaveBeenCalled()+ const stream = runStreamLogic({ streamKey: MOCK_CONVERSATION_ID })+ expect(stream.values.piRuntime).toBe(runtime === TaskRuntimeEnumApi.Pi)+ expect(stream.values.threadItems).toEqual(+ expect.arrayContaining([+ expect.objectContaining({ type: 'assistant_message', text: 'Saved run output' }),+ ])+ )+ }+ )it('does not bootstrap a sandbox run without a latest_run', async () => {logic.unmount()diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsxindex aab2b25483a8..d1522a444d6e 100644--- a/frontend/src/scenes/max/maxThreadLogic.tsx+++ b/frontend/src/scenes/max/maxThreadLogic.tsx@@ -3078,10 +3078,6 @@ export const maxThreadLogic = kea<maxThreadLogicType>([// runStreamLogic, which replays logs/ then opens SSE if non-terminal. The LangGraph// reconnect path below is never entered for sandbox runtimes (coexistence).if (conversation.agent_runtime === 'sandbox') {- if (isPiTaskRuntime(conversation.task?.runtime)) {- return- }-// runStreamLogic and posthogAiContextLogic are connected (so already mounted) for this// conversation. Reset their per-conversation state before replaying this run's history.actions.resetSandboxStream()@@ -3092,6 +3088,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([actions.bootstrapSandboxRun({taskId: conversation.task.id,runId,+ taskRuntime: conversation.task.runtime,})}}diff --git a/products/posthog_ai/frontend/components/RunSurfaceImpl.test.tsx b/products/posthog_ai/frontend/components/RunSurfaceImpl.test.tsxindex 38a5c962cc94..08e9dee8cf7e 100644--- a/products/posthog_ai/frontend/components/RunSurfaceImpl.test.tsx+++ b/products/posthog_ai/frontend/components/RunSurfaceImpl.test.tsx@@ -143,7 +143,7 @@ describe('RunSurface', () => {})})- it('keeps a Pi task behind the unavailable banner until Pi web sessions are on', () => {+ it.each(['live', 'read-only'] as const)('renders Pi logs with the rollout flag off in %s mode', (interaction) => {const bootstrapRun = jest.fn();(useActions as jest.Mock).mockReturnValue({ bootstrapRun, reset: jest.fn(), loadTask: jest.fn() })setValues({@@ -152,14 +152,18 @@ describe('RunSurface', () => {})render(- <RunSurface.Root taskId="task-1" runId="run-1" interaction="live">+ <RunSurface.Root taskId="task-1" runId="run-1" interaction={interaction}><RunSurface.Thread /></RunSurface.Root>)- expect(screen.getByText("Pi session logs aren't available in PostHog yet.")).toBeInTheDocument()- expect(screen.queryByTestId('thread')).not.toBeInTheDocument()- expect(bootstrapRun).not.toHaveBeenCalled()+ expect(screen.getByTestId('thread')).toBeInTheDocument()+ expect(bootstrapRun).toHaveBeenCalledWith({+ taskId: 'task-1',+ runId: 'run-1',+ taskRuntime: TaskRuntimeEnumApi.Pi,+ pagedHistory: true,+ })})describe('Composer slot', () => {diff --git a/products/posthog_ai/frontend/components/RunSurfaceImpl.tsx b/products/posthog_ai/frontend/components/RunSurfaceImpl.tsxindex 57f85009a39f..935b3a940148 100644--- a/products/posthog_ai/frontend/components/RunSurfaceImpl.tsx+++ b/products/posthog_ai/frontend/components/RunSurfaceImpl.tsx@@ -3,14 +3,13 @@ import { createContext, type ReactNode, useCallback, useContext, useEffect, useMimport { LemonBanner, LemonButton, LemonDivider } from '@posthog/lemon-ui'-import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { cn } from 'lib/utils/css-classes'import { useThreadSkin } from '../hooks/useThreadSkin'import { isLogicRetained, RETAINED_RUN_STREAMS, retainMountedLogic } from '../logics/retainedLogics'import { findLiveRunStreamKey, isTerminalRunStatus, runStreamLogic } from '../logics/runStreamLogic'import { taskLogic } from '../logics/taskLogic'-import { isPiTaskRuntime, OriginProduct } from '../types/taskTypes'+import { OriginProduct } from '../types/taskTypes'import { type TurnTrailer } from '../utils/turnTrailers'import { ContextUsageChip } from './ContextUsageChip'import { FeedbackPromptTrailer } from './FeedbackPromptTrailer'@@ -128,7 +127,6 @@ function RunSurfaceRoot({// The runtime and scout flag live on the task (not the run), so the surface owns loading it once and// exposing it to the slots. The runner already has the task loaded; an embed fetches it here.const { task, taskLoading, taskError, taskNotFound } = useValues(taskLogic({ taskId }))- const piAcpEnabled = useFeatureFlag('PI_ACP')const { loadTask } = useActions(taskLogic({ taskId }))useEffect(() => {// A pending surface (optimistic create) has no task yet, so don't fetch an empty id.@@ -153,10 +151,6 @@ function RunSurfaceRoot({}}- if (task && isPiTaskRuntime(task.runtime) && !piAcpEnabled) {- return <LemonBanner type="info">Pi session logs aren't available in PostHog yet.</LemonBanner>- }-const isScout = task?.origin_product === OriginProduct.SIGNALS_SCOUTreturn (