: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 long inactivity gaps instead of fast-forwarding (#88542)
Hayne Ryua3af3bbdb83a
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.tsindex 1aa92810a040..d2309356cfc0 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts@@ -28,7 +28,12 @@ import {recordingMetaJson,setupSessionRecordingTest,} from './__mocks__/test-setup'-import { findNewEvents, findSegmentForTimestamp, stripRrwebScriptShims } from './sessionRecordingPlayerLogic'+import {+ findNewEvents,+ findSegmentForTimestamp,+ INSTANT_SKIP_INACTIVITY_THRESHOLD_MS,+ stripRrwebScriptShims,+} from './sessionRecordingPlayerLogic'import { markLoaded } from './snapshot-store/test-utils'import { snapshotDataLogic } from './snapshotDataLogic'import { deleteRecording as deleteRecordingMock } from './utils/playerUtils'@@ -272,6 +277,52 @@ describe('sessionRecordingPlayerLogic', () => {})})+ describe('inactivity segment traversal', () => {+ const START = 1682952380877+ const inactiveSegment = (kind: 'gap' | 'window', durationMs: number): RecordingSegment =>+ ({+ kind,+ isActive: false,+ startTimestamp: START,+ endTimestamp: START + durationMs,+ durationMs,+ windowId: kind === 'window' ? 1 : undefined,+ }) as RecordingSegment++ it.each([+ [+ 'seeks over a gap past the threshold while playing',+ 'gap',+ INSTANT_SKIP_INACTIVITY_THRESHOLD_MS + 1,+ true,+ true,+ ],+ ['fast-forwards a gap exactly at the threshold', 'gap', INSTANT_SKIP_INACTIVITY_THRESHOLD_MS, true, false],+ [+ 'does not seek when paused, even over the threshold',+ 'gap',+ INSTANT_SKIP_INACTIVITY_THRESHOLD_MS + 1,+ false,+ false,+ ],+ ['fast-forwards a dense inactive window of any length', 'window', 35 * 3600 * 1000, true, false],+ ] as const)('%s', async (_name, kind, durationMs, playing, expectSeek) => {+ if (!playing) {+ logic.actions.setPause()+ }+ logic.actions.setCurrentTimestamp(START)+ const segment = inactiveSegment(kind, durationMs)+ const expectation = expectLogic(logic, () => logic.actions.setCurrentSegment(segment))+ if (expectSeek) {+ await expectation.toDispatchActions([logic.actionCreators.seekToTimestamp(segment.endTimestamp)])+ } else {+ await expectation+ .toDispatchActions([logic.actionCreators.setSkippingInactivity(true)])+ .toNotHaveDispatchedActions(['seekToTimestamp'])+ }+ })+ })+describe('terminal data failures', () => {// Give-up signals must surface as a player error even when partial data already loaded —// otherwise the affected range buffers forever with no error shown.diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.tsindex 8624b7e26142..eb34ad6f24b5 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts@@ -291,6 +291,10 @@ export function findNewEvents(allSnapshots: eventWithTime[], currentEvents: evenreturn newEvents}+// Longer than any legit in-session idle span (the default session idle timeout is 30 minutes),+// so a gap past this exists only in recordings with corrupted timestamps.+export const INSTANT_SKIP_INACTIVITY_THRESHOLD_MS = 60 * 60 * 1000+/** Find the segment containing this timestamp, falling back to the nearest valid one if out of range. */export function findSegmentForTimestamp(segments: RecordingSegment[], timestamp?: number): RecordingSegment | null {if (timestamp === undefined) {@@ -2320,6 +2324,23 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(actions.seekToTimestamp(segment.endTimestamp)return}+ // fast-forwarding a multi-hour span saturates the main thread; only 'gap' segments+ // are event-free, so only they are safe to jump with a seek+ const remainingMs =+ segment.endTimestamp -+ clamp(+ values.currentTimestamp ?? segment.startTimestamp,+ segment.startTimestamp,+ segment.endTimestamp+ )+ if (+ values.playingState === SessionPlayerState.PLAY &&+ segment.kind === 'gap' &&+ remainingMs > INSTANT_SKIP_INACTIVITY_THRESHOLD_MS+ ) {+ actions.seekToTimestamp(segment.endTimestamp)+ return+ }actions.setSkippingInactivity(true)} else {actions.setSkippingInactivity(false)@@ -2606,6 +2627,15 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(actions.setEndReached(false)if (nextTimestamp !== undefined) {+ // resuming inside a long gap re-enters it without a segment change, so jump here too+ const segment = values.segmentForTimestamp(nextTimestamp)+ if (+ values.skipInactivitySetting &&+ segment?.kind === 'gap' &&+ segment.endTimestamp - nextTimestamp > INSTANT_SKIP_INACTIVITY_THRESHOLD_MS+ ) {+ nextTimestamp = segment.endTimestamp+ }actions.seekToTimestamp(nextTimestamp, true)}