: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(experiments): report the duration floor on an empty recordings list (#96094)
Marcel Poelker3ceeef65c160
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex ef15d1c0779c..57b7eb80b397 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -183,8 +183,29 @@ export interface ExperimentRecordingsListRenderedContext extends ExperimentRecor*/retention_period: string | nullreplay_opt_in: boolean- /** Replay's default floor drops sessions under 5 active seconds, so it can empty a list. */+ /**+ * Whether any duration filter was applied. Replay applies a default floor to every list, so+ * this is true on nearly every render and separates almost nothing. A dashboard tile reads it,+ * so its meaning is frozen; the four properties below are what answers whether the floor is+ * why the list came back empty.+ */duration_filter_active: boolean+ /** Which duration the floor measures: `active_seconds`, `duration`, or `inactive_seconds`. */+ duration_filter_key: string | null+ /** The floor's threshold in seconds. */+ duration_filter_seconds: number | null+ /** `gt` for a floor, `lt` for a ceiling. The viewer can flip it in the playlist filter bar. */+ duration_filter_operator: string | null+ /**+ * How many duration filters were applied. The three properties above describe the first, so a+ * count above one says they describe part of the set rather than all of it.+ */+ duration_filter_count: number+ /**+ * Whether the applied filter differs from replay's default floor, which counts removing the+ * filter as a difference. The three properties above are null when the viewer removed it.+ */+ duration_filter_customized: boolean/** Whether the exposure event is ever seen with a session id. Null while the check is out. */exposure_linkable: boolean | null}diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.tsindex 78cd606aab01..4fef2f8761e1 100644--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts@@ -12,7 +12,15 @@ import { teamLogic } from 'scenes/teamLogic'import { ExperimentMetricType, NodeKind } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'-import { Experiment, FilterLogicalOperator, SessionRecordingSidebarTab, TeamType } from '~/types'+import {+ Experiment,+ FilterLogicalOperator,+ PropertyFilterType,+ PropertyOperator,+ RecordingDurationFilter,+ SessionRecordingSidebarTab,+ TeamType,+} from '~/types'import {experimentsInSessionExposureRetrieve,@@ -810,6 +818,11 @@ describe('experimentReplayTabLogic', () => {retention_period: '90d',replay_opt_in: true,duration_filter_active: true,+ duration_filter_key: 'active_seconds',+ duration_filter_seconds: 5,+ duration_filter_operator: 'gt',+ duration_filter_count: 1,+ duration_filter_customized: false,exposure_linkable: true,variant: 'test',exposure_scope: 'all_exposed',@@ -821,6 +834,81 @@ describe('experimentReplayTabLogic', () => {filled.unmount()})+ it.each([+ {+ name: 'a floor the viewer raised, on another duration key',+ duration: [+ {+ type: PropertyFilterType.Recording,+ key: 'duration',+ value: 60,+ operator: PropertyOperator.GreaterThan,+ } as RecordingDurationFilter,+ ],+ expected: {+ duration_filter_active: true,+ duration_filter_key: 'duration',+ duration_filter_seconds: 60,+ duration_filter_operator: 'gt',+ duration_filter_count: 1,+ duration_filter_customized: true,+ },+ },+ {+ name: 'a floor the viewer removed',+ duration: [],+ expected: {+ duration_filter_active: false,+ duration_filter_key: null,+ duration_filter_seconds: null,+ duration_filter_operator: null,+ duration_filter_count: 0,+ duration_filter_customized: true,+ },+ },+ {+ name: 'a duration set with a second, stricter entry',+ duration: [+ {+ type: PropertyFilterType.Recording,+ key: 'active_seconds',+ value: 5,+ operator: PropertyOperator.GreaterThan,+ } as RecordingDurationFilter,+ {+ type: PropertyFilterType.Recording,+ key: 'active_seconds',+ value: 30,+ operator: PropertyOperator.GreaterThan,+ } as RecordingDurationFilter,+ ],+ expected: {+ duration_filter_active: true,+ duration_filter_key: 'active_seconds',+ duration_filter_seconds: 5,+ duration_filter_operator: 'gt',+ duration_filter_count: 2,+ duration_filter_customized: true,+ },+ },+ ])('reports $name on an empty list', async ({ duration, expected }) => {+ // Replay applies its default floor to every list, so a report that only said a duration+ // filter was present cannot tell the floor everyone gets from one the viewer chose. The+ // viewer edits it in the playlist's own filter bar, so the report has to read that rather+ // than the filters the tab pushed down.+ //+ // The last case is the fail-safe one: the reported key, threshold, and operator describe+ // the first entry, so a set whose first entry is the default must still report as+ // customized, and its count must say that the report names part of the set.+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)+ logic.actions.playlistFiltersChanged({ ...logic.values.recordingsFilters, duration })+ logic.actions.recordingsLoaded([])+ await expectLogic(logic).toFinishAllListeners()++ expect(listsRendered(captureSpy, 42)).toHaveLength(1)+ expect(listsRendered(captureSpy, 42)[0][1]).toMatchObject(expected)+ })+it('tells a refused metric filter apart from one that matched nothing, once it has answered', async () => {// Both leave the list with an empty session set, since a refusal must never widen the list// back out. Folded together, a broken endpoint would inflate the count of filters thatdiff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.tsindex 220ddc75af37..19de850ae808 100644--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts@@ -31,7 +31,10 @@ import {} from 'lib/utils/eventUsageLogic'import { addProductIntentForCrossSell } from 'lib/utils/product-intents'import { playerSidebarLogic } from 'scenes/session-recordings/player/sidebar/playerSidebarLogic'-import { DEFAULT_RECORDING_FILTERS } from 'scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic'+import {+ DEFAULT_RECORDING_FILTERS,+ defaultRecordingDurationFilter,+} from 'scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic'import { teamLogic } from 'scenes/teamLogic'import {@@ -44,6 +47,7 @@ import {import {Experiment,FilterLogicalOperator,+ RecordingDurationFilter,RecordingUniversalFilters,SessionRecordingRetentionPeriod,SessionRecordingSidebarTab,@@ -160,7 +164,8 @@ export type ExperimentWatchEmptyAction = 'exposure_docs' | 'replay_settings'** `unknown_in_window` is the residue — replay is on, the run window is inside retention, and the* filters still matched nothing. Exposure linkage and the duration floor both live in there, which- * is why the event carries `exposure_linkable` and `duration_filter_active` alongside the reason.+ * is why the event carries `exposure_linkable` and the `duration_filter_*` properties alongside+ * the reason.*/export enum ExperimentReplayListEmptyReason {/** The project does not record sessions, so no experiment on it can have any. */@@ -245,10 +250,13 @@ export interface experimentReplayTabLogicValues {linkabilityLoaded: boolean // viewRecordingsLinkabilityLogicseenTogetherMapLoading: boolean // viewRecordingsLinkabilityLogicunlinkableEventNames: Set<string> // viewRecordingsLinkabilityLogic+ appliedDurationFilter: RecordingDurationFilter | null+ appliedDurationFilterCount: numberbehaviorComparisonAvailable: booleanbehaviorComparisonOpen: booleanbucketSessionIds: string[] | undefineddurationFilterActive: boolean+ durationFilterCustomized: booleaneffectiveExposureScope: ExperimentReplayExposureScopeeffectiveMetricUuids: string[]effectiveVariantKey: string | null@@ -534,6 +542,18 @@ export interface experimentReplayTabLogicMeta {playlistFilters: RecordingUniversalFilters | null,recordingsFilters: RecordingUniversalFilters) => boolean+ appliedDurationFilter: (+ playlistFilters: RecordingUniversalFilters | null,+ recordingsFilters: RecordingUniversalFilters+ ) => RecordingDurationFilter | null+ appliedDurationFilterCount: (+ playlistFilters: RecordingUniversalFilters | null,+ recordingsFilters: RecordingUniversalFilters+ ) => number+ durationFilterCustomized: (+ appliedDurationFilterCount: number,+ appliedDurationFilter: RecordingDurationFilter | null+ ) => booleanlistEmptyReason: (currentTeam: TeamPublicType | TeamType | null,bucketSessionIds: string[] | undefined,@@ -997,8 +1017,10 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([return !unlinkableEventNames.has(exposureEventName)},],- // Replay's default floor keeps out sessions under 5 active seconds, which is enough to empty- // a list on its own, so an empty-list report says whether it was applied.+ // Whether the list ran under any duration filter at all. Replay applies a default floor to+ // every list, so this is true on nearly every render and separates almost nothing. A+ // dashboard tile reads it, so it keeps its meaning; `appliedDurationFilter` below is what+ // tells a reader whether the floor emptied the list.durationFilterActive: [(s) => [s.playlistFilters, s.recordingsFilters],(@@ -1006,6 +1028,41 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([recordingsFilters: RecordingUniversalFilters): boolean => (playlistFilters ?? recordingsFilters).duration.length > 0,],+ // The duration filter the list actually ran under, which the viewer can edit in the+ // playlist's own filter bar: they can change the threshold, swap the key between+ // `active_seconds`, `duration`, and `inactive_seconds`, and flip the operator between `gt`+ // and `lt`. Null when no duration filter is applied, which the tab does itself for a watch+ // card. The filter bar writes one entry, but the query conversion carries every duration+ // predicate through `having_predicates` and back, so a set from another writer can hold+ // more. This describes the first entry only, so it is reported next to the entry count.+ appliedDurationFilter: [+ (s) => [s.playlistFilters, s.recordingsFilters],+ (+ playlistFilters: RecordingUniversalFilters | null,+ recordingsFilters: RecordingUniversalFilters+ ): RecordingDurationFilter | null => (playlistFilters ?? recordingsFilters).duration[0] ?? null,+ ],+ // How many duration filters the list ran under. The reported key, threshold, and operator+ // describe the first, so this is what tells a reader whether they describe the whole set.+ appliedDurationFilterCount: [+ (s) => [s.playlistFilters, s.recordingsFilters],+ (playlistFilters: RecordingUniversalFilters | null, recordingsFilters: RecordingUniversalFilters): number =>+ (playlistFilters ?? recordingsFilters).duration.length,+ ],+ // Whether the applied filter differs from replay's default floor, which counts removing it+ // as a difference. A reader needs this to tell an empty list under the floor everyone gets+ // from an empty list under a threshold the viewer chose. More than one duration filter+ // counts as a difference too, so that a second, stricter entry can never report as the+ // default that `appliedDurationFilter` read off the first.+ durationFilterCustomized: [+ (s) => [s.appliedDurationFilterCount, s.appliedDurationFilter],+ (appliedDurationFilterCount: number, appliedDurationFilter: RecordingDurationFilter | null): boolean =>+ appliedDurationFilterCount > 1 ||+ appliedDurationFilter === null ||+ appliedDurationFilter.key !== defaultRecordingDurationFilter.key ||+ appliedDurationFilter.value !== defaultRecordingDurationFilter.value ||+ appliedDurationFilter.operator !== defaultRecordingDurationFilter.operator,+ ],/*** The cause to report when the list comes back with nothing, first match wins. The order is* cheapest-and-most-certain first: a project with replay off can have no recordings at all,@@ -1470,6 +1527,11 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([retention_period: values.currentTeam?.session_recording_retention_period ?? null,replay_opt_in: !!values.currentTeam?.session_recording_opt_in,duration_filter_active: values.durationFilterActive,+ duration_filter_key: values.appliedDurationFilter?.key ?? null,+ duration_filter_seconds: values.appliedDurationFilter?.value ?? null,+ duration_filter_operator: values.appliedDurationFilter?.operator ?? null,+ duration_filter_count: values.appliedDurationFilterCount,+ duration_filter_customized: values.durationFilterCustomized,exposure_linkable: values.exposureLinkable,})},