: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(tasks): gate desktop deep link by access (#86942)
Vojta Bartoš187efe29934b
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsxindex 118b62072e15..d6d6fc9f98d3 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx@@ -125,6 +125,7 @@ const meta: Meta = {decorators: [mswDecorator({get: {+ '/api/code/invites/check-access/': { has_access: true, has_loops_access: false },'/api/projects/:team_id/tasks/': listResponse(TASKS),'/api/projects/:team_id/tasks/repositories/': { repositories: ['PostHog/posthog'] },// Exact ids (not `:id`) so they never shadow the `repositories` action route.diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsxindex 48345baf7d75..6a0447e22118 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx@@ -6,6 +6,7 @@ import { LemonButton } from '@posthog/lemon-ui'import { NotFound } from 'lib/components/NotFound'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { urls } from 'scenes/urls'import { isPiTaskRuntime } from '../../../types/taskTypes'import { taskDetailSceneLogic } from '../taskDetailSceneLogic'@@ -26,7 +27,7 @@ export function TaskDetailPage({ taskId, isMobile }: TaskDetailPageProps): JSX.EuseValues(sceneLogic)const { runTask, deleteTask, loadTask } = useActions(sceneLogic)const { featureFlags } = useValues(featureFlagLogic)- const { activeCreation } = useValues(taskTrackerSceneLogic)+ const { activeCreation, hasDesktopAccess } = useValues(taskTrackerSceneLogic)const sceneMenuBarEnabled = !!featureFlags[FEATURE_FLAGS.SCENE_MENU_BAR]if (taskNotFound && !task) {@@ -48,15 +49,18 @@ export function TaskDetailPage({ taskId, isMobile }: TaskDetailPageProps): JSX.E<TaskHeaderActionsSkeleton />) : (<div className="flex items-center gap-2">- <LemonButton- type="secondary"- size="small"- icon={<IconExternal />}- onClick={() => window.open(`posthog-code://task/${task.id}`, '_blank')}- className="hidden lg:inline-flex"- >- Open in PostHog Desktop- </LemonButton>+ {hasDesktopAccess && (+ <LemonButton+ type="secondary"+ size="small"+ icon={<IconExternal />}+ to={urls.codeTaskLink(task.id)}+ targetBlank+ className="hidden lg:inline-flex"+ >+ Open in PostHog Desktop+ </LemonButton>+ )}{prUrl && (<LemonButtontype="secondary"diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.tsindex 9d465255c787..7b12938e2201 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts@@ -45,6 +45,7 @@ describe('taskTrackerSceneLogic', () => {runBody = nulluseMocks({get: {+ '/api/code/invites/check-access/': { has_access: true, has_loops_access: false },'/api/projects/:team/tasks/': { results: [], count: 0 },'/api/projects/:team/tasks/repositories/': { repositories: [] },'/api/environments/:team/integrations/': { results: [] },@@ -76,6 +77,16 @@ describe('taskTrackerSceneLogic', () => {toolEvents?.unmount()})+ it('loads PostHog Desktop access and exposes it to the task UI', async () => {+ logic.mount()++ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.hasDesktopAccess).toBe(true)++ logic.actions.loadDesktopAccessSuccess({ has_access: false, has_loops_access: false })+ expect(logic.values.hasDesktopAccess).toBe(false)+ })+// PostHog AI can run without a repo: a description-only submit must still create and run the task with a// null repository, not bail. Guards against re-adding a "Repository is required" gate on the send path.it('creates and runs a task with no repository selected', async () => {diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.tsindex 10093822af4c..a520e9cb1a60 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts@@ -1,4 +1,5 @@import { MakeLogicType, actions, connect, events, kea, key, listeners, path, props, reducers, selectors } from 'kea'+import { loaders } from 'kea-loaders'import { router, urlToAction } from 'kea-router'import { lemonToast } from '@posthog/lemon-ui'@@ -8,8 +9,9 @@ import { uuid } from 'lib/utils/dom'import { projectLogic } from 'scenes/projectLogic'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'-import { tasksCreate, tasksRunCreate } from 'products/tasks/frontend/generated/api'+import { codeInvitesCheckAccessRetrieve, tasksCreate, tasksRunCreate } from 'products/tasks/frontend/generated/api'import {+ type LegacyDesktopAccessResponseApi,type ModelChoiceApi,OriginProductEnumApi,ReasoningEffortEnumApi,@@ -132,7 +134,10 @@ export interface taskTrackerSceneLogicValues {overrideHeadlines: string[] | null // welcomeOverrideLogicactiveSuggestionGroup: SuggestionGroup | nullconsentBlocked: boolean+ desktopAccess: LegacyDesktopAccessResponseApi | null+ desktopAccessLoading: booleandisplayHeadline: string+ hasDesktopAccess: booleanheadlineSeed: numberisSubmittingTask: booleannewTaskData: TaskCreateForm@@ -321,6 +326,21 @@ export interface taskTrackerSceneLogicActions {clearConsentBlock: () => {value: true}+ loadDesktopAccess: () => any+ loadDesktopAccessFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadDesktopAccessSuccess: (+ desktopAccess: LegacyDesktopAccessResponseApi,+ payload?: any+ ) => {+ desktopAccess: LegacyDesktopAccessResponseApi+ payload?: any+ }maybeAutoSelectIntegration: () => {value: true}@@ -360,6 +380,7 @@ export interface taskTrackerSceneLogicActions {export interface taskTrackerSceneLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {+ hasDesktopAccess: (desktopAccess: LegacyDesktopAccessResponseApi | null) => booleandisplayHeadline: (overrideHeadlines: string[] | null, headlineSeed: number) => string}}@@ -495,7 +516,20 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([],}),+ loaders({+ desktopAccess: [+ null as LegacyDesktopAccessResponseApi | null,+ {+ loadDesktopAccess: async () => codeInvitesCheckAccessRetrieve(),+ },+ ],+ }),+selectors({+ hasDesktopAccess: [+ (s) => [s.desktopAccess],+ (desktopAccess: LegacyDesktopAccessResponseApi | null): boolean => desktopAccess?.has_access ?? false,+ ],// Contextual headlines registered by the active scene (welcomeOverrideLogic) win over the// generic defaults; the seed keeps the pick stable across re-renders.displayHeadline: [@@ -748,6 +782,7 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([events(({ actions, values, cache }) => ({afterMount: () => {+ actions.loadDesktopAccess()actions.loadTasks(values.taskListParams)actions.loadRepositories()// Roll a headline seed once per mount (pickHeadline forces index 0 under Storybook fordiff --git a/products/tasks/backend/temporal/process_task/README.md b/products/tasks/backend/temporal/process_task/README.mdindex 93bfe53a455e..69ff7514c984 100644--- a/products/tasks/backend/temporal/process_task/README.md+++ b/products/tasks/backend/temporal/process_task/README.md@@ -204,7 +204,7 @@ Set `SANDBOX_API_URL` to the ngrok URL. `SITE_URL` stays as `http://localhost:80## Frontend-- **TaskDetailPage** (`frontend/components/TaskDetailPage.tsx`) — Task detail view with run history, "Run task" button, "Open in PostHog Desktop" link+- **TaskDetailPage** (`frontend/components/TaskDetailPage.tsx`) — Task detail view with run history, "Run task" button, and an "Open in PostHog Desktop" link for users with Desktop access- **TaskSessionView** (`frontend/components/TaskSessionView.tsx`) — Live log streaming with hedgehog animation during agent execution- PostHog Desktop integration via `posthog-code://task/{id}` deep links