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(logs): send the missing-link prompt to PostHog AI in every view (#116056)

Jon McCallum2de72a644a65
diff --git a/products/logs/frontend/components/LogsViewer/LogContextLinks/MissingLinkInvestigate.tsx b/products/logs/frontend/components/LogsViewer/LogContextLinks/MissingLinkInvestigate.tsx
index ce8a713bd0ea..41d9c845d767 100644
--- a/products/logs/frontend/components/LogsViewer/LogContextLinks/MissingLinkInvestigate.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogContextLinks/MissingLinkInvestigate.tsx
@@ -9,8 +9,6 @@ import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { humanList } from 'lib/utils/strings'
import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
-import { todayShellLogic } from '~/layout/today/todayShellLogic'
-
import { getServiceName } from 'products/logs/frontend/components/LogsViewer/LogContextSelector/logContextUtils'
import { ParsedLogMessage } from 'products/logs/frontend/types'
@@ -52,12 +50,9 @@ export function MissingLinkInvestigate({
surface: LogContextLinksSurface
onLeave?: () => void
}): JSX.Element {
- const { isMaxAvailable, effectivePhaiView } = useValues(maxGlobalLogic)
- const { todayRailEnabled } = useValues(todayShellLogic)
- const { launching } = useValues(missingLinkInvestigateLogic)
+ const { isMaxAvailable } = useValues(maxGlobalLogic)
+ const { launching, startsSidePanelTask } = useValues(missingLinkInvestigateLogic)
const { startTask } = useActions(missingLinkInvestigateLogic)
- // Only the new PostHog AI side panel turns a run prompt into a task; the legacy view would start a chat.
- const canStartTask = isMaxAvailable && effectivePhaiView === 'new' && !todayRailEnabled
useOnMountEffect(() => captureInvestigate('shown', log, missing, surface))
@@ -84,12 +79,12 @@ export function MissingLinkInvestigate({
}
data-attr={`logs-${surface}-missing-link-agent-prompt`}
/>
- {canStartTask && (
+ {isMaxAvailable && (
<LemonButton
size="xsmall"
type="tertiary"
icon={<IconSparkles />}
- loading={launching}
+ loading={startsSidePanelTask && launching}
onClick={() => {
captureInvestigate('clicked', log, missing, surface, 'posthog-ai-task')
startTask(buildMissingLinkPrompt(log, missing), onLeave ?? (() => {}))
diff --git a/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.test.ts b/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.test.ts
new file mode 100644
index 000000000000..314e22a88192
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.test.ts
@@ -0,0 +1,72 @@
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
+import { newInternalTab } from 'lib/utils/newInternalTab'
+import { MAX_SIDE_PANEL_ID } from 'scenes/max/components/PhaiSidePanelChat'
+import { maxMocks } from 'scenes/max/testUtils'
+import { urls } from 'scenes/urls'
+
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+import { SidePanelTab } from '~/types'
+
+import { composerSeedLogic } from 'products/posthog_ai/frontend/api/logics'
+
+import { missingLinkInvestigateLogic } from './missingLinkInvestigateLogic'
+
+jest.mock('lib/utils/newInternalTab')
+
+describe('missingLinkInvestigateLogic', () => {
+ let logic: ReturnType<typeof missingLinkInvestigateLogic.build>
+
+ beforeEach(() => {
+ useMocks(maxMocks)
+ initKeaTests()
+ sidePanelStateLogic.mount()
+ sidePanelStateLogic.actions.setSidePanelAvailable(true)
+ composerSeedLogic({ panelId: MAX_SIDE_PANEL_ID }).mount()
+ logic = missingLinkInvestigateLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ composerSeedLogic({ panelId: MAX_SIDE_PANEL_ID }).unmount()
+ })
+
+ test.each([
+ { name: 'new view, no rail', flags: [FEATURE_FLAGS.PHAI_SANDBOX_MODE], route: 'side-panel-task' },
+ { name: 'legacy view, no rail', flags: [], route: 'legacy-ask' },
+ {
+ name: 'new view, rail',
+ flags: [FEATURE_FLAGS.PHAI_SANDBOX_MODE, FEATURE_FLAGS.TODAY_RAIL_NAV],
+ route: 'ai-scene',
+ },
+ { name: 'legacy view, rail', flags: [FEATURE_FLAGS.TODAY_RAIL_NAV], route: 'ai-scene' },
+ ])('$name sends the prompt to PostHog AI', async ({ flags, route }) => {
+ featureFlagLogic.actions.setFeatureFlags(flags, Object.fromEntries(flags.map((flag) => [flag, true])))
+ router.actions.push('/logs')
+ ;(newInternalTab as jest.Mock).mockClear()
+
+ await expectLogic(logic, () => {
+ logic.actions.startTask('Find the missing session ID', () => {})
+ }).toFinishAllListeners()
+
+ const seed = composerSeedLogic({ panelId: MAX_SIDE_PANEL_ID }).values.seed
+ expect({
+ seeded: seed?.prompt ?? null,
+ sidePanelTab: sidePanelStateLogic.values.sidePanelOpen ? sidePanelStateLogic.values.selectedTab : null,
+ newTab: (newInternalTab as jest.Mock).mock.calls.map(([url]) => url),
+ path: removeProjectIdIfPresent(router.values.location.pathname) + router.values.location.search,
+ }).toEqual({
+ seeded: route === 'side-panel-task' ? 'Find the missing session ID' : null,
+ sidePanelTab: route === 'side-panel-task' ? SidePanelTab.Max : null,
+ newTab: route === 'legacy-ask' ? [urls.ai(undefined, 'Find the missing session ID')] : [],
+ path: route === 'ai-scene' ? urls.ai(undefined, 'Find the missing session ID') : '/logs',
+ })
+ })
+})
diff --git a/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.ts b/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.ts
index d8655e2d5ac6..41065851edc3 100644
--- a/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/LogContextLinks/missingLinkInvestigateLogic.ts
@@ -1,9 +1,12 @@
import { MakeLogicType, actions, connect, kea, listeners, path, selectors } from 'kea'
+import { router } from 'kea-router'
import { MAX_SIDE_PANEL_ID } from 'scenes/max/components/PhaiSidePanelChat'
-import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
+import { PhaiViewMode, maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
+import { urls } from 'scenes/urls'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
+import { todayShellLogic } from '~/layout/today/todayShellLogic'
import { SidePanelTab } from '~/types'
import { logsViewerModalLogic } from 'products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic'
@@ -18,8 +21,11 @@ import {
export interface missingLinkInvestigateLogicValues {
seed: ComposerSeed | null // composerSeedLogic
dataProcessingAccepted: boolean // maxGlobalLogic
+ effectivePhaiView: PhaiViewMode // maxGlobalLogic
activeCreation: ActiveCreation | null // runnerPanelLogic
+ todayRailEnabled: boolean // todayShellLogic
launching: boolean
+ startsSidePanelTask: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -30,6 +36,9 @@ export interface missingLinkInvestigateLogicActions {
closeLogsViewerModal: () => {
value: true
} // logsViewerModalLogic
+ askSidePanelMax: (prompt: string) => {
+ prompt: string
+ } // maxGlobalLogic
clearActiveCreation: () => {
value: true
} // runnerPanelLogic
@@ -55,6 +64,7 @@ export interface missingLinkInvestigateLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface missingLinkInvestigateLogicMeta {
__keaTypeGenInternalSelectorTypes: {
+ startsSidePanelTask: (effectivePhaiView: PhaiViewMode, todayRailEnabled: boolean) => boolean
launching: (seed: ComposerSeed | null, activeCreation: ActiveCreation | null) => boolean
}
}
@@ -80,7 +90,9 @@ export const missingLinkInvestigateLogic = kea<missingLinkInvestigateLogicType>(
connect(() => ({
values: [
maxGlobalLogic,
- ['dataProcessingAccepted'],
+ ['dataProcessingAccepted', 'effectivePhaiView'],
+ todayShellLogic,
+ ['todayRailEnabled'],
composerSeedLogic({ panelId: MAX_SIDE_PANEL_ID }),
['seed'],
runnerPanelLogic({ panelId: MAX_SIDE_PANEL_ID }),
@@ -93,6 +105,8 @@ export const missingLinkInvestigateLogic = kea<missingLinkInvestigateLogicType>(
['clearActiveCreation', 'setHistoryExpanded'],
sidePanelStateLogic,
['openSidePanel'],
+ maxGlobalLogic,
+ ['askSidePanelMax'],
logsViewerModalLogic,
['closeLogsViewerModal'],
],
@@ -103,6 +117,13 @@ export const missingLinkInvestigateLogic = kea<missingLinkInvestigateLogicType>(
}),
selectors({
+ // Only the new view's side panel turns a seed into a task. The rail moves PostHog AI to its own
+ // scene, and the legacy view has no tasks, so both of those take the prompt as a chat question.
+ startsSidePanelTask: [
+ (s) => [s.effectivePhaiView, s.todayRailEnabled],
+ (effectivePhaiView: PhaiViewMode, todayRailEnabled: boolean): boolean =>
+ effectivePhaiView === 'new' && !todayRailEnabled,
+ ],
// The side panel holds a seed it has not taken yet, and submits it after any submission in flight,
// so a second launch now would queue a duplicate task. A creation without a task ID is still
// submitting: success adds the ID and failure clears the creation, which ends the guard either way.
@@ -118,6 +139,17 @@ export const missingLinkInvestigateLogic = kea<missingLinkInvestigateLogicType>(
// The drawer and the logs modal sit above the side panel, so close them before it opens.
closeHost()
actions.closeLogsViewerModal()
+ if (values.todayRailEnabled) {
+ // The rail keeps PostHog AI in the /ai scene, in the same tab. Its `ask` seeds a task in the
+ // new view and starts a chat in the legacy view, and both remove the prompt from the URL.
+ router.actions.push(urls.ai(undefined, prompt))
+ return
+ }
+ if (!values.startsSidePanelTask) {
+ // The legacy view: the shared ask path opens the question in a new PostHog AI tab.
+ actions.askSidePanelMax(prompt)
+ return
+ }
if (values.launching) {
// Show the investigation already starting rather than queueing a second one.
actions.openSidePanel(SidePanelTab.Max)