: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(posthog-ai): prevent duplicate tasks from url prompts (#98536)
Georgiy Tarasovee27d379dd3a
diff --git a/docs/published/handbook/engineering/ai/sandboxed-agents.md b/docs/published/handbook/engineering/ai/sandboxed-agents.mdindex bfb0aebe95c3..49a822e9ce2c 100644--- a/docs/published/handbook/engineering/ai/sandboxed-agents.md+++ b/docs/published/handbook/engineering/ai/sandboxed-agents.md@@ -103,6 +103,13 @@ class OriginProduct(models.TextChoices):Then create and run a Django migration.+### Starting a task from a deep link++In the new PostHog AI view, `/ai?ask=...` hands the prompt to the task composer once.+The handoff removes `ask` from the current browser history entry while preserving other query parameters and the hash.+Changing the panel state or remounting the view therefore does not submit the prompt again.+Without organization-level AI data-processing consent, the prompt only prefills the composer.+## Fine-grained access tokensEvery sandboxed agent gets a scoped OAuth access token that controls what PostHog resources it can access.diff --git a/frontend/src/scenes/max/phaiAiComposerSeedLogic.test.ts b/frontend/src/scenes/max/phaiAiComposerSeedLogic.test.tsindex dc02bde5cc70..6d27f6af6c3b 100644--- a/frontend/src/scenes/max/phaiAiComposerSeedLogic.test.ts+++ b/frontend/src/scenes/max/phaiAiComposerSeedLogic.test.ts@@ -25,7 +25,7 @@ describe('phaiAiComposerSeedLogic', () => {{ consent: true, autoSubmit: true },{ consent: false, autoSubmit: false },])(- 'forwards the /ai ask query as a seed with autoSubmit=$autoSubmit when consent is $consent',+ 'forwards each /ai ask navigation once with autoSubmit=$autoSubmit when consent is $consent',({ consent, autoSubmit }) => {initKeaTests(true, undefined, undefined, {...MOCK_DEFAULT_ORGANIZATION,@@ -34,7 +34,7 @@ describe('phaiAiComposerSeedLogic', () => {seedLogic = composerSeedLogic()seedLogic.mount()- router.actions.push(urls.ai(undefined, 'Explain this dashboard'))+ router.actions.push(urls.ai(undefined, 'Explain this dashboard'), { source: 'homepage' }, { panel: 'max' })logic = phaiAiComposerSeedLogic()logic.mount()@@ -43,6 +43,18 @@ describe('phaiAiComposerSeedLogic', () => {prompt: 'Explain this dashboard',autoSubmit,})+ expect(router.values.searchParams).toEqual({ source: 'homepage' })+ expect(router.values.hashParams).toEqual({ panel: 'max' })++ seedLogic.actions.consumeSeed()+ router.actions.replace(router.values.location.pathname, router.values.searchParams, {})+ expect(seedLogic.values.seed).toBeNull()+ logic.unmount()+ logic.mount()+ expect(seedLogic.values.seed).toBeNull()++ router.actions.push(urls.ai(undefined, 'Explain this dashboard'))+ expect(seedLogic.values.seed).toEqual({ prompt: 'Explain this dashboard', autoSubmit })})})diff --git a/frontend/src/scenes/max/phaiAiComposerSeedLogic.ts b/frontend/src/scenes/max/phaiAiComposerSeedLogic.tsindex 64b5a27f405c..dce2f01c9efe 100644--- a/frontend/src/scenes/max/phaiAiComposerSeedLogic.ts+++ b/frontend/src/scenes/max/phaiAiComposerSeedLogic.ts@@ -1,5 +1,5 @@import { MakeLogicType, connect, kea, path } from 'kea'-import { urlToAction } from 'kea-router'+import { router, urlToAction } from 'kea-router'import { urls } from 'scenes/urls'@@ -35,12 +35,16 @@ export const phaiAiComposerSeedLogic = kea<phaiAiComposerSeedLogicType>([}),urlToAction(({ actions, values }) => ({- [urls.ai()]: (_, search) => {+ [urls.ai()]: (_, search, hash) => {if (search.ask && !search.chat) {+ const { ask, ...remainingSearch } = search+ // Hash changes also run this handler. Remove the prompt before handing it off so they+ // cannot submit it again.+ router.actions.replace(router.values.location.pathname, remainingSearch, hash)// `ask` is URL-controlled — same org-level AI data-processing consent gate as the legacy// `askMax` path: without approval the seed only prefills the composer, and the user's own// send goes through the composer's consent flow.- actions.setSeed({ prompt: String(search.ask), autoSubmit: values.dataProcessingAccepted })+ actions.setSeed({ prompt: String(ask), autoSubmit: values.dataProcessingAccepted })}},})),