: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(today): keep the rail's recent list in step with new sessions (#111743)
Vojta Bartošb61412aa9869
diff --git a/frontend/src/layout/today/todaySessionMenuLogic.ts b/frontend/src/layout/today/todaySessionMenuLogic.tsindex b941f7e6d753..8b537b7b0185 100644--- a/frontend/src/layout/today/todaySessionMenuLogic.ts+++ b/frontend/src/layout/today/todaySessionMenuLogic.ts@@ -49,7 +49,7 @@ export interface todaySessionMenuLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface todaySessionMenuLogicActions {loadPinnedTasks: () => any // todaySpacesLogic- loadRecentTasks: () => any // todaySpacesLogic+ loadRecentTasks: (_?: void | undefined) => void // todaySpacesLogicanalyzeSession: (sessionId: string,runId: stringdiff --git a/frontend/src/layout/today/todaySessionSelectionLogic.ts b/frontend/src/layout/today/todaySessionSelectionLogic.tsindex d8950374a990..3547c9e5a08e 100644--- a/frontend/src/layout/today/todaySessionSelectionLogic.ts+++ b/frontend/src/layout/today/todaySessionSelectionLogic.ts@@ -79,7 +79,7 @@ export interface todaySessionSelectionLogicActions {url: string} // routerloadPinnedTasks: () => any // todaySpacesLogic- loadRecentTasks: () => any // todaySpacesLogic+ loadRecentTasks: (_?: void | undefined) => void // todaySpacesLogicarchiveSelected: () => {value: true}diff --git a/frontend/src/layout/today/todaySpacesLogic.test.ts b/frontend/src/layout/today/todaySpacesLogic.test.tsindex 5b39919b676d..fff778d0a97a 100644--- a/frontend/src/layout/today/todaySpacesLogic.test.ts+++ b/frontend/src/layout/today/todaySpacesLogic.test.ts@@ -1,8 +1,10 @@+import { expectLogic } from 'kea-test-utils'+import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { DEFAULT_RECENT_FILTERS, TodayRecentFilters } from './todayRecentFilters'-import { todaySpacesLogic } from './todaySpacesLogic'+import { recentRefreshIsDue, todaySpacesLogic } from './todaySpacesLogic'const SAVED_FILTERS_KEY = 'layout.today.todaySpacesLogic.recentFilters'@@ -18,6 +20,16 @@ describe('todaySpacesLogic', () => {})})+ // The plugin that owns the reload reads `document.hidden`, so a test drives that rather than a clock.+ const setPageHidden = (hidden: boolean): void => {+ Object.defineProperty(document, 'hidden', { value: hidden, configurable: true })+ document.dispatchEvent(new Event('visibilitychange'))+ }++ afterEach(() => {+ Object.defineProperty(document, 'hidden', { value: false, configurable: true })+ })+it.each<[string, object, Partial<TodayRecentFilters>, boolean]>([['an untouched menu stays clear', { createdBy: 'anyone', sources: [] }, {}, false],[@@ -35,4 +47,38 @@ describe('todaySpacesLogic', () => {expect(logic.values.recentFilters).toEqual({ ...DEFAULT_RECENT_FILTERS, ...expected })expect(logic.values.recentFiltersActive).toBe(active)})++ // A session another client started reaches the rail only on a return to the tab, so the reload has to be+ // registered as a disposable. A plain afterMount load passes every other test in this file.+ it.each<[string, number, boolean]>([+ ['reloads Recent once the cooldown has passed', 20_000, true],+ ['keeps the list it has inside the cooldown', 5_000, false],+ ])('a return to the tab %s', async (_, sinceLastLoad, reloads) => {+ initKeaTests()+ const logic = todaySpacesLogic()+ logic.mount()+ await expectLogic(logic).toDispatchActions(['loadRecentTasksSuccess']).toFinishAllListeners()+ // Age the last load instead of running a clock, so the cooldown is the only variable.+ logic.cache.recentTasksLoadedAt = Date.now() - sinceLastLoad++ const expectation = expectLogic(logic, () => {+ setPageHidden(true)+ setPageHidden(false)+ }).toFinishAllListeners()++ await (reloads+ ? expectation.toDispatchActions(['loadRecentTasks'])+ : expectation.toNotHaveDispatchedActions(['loadRecentTasks']))+ })++ it.each<[string, number | undefined, boolean]>([+ ['a rail that has never loaded refreshes', undefined, true],+ ['a return moments later keeps what it has', 14_000, false],+ ['a return once the cooldown passes refreshes', 15_000, true],+ ])('holds a flick between tabs to one Recent request: %s', (_, sinceLastLoad, due) => {+ const now = 1_000_000+ const loadedAt = sinceLastLoad === undefined ? undefined : now - sinceLastLoad++ expect(recentRefreshIsDue(loadedAt, now)).toBe(due)+ })})diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.tsindex f2d2156237b5..4732f1a683a3 100644--- a/frontend/src/layout/today/todaySpacesLogic.ts+++ b/frontend/src/layout/today/todaySpacesLogic.ts@@ -79,6 +79,10 @@ const UNREAD_ACTIVITY_DEBOUNCE_MS = 100// A space whose latest activity sits below this page shows no faces.const SPACE_PRESENCE_FETCH_LIMIT = 100const SPACE_PRESENCE_POLL_INTERVAL_MS = 90_000+// Other clients start sessions this tab never hears about, so Recent reloads on a timer and on each return to+// the tab, and the cooldown holds a flick between tabs to one request.+const RECENT_REFRESH_INTERVAL_MS = 60_000+const RECENT_REFRESH_COOLDOWN_MS = 15_000export type TodayWorkSectionId = 'pinned' | 'recent' | 'spaces'@@ -90,6 +94,10 @@ export function spaceIdForPath(pathname: string): string | null {return match && match[1] !== 'new' ? match[1] : null}+export function recentRefreshIsDue(loadedAt: number | undefined, now: number = Date.now()): boolean {+ return loadedAt === undefined || now - loadedAt >= RECENT_REFRESH_COOLDOWN_MS+}+/** The personal space first, then the team's general space, then starred spaces, then the rest by name. */export function sortSpaces(spaces: ChannelDTOApi[]): ChannelDTOApi[] {const rank = (space: ChannelDTOApi): number =>@@ -227,7 +235,7 @@ export interface todaySpacesLogicActions {loadPullRequestStates: (sessionIds: string[]) => {sessionIds: string[]}- loadRecentTasks: () => any+ loadRecentTasks: (_: void) => voidloadRecentTasksFailure: (error: string,errorObject?: any@@ -237,10 +245,10 @@ export interface todaySpacesLogicActions {}loadRecentTasksSuccess: (recentTasks: TaskListItemApi[],- payload?: any+ payload?: void) => {recentTasks: TaskListItemApi[]- payload?: any+ payload?: void}loadSpaceActivity: () => anyloadSpaceActivityFailure: (@@ -471,7 +479,7 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([recentTasks: [[] as TaskListItemApi[],{- loadRecentTasks: async () => {+ loadRecentTasks: async (_: void, breakpoint) => {if (!values.currentTeamId || !values.user) {return []}@@ -481,6 +489,8 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([basic: true,limit: RECENT_SESSION_LIMIT,})+ // A slower earlier reply must not overwrite what a newer refresh already returned.+ breakpoint()return response.results},},@@ -723,7 +733,7 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([),],}),- listeners(({ actions, values }) => {+ listeners(({ actions, values, cache }) => {// Reading a session anywhere in the app clears it, so the rail follows the open session rather than clicks.const markOpenSessionRead = (): void => {const { location, searchParams } = router.values@@ -742,7 +752,10 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([markOpenSessionRead()},loadTaskActivitySuccess: markOpenSessionRead,- loadRecentTasks: () => actions.loadTaskActivity(),+ loadRecentTasks: () => {+ cache.recentTasksLoadedAt = Date.now()+ actions.loadTaskActivity()+ },markSessionRead: async ({ marker, activityIds }) => {try {await taskActivityMarkReadCreate(String(values.currentTeamId), { activities: [marker] })@@ -801,12 +814,19 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([}actions.loadSpaces()actions.loadPinnedTasks()- actions.loadRecentTasks()// Setup runs now and again whenever the tab comes back, so the faces refresh on return.cache.disposables.add(() => {actions.loadSpaceActivity()const pollTimer = window.setInterval(() => actions.loadSpaceActivity(), SPACE_PRESENCE_POLL_INTERVAL_MS)return () => clearInterval(pollTimer)}, 'spacePresencePoll')+ // A disposable rather than a plain afterMount load, so setup runs again on each return to the tab.+ cache.disposables.add(() => {+ if (recentRefreshIsDue(cache.recentTasksLoadedAt)) {+ actions.loadRecentTasks()+ }+ const pollTimer = window.setInterval(() => actions.loadRecentTasks(), RECENT_REFRESH_INTERVAL_MS)+ return () => clearInterval(pollTimer)+ }, 'recentTasksPoll')}),])diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.tsindex 692f6436e720..464a231fdb51 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts@@ -9,6 +9,7 @@ import { phaiAiComposerSeedLogic } from 'scenes/max/phaiAiComposerSeedLogic'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { urls } from 'scenes/urls'+import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'@@ -853,6 +854,31 @@ describe('taskTrackerSceneLogic', () => {expect(logic.values.persistedRepositoryConfig).toEqual({ integrationId: 7, repository: 'acme/remembered' })})+ it('refreshes the rail’s Recent list when a composer creates a session', async () => {+ useMocks({+ get: {+ '/api/projects/:team/task_channels/': [],+ '/api/projects/:team/task_activity/': { results: [] },+ },+ })+ const rail = todaySpacesLogic()+ rail.mount()+ // Step past the load the rail does on mount, so the assertion below can only match a later one.+ await expectLogic(rail).toDispatchActions(['loadRecentTasksSuccess']).toFinishAllListeners()++ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ logic.actions.setNewTaskData({ description: 'ship it' })++ await expectLogic(rail, () => {+ logic.actions.submitNewTask()+ })+ .toFinishAllListeners()+ .toDispatchActions(['loadRecentTasks'])++ rail.unmount()+ })+// The side panel shares this logic, so a hidden picker can still hold a remembered repo. It must not reach the requests.it.each(['global', 'runner'])('keeps a repository hidden by a %s override out of requests', async (scope) => {useMocks({diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.tsindex b4d649d141e9..cb33ef45f77b 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.ts@@ -14,6 +14,8 @@ import { projectLogic } from 'scenes/projectLogic'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { urls } from 'scenes/urls'+import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'+import { codeInvitesCheckAccessRetrieve, tasksCreate, tasksRunCreate } from 'products/tasks/frontend/generated/api'import {type ClaudeTaskRunCreateSchemaApi,@@ -1056,6 +1058,8 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([actions.submitNewTaskSuccess()actions.loadTasks(values.taskListParams)actions.loadRepositories()+ // Every composer submits through here, so this is the one place that reaches all of them.+ todaySpacesLogic.findMounted()?.actions.loadRecentTasks()props.onTaskCreated?.(newTask.id)} catch (error) {if (disposables.isDisposed) {diff --git a/products/tasks/frontend/spaces/newSessionSceneLogic.ts b/products/tasks/frontend/spaces/newSessionSceneLogic.tsindex 528404c41c7a..1f1d4d5f8ea9 100644--- a/products/tasks/frontend/spaces/newSessionSceneLogic.ts+++ b/products/tasks/frontend/spaces/newSessionSceneLogic.ts@@ -67,7 +67,6 @@ export interface newSessionSceneLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface newSessionSceneLogicActions {- loadRecentTasks: () => any // todaySpacesLogicloadSpaces: () => any // todaySpacesLogicpickSpace: (spaceId: string) => {spaceId: string@@ -105,7 +104,7 @@ export const newSessionSceneLogic = kea<newSessionSceneLogicType>([path(['products', 'tasks', 'spaces', 'newSessionSceneLogic']),connect(() => ({values: [todaySpacesLogic, ['sortedSpaces', 'spacesLoading', 'spacesUnavailable', 'lastSpaceId']],- actions: [todaySpacesLogic, ['loadSpaces', 'loadRecentTasks']],+ actions: [todaySpacesLogic, ['loadSpaces']],})),actions({pickSpace: (spaceId: string) => ({ spaceId }),@@ -144,7 +143,7 @@ export const newSessionSceneLogic = kea<newSessionSceneLogicType>([],],}),- listeners(({ actions, values }) => ({+ listeners(({ values }) => ({// Like PostHog Desktop, a pick moves to that space's own New session, so it becomes the last space too.pickSpace: ({ spaceId }) => {router.actions.push(urls.taskSpaceNewSession(spaceId))@@ -155,7 +154,6 @@ export const newSessionSceneLogic = kea<newSessionSceneLogicType>([space_role: values.space?.system_role ?? null,space_source: values.spaceChoice.source,})- actions.loadRecentTasks()router.actions.push(urls.aiTask(sessionId))},})),diff --git a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.tsindex a9665303ba61..ac2c7c1d42c5 100644--- a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts+++ b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts@@ -103,7 +103,7 @@ export interface spaceFeedSelectionLogicActions {} // spaceFeedViewLogicloadSessions: () => any // spaceSceneLogicloadPinnedTasks: () => any // todaySpacesLogic- loadRecentTasks: () => any // todaySpacesLogic+ loadRecentTasks: (_?: void | undefined) => void // todaySpacesLogicarchiveSelected: () => {value: true}