: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(replay): warn and mark recordings with a late full snapshot (#64260)
Tue Haulundc2eb3ad080e8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 485e8b64047c..aa3f6d9d03cb 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4264,6 +4264,10 @@ snapshots:hash: v1.k794b7964.55820e6d4062b19b7be7b87d629e5009054147a9c168d7817d82c199bc2bf9bc.5Y3qGvAMQcUBJsjBoJjEoB9nM3y9RYol-LvUG5FoJHUreplay-player-recordingdeleted--without-timestamp--light:hash: v1.k794b7964.b05e8572dd694a62581f650a04dfd9c2f3e4185aedcd4d436bf9ff141543e56e.NJybpc6_7iPoUGlSopTmBRqYyVY3cnDsnPiI9yGYNHI+ replay-player-seekbar--late-full-snapshot--dark:+ hash: v1.k794b7964.2886d7b28515a368e890990d35cad871255b709897f865a8fead51ca37d88e8f.SL7wEXVZ3VaEgDdDhKt9klNijvd78tN-1pSJ2uIaqfM+ replay-player-seekbar--late-full-snapshot--light:+ hash: v1.k794b7964.9f483e5662ab30becd97b6180b1e99ef6755f6189f63b45bcd959e4785b1087b.Jawj15BENeCV-XD75Plb1zTDIPWke_ERmIGq9VBUQuUreplay-scenes-activity-modal--event-explorer-with-modal-not-found--dark:hash: v1.k794b7964.24c95f96550f63168ee26cc5e15a65ee85900aafc69405e43cc8d1851ee8dbc2.xvGrD7kg07_HIXfNWRdcg2sEWhnQvWfAASy3jF8Se0wreplay-scenes-activity-modal--event-explorer-with-modal-not-found--light:diff --git a/frontend/src/scenes/session-recordings/__mocks__/recording_snapshots.ts b/frontend/src/scenes/session-recordings/__mocks__/recording_snapshots.tsindex beadf5e24515..18b6ace9d891 100644--- a/frontend/src/scenes/session-recordings/__mocks__/recording_snapshots.ts+++ b/frontend/src/scenes/session-recordings/__mocks__/recording_snapshots.ts@@ -11,6 +11,22 @@ const lineTwo =export const snapshotsAsJSONLines = (): string => `${lineOne}\n${lineTwo}\n`+// a real full snapshot node, but emitted `lateByMs` after the first snapshot+export const lateFullSnapshotAsJSONLines = (baseTimestamp: number, lateByMs: number): string => {+ const firstLine = snapshotsAsJSONLines().trim().split('\n')[0]+ const parsed = JSON.parse(firstLine)+ const meta = parsed.data.find((e: { type: number }) => e.type === 4)+ const fullSnapshot = parsed.data.find((e: { type: number }) => e.type === 2)+ const incremental = parsed.data.find((e: { type: number }) => e.type === 3)+ const data = [+ { ...meta, timestamp: baseTimestamp },+ { ...incremental, timestamp: baseTimestamp + 2000 },+ { ...fullSnapshot, timestamp: baseTimestamp + lateByMs },+ { ...incremental, timestamp: baseTimestamp + lateByMs + 1000 },+ ]+ return `${JSON.stringify({ window_id: parsed.window_id, data })}\n`+}+export const convertSnapshotsByWindowId = (snapshotsByWindowId: { [key: string]: eventWithTime[] },registerWindowId?: RegisterWindowIdCallbackdiff --git a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx b/frontend/src/scenes/session-recordings/player/PurePlayer.tsxindex 605a5becaf60..a05fe7cbaec8 100644--- a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx+++ b/frontend/src/scenes/session-recordings/player/PurePlayer.tsx@@ -14,6 +14,7 @@ import { HotkeysInterface, useKeyboardHotkeys } from 'lib/hooks/useKeyboardHotkeimport { usePageVisibilityCb } from 'lib/hooks/usePageVisibility'import { useResizeBreakpoints } from 'lib/hooks/useResizeObserver'import { Link } from 'lib/lemon-ui/Link'+import { humanFriendlyDuration } from 'lib/utils/durations'import { useNotebookDrag } from 'scenes/notebooks/AddToNotebook/DraggableToNotebook'import { PlayerFrameCommentOverlay } from 'scenes/session-recordings/player/commenting/PlayerFrameCommentOverlay'import { RecordingDeleted } from 'scenes/session-recordings/player/RecordingDeleted'@@ -88,6 +89,8 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsshowingClipParams,isMuted,endReached,+ hasLateFullSnapshot,+ leadingUnplayableMs,} = useValues(sessionRecordingPlayerLogic)const {@@ -148,6 +151,20 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerProps[isOldAndInvalid])+ useEffect(+ () => {+ if (hasLateFullSnapshot) {+ posthog.capture('session loaded with late full snapshot', {+ viewedSessionRecording: sessionRecordingId,+ recordingStartTime: sessionPlayerData?.start,+ leadingUnplayableMs,+ })+ }+ },+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [hasLateFullSnapshot]+ )+// Track if the recording has ended to be able to reliably get it from the BE and stop the recordinguseEffect(() => {if (typeof window !== 'undefined') {@@ -322,6 +339,20 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerProps) : (<div className="flex w-full h-full"><div className="flex flex-col flex-1 w-full relative">+ {hasLateFullSnapshot && !hidePlayerElements ? (+ <LemonBanner+ type="warning"+ dismissKey={`late-full-snapshot-${sessionRecordingId}`}+ >+ The first{' '}+ {humanFriendlyDuration(leadingUnplayableMs / 1000, { maxUnits: 2 })} of this+ recording can't be shown — the initial snapshot of the screen arrived late,+ so playback starts from the first frame we can render.{' '}+ <Link to="https://posthog.com/docs/session-replay/troubleshooting">+ Learn more+ </Link>+ </LemonBanner>+ ) : null}<div className="relative">{showMeta ? <PlayerMetaBar /> : null}</div><divclassName="SessionRecordingPlayer__body"diff --git a/frontend/src/scenes/session-recordings/player/controller/Seekbar.scss b/frontend/src/scenes/session-recordings/player/controller/Seekbar.scssindex 845d91ad0d8a..7bf8ab6780c5 100644--- a/frontend/src/scenes/session-recordings/player/controller/Seekbar.scss+++ b/frontend/src/scenes/session-recordings/player/controller/Seekbar.scss@@ -105,6 +105,24 @@}}+ .PlayerSeekbar__unplayable {+ position: absolute;+ top: 0;+ left: 0;+ z-index: 4;+ height: 100%;+ cursor: help;+ background: repeating-linear-gradient(+ 45deg,+ var(--danger) 0,+ var(--danger) 2px,+ transparent 2px,+ transparent 6px+ );+ border-radius: var(--bar-height) 0 0 var(--bar-height);+ opacity: 0.6;+ }+.PlayerSeekbar__played {position: absolute;top: 0;diff --git a/frontend/src/scenes/session-recordings/player/controller/Seekbar.stories.tsx b/frontend/src/scenes/session-recordings/player/controller/Seekbar.stories.tsxnew file mode 100644index 000000000000..4bca7ecbfc0a--- /dev/null+++ b/frontend/src/scenes/session-recordings/player/controller/Seekbar.stories.tsx@@ -0,0 +1,97 @@+import type { Meta, StoryObj } from '@storybook/react'+import { BindLogic } from 'kea'+import { HttpResponse } from 'msw'++import recordingEventsJson from 'scenes/session-recordings/__mocks__/recording_events_query'+import { recordingMetaJson } from 'scenes/session-recordings/__mocks__/recording_meta'+import { lateFullSnapshotAsJSONLines } from 'scenes/session-recordings/__mocks__/recording_snapshots'+import {+ SessionRecordingPlayerMode,+ sessionRecordingPlayerLogic,+} from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'++import { mswDecorator } from '~/mocks/browser'++import { PlayerController } from './PlayerController'++// first snapshot at the recording start, but the full snapshot only arrives 60s later+const LATE_SNAPSHOT_BASE = 1682952380877 // 2023-05-01T14:46:20.877Z++const lateRecordingMeta = {+ ...recordingMetaJson,+ recording_duration: 65,+ start_time: '2023-05-01T14:46:20.877000Z',+ end_time: '2023-05-01T14:47:25.877000Z',+}++type Story = StoryObj<{ width: number }>+const meta: Meta<{ width: number }> = {+ title: 'Replay/Player/Seekbar',+ component: PlayerController,+ parameters: {+ layout: 'fullscreen',+ viewMode: 'story',+ mockDate: '2023-05-01',+ testOptions: {+ waitForSelector: '.PlayerSeekbar__unplayable',+ },+ },+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/notebooks/recording_comments': { results: [] },+ '/api/environments/:team_id/session_recordings/:id/snapshots': ({ request }) => {+ if (new URL(request.url).searchParams.get('source') === 'blob_v2') {+ return new HttpResponse(lateFullSnapshotAsJSONLines(LATE_SNAPSHOT_BASE, 60000))+ }+ return [+ 200,+ {+ sources: [+ {+ source: 'blob_v2',+ start_timestamp: lateRecordingMeta.start_time,+ end_timestamp: lateRecordingMeta.end_time,+ blob_key: '0',+ },+ ],+ },+ ]+ },+ '/api/environments/:team_id/session_recordings/:id': () => [200, lateRecordingMeta],+ },+ post: {+ '/api/environments/:team_id/query/:kind': async ({ request }) => {+ const body = (await request.json()) as Record<string, any>+ if (body.query.kind === 'EventsQuery') {+ return [200, recordingEventsJson]+ }+ return [200, { results: [] }]+ },+ },+ }),+ ],+ render: ({ width }) => {+ return (+ <div style={{ width: `${width}px` }} className="relative bg-surface-primary p-2 overflow-hidden min-h-20">+ <BindLogic+ logic={sessionRecordingPlayerLogic}+ props={{+ playerKey: 'storybook',+ sessionRecordingId: '12345',+ mode: SessionRecordingPlayerMode.Standard,+ }}+ >+ <PlayerController />+ </BindLogic>+ </div>+ )+ },+}++export default meta++// the leading section before the late full snapshot is hatched as unplayable on the scrubber+export const LateFullSnapshot: Story = {+ args: { width: 800 },+}diff --git a/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx b/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsxindex 6735ce5de342..24bd32ecb680 100644--- a/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx+++ b/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx@@ -7,7 +7,9 @@ import React from 'react'import { SourceLoadingState } from '@posthog/replay-shared'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'+import { Tooltip } from 'lib/lemon-ui/Tooltip'import { cn } from 'lib/utils/css-classes'+import { humanFriendlyDuration } from 'lib/utils/durations'import { playerInspectorLogic } from '../inspector/playerInspectorLogic'import { playerMetaLogic } from '../player-meta/playerMetaLogic'@@ -75,7 +77,8 @@ const SeekbarSources = React.memo(function SeekbarSourcesRaw({})export function Seekbar(): JSX.Element {- const { sessionRecordingId, logicProps, hasSnapshots } = useValues(sessionRecordingPlayerLogic)+ const { sessionRecordingId, logicProps, hasSnapshots, hasLateFullSnapshot, leadingUnplayableMs } =+ useValues(sessionRecordingPlayerLogic)const { seekToTime } = useActions(sessionRecordingPlayerLogic)const { seekbarItems } = useValues(playerInspectorLogic(logicProps))const { endTimeMs, thumbLeftPos, isScrubbing } = useValues(seekbarLogic(logicProps))@@ -133,6 +136,20 @@ export function Seekbar(): JSX.Element {endTimeMs={endTimeMs}onSeekToSegment={seekToTime}/>+ {hasLateFullSnapshot && endTimeMs > 0 ? (+ <Tooltip+ title={`The first ${humanFriendlyDuration(leadingUnplayableMs / 1000, {+ maxUnits: 2,+ })} can't be played — the initial screen snapshot arrived late`}+ placement="top"+ >+ <div+ className="PlayerSeekbar__unplayable"+ // eslint-disable-next-line react/forbid-dom-props+ style={{ width: `${Math.min(100, (leadingUnplayableMs / endTimeMs) * 100)}%` }}+ />+ </Tooltip>+ ) : null}<divclassName="PlayerSeekbar__played"// eslint-disable-next-line react/forbid-dom-propsdiff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.tsindex 283e99ea2016..7a26da1bc5a7 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts@@ -437,6 +437,9 @@ describe('sessionRecordingPlayerLogic', () => {const inc = (timestamp: number): RecordingSnapshot => makeSnapshot(timestamp, EventType.IncrementalSnapshot)const fs = (timestamp: number): RecordingSnapshot => makeSnapshot(timestamp, EventType.FullSnapshot)+ // second-window incremental for the multi-window case+ const w2inc = (timestamp: number): RecordingSnapshot =>+ ({ timestamp, type: EventType.IncrementalSnapshot, windowId: 2, data: {} }) as unknown as RecordingSnapshot// Seeds the snapshot store and the coordinator's processed snapshots (which// segments derive from) directly, bypassing the network loading machinery.@@ -560,6 +563,54 @@ describe('sessionRecordingPlayerLogic', () => {expect(logic.values.playerError).toBeNull()expect(logic.values.currentTimestamp).toBe(START + 61500)})++ it.each([+ {+ description: 'reports the leading unplayable span when the initial full snapshot is late',+ firstSourceSnapshots: [inc(START), inc(START + 1000)],+ secondSourceSnapshots: [fs(LATE_FS_TS)],+ expectedLeadingUnplayableMs: LATE_FS_TS - START,+ expectedHasLate: true,+ },+ {+ description: 'reports no unplayable span when a full snapshot exists at the start',+ firstSourceSnapshots: [fs(START), inc(START + 1000)],+ secondSourceSnapshots: [inc(LATE_FS_TS)],+ expectedLeadingUnplayableMs: 0,+ expectedHasLate: false,+ },+ {+ description: 'reports no unplayable span when no full snapshot exists anywhere',+ firstSourceSnapshots: [inc(START), inc(START + 1000)],+ secondSourceSnapshots: [inc(START + 61000), inc(START + 62000)],+ expectedLeadingUnplayableMs: 0,+ expectedHasLate: false,+ },+ {+ description: 'measures the span but does not flag a late snapshot below the warning threshold',+ firstSourceSnapshots: [inc(START), fs(START + 5000)],+ secondSourceSnapshots: [inc(LATE_FS_TS)],+ expectedLeadingUnplayableMs: 5000,+ expectedHasLate: false,+ },+ {+ // multi-window: the first window renders from its own start, so a later window+ // lacking a full snapshot must not extend the leading unplayable span+ description: 'does not flag when the first window renders but a later window lacks a full snapshot',+ firstSourceSnapshots: [fs(START), inc(START + 1000)],+ secondSourceSnapshots: [w2inc(START + 61000), w2inc(START + 62000)],+ expectedLeadingUnplayableMs: 0,+ expectedHasLate: false,+ },+ ])(+ '$description',+ ({ firstSourceSnapshots, secondSourceSnapshots, expectedLeadingUnplayableMs, expectedHasLate }) => {+ seedRecording(firstSourceSnapshots, secondSourceSnapshots)++ expect(logic.values.leadingUnplayableMs).toBe(expectedLeadingUnplayableMs)+ expect(logic.values.hasLateFullSnapshot).toBe(expectedHasLate)+ }+ )})describe('delete session recording', () => {diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.tsindex 919aea11b74e..a2d38fe1a27c 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts@@ -154,6 +154,10 @@ const ReplayIframeDatakeyPrefix = 'ph_replay_fixed_heatmap_'// extra seek on nearly every playback.const MIN_CLAMPABLE_DEAD_ZONE_MS = 1000+// a leading unplayable region longer than this is worth surfacing to the user (banner + scrubber+// marker); below it the dead-zone clamp handles things silently and a warning would be noise+const LATE_FULL_SNAPSHOT_THRESHOLD_MS = 20000+export type SeekRenderability =// a FullSnapshot exists at or before the timestamp for its window| { kind: 'renderable' }@@ -1133,6 +1137,37 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(},],+ // The leading span playback can't render — when the initial full snapshot was lost or arrived+ // late, this is the offset from start to the FullSnapshot the player clamps the playhead to.+ // Derived from seekRenderability so the scrubber marker matches where playback actually starts,+ // window-aware and excluding the no-full-snapshot-anywhere case (handled by the unplayable takeover).+ // The `clampToFullSnapshot` verdict already requires the data before the recovery point to be+ // loaded (and so can't later flip to `renderable`), so it gates itself — surfacing the marker as+ // soon as playback would clamp rather than waiting for the whole recording to finish loading.+ leadingUnplayableMs: [+ (s) => [s.sessionPlayerData, s.seekRenderability],+ (+ sessionPlayerData: SessionPlayerData,+ seekRenderability: (timestamp: number) => SeekRenderability+ ): number => {+ const start = sessionPlayerData.start?.valueOf()+ if (start == null) {+ return 0+ }+ const firstWindowSegment = sessionPlayerData.segments.find((segment) => segment.kind === 'window')+ if (!firstWindowSegment) {+ return 0+ }+ const renderability = seekRenderability(firstWindowSegment.startTimestamp)+ return renderability.kind === 'clampToFullSnapshot' ? Math.max(0, renderability.timestamp - start) : 0+ },+ ],++ hasLateFullSnapshot: [+ (s) => [s.leadingUnplayableMs],+ (leadingUnplayableMs: number): boolean => leadingUnplayableMs > LATE_FULL_SNAPSHOT_THRESHOLD_MS,+ ],+debugSnapshots: [(s) => [s.sessionPlayerData, s.debugSettings],(sessionPlayerData: SessionPlayerData, debugSettings): eventWithTime[] => {