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(max): open the active chat from the side panel expand button (#87171)

Paul D'Ambra543dacb1b7fb
diff --git a/frontend/src/scenes/max/Max.tsx b/frontend/src/scenes/max/Max.tsx
index 3c37eac928f2..143f306ae2ef 100644
--- a/frontend/src/scenes/max/Max.tsx
+++ b/frontend/src/scenes/max/Max.tsx
@@ -40,6 +40,7 @@ import { ThreadAutoScroller } from './components/ThreadAutoScroller'
import { ConversationHistory } from './ConversationHistory'
import { HistoryPreview } from './HistoryPreview'
import { Intro } from './Intro'
+import { mainFocusUrl } from './mainFocusUrl'
import { MaxLogicProps, SIDE_PANEL_PANEL_ID, maxLogic } from './maxLogic'
import { MaxThreadLogicProps, maxThreadLogic } from './maxThreadLogic'
import { SandboxComposerSurfaces, Thread } from './Thread'
@@ -104,7 +105,9 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:
// The new posthog_ai view's back button walks its own panel view state (run -> history -> composer)
// rather than legacy Max's conversation stack — mounting this tiny headless logic in legacy view is
// harmless (unconditional hooks).
- const { canGoBack: panelCanGoBack } = useValues(runnerPanelLogic({ panelId: MAX_SIDE_PANEL_ID }))
+ const { canGoBack: panelCanGoBack, activeCreation: panelActiveCreation } = useValues(
+ runnerPanelLogic({ panelId: MAX_SIDE_PANEL_ID })
+ )
const { goBack: panelGoBack } = useActions(runnerPanelLogic({ panelId: MAX_SIDE_PANEL_ID }))
const threadProps: MaxThreadLogicProps = {
@@ -118,6 +121,12 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:
const isNewView = effectivePhaiView === 'new'
const headerBackDisabled = isNewView ? !panelCanGoBack : backButtonDisabled
+ const openAsMainFocusUrl = mainFocusUrl({
+ isNewView,
+ activeCreation: panelActiveCreation,
+ conversationId,
+ })
+
const content = !isMaxAvailable ? (
<MaxNotConfigured />
) : (
@@ -221,7 +230,8 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:
buttonProps={{
iconOnly: true,
}}
- to={urls.ai(conversationId ?? undefined)}
+ to={openAsMainFocusUrl ?? undefined}
+ disabledReason={openAsMainFocusUrl ? undefined : 'This chat is still starting'}
onClick={() => {
closeSidePanel()
}}
diff --git a/frontend/src/scenes/max/mainFocusUrl.test.ts b/frontend/src/scenes/max/mainFocusUrl.test.ts
new file mode 100644
index 000000000000..1e92a4b06f5b
--- /dev/null
+++ b/frontend/src/scenes/max/mainFocusUrl.test.ts
@@ -0,0 +1,36 @@
+import { MainFocusUrlInput, mainFocusUrl } from './mainFocusUrl'
+
+describe('mainFocusUrl', () => {
+ const cases: [string, MainFocusUrlInput, string | null][] = [
+ [
+ 'new view with a run open',
+ {
+ isNewView: true,
+ activeCreation: { streamKey: 'run-1', taskId: 'task-1', runId: 'run-1' },
+ conversationId: null,
+ },
+ '/tasks/task-1?runId=run-1',
+ ],
+ [
+ 'new view with a run that never started',
+ { isNewView: true, activeCreation: { streamKey: 'run-1', taskId: 'task-1' }, conversationId: null },
+ '/tasks/task-1',
+ ],
+ [
+ 'new view with a task still being created',
+ { isNewView: true, activeCreation: { streamKey: 'draft-1' }, conversationId: null },
+ null,
+ ],
+ ['new view with nothing open', { isNewView: true, activeCreation: null, conversationId: null }, '/ai'],
+ [
+ 'legacy view with a chat open',
+ { isNewView: false, activeCreation: null, conversationId: 'conversation-1' },
+ '/ai?chat=conversation-1',
+ ],
+ ['legacy view with nothing open', { isNewView: false, activeCreation: null, conversationId: null }, '/ai'],
+ ]
+
+ it.each(cases)('opens what the panel is showing: %s', (_name, input, expected) => {
+ expect(mainFocusUrl(input)).toBe(expected)
+ })
+})
diff --git a/frontend/src/scenes/max/mainFocusUrl.ts b/frontend/src/scenes/max/mainFocusUrl.ts
new file mode 100644
index 000000000000..d9efe1a0e067
--- /dev/null
+++ b/frontend/src/scenes/max/mainFocusUrl.ts
@@ -0,0 +1,35 @@
+import { combineUrl } from 'kea-router'
+
+import { urls } from 'scenes/urls'
+
+import type { ActiveCreation } from 'products/posthog_ai/frontend/api/logics'
+
+export interface MainFocusUrlInput {
+ /** Whether the panel is running the new PostHog AI view rather than the legacy Max chat. */
+ isNewView: boolean
+ /** The run the new view's panel has open, if any. */
+ activeCreation: ActiveCreation | null
+ /** The conversation the legacy view has open, if any. */
+ conversationId: string | null
+}
+
+/**
+ * Where the side panel's "Open as main focus" button goes, or null when the open chat has nowhere to go
+ * yet. The new view's panel runs tasks rather than Max conversations, so its open chat is a task run and
+ * `conversationId` stays null there.
+ */
+export function mainFocusUrl({ isNewView, activeCreation, conversationId }: MainFocusUrlInput): string | null {
+ if (!isNewView) {
+ return urls.ai(conversationId ?? undefined)
+ }
+ if (!activeCreation) {
+ return urls.ai()
+ }
+ if (!activeCreation.taskId) {
+ // A task still being created has no page to open, and the panel holds the only copy of its
+ // pending thread — so the button has to wait rather than send the user somewhere else.
+ return null
+ }
+ // The panel keeps streaming the run it opened, while the task page otherwise defaults to the newest.
+ return combineUrl(urls.taskDetail(activeCreation.taskId), { runId: activeCreation.runId }).url
+}