: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
feat(aio): remember tab timeframe (#82411)
willwearingbed36de72ce4
diff --git a/frontend/src/lib/logic/persistence.test.ts b/frontend/src/lib/logic/persistence.test.tsnew file mode 100644index 000000000000..5595b1ca5353--- /dev/null+++ b/frontend/src/lib/logic/persistence.test.ts@@ -0,0 +1,24 @@+import { getCurrentTeamId } from 'lib/utils/getAppContext'++import { buildTeamScopedPersistenceConfig, buildTeamScopedStorageConfig } from './persistence'++jest.mock('lib/utils/getAppContext')++const mockGetCurrentTeamId = getCurrentTeamId as jest.MockedFunction<typeof getCurrentTeamId>++describe('team-scoped persistence', () => {+ beforeEach(() => {+ mockGetCurrentTeamId.mockReset()+ })++ it.each([+ ['prefix config', () => buildTeamScopedPersistenceConfig('filters__')],+ ['storage config', () => buildTeamScopedStorageConfig('filters')],+ ])('fails closed without a project ID for %s', (_, buildConfig) => {+ mockGetCurrentTeamId.mockImplementation(() => {+ throw new Error('Project ID is not known.')+ })++ expect(buildConfig).toThrow('Project ID is not known.')+ })+})diff --git a/frontend/src/lib/logic/persistence.ts b/frontend/src/lib/logic/persistence.tsnew file mode 100644index 000000000000..bbbe964f4372--- /dev/null+++ b/frontend/src/lib/logic/persistence.ts@@ -0,0 +1,25 @@+import { getCurrentTeamId } from 'lib/utils/getAppContext'++interface TeamScopedPersistenceConfig {+ persist: true+ prefix: string+}++interface TeamScopedStorageConfig {+ persist: true+ storageKey: string+}++const getTeamStoragePrefix = (): string => {+ return `${getCurrentTeamId()}__`+}++export const buildTeamScopedPersistenceConfig = (prefix: string = ''): TeamScopedPersistenceConfig => ({+ persist: true,+ prefix: `${getTeamStoragePrefix()}${prefix}`,+})++export const buildTeamScopedStorageConfig = (storageKey: string): TeamScopedStorageConfig => ({+ persist: true,+ storageKey: `${getTeamStoragePrefix()}${storageKey}`,+})diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeLLMTrace.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeLLMTrace.tsxindex bb0514cfda38..ae87388f698c 100644--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeLLMTrace.tsx+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeLLMTrace.tsx@@ -45,12 +45,12 @@ const Component = (props: NotebookNodeProps<NotebookNodeLLMTraceAttributes>): JSconst ContextualTraceList = ({ attributes }: NotebookNodeProps<NotebookNodeLLMTraceAttributes>): JSX.Element | null => {const { expanded, notebookLogic } = useValues(notebookNodeLogic)const { setMenuItems } = useActions(notebookNodeLogic)- const { groupKey, groupTypeIndex, personId, tabId } = attributes+ const { groupKey, groupTypeIndex, nodeId, personId, tabId } = attributesconst group = groupKey && groupTypeIndex !== undefined ? { groupKey, groupTypeIndex } : undefinedconst logicKey = getLogicKey({ groupKey, personId, tabId })- const sharedLogic = aiObservabilitySharedLogic({ logicKey, personId, group })- const tracesLogic = aiObservabilityTracesTabLogic({ personId, group })+ const sharedLogic = aiObservabilitySharedLogic({ logicKey: nodeId, personId, group })+ const tracesLogic = aiObservabilityTracesTabLogic({ logicKey: nodeId, personId, group })const { setDates, setShouldFilterTestAccounts, setPropertyFilters } = useActions(sharedLogic)const { setTracesQuery } = useActions(tracesLogic)const { tracesQuery } = useValues(tracesLogic)@@ -109,7 +109,7 @@ const ContextualSettings = ({const { personId, groupKey, groupTypeIndex, nodeId } = attributesconst group = groupKey && groupTypeIndex !== undefined ? { groupKey, groupTypeIndex } : undefinedconst sharedLogic = aiObservabilitySharedLogic({ logicKey: nodeId, personId, group })- const tracesLogic = aiObservabilityTracesTabLogic({ personId, group })+ const tracesLogic = aiObservabilityTracesTabLogic({ logicKey: nodeId, personId, group })const { setDates, setPropertyFilters } = useActions(sharedLogic)const { setTracesQuery } = useActions(tracesLogic)const { tracesQuery } = useValues(tracesLogic)diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.tsindex 1d54014ab0ac..0c2e3844226d 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts@@ -3,6 +3,7 @@ import { actionToUrl } from 'kea-router'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { buildTeamScopedPersistenceConfig } from 'lib/logic/persistence'import { getDefaultInterval, isValidRelativeOrAbsoluteDate, updateDatesWithInterval } from 'lib/utils/dateFilters'import { uuid } from 'lib/utils/dom'import { teamLogic } from 'scenes/teamLogic'@@ -205,9 +206,6 @@ export interface DateFilterState extends DateRange {interval: IntervalType}-const teamId = window.POSTHOG_APP_CONTEXT?.current_team?.id-const persistConfig = { persist: true, prefix: `${teamId}__` }-const INITIAL_DATE_FROM = '-7d' as string | nullconst INITIAL_DATE_TO = null as string | nullconst INITIAL_INTERVAL = getDefaultInterval(INITIAL_DATE_FROM, INITIAL_DATE_TO)@@ -623,161 +621,169 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([setDrillDownLevel: (level: MarketingAnalyticsDrillDownLevel) => ({ level }),setInitialized: true,}),- reducers({- activeTab: [- MarketingAnalyticsTab.DASHBOARD as MarketingAnalyticsTab,- {- setActiveTab: (_, { tab }) => tab,- },- ],- initialized: [- false,- {- setInitialized: () => true,- },- ],- draftConversionGoal: [- null as ConversionGoalFilter | null,- {- setDraftConversionGoal: (_, { goal }) => goal,- },- ],- conversionGoalInput: [- {- ...defaultConversionGoalFilter,- conversion_goal_id: uuid(),- conversion_goal_name: '',- } as ConversionGoalFilter,- {- setConversionGoalInput: (_, { goal }) => goal,- },- ],- compareFilter: [- { compare: true } as CompareFilter,- persistConfig,- {- setCompareFilter: (_, { compareFilter }) => compareFilter,- syncFromUrl: (state, { params }) => {- if (params.compare === undefined && params.compare_to === undefined) {- return state- }- return {- ...state,- ...(params.compare !== undefined ? { compare: params.compare } : {}),- ...(params.compare_to !== undefined ? { compare_to: params.compare_to } : {}),- }+ reducers(() => {+ const persistConfig = buildTeamScopedPersistenceConfig()++ return {+ activeTab: [+ MarketingAnalyticsTab.DASHBOARD as MarketingAnalyticsTab,+ {+ setActiveTab: (_, { tab }) => tab,},- },- ],- integrationFilter: [- { integrationSourceIds: [] } as IntegrationFilter,- persistConfig,- {- setIntegrationFilter: (_, { integrationFilter }) => integrationFilter,- syncFromUrl: (state, { params }) =>- params.integrationSourceIds ? { integrationSourceIds: params.integrationSourceIds } : state,- },- ],- dateFilter: [- {- dateFrom: INITIAL_DATE_FROM,- dateTo: INITIAL_DATE_TO,- interval: INITIAL_INTERVAL,- },- persistConfig,- {- setDates: (_, { dateFrom, dateTo }) => {- if (dateTo && !isValidRelativeOrAbsoluteDate(dateTo)) {- dateTo = INITIAL_DATE_TO- }- if (dateFrom && !isValidRelativeOrAbsoluteDate(dateFrom)) {- dateFrom = INITIAL_DATE_FROM- }- return {- dateFrom,- dateTo,- interval: getDefaultInterval(dateFrom, dateTo),- }+ ],+ initialized: [+ false,+ {+ setInitialized: () => true,},- setDateInterval: (state, { interval }) => {- const { dateFrom, dateTo } = updateDatesWithInterval(interval, state.dateFrom, state.dateTo)- return {- dateFrom,- dateTo,- interval,- }+ ],+ draftConversionGoal: [+ null as ConversionGoalFilter | null,+ {+ setDraftConversionGoal: (_, { goal }) => goal,},- setDatesAndInterval: (_, { dateFrom, dateTo, interval }) => {- if (!dateFrom && !dateTo) {- dateFrom = INITIAL_DATE_FROM- dateTo = INITIAL_DATE_TO- }- if (dateTo && !isValidRelativeOrAbsoluteDate(dateTo)) {- dateTo = INITIAL_DATE_TO- }- if (dateFrom && !isValidRelativeOrAbsoluteDate(dateFrom)) {- dateFrom = INITIAL_DATE_FROM- }- return {- dateFrom,- dateTo,- interval: interval || getDefaultInterval(dateFrom, dateTo),- }+ ],+ conversionGoalInput: [+ {+ ...defaultConversionGoalFilter,+ conversion_goal_id: uuid(),+ conversion_goal_name: '',+ } as ConversionGoalFilter,+ {+ setConversionGoalInput: (_, { goal }) => goal,},- syncFromUrl: (state, { params }) => {- if (params.dateFrom === undefined && params.dateTo === undefined && params.interval === undefined) {- return state- }- const dateFrom = params.dateFrom ?? state.dateFrom- const dateTo = params.dateTo ?? state.dateTo- const interval = params.interval ?? state.interval- return { dateFrom, dateTo, interval }+ ],+ compareFilter: [+ { compare: true } as CompareFilter,+ persistConfig,+ {+ setCompareFilter: (_, { compareFilter }) => compareFilter,+ syncFromUrl: (state, { params }) => {+ if (params.compare === undefined && params.compare_to === undefined) {+ return state+ }+ return {+ ...state,+ ...(params.compare !== undefined ? { compare: params.compare } : {}),+ ...(params.compare_to !== undefined ? { compare_to: params.compare_to } : {}),+ }+ },},- },- ],- columnConfigModalVisible: [- false,- {- showColumnConfigModal: () => true,- hideColumnConfigModal: () => false,- },- ],- conversionGoalModalVisible: [- false,- {- showConversionGoalModal: () => true,- hideConversionGoalModal: () => false,- },- ],- chartDisplayType: [- ChartDisplayType.ActionsAreaGraph as ChartDisplayType,- persistConfig,- {- setChartDisplayType: (_, { chartDisplayType }) => chartDisplayType,- syncFromUrl: (state, { params }) =>- params.chartDisplayType !== undefined ? params.chartDisplayType : state,- },- ],- tileColumnSelection: [- MarketingAnalyticsColumnsSchemaNames.Cost as validColumnsForTiles,- persistConfig,- {- setTileColumnSelection: (_, { column }) => column,- syncFromUrl: (state, { params }) =>- params.tileColumnSelection !== undefined- ? (params.tileColumnSelection as validColumnsForTiles)- : state,- },- ],- _drillDownLevel: [- MarketingAnalyticsDrillDownLevel.Campaign as MarketingAnalyticsDrillDownLevel,- persistConfig,- {- setDrillDownLevel: (_, { level }) => level,- syncFromUrl: (state, { params }) =>- params.drillDownLevel !== undefined ? params.drillDownLevel : state,- },- ],+ ],+ integrationFilter: [+ { integrationSourceIds: [] } as IntegrationFilter,+ persistConfig,+ {+ setIntegrationFilter: (_, { integrationFilter }) => integrationFilter,+ syncFromUrl: (state, { params }) =>+ params.integrationSourceIds ? { integrationSourceIds: params.integrationSourceIds } : state,+ },+ ],+ dateFilter: [+ {+ dateFrom: INITIAL_DATE_FROM,+ dateTo: INITIAL_DATE_TO,+ interval: INITIAL_INTERVAL,+ },+ persistConfig,+ {+ setDates: (_, { dateFrom, dateTo }) => {+ if (dateTo && !isValidRelativeOrAbsoluteDate(dateTo)) {+ dateTo = INITIAL_DATE_TO+ }+ if (dateFrom && !isValidRelativeOrAbsoluteDate(dateFrom)) {+ dateFrom = INITIAL_DATE_FROM+ }+ return {+ dateFrom,+ dateTo,+ interval: getDefaultInterval(dateFrom, dateTo),+ }+ },+ setDateInterval: (state, { interval }) => {+ const { dateFrom, dateTo } = updateDatesWithInterval(interval, state.dateFrom, state.dateTo)+ return {+ dateFrom,+ dateTo,+ interval,+ }+ },+ setDatesAndInterval: (_, { dateFrom, dateTo, interval }) => {+ if (!dateFrom && !dateTo) {+ dateFrom = INITIAL_DATE_FROM+ dateTo = INITIAL_DATE_TO+ }+ if (dateTo && !isValidRelativeOrAbsoluteDate(dateTo)) {+ dateTo = INITIAL_DATE_TO+ }+ if (dateFrom && !isValidRelativeOrAbsoluteDate(dateFrom)) {+ dateFrom = INITIAL_DATE_FROM+ }+ return {+ dateFrom,+ dateTo,+ interval: interval || getDefaultInterval(dateFrom, dateTo),+ }+ },+ syncFromUrl: (state, { params }) => {+ if (+ params.dateFrom === undefined &&+ params.dateTo === undefined &&+ params.interval === undefined+ ) {+ return state+ }+ const dateFrom = params.dateFrom ?? state.dateFrom+ const dateTo = params.dateTo ?? state.dateTo+ const interval = params.interval ?? state.interval+ return { dateFrom, dateTo, interval }+ },+ },+ ],+ columnConfigModalVisible: [+ false,+ {+ showColumnConfigModal: () => true,+ hideColumnConfigModal: () => false,+ },+ ],+ conversionGoalModalVisible: [+ false,+ {+ showConversionGoalModal: () => true,+ hideConversionGoalModal: () => false,+ },+ ],+ chartDisplayType: [+ ChartDisplayType.ActionsAreaGraph as ChartDisplayType,+ persistConfig,+ {+ setChartDisplayType: (_, { chartDisplayType }) => chartDisplayType,+ syncFromUrl: (state, { params }) =>+ params.chartDisplayType !== undefined ? params.chartDisplayType : state,+ },+ ],+ tileColumnSelection: [+ MarketingAnalyticsColumnsSchemaNames.Cost as validColumnsForTiles,+ persistConfig,+ {+ setTileColumnSelection: (_, { column }) => column,+ syncFromUrl: (state, { params }) =>+ params.tileColumnSelection !== undefined+ ? (params.tileColumnSelection as validColumnsForTiles)+ : state,+ },+ ],+ _drillDownLevel: [+ MarketingAnalyticsDrillDownLevel.Campaign as MarketingAnalyticsDrillDownLevel,+ persistConfig,+ {+ setDrillDownLevel: (_, { level }) => level,+ syncFromUrl: (state, { params }) =>+ params.drillDownLevel !== undefined ? params.drillDownLevel : state,+ },+ ],+ }}),selectors({drillDownLevel: [diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsxindex b3d0e63b386e..517e0f01da19 100644--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx@@ -28,11 +28,11 @@ import { IconOpenInNew } from 'lib/lemon-ui/icons'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { Link } from 'lib/lemon-ui/Link/Link'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { buildTeamScopedPersistenceConfig } from 'lib/logic/persistence'import { trackedActionToUrl } from 'lib/logic/scenes/trackedActionToUrl'import { getDefaultInterval, isValidRelativeOrAbsoluteDate } from 'lib/utils/dateFilters'import { isDefinitionStale } from 'lib/utils/definitions'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'-import { getCurrentTeamId } from 'lib/utils/getAppContext'import { UnexpectedNeverError, isNotNil } from 'lib/utils/guards'import { objectsEqual } from 'lib/utils/objects'import { addProductIntentForCrossSell } from 'lib/utils/product-intents'@@ -851,12 +851,12 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([},})),reducers(() => {- const persistConfig = { persist: true, prefix: `${getCurrentTeamId()}__` }+ const persistConfig = buildTeamScopedPersistenceConfig()// The precompute toggle changed from opt-in (default `false`) to a tri-state where// `null` means "use the team default". Legacy users persisted the old `false`, which// would now read as an explicit opt-out. A versioned prefix orphans that stale value so// they rehydrate `null` and the backend's per-team default applies.- const precomputePersistConfig = { persist: true, prefix: `${getCurrentTeamId()}__precompute_optout_v2__` }+ const precomputePersistConfig = buildTeamScopedPersistenceConfig('precompute_optout_v2__')return {surveyModalPath: [null as string | null,diff --git a/products/ai_observability/frontend/aiObservabilityLogic.test.ts b/products/ai_observability/frontend/aiObservabilityLogic.test.tsindex f798c256ab4f..cfd4c568a643 100644--- a/products/ai_observability/frontend/aiObservabilityLogic.test.ts+++ b/products/ai_observability/frontend/aiObservabilityLogic.test.ts@@ -84,6 +84,7 @@ describe('aiObservabilitySharedLogic', () => {let logic: ReturnType<typeof aiObservabilitySharedLogic.build>beforeEach(() => {+ window.localStorage.clear()initKeaTests()sceneLogic.mount()router.actions.push(urls.aiObservabilityTraces())@@ -158,8 +159,7 @@ describe('aiObservabilitySharedLogic', () => {expect(router.values.searchParams).toEqual({ review_search: 'abc' })})- it('should reset filters when switching tabs without params', () => {- // Set some filters first+ it('should reset non-date filters when switching tabs without params', () => {logic.actions.setPropertyFilters([{type: PropertyFilterType.Event,@@ -172,15 +172,13 @@ describe('aiObservabilitySharedLogic', () => {logic.actions.setShouldFilterTestAccounts(true)logic.actions.setSearchQuery('walrus')- // Navigate to another tab without paramsrouter.actions.push(urls.aiObservabilityGenerations())- // Should reset to defaultsexpectLogic(logic).toMatchValues({propertyFilters: [],dateFilter: {- dateFrom: '-1h',- dateTo: null,+ dateFrom: '-30d',+ dateTo: '-1d',},shouldFilterTestAccounts: false,searchQuery: '',@@ -225,6 +223,33 @@ describe('aiObservabilitySharedLogic', () => {})})+ it('keeps dashboard dates while restoring shared filters from the URL', () => {+ router.actions.push(urls.aiObservabilityDashboard(), {+ date_from: '-30d',+ filters: [+ {+ type: PropertyFilterType.Event,+ key: '$ai_model',+ value: 'example-model',+ operator: PropertyOperator.Exact,+ },+ ],+ })++ expect(router.values.searchParams.date_from).toBe('-30d')+ expectLogic(logic).toMatchValues({+ dashboardDateFilter: { dateFrom: '-30d', dateTo: null },+ propertyFilters: [+ {+ type: PropertyFilterType.Event,+ key: '$ai_model',+ value: 'example-model',+ operator: PropertyOperator.Exact,+ },+ ],+ })+ })+it('syncs the trace content search between the URL, state, and traces query', () => {featureFlagLogic.mount()featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.LLM_OBSERVABILITY_TRACE_SEARCH], {@@ -574,6 +599,57 @@ describe('AI observability persisted preferences', () => {secondLogic.unmount()})+ it('restores persisted event dates on clean tabs and lets URL dates override them', () => {+ router.actions.push(urls.aiObservabilityTraces())+ const firstLogic = aiObservabilitySharedLogic()+ firstLogic.mount()+ firstLogic.actions.setDates('-30d', '-1d')+ firstLogic.unmount()++ router.actions.push(urls.aiObservabilityGenerations())+ const secondLogic = aiObservabilitySharedLogic()+ secondLogic.mount()++ expect(secondLogic.values.dateFilter).toEqual({ dateFrom: '-30d', dateTo: '-1d' })++ router.actions.push(urls.aiObservabilityTraces(), { date_from: '-7d' })++ expect(secondLogic.values.dateFilter).toEqual({ dateFrom: '-7d', dateTo: null })++ secondLogic.unmount()+ })++ it('keeps notebook date filters separate from the saved scene timeframe', () => {+ const savedSceneLogic = aiObservabilitySharedLogic()+ savedSceneLogic.mount()+ savedSceneLogic.actions.setDates('-30d', null)+ savedSceneLogic.unmount()++ const notebookLogic = aiObservabilitySharedLogic({ logicKey: 'notebook-node' })+ notebookLogic.mount()+ expect(notebookLogic.values.dateFilter).toEqual({ dateFrom: '-1h', dateTo: null })+ notebookLogic.actions.setDates('-7d', null)+ notebookLogic.unmount()++ const remountedSceneLogic = aiObservabilitySharedLogic()+ remountedSceneLogic.mount()+ expect(remountedSceneLogic.values.dateFilter).toEqual({ dateFrom: '-30d', dateTo: null })+ remountedSceneLogic.unmount()+ })++ it('drops invalid URL dates without replacing the saved scene timeframe', () => {+ router.actions.push(urls.aiObservabilityTraces())+ const logic = aiObservabilitySharedLogic()+ logic.mount()+ logic.actions.setDates('-30d', null)++ router.actions.push(urls.aiObservabilityTraces(), { date_from: 'not-a-date' })++ expect(logic.values.dateFilter).toEqual({ dateFrom: '-30d', dateTo: null })+ expect(router.values.searchParams.date_from).toBe('-30d')+ logic.unmount()+ })+it('persists selected dashboard across remount', () => {const firstLogic = aiObservabilityDashboardLogic()firstLogic.mount()diff --git a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts b/products/ai_observability/frontend/aiObservabilitySharedLogic.tsindex 1a02829170f0..f39615f17000 100644--- a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts+++ b/products/ai_observability/frontend/aiObservabilitySharedLogic.ts@@ -20,6 +20,7 @@ import type { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { trackedActionToUrl } from 'lib/logic/scenes/trackedActionToUrl'+import { isValidRelativeOrAbsoluteDate } from 'lib/utils/dateFilters'import { objectsEqual } from 'lib/utils/objects'import { projectLogic } from 'scenes/projectLogic'import { sceneLogic } from 'scenes/sceneLogic'@@ -36,6 +37,7 @@ import type { FeatureFlagsSet } from '../../../frontend/src/lib/logic/featureFlaimport type { ProductIntentProperties } from '../../../frontend/src/lib/utils/product-intents'import type { UserType } from '../../../frontend/src/types'import { AI_OBSERVABILITY_CLUSTER_URL_PATTERN } from './clusters/constants'+import { buildAiObservabilityStorageConfig } from './preferenceStorage'import { parserRecipesLogic } from './settings/parserRecipesLogic'import { hasRecentAIEvents } from './utils/aiEvents'@@ -273,7 +275,7 @@ export type aiObservabilitySharedLogicType = MakeLogicType<export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([path(['products', 'ai_observability', 'frontend', 'aiObservabilitySharedLogic']),props({} as AIObservabilitySharedLogicProps),- key((props: AIObservabilitySharedLogicProps) => `${props?.personId || 'aiObservabilityScene'}`),+ key((props: AIObservabilitySharedLogicProps) => props.logicKey || props.personId || 'aiObservabilityScene'),connect(() => ({// Mount the parser-recipe logic so a team's custom recipes reach the trace-rendering// normalizer on any AI observability page, not just the settings scene.@@ -318,12 +320,16 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([applyUrlState: (state: ApplyUrlStatePayload) => state,}),- reducers({+ reducers(({ props }) => ({dateFilter: [{dateFrom: INITIAL_EVENTS_DATE_FROM,dateTo: INITIAL_DATE_TO,},+ {+ ...buildAiObservabilityStorageConfig('events.dateFilter'),+ persist: !props.logicKey,+ },{setDates: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),applyUrlState: (_, { dateFrom, dateTo }) => ({ dateFrom, dateTo }),@@ -392,7 +398,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([applyUrlState: (state, { searchQuery }) => searchQuery ?? state,},],- }),+ })),loaders(() => ({hasSentAiEvent: {@@ -500,12 +506,35 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([}),urlToAction(({ actions, values, cache }) => {- function applySearchParams(searchParams: Record<string, unknown>): void {+ function applySearchParams(searchParams: Record<string, unknown>, applyEventDateParams: boolean = true): void {const { filters, date_from, date_to, filter_test_accounts, trace_search } = searchParamsconst parsedFilters = isAnyPropertyFilters(filters) ? filters : []- const newDateFrom = (date_from as string | null) || INITIAL_EVENTS_DATE_FROM- const newDateTo = (date_to as string | null) || INITIAL_DATE_TO+ const hasDateFromParam = applyEventDateParams && typeof date_from === 'string' && date_from.length > 0+ const hasDateToParam = applyEventDateParams && typeof date_to === 'string' && date_to.length > 0+ const hasDateFromOverride =+ applyEventDateParams &&+ typeof date_from === 'string' &&+ date_from.length > 0 &&+ isValidRelativeOrAbsoluteDate(date_from)+ const hasDateToOverride =+ applyEventDateParams &&+ typeof date_to === 'string' &&+ date_to.length > 0 &&+ isValidRelativeOrAbsoluteDate(date_to)+ const hasInvalidDateParam =+ (hasDateFromParam && !hasDateFromOverride) || (hasDateToParam && !hasDateToOverride)+ const hasDateOverride = hasDateFromOverride || hasDateToOverride+ const newDateFrom = hasDateOverride+ ? hasDateFromOverride+ ? date_from+ : INITIAL_EVENTS_DATE_FROM+ : values.dateFilter.dateFrom+ const newDateTo = hasDateOverride+ ? hasDateToOverride+ ? date_to+ : INITIAL_DATE_TO+ : values.dateFilter.dateToconst filterTestAccountsValue = [true, 'true', 1, '1'].includes(filter_test_accounts as string | number | boolean)@@ -516,7 +545,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([const testAccountsChanged = filterTestAccountsValue !== values.shouldFilterTestAccountsconst searchQueryChanged = newSearchQuery !== values.searchQuery- if (filtersChanged || datesChanged || testAccountsChanged || searchQueryChanged) {+ if (filtersChanged || datesChanged || testAccountsChanged || searchQueryChanged || hasInvalidDateParam) {// Dispatch a single batched action so actionToUrl produces one URL// change instead of up to 3 separate ones. The actionToUrl handler// for applyUrlState rewrites the shared params and drops stale@@ -566,7 +595,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([}function applyDashboard(searchParams: Record<string, unknown>): void {- applySearchParams(searchParams)+ applySearchParams(searchParams, false)const hasDateOverride =typeof searchParams.date_from === 'string' || typeof searchParams.date_to === 'string'@@ -635,14 +664,26 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([return { ...passthroughSearchParams(), filters, date_from, date_to, filter_test_accounts, trace_search }}+ function dateSearchParams(dateFrom: string | null, dateTo: string | null): Record<string, unknown> {+ if (router.values.location.pathname.endsWith(urls.aiObservabilityDashboard())) {+ return {+ date_from: router.values.searchParams.date_from,+ date_to: router.values.searchParams.date_to,+ }+ }+ return {+ date_from: dateFrom === INITIAL_EVENTS_DATE_FROM ? undefined : dateFrom || undefined,+ date_to: dateTo || undefined,+ }+ }+return {applyUrlState: ({ propertyFilters, dateFrom, dateTo, shouldFilterTestAccounts, searchQuery }) => [router.values.location.pathname,{...passthroughSearchParams(),filters: propertyFilters.length > 0 ? propertyFilters : undefined,- date_from: dateFrom === INITIAL_EVENTS_DATE_FROM ? undefined : dateFrom || undefined,- date_to: dateTo || undefined,+ ...dateSearchParams(dateFrom, dateTo),filter_test_accounts: shouldFilterTestAccounts ? 'true' : undefined,trace_search:(searchQuery ?? (router.values.searchParams.trace_search as string | undefined)) || undefined,diff --git a/products/ai_observability/frontend/preferenceStorage.ts b/products/ai_observability/frontend/preferenceStorage.tsindex 85a489a0661b..7e91fd0afc5e 100644--- a/products/ai_observability/frontend/preferenceStorage.ts+++ b/products/ai_observability/frontend/preferenceStorage.ts@@ -1,16 +1,5 @@-import { getCurrentTeamIdOrNone } from 'lib/utils/getAppContext'+import { buildTeamScopedStorageConfig } from 'lib/logic/persistence'-interface AIObservabilityPreferenceStorageConfig {- persist: true+export const buildAiObservabilityStorageConfig = (storageKey: string-}--export function buildAiObservabilityStorageConfig(storageKey: string): AIObservabilityPreferenceStorageConfig {- const teamId = getCurrentTeamIdOrNone()- const teamPrefix = teamId ? `${teamId}__` : ''-- return {- persist: true,- storageKey: `${teamPrefix}ai_observability.${storageKey}`,- }-}+): ReturnType<typeof buildTeamScopedStorageConfig> => buildTeamScopedStorageConfig(`ai_observability.${storageKey}`)diff --git a/products/ai_observability/frontend/tabs/aiObservabilityTracesTabLogic.ts b/products/ai_observability/frontend/tabs/aiObservabilityTracesTabLogic.tsindex e21ae7b82116..962a47b197d2 100644--- a/products/ai_observability/frontend/tabs/aiObservabilityTracesTabLogic.ts+++ b/products/ai_observability/frontend/tabs/aiObservabilityTracesTabLogic.ts@@ -15,6 +15,7 @@ import { buildAiObservabilityStorageConfig } from '../preferenceStorage'import { LLM_TRACES_PAGE_SIZE } from '../utils'export interface AIObservabilityTracesTabLogicProps {+ logicKey?: stringpersonId?: stringgroup?: {groupKey: string@@ -89,11 +90,11 @@ export type aiObservabilityTracesTabLogicType = MakeLogicType<export const aiObservabilityTracesTabLogic = kea<aiObservabilityTracesTabLogicType>([path(['products', 'ai_observability', 'frontend', 'tabs', 'aiObservabilityTracesTabLogic']),- key((props: AIObservabilityTracesTabLogicProps) => props?.personId || 'aiObservabilityScene'),+ key((props: AIObservabilityTracesTabLogicProps) => props.logicKey || props.personId || 'aiObservabilityScene'),props({} as AIObservabilityTracesTabLogicProps),connect((props: AIObservabilityTracesTabLogicProps) => ({values: [- aiObservabilitySharedLogic({ personId: props.personId, group: props.group }),+ aiObservabilitySharedLogic({ logicKey: props.logicKey, personId: props.personId, group: props.group }),['dateFilter', 'shouldFilterTestAccounts', 'shouldFilterSupportTraces', 'propertyFilters', 'searchQuery'],groupsModel,['groupsTaxonomicTypes'],