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): don't crash the bare /ai scene when panelId is missing (#65454)

Hugues Pouillot8f5baeafbd74
diff --git a/frontend/src/scenes/max/maxLogic.tsx b/frontend/src/scenes/max/maxLogic.tsx
index d6306051c5c8..b8fa75a2f092 100644
--- a/frontend/src/scenes/max/maxLogic.tsx
+++ b/frontend/src/scenes/max/maxLogic.tsx
@@ -130,6 +130,9 @@ const CHAT_TITLE_HISTORY = 'Chat history'
// Fixed panelId for the floating side panel chat, which is not a scene tab.
export const SIDE_PANEL_PANEL_ID = 'sidepanel'
+// Fallback panelId for the bare /ai scene, which has no tab id and no side panel chrome.
+export const SCENE_PANEL_ID = 'scene'
+
export interface MaxLogicProps {
panelId?: string
initialFrontendConversationId?: string
@@ -148,7 +151,7 @@ function sceneTabId(panelId?: string, syncUrl?: boolean): string | null {
export const maxLogic = kea<maxLogicType>([
props({} as MaxLogicProps),
- key((props) => props.panelId || 'scene'),
+ key((props) => props.panelId || SCENE_PANEL_ID),
path((key) => ['scenes', 'max', 'maxLogic', key]),
connect(() => ({
diff --git a/frontend/src/scenes/max/maxThreadLogic.test.ts b/frontend/src/scenes/max/maxThreadLogic.test.ts
index 04b08f663bce..bddbeb2a1f86 100644
--- a/frontend/src/scenes/max/maxThreadLogic.test.ts
+++ b/frontend/src/scenes/max/maxThreadLogic.test.ts
@@ -108,6 +108,13 @@ describe('maxThreadLogic', () => {
jest.restoreAllMocks()
})
+ it('builds for the bare scene without a panelId, falling back to the scene key', () => {
+ const sceneLogic = maxThreadLogic({ conversationId: MOCK_CONVERSATION_ID })
+ expect(() => sceneLogic.mount()).not.toThrow()
+ expect(sceneLogic.key).toBe(`${MOCK_CONVERSATION_ID}-scene`)
+ sceneLogic.unmount()
+ })
+
it('selects threadGroup without a human message', async () => {
await expectLogic(logic, () => {
logic.actions.setThread([
diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsx
index 513cf6ff7ace..f095e0ef7aec 100644
--- a/frontend/src/scenes/max/maxThreadLogic.tsx
+++ b/frontend/src/scenes/max/maxThreadLogic.tsx
@@ -78,7 +78,7 @@ import {
import { PENDING_AI_PROMPT_KEY } from './max-storage-keys'
import { MaxBillingContext, MaxBillingContextSubscriptionLevel, maxBillingContextLogic } from './maxBillingContextLogic'
import { maxGlobalLogic } from './maxGlobalLogic'
-import { SIDE_PANEL_PANEL_ID, maxLogic } from './maxLogic'
+import { SCENE_PANEL_ID, SIDE_PANEL_PANEL_ID, maxLogic } from './maxLogic'
import type { maxThreadLogicType } from './maxThreadLogicType'
import { AttachedContext, MaxUIContext } from './maxTypes'
import { posthogAiContextLogic } from './posthogAiContextLogic'
@@ -122,12 +122,9 @@ export interface MaxThreadLogicProps {
}
export const maxThreadLogic = kea<maxThreadLogicType>([
- key((props) => {
- if (!props.panelId) {
- throw new Error('Max thread logic must have a panelId prop')
- }
- return `${props.conversationId}-${props.panelId}`
- }),
+ // Mirror maxLogic's key fallback: the bare /ai scene has no panelId, and both logics must
+ // resolve to the same `scene` instance (maxThreadLogic connects to maxLogic({ panelId })).
+ key((props) => `${props.conversationId}-${props.panelId || SCENE_PANEL_ID}`),
path((key) => ['scenes', 'max', 'maxThreadLogic', key]),