: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(replay): jump to the first matching event in playlists (#73157)
Marcel Poelkerb4423364d1a3
diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.tsindex e08d673dbcf0..1765257d04e1 100644--- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.test.ts@@ -2,11 +2,16 @@ import { expectLogic } from 'kea-test-utils'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'-import { playerInspectorLogic } from 'scenes/session-recordings/player/inspector/playerInspectorLogic'+import {+ PlayerInspectorLogicProps,+ playerInspectorLogic,+} from 'scenes/session-recordings/player/inspector/playerInspectorLogic'import { sessionRecordingExperimentContextLogic } from 'scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic'import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'+import { DEFAULT_RECORDING_FILTERS } from 'scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic'+import { useMocks } from '~/mocks/jest'import { SessionRecordingType } from '~/types'import { setupSessionRecordingTest } from '../__mocks__/test-setup'@@ -244,40 +249,186 @@ describe('playerInspectorLogic', () => {})describe('matching events', () => {- it('waits for the recording start before seeking to the first matching event', async () => {- const matchingProps = {- sessionRecordingId: '1',- playerKey: 'matching-event',- skipToFirstMatchingEvent: true,- matchingEventsMatchType: {- matchType: 'uuid' as const,- matchedEvents: [- {- uuid: 'matching-event',- timestamp: '2025-01-01T00:00:10.000Z',- session_id: '1',- window_id: '1',- },- ],- },- }- const playerLogic = sessionRecordingPlayerLogic(matchingProps)- const matchingLogic = playerInspectorLogic(matchingProps)+ const matchingProps = (+ playerKey: string,+ options: { matchTimestamp?: string; skipToFirstMatchingEvent?: boolean; autoPlay?: boolean } = {}+ ): PlayerInspectorLogicProps => ({+ sessionRecordingId: '1',+ playerKey,+ skipToFirstMatchingEvent: options.skipToFirstMatchingEvent,+ autoPlay: options.autoPlay,+ matchingEventsMatchType: {+ matchType: 'uuid' as const,+ matchedEvents: [+ { uuid: 'matching-event', timestamp: options.matchTimestamp ?? '2025-01-01T00:00:10.000Z' },+ ],+ },+ })++ const mountLogics = (+ props: PlayerInspectorLogicProps+ ): {+ playerLogic: ReturnType<typeof sessionRecordingPlayerLogic.build>+ matchingLogic: ReturnType<typeof playerInspectorLogic.build>+ } => {+ const playerLogic = sessionRecordingPlayerLogic(props)+ const matchingLogic = playerInspectorLogic(props)playerLogic.mount()matchingLogic.mount()+ return { playerLogic, matchingLogic }+ }- await expectLogic(matchingLogic).toDispatchActions(['loadMatchingEventsSuccess'])- await expectLogic(playerLogic).toNotHaveDispatchedActions(['seekToTime'])-+ const loadRecordingMeta = (): void => {dataLogic.actions.loadRecordingMetaSuccess({id: '1',start_time: '2025-01-01T00:00:00.000Z',end_time: '2025-01-01T00:01:00.000Z',recording_duration: 60,} as SessionRecordingType)+ }++ it.each([+ ['armed via the skipToFirstMatchingEvent prop', { skipToFirstMatchingEvent: true }],+ ['armed during player initialization', {}],+ ])('seeks to the first matching event once the recording is ready (%s)', async (label, options) => {+ const { playerLogic, matchingLogic } = mountLogics(matchingProps(`skip-${label}`, options))++ await expectLogic(matchingLogic).toDispatchActions(['loadMatchingEventsSuccess'])+ await expectLogic(playerLogic).toNotHaveDispatchedActions(['seekToTime'])++ // Meta initializes the player, which arms the skip flag (no t/timestamp URL param)+ loadRecordingMeta()+ await expectLogic(playerLogic).toDispatchActions([+ 'setSkipToFirstMatchingEvent',+ playerLogic.actionCreators.seekToTime(9000),+ ])++ matchingLogic.unmount()+ playerLogic.unmount()+ })+ it('still auto-skips when autoplay has started playback', async () => {+ // Autoplay seeks through the internal seekToTimestamp path; only user-facing seeks+ // (seekToTime, scrubbing) consume the pending skip. If an internal seek ever counted+ // as user intent, the skip would silently stop firing on autoplaying playlists.+ const { playerLogic, matchingLogic } = mountLogics(matchingProps('autoplay', { autoPlay: true }))++ await expectLogic(matchingLogic).toDispatchActions(['loadMatchingEventsSuccess'])+ loadRecordingMeta()++ await expectLogic(playerLogic).toDispatchActions([+ 'seekToTimestamp', // autoplay's internal seek+ playerLogic.actionCreators.seekToTime(9000),+ ])++ matchingLogic.unmount()+ playerLogic.unmount()+ })++ it.each([+ [+ 'seeked',+ (playerLogic: ReturnType<typeof sessionRecordingPlayerLogic.build>) =>+ playerLogic.actions.seekToTime(5000),+ ],+ [+ 'scrubbed',+ (playerLogic: ReturnType<typeof sessionRecordingPlayerLogic.build>) => playerLogic.actions.startScrub(),+ ],+ ])('does not auto-skip after the user has %s', async (interaction, interact) => {+ // Backend matching events resolve on their own schedule, often seconds into playback —+ // a viewer who has already navigated must not have the playhead yanked when they land+ let releaseMatchingEvents: () => void = () => {}+ const gate = new Promise<void>((resolve) => (releaseMatchingEvents = resolve))+ useMocks({+ get: {+ '/api/environments/:team_id/session_recordings/matching_events': async () => {+ await gate+ return [200, { results: [{ uuid: 'matching-event', timestamp: '2025-01-01T00:00:10.000Z' }] }]+ },+ },+ })++ const { playerLogic, matchingLogic } = mountLogics({+ sessionRecordingId: '1',+ playerKey: `user-${interaction}`,+ matchingEventsMatchType: { matchType: 'backend' as const, filters: DEFAULT_RECORDING_FILTERS },+ })++ loadRecordingMeta()+ // The player is ready and the skip armed, but matching events are still loading+ await expectLogic(playerLogic).toDispatchActions(['setSkipToFirstMatchingEvent'])+ interact(playerLogic)++ releaseMatchingEvents()+ await expectLogic(matchingLogic).toDispatchActions([+ 'loadMatchingEventsSuccess',+ 'trySkipToFirstMatchingEvent',+ ])+ await expectLogic(playerLogic).toNotHaveDispatchedActions([playerLogic.actionCreators.seekToTime(9000)])++ matchingLogic.unmount()+ playerLogic.unmount()+ })++ it('does not skip again when matching events reload after the skip has fired', async () => {+ // Playlist filters can change under an open recording without user intent (e.g. an+ // async session-id list resolving into the filters), which reloads matching events —+ // that reload must not re-arm the auto-skip and yank the playhead mid-playback.+ const { playerLogic, matchingLogic } = mountLogics(+ matchingProps('reload-after-skip', { skipToFirstMatchingEvent: true })+ )++ await expectLogic(matchingLogic).toDispatchActions(['loadMatchingEventsSuccess'])+ loadRecordingMeta()await expectLogic(playerLogic).toDispatchActions([playerLogic.actionCreators.seekToTime(9000)])+ // What propsChanged dispatches when the playlist filters change under the recording+ matchingLogic.actions.loadMatchingEvents()+ await expectLogic(matchingLogic).toDispatchActions([+ 'loadMatchingEventsSuccess',+ 'trySkipToFirstMatchingEvent',+ ])+ await expectLogic(playerLogic).toNotHaveDispatchedActions(['seekToTime'])++ matchingLogic.unmount()+ playerLogic.unmount()+ })++ it('does not seek when the earliest match falls after the recording ends', async () => {+ // The matching-events query has slack past the recording window; seeking there would+ // pin the player to its final frame and trigger end-reached.+ const props = matchingProps('match-past-end', {+ matchTimestamp: '2025-01-01T00:02:00.000Z',+ skipToFirstMatchingEvent: true,+ })+ const { playerLogic, matchingLogic } = mountLogics(props)++ await expectLogic(matchingLogic).toDispatchActions(['loadMatchingEventsSuccess'])+ loadRecordingMeta()++ // The deferred arming trigger is the last chance for a seek to fire+ await expectLogic(matchingLogic).toDispatchActions([+ 'setSkipToFirstMatchingEvent',+ 'trySkipToFirstMatchingEvent',+ ])+ await expectLogic(playerLogic).toNotHaveDispatchedActions(['seekToTime'])++ // The out-of-window verdict is terminal: a filter change reloading matching events+ // with an in-window match must not fire the skip mid-playback+ playerInspectorLogic({+ ...props,+ matchingEventsMatchType: {+ matchType: 'uuid' as const,+ matchedEvents: [{ uuid: 'in-window-event', timestamp: '2025-01-01T00:00:10.000Z' }],+ },+ })+ await expectLogic(matchingLogic).toDispatchActions([+ 'loadMatchingEventsSuccess',+ 'trySkipToFirstMatchingEvent',+ ])+ await expectLogic(playerLogic).toNotHaveDispatchedActions(['seekToTime'])+matchingLogic.unmount()playerLogic.unmount()})diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.tsindex d03b7ecc516e..e093fd78bc78 100644--- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts+++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts@@ -431,6 +431,7 @@ export interface playerInspectorLogicValues {windowIds: number[] // sessionRecordingDataCoordinatorLogicexperimentItems: ExperimentSessionContextItemApi[] // sessionRecordingExperimentContextLogiccurrentPlayerTime: number // sessionRecordingPlayerLogic+ currentTimestamp: number | undefined // sessionRecordingPlayerLogicdoctorDiagnostics: DoctorDiagnostics | null // sessionRecordingPlayerLogicskipToFirstMatchingEvent: boolean // sessionRecordingPlayerLogicallContextItems: InspectorListItem[]@@ -578,9 +579,15 @@ export interface playerInspectorLogicActions {forcePlay: booleantimeInMilliseconds: number} // sessionRecordingPlayerLogic+ setSkipToFirstMatchingEvent: (skipToFirstMatchingEvent: boolean) => {+ skipToFirstMatchingEvent: boolean+ } // sessionRecordingPlayerLogicsetSkippingToMatchingEvent: (isSkippingToMatchingEvent: boolean) => {isSkippingToMatchingEvent: boolean} // sessionRecordingPlayerLogic+ startScrub: () => {+ value: true+ } // sessionRecordingPlayerLogicloadMatchingEvents: () => anyloadMatchingEventsFailure: (error: string,@@ -838,7 +845,7 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>(['loadRecordingMetaSuccess',],sessionRecordingPlayerLogic(props),- ['seekToTime', 'setSkippingToMatchingEvent'],+ ['seekToTime', 'setSkippingToMatchingEvent', 'setSkipToFirstMatchingEvent', 'startScrub'],playerInspectorLogsLogic(props),['loadLogs', 'loadMoreLogs', 'markLogsInitialLoadRequested'],],@@ -873,7 +880,7 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>(['uuidToIndex',],sessionRecordingPlayerLogic(props),- ['currentPlayerTime', 'skipToFirstMatchingEvent', 'doctorDiagnostics'],+ ['currentPlayerTime', 'currentTimestamp', 'skipToFirstMatchingEvent', 'doctorDiagnostics'],performanceEventDataLogic({ key: props.playerKey, sessionRecordingId: props.sessionRecordingId }),['allPerformanceEvents'],featureFlagLogic,@@ -918,11 +925,19 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([setItemExpanded: () => true,},],+ // Once set, the auto-skip is consumed for this recording and never re-arms: matching+ // events can reload without user intent (playlist filters changing under an open+ // recording, e.g. an async session-id list resolving), and a reload-triggered reset+ // would yank the playhead mid-playback.hasSkippedToFirstMatchingEvent: [false,{- loadMatchingEvents: () => false,markSkippedToFirstMatchingEvent: () => true,+ // A seek or scrub also consumes a pending auto-skip: the matching-events query+ // can resolve seconds into playback, and yanking the playhead after the viewer+ // has already navigated is worse than not skipping at all.+ seekToTime: () => true,+ startScrub: () => true,},],})),@@ -2146,12 +2161,28 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([loadRecordingMetaSuccess: () => {actions.trySkipToFirstMatchingEvent()},+ setSkipToFirstMatchingEvent: async ({ skipToFirstMatchingEvent }, breakpoint) => {+ if (!skipToFirstMatchingEvent) {+ return+ }+ // In playlist embeds the flag is armed by initializePlayerFromStart, which only runs+ // once snapshots start syncing — usually after both matching events and meta have+ // loaded, so without this trigger the skip never fires. The arming is also dispatched+ // before the player's initial timestamp exists (which the skip requires) and no later+ // trigger is guaranteed, so defer past that synchronous init chain rather than firing+ // inline.+ await breakpoint(1)+ actions.trySkipToFirstMatchingEvent()+ },trySkipToFirstMatchingEvent: () => {if (!values.skipToFirstMatchingEvent ||values.hasSkippedToFirstMatchingEvent ||!values.start ||- !values.matchingEvents?.length+ !values.matchingEvents?.length ||+ // seekToTime no-ops until the player has an initial timestamp — bail without+ // consuming the skip so a later trigger retries once the player is ready+ values.currentTimestamp == null) {return}@@ -2159,7 +2190,16 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([const earliestMatchingEvent = values.matchingEvents.reduce((previous, current) =>previous.timestamp < current.timestamp ? previous : current)- const { timeInRecording } = timeRelativeToStart(earliestMatchingEvent, values.start)+ const { timestamp, timeInRecording } = timeRelativeToStart(earliestMatchingEvent, values.start)+ // The matching-events query has slack around the recording window, so the earliest+ // match can fall past the playable range — seeking there would pin the player to its+ // final frame and immediately trigger end-reached (auto-advancing playlists). The+ // verdict is terminal for this recording: consume the flag so a matching-events+ // reload can't fire the skip mid-playback.+ if (values.end && timestamp.isAfter(values.end)) {+ actions.markSkippedToFirstMatchingEvent()+ return+ }const seekTime = Math.max(0, ceilMsToClosestSecond(timeInRecording) - 1000)actions.markSkippedToFirstMatchingEvent()diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.tsindex d3a62ccf88e2..b09af9b4af37 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts@@ -1046,6 +1046,39 @@ describe('sessionRecordingsPlaylistLogic', () => {})})+ describe('matchingEventsMatchType', () => {+ it('classifies a bare event-property filter as backend', () => {+ // The shape the experiments server-side-flag exposure fallback produces+ // ($feature/<key> with no event filter). Classifying it as 'none' would silently+ // drop match indicators and skip-to-first-matching-event for those lists.+ logic = sessionRecordingsPlaylistLogic({+ logicKey: 'match-type-tests',+ filters: {+ ...DEFAULT_RECORDING_FILTERS,+ filter_group: {+ type: FilterLogicalOperator.And,+ values: [+ {+ type: FilterLogicalOperator.And,+ values: [+ {+ key: '$feature/my-flag',+ type: PropertyFilterType.Event,+ value: ['test'],+ operator: PropertyOperator.Exact,+ },+ ],+ },+ ],+ },+ },+ })+ logic.mount()++ expect(logic.values.matchingEventsMatchType.matchType).toBe('backend')+ })+ })+describe('resetting filters', () => {beforeEach(() => {logic = sessionRecordingsPlaylistLogic({