: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
feat(posthog_ai): surface the debug logs toggle wherever agent runs render (#88513)
Georgiy Tarasov50490aa1a76d
diff --git a/common/storybook/.storybook/test-runner.ts b/common/storybook/.storybook/test-runner.tsindex fa9815b333e3..a3383b17b99b 100644--- a/common/storybook/.storybook/test-runner.ts+++ b/common/storybook/.storybook/test-runner.ts@@ -705,7 +705,7 @@ async function expectLocatorToMatchStorySnapshot(theme: SnapshotTheme,options?: LocatorScreenshotOptions): Promise<void> {- const image = await locator.screenshot({ ...options })+ const image = await takeSnapshotImage(locator, context, options)let customSnapshotIdentifier = `${context.id}--${theme}`if (browser !== 'chromium') {customSnapshotIdentifier += `--${browser}`@@ -723,6 +723,31 @@ async function expectLocatorToMatchStorySnapshot(})}+/**+ * Screenshot the snapshot target, naming the one cause Playwright reports opaquely: a story that+ * renders nothing. `#storybook-root` is `display: inline-block` here, so an empty render collapses it+ * to zero size, and all Playwright says - after a full 10s wait, three times over - is "element is not+ * visible".+ */+async function takeSnapshotImage(+ locator: Locator | Page,+ context: TestContext,+ options?: LocatorScreenshotOptions+): Promise<Buffer> {+ try {+ return await locator.screenshot({ ...options })+ } catch (error) {+ const box = 'boundingBox' in locator ? await locator.boundingBox().catch(() => null) : null+ if (box && !box.width && !box.height) {+ throw new Error(+ `Story "${context.id}" rendered nothing, so there is no screenshot to take. ` ++ `Wrap it in a decorator that gives the snapshot a sized box, or tag it 'test-skip'.`+ )+ }+ throw error+ }+}+/*** Just like the `waitForPageReady` helper offered by Playwright - except we only wait for `networkidle` in CI,* as it doesn't work with local Storybook (the live reload feature keeps up a long-running request, so we aren't idle).diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 959bf6dbe964..53cd7040f2c1 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5216,6 +5216,18 @@ snapshots:hash: v1.k794b7964.e893edaa31202a96439233ff254af446b1ae72107ca4d187a0ab27abc87db8ac.ClRtYW3AIl8tt8UNlaLx_52ymgYxs4FUUHPusEIzAs8products-posthog-ai-composer--with-up-next-queue--light:hash: v1.k794b7964.c6aa2aa587283120fba069845efe3f499ad93f57f01a44fe60714bf6de06aa77.sXADx8Z_E97Ez10RF94ejn6saVtul9mmzMW6g6F-M8U+ products-posthog-ai-debuglogsmenu--non-staff--dark:+ hash: v1.k794b7964.8fbc222393e4a977c643005d53ec8b83d55ee078f87f00dc53e4a2422df58f16.HSRv6p696X41lVON7tvCZSWNH-xgjRDLiMUZjwHmuFk+ products-posthog-ai-debuglogsmenu--non-staff--light:+ hash: v1.k794b7964.5c4e9384cff0bfaeea7fcab369e52179c576c8ecab3960edb30eb031071b5091.3-NFLn-uU22oAcen8uB73UcbF1ktLICdW0MwGHAp4Eg+ products-posthog-ai-debuglogsmenu--staff-lemon--dark:+ hash: v1.k794b7964.c4d50490323fb17c3cc6b0b324af1e3351992787149dc6aecee3c15055f7fc14.ZzMowbKOCuzoUivKDYslwR3BvWYfspaQeVtrOdLI-z8+ products-posthog-ai-debuglogsmenu--staff-lemon--light:+ hash: v1.k794b7964.78fb2fa6f9ab6fe54685d13a80fa72790826b6ae2ec0fd39d7a266752574d7fd.gLSdW7nWD1e9fXp1wY8CEPYHSsiYEuBPOuFUYpFACfM+ products-posthog-ai-debuglogsmenu--staff-primitive--dark:+ hash: v1.k794b7964.7c7d0d318d47ab1aaabaeeffa5cfae450ea600f2c8cdfda0dc8e9fccb86bff2f.5Jz5nz-ow5GYNJ2Em60NDBw258PubMRxJgwf8nS4jI4+ products-posthog-ai-debuglogsmenu--staff-primitive--light:+ hash: v1.k794b7964.f19770892ea0bf6cae9997d6e364c4694a74f607e4e087d83c850a92cbaaae75.FxREU9FWVvU9WvA0uMJYiYzrSDQDhi_TBKi4lAV_pq8products-posthog-ai-onboardingtakeover--awaiting-clip--dark:hash: v1.k794b7964.ce34e421ee0ac8dc6b49c9bc2d52791298561b4ab0ae74add1780c7b1e82114f.QZzI-wxiMSzGEymlFhQuyVyPBJs10NJUpnH6GOxDlO0products-posthog-ai-onboardingtakeover--awaiting-clip--light:diff --git a/frontend/src/scenes/max/Max.tsx b/frontend/src/scenes/max/Max.tsxindex 143f306ae2ef..3df7a3adcf40 100644--- a/frontend/src/scenes/max/Max.tsx+++ b/frontend/src/scenes/max/Max.tsx@@ -28,6 +28,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { SidePanelTab } from '~/types'import { runnerPanelLogic } from 'products/posthog_ai/frontend/api/logics'+import { DebugLogsMenu } from 'products/posthog_ai/frontend/api/primitives'import { AiFirstMaxInstance } from './components/AiFirstMaxInstance'import { AnimatedBackButton } from './components/AnimatedBackButton'@@ -225,6 +226,9 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:<IconShare className="text-tertiary size-3 group-hover:text-primary z-10" /></ButtonPrimitive>)}+ {/* The new view is the runner (always sandbox); legacy view only shows debug rows on a+ sandbox conversation, so the menu stays hidden on LangGraph threads. */}+ {(isNewView || conversation?.agent_runtime === 'sandbox') && <DebugLogsMenu variant="primitive" />}<PhaiViewToggle variant="primitive" /><LinkbuttonProps={{diff --git a/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx b/frontend/src/scenes/max/components/AiFirstMaxInstance.tsxindex c5c85c8c588e..3ef92e10f82e 100644--- a/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx+++ b/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx@@ -10,6 +10,7 @@ import { urls } from 'scenes/urls'import { SceneName } from '~/layout/scenes/components/SceneTitleSection'+import { DebugLogsMenu } from 'products/posthog_ai/frontend/api/primitives'import { EmbeddedRunner } from 'products/posthog_ai/frontend/api/runner'import { Intro } from '../Intro'@@ -29,11 +30,14 @@ export function ChatHeader({tabId,children,hideBorder,+ isSandboxRuntime,}: {conversationId: string | nulltabId?: stringchildren?: React.ReactNodehideBorder?: boolean+ /** Debug rows only exist on the sandbox runtime, so the staff menu that reveals them is hidden elsewhere. */+ isSandboxRuntime?: boolean}): JSX.Element {const { openSidePanelMax } = useActions(maxGlobalLogic)const { chatTitle } = useValues(maxLogic)@@ -57,6 +61,7 @@ export function ChatHeader({)}</div><div className="flex items-center gap-2">+ {isSandboxRuntime && <DebugLogsMenu variant="lemon" />}<PhaiViewToggle variant="lemon" />{conversationId ? (<LemonButton@@ -105,6 +110,8 @@ export function AiFirstMaxInstance({ tabId }: AiFirstMaxInstanceProps): JSX.Elemreturn (<div className="flex flex-col grow overflow-hidden h-full"><div className="flex w-full items-center justify-end gap-2 py-2 px-2 border-b border-primary">+ {/* The new view is the runner, which is always the sandbox runtime — no runtime check needed. */}+ <DebugLogsMenu variant="lemon" /><PhaiViewToggle variant="lemon" /></div><div className="flex flex-col flex-1 min-h-0">@@ -127,7 +134,11 @@ export function AiFirstMaxInstance({ tabId }: AiFirstMaxInstanceProps): JSX.Elem<BindLogic logic={maxLogic} props={{ panelId: tabId }}><BindLogic logic={maxThreadLogic} props={threadProps}><div className="flex flex-col grow overflow-hidden">- <ChatHeader conversationId={conversationId} tabId={tabId} />+ <ChatHeader+ conversationId={conversationId}+ tabId={tabId}+ isSandboxRuntime={conversation?.agent_runtime === 'sandbox'}+ />{isMaxAvailable ? (<ChatAreathreadVisible={threadVisible}diff --git a/products/posthog_ai/frontend/api/primitives.ts b/products/posthog_ai/frontend/api/primitives.tsindex 3a35cc4ef8d4..478e25c24ed1 100644--- a/products/posthog_ai/frontend/api/primitives.ts+++ b/products/posthog_ai/frontend/api/primitives.ts@@ -78,6 +78,10 @@ export { RunAlertActivity } from '../components/RunAlertActivity'export { TaskRunStatusDot } from '../components/TaskRunStatusDot'export { TaskRunLivenessDot } from '../components/TaskRunLivenessDot'+// Debug-logs overflow menu for hosts with no scene chrome (the PostHog AI scene and side panel).+export { DebugLogsMenu } from '../components/DebugLogsMenu'+export type { DebugLogsMenuProps } from '../components/DebugLogsMenu'+export { PermissionInput } from '../components/PermissionInput'export { QuestionInput } from '../components/QuestionInput'export { ResourcesBar } from '../components/ResourcesBar'diff --git a/products/posthog_ai/frontend/components/DebugLogsMenu.stories.tsx b/products/posthog_ai/frontend/components/DebugLogsMenu.stories.tsxnew file mode 100644index 000000000000..16ab6e4048f5--- /dev/null+++ b/products/posthog_ai/frontend/components/DebugLogsMenu.stories.tsx@@ -0,0 +1,57 @@+import { MOCK_DEFAULT_USER } from 'lib/api.mock'++import type { Meta, StoryObj } from '@storybook/react'++import { mswDecorator } from '~/mocks/browser'+import preflightJson from '~/mocks/fixtures/_preflight.json'++import { DebugLogsMenu } from './DebugLogsMenu'++// The menu is driven entirely by `debugLogsLogic`, which reads `userLogic` and `preflightLogic`. Storybook's+// default mock user is staff, so the `Staff` stories render the trigger; `NonStaff` overrides the user to+// show the other branch, where the whole component collapses to null.+const meta: Meta<typeof DebugLogsMenu> = {+ title: 'Products/PostHog AI/DebugLogsMenu',+ component: DebugLogsMenu,+ tags: ['autodocs'],+}+export default meta++type Story = StoryObj<typeof DebugLogsMenu>++/** Small secondary button, matching the `/ai` header. Open it to reach the switch. */+export const StaffLemon: Story = {+ args: { variant: 'lemon' },+}++/** Icon-only chrome, matching the side-panel header. */+export const StaffPrimitive: Story = {+ args: { variant: 'primitive' },+}++/**+ * A non-staff viewer gets no trigger at all, so the header shows no empty affordance. The component+ * renders nothing here, so the frame below stands in for it. `is_debug` has to be mocked off too: the+ * default preflight fixture sets it, which makes `isDev` true and would grant control regardless of+ * the user.+ */+export const NonStaff: Story = {+ args: { variant: 'lemon' },+ decorators: [+ mswDecorator({+ get: {+ '/api/users/@me/': () => [200, { ...MOCK_DEFAULT_USER, is_staff: false, is_impersonated: false }],+ '/_preflight': () => [200, { ...preflightJson, is_debug: false }],+ },+ }),+ // The snapshot runtime makes `#storybook-root` hug its content, so a story that renders null+ // leaves the screenshot a zero-size target and the run times out. The frame is a fixed box:+ // caption only today, and holding the trigger beside it if the staff gate ever regresses.+ (Story): JSX.Element => (+ <div className="flex gap-2 items-center px-3 h-10 rounded border border-dashed w-fit text-muted">+ <span>No staff menu</span>+ <Story />+ </div>+ ),+ ],+}diff --git a/products/posthog_ai/frontend/components/DebugLogsMenu.tsx b/products/posthog_ai/frontend/components/DebugLogsMenu.tsxnew file mode 100644index 000000000000..eedc4fcd2b3e--- /dev/null+++ b/products/posthog_ai/frontend/components/DebugLogsMenu.tsx@@ -0,0 +1,78 @@+import { useActions, useValues } from 'kea'++import { IconEllipsis } from '@posthog/icons'+import { LemonSwitch } from '@posthog/lemon-ui'++import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { LemonMenu } from 'lib/lemon-ui/LemonMenu/LemonMenu'+import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'++import { debugLogsLogic } from '../logics/debugLogsLogic'++export interface DebugLogsMenuProps {+ /**+ * `lemon` matches the small secondary buttons in the main `/ai` header; `primitive` matches the+ * icon-only chrome in the side-panel header. Mirrors `PhaiViewToggle`, which sits beside it.+ */+ variant?: 'lemon' | 'primitive'+}++/**+ * Overflow menu carrying the debug-logs preference for hosts that have no scene chrome to hang it on.+ * The `/tasks` runner uses the scene menu bar and scene panel instead; this is the form the PostHog AI+ * scene and side panel use, where the only surface is a hand-rolled header.+ *+ * Renders nothing unless the current user may control debug logs, so a non-staff viewer never sees an+ * empty kebab. Debug rows exist only on the sandbox runtime, so the host decides whether the thread+ * below it can show them at all - keeping this component free of any conversation or runtime knowledge.+ */+export function DebugLogsMenu({ variant = 'lemon' }: DebugLogsMenuProps): JSX.Element | null {+ const { canControlDebugLogs, debugLogsEnabled } = useValues(debugLogsLogic)+ const { setDebugLogsEnabled } = useActions(debugLogsLogic)++ if (!canControlDebugLogs) {+ return null+ }++ return (+ <LemonMenu+ // Keep the menu open when the switch flips, so the debug rows appearing behind it are visible+ // straight away. Clicking outside closes it.+ closeOnClickInside={false}+ items={[+ {+ custom: true,+ label: () => (+ <LemonSwitch+ data-attr="run-toggle-debug-logs"+ className="px-2 py-1"+ checked={debugLogsEnabled}+ onChange={setDebugLogsEnabled}+ fullWidth+ label="Show debug logs"+ />+ ),+ },+ ]}+ >+ {variant === 'primitive' ? (+ <ButtonPrimitive+ iconOnly+ tooltip="Staff options"+ tooltipPlacement="bottom-end"+ data-attr="run-staff-menu"+ >+ <IconEllipsis className="text-tertiary size-3 group-hover:text-primary z-10" />+ </ButtonPrimitive>+ ) : (+ <LemonButton+ size="small"+ type="secondary"+ icon={<IconEllipsis />}+ tooltip="Staff options"+ data-attr="run-staff-menu"+ />+ )}+ </LemonMenu>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDebugLogsPanelToggle.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDebugLogsPanelToggle.tsxnew file mode 100644index 000000000000..ac7bb062a6ad--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDebugLogsPanelToggle.tsx@@ -0,0 +1,39 @@+import { useActions, useValues } from 'kea'++import { LemonSwitch } from '@posthog/lemon-ui'++import { ScenePanelActionsSection, ScenePanelDivider } from '~/layout/scenes/SceneLayout'++import { debugLogsLogic } from '../../../logics/debugLogsLogic'++/**+ * Scene-panel twin of `TaskDebugLogsMenu` — the same debug-logs toggle for users without the scene+ * menu bar. Both surfaces read and write the one persisted preference, so the menu bar and the panel+ * never disagree. Renders nothing (not even its divider) unless the current user may control debug+ * logs: impersonated sessions force debug logs on and have no toggle.+ */+export function TaskDebugLogsPanelToggle(): JSX.Element | null {+ const { canControlDebugLogs, debugLogsEnabled } = useValues(debugLogsLogic)+ const { setDebugLogsEnabled } = useActions(debugLogsLogic)++ if (!canControlDebugLogs) {+ return null+ }++ return (+ <>+ <ScenePanelActionsSection>+ <LemonSwitch+ data-attr="task-toggle-debug-logs"+ className="px-2 py-1"+ checked={debugLogsEnabled}+ onChange={setDebugLogsEnabled}+ fullWidth+ label="Show debug logs"+ />+ </ScenePanelActionsSection>++ <ScenePanelDivider />+ </>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsxindex 8dd984b9568b..f1ad0090737f 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx@@ -25,6 +25,7 @@ import {import { Task, TaskRun } from '../../../types/taskTypes'import { TaskDebugLogsMenu } from './TaskDebugLogsMenu'+import { TaskDebugLogsPanelToggle } from './TaskDebugLogsPanelToggle'import { TaskPanelSkeleton, TaskRunMetadataSkeleton } from './taskDetailSkeletons'import { TaskErrorBanner } from './TaskErrorBanner'import { TaskRunMetadata } from './TaskRunMetadata'@@ -111,6 +112,8 @@ export function TaskRunSceneShell({<ScenePanelDivider />+ <TaskDebugLogsPanelToggle />+<ScenePanelActionsSection><ButtonPrimitive menuItem variant="danger" onClick={onArchive}><IconArchive />