: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(aio): prefill PostHog AI composer from /ai?ask= without consent (#72743)
Radu Raicea43ac89561af1
diff --git a/frontend/src/scenes/max/maxLogic.test.ts b/frontend/src/scenes/max/maxLogic.test.tsindex 0dfd1596f1e9..3b282fea780b 100644--- a/frontend/src/scenes/max/maxLogic.test.ts+++ b/frontend/src/scenes/max/maxLogic.test.ts@@ -1,3 +1,5 @@+import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'+import { router } from 'kea-router'import { expectLogic, partial } from 'kea-test-utils'@@ -12,6 +14,7 @@ import { initKeaTests } from '~/test/init'import { ConversationDetail, SidePanelTab } from '~/types'import {+ PENDING_MAX_CONTEXT_KEY,QUESTION_SUGGESTIONS_DATA,SIDE_PANEL_PANEL_ID,maxLogic,@@ -27,6 +30,7 @@ describe('maxLogic', () => {beforeEach(() => {localStorage.clear()+ sessionStorage.clear()useMocks(maxMocks)initKeaTests()})@@ -109,6 +113,61 @@ describe('maxLogic', () => {featureFlagLogic.unmount()})+ // The /ai?ask= deep link (e.g. "Start with AI") must not silently vanish when the org hasn't+ // granted AI data-processing consent: askMax no-ops in that case, so the handler has to fall back+ // to prefilling the composer. With consent it auto-sends via askMax instead.+ describe('ask URL parameter', () => {+ it('prefills the composer without auto-sending when AI consent is not granted', async () => {+ initKeaTests(true, undefined, undefined, {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: false,+ })+ useMocks(maxMocks)+ router.actions.push(urls.ai(undefined, 'Explore my traces'))++ logic = maxLogic({ panelId: 'test' })+ logic.mount()++ await expectLogic(logic).toMatchValues({ question: 'Explore my traces' })+ })++ it('clears any pending deep-link context even when consent is not granted', async () => {+ initKeaTests(true, undefined, undefined, {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: false,+ })+ useMocks(maxMocks)+ sessionStorage.setItem(+ PENDING_MAX_CONTEXT_KEY,+ JSON.stringify({ context: { dashboards: [] }, timestamp: Date.now() })+ )+ router.actions.push(urls.ai(undefined, 'Explore my traces'))++ logic = maxLogic({ panelId: 'test' })+ logic.mount()++ await expectLogic(logic).toMatchValues({ question: 'Explore my traces' })+ expect(sessionStorage.getItem(PENDING_MAX_CONTEXT_KEY)).toBeNull()+ })++ it('auto-sends via askMax without prefilling when AI consent is granted', async () => {+ initKeaTests(true, undefined, undefined, {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: true,+ })+ useMocks(maxMocks)+ router.actions.push(urls.ai(undefined, 'Explore my traces'))++ logic = maxLogic({ panelId: 'test' })+ logic.mount()++ await expectLogic(logic).toDispatchActions([+ logic.actionCreators.askMax('Explore my traces', true, undefined),+ ])+ expect(logic.values.question).toBe('')+ })+ })+it('does not reset conversation when 404 occurs during active message generation', async () => {router.actions.push('', {}, { panel: 'max' })sidePanelStateLogic.mount()diff --git a/frontend/src/scenes/max/maxLogic.tsx b/frontend/src/scenes/max/maxLogic.tsxindex c9c1bbb161e6..ded345bd44ef 100644--- a/frontend/src/scenes/max/maxLogic.tsx+++ b/frontend/src/scenes/max/maxLogic.tsx@@ -885,6 +885,11 @@ export const maxLogic = kea<maxLogicType>([actions.startNewConversation()}+ // kea-router coerces numeric-looking URL params to numbers+ const askPrompt = String(search.ask)++ // Consume any pending deep-link context up front, before the consent gate, so an+ // unapproved link doesn't leave a stale entry behind for a later one to pick up.let uiContext: Partial<MaxUIContext> | undefined = undefinedtry {const stored = sessionStorage.getItem(PENDING_MAX_CONTEXT_KEY)@@ -900,11 +905,18 @@ export const maxLogic = kea<maxLogicType>([// sessionStorage unavailable or data malformed, agent will handle it}+ if (!values.dataProcessingAccepted) {+ // Without AI data-processing consent, askMax silently no-ops and the prompt is lost.+ // Prefill the composer instead so the deep-linked prompt stays visible and the user's+ // manual submit runs it (which surfaces the consent flow).+ actions.setQuestion(askPrompt)+ return+ }+window.setTimeout(() => {// ensure maxThreadLogic is mounted// Pass context directly to askMax to avoid timing issues- // kea-router coerces numeric-looking URL params to numbers- actions.askMax(String(search.ask), true, uiContext)+ actions.askMax(askPrompt, true, uiContext)}, 100)return}