: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(max): stop maxGlobalLogic crashing the app when tasksLogic is unmounted (#118454)
posthog[bot]c35342257d05
diff --git a/frontend/src/scenes/max/maxGlobalLogic.test.ts b/frontend/src/scenes/max/maxGlobalLogic.test.tsindex 269eb36d2bbc..5c108c22e8c8 100644--- a/frontend/src/scenes/max/maxGlobalLogic.test.ts+++ b/frontend/src/scenes/max/maxGlobalLogic.test.ts@@ -53,6 +53,13 @@ describe('maxGlobalLogic', () => {jest.restoreAllMocks()})+ // GlobalModals mounts this logic on every page. Mounting it alone must not mount the task list,+ // or every boot fetches tasks, and a boot where the task list cannot build crashes the app.+ it('mounts without mounting the task list', () => {+ expect(logic.isMounted()).toBe(true)+ expect(tasksLogic.findMounted()).toBeNull()+ })+// Opening a conversation in the side panel must surface it in the side panel chat without// replacing the main content. The side panel floats over whatever scene you're on; the rendered// scene is chosen by the route, so the page (insight, survey, …) must stay put.diff --git a/frontend/src/scenes/max/maxGlobalLogic.tsx b/frontend/src/scenes/max/maxGlobalLogic.tsxindex dffc48c581c6..e98134f69715 100644--- a/frontend/src/scenes/max/maxGlobalLogic.tsx+++ b/frontend/src/scenes/max/maxGlobalLogic.tsx@@ -20,6 +20,7 @@ import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePaneimport { Conversation, ConversationDetail, SidePanelTab } from '~/types'import { conversationsDestroy } from 'products/posthog_ai/frontend/generated/api'+import { taskEventsLogic } from 'products/posthog_ai/frontend/logics/taskEventsLogic'import { tasksLogic } from 'products/posthog_ai/frontend/logics/tasksLogic'import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'@@ -402,7 +403,7 @@ export const maxGlobalLogic = kea<maxGlobalLogicType>([},// A chat and its task are deleted together on the server, so removing a task from the merged// list must drop the chat row too, or the chat resurfaces as a row of its own.- [tasksLogic.actionTypes.deleteTaskSuccess]: () => {+ [taskEventsLogic.actionTypes.taskDeleted]: () => {actions.loadConversationHistory()},askSidePanelMax: ({ prompt }) => {diff --git a/products/posthog_ai/frontend/logics/taskEventsLogic.ts b/products/posthog_ai/frontend/logics/taskEventsLogic.tsnew file mode 100644index 000000000000..dcd28f786bcc--- /dev/null+++ b/products/posthog_ai/frontend/logics/taskEventsLogic.ts@@ -0,0 +1,21 @@+import { MakeLogicType, actions, kea, path } from 'kea'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface taskEventsLogicActions {+ taskDeleted: () => {+ value: true+ }+}++export type taskEventsLogicType = MakeLogicType<{}, taskEventsLogicActions>++/**+ * Global bus for task lifecycle events. It holds no state and fetches nothing, so a host can connect+ * to it at boot without mounting `tasksLogic` or loading the task list.+ */+export const taskEventsLogic = kea<taskEventsLogicType>([+ path(['products', 'posthog_ai', 'frontend', 'logics', 'taskEventsLogic']),+ actions({+ taskDeleted: true,+ }),+])diff --git a/products/posthog_ai/frontend/logics/tasksLogic.ts b/products/posthog_ai/frontend/logics/tasksLogic.tsindex 6e102f6fdeda..b37f01971bf3 100644--- a/products/posthog_ai/frontend/logics/tasksLogic.ts+++ b/products/posthog_ai/frontend/logics/tasksLogic.ts@@ -18,6 +18,7 @@ import { TasksListOrdering } from 'products/tasks/frontend/generated/api.schemasimport type { UserType } from '../../../../frontend/src/types'import { loadErrorMessage } from '../lib/load-error'import { OriginProduct, Task, TaskAssigneeFilter, TaskListParams, TaskUpsertProps } from '../types/taskTypes'+import { taskEventsLogic } from './taskEventsLogic'import { taskHistoryLogic } from './taskHistoryLogic'function hasTasksFlag(featureFlags: FeatureFlagsSet): boolean {@@ -54,6 +55,9 @@ export interface tasksLogicActions {flags: string[]variants: Record<string, boolean | string>} // featureFlagLogic+ taskDeleted: () => {+ value: true+ } // taskEventsLogicloadUserSuccess: (user: UserType | null,payload?:@@ -216,7 +220,14 @@ export const tasksLogic = kea<tasksLogicType>([connect(() => ({values: [userLogic, ['user'], featureFlagLogic, ['featureFlags']],- actions: [featureFlagLogic, ['setFeatureFlags'], userLogic, ['loadUserSuccess']],+ actions: [+ featureFlagLogic,+ ['setFeatureFlags'],+ taskEventsLogic,+ ['taskDeleted'],+ userLogic,+ ['loadUserSuccess'],+ ],})),actions({@@ -484,6 +495,7 @@ export const tasksLogic = kea<tasksLogicType>([if (payload) {taskHistoryLogic.findMounted()?.actions.taskArchived(payload.taskId)}+ actions.taskDeleted()},renameTaskFailure: ({ error, errorObject }) => {lemonToast.error(`Couldn't rename the task: ${loadErrorMessage(error, errorObject)}`)