Skip to content

: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.

fix(replay): stop unauthorized snapshot sources from buffering forever (#78240)

posthog[bot]b16e7214dec0
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
index 85f2aaf76da0..c9ba03d0cad8 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
@@ -9,6 +9,7 @@ import { IconSkipBackward } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { cn } from 'lib/utils/css-classes'
import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
+import { urls } from 'scenes/urls'
import { getCurrentExporterData } from '~/exporter/exporterViewLogic'
import { SessionPlayerState } from '~/types'
@@ -87,6 +88,7 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {
if (currentPlayerState === SessionPlayerState.ERROR) {
const isMissingFullSnapshot = playerError === 'noPlayableFullSnapshot'
+ const isUnauthorized = playerError === 'snapshotUnauthorized'
content = (
<div className="flex flex-col justify-center items-center p-6 bg-surface-primary rounded m-6 gap-2 max-w-120 shadow-sm">
<IconWarning className="text-danger text-5xl" />
@@ -94,9 +96,16 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {
<div className="text-secondary text-sm text-center">
{isMissingFullSnapshot
? 'This part of the recording is missing the snapshot data needed to render it. The data never reached PostHog, usually because the browser was closed or went offline before the recording finished uploading.'
- : 'An error occurred that is preventing this recording from being played. You can refresh the page to reload the recording.'}
+ : isUnauthorized
+ ? 'Your session has expired. Sign in again to keep watching this recording.'
+ : 'An error occurred that is preventing this recording from being played. You can refresh the page to reload the recording.'}
</div>
- {!isMissingFullSnapshot && (
+ {isUnauthorized && (
+ <LemonButton to={urls.login()} type="primary" fullWidth center>
+ Sign in
+ </LemonButton>
+ )}
+ {!isMissingFullSnapshot && !isUnauthorized && (
<LemonButton
onClick={() => {
window.location.reload()
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
index ce3da9eb7b9d..9481a1ccc718 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
@@ -538,6 +538,7 @@ export interface sessionRecordingPlayerLogicValues {
url: string
}[] // sessionRecordingDataCoordinatorLogic
allSourcesLoaded: boolean // snapshotDataLogic
+ isSnapshotUnauthorized: boolean // snapshotDataLogic
snapshotSources: SessionRecordingSnapshotSource[] | null // snapshotDataLogic
snapshotStore: SnapshotStore // snapshotDataLogic
snapshotsLoaded: boolean // snapshotDataLogic
@@ -1130,6 +1131,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
'snapshotStore',
'allSourcesLoaded',
'storeVersion',
+ 'isSnapshotUnauthorized',
],
sessionRecordingDataCoordinatorLogic(props),
[
@@ -2538,20 +2540,26 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
loadSnapshotsForSourceFailure: () => {
if (Object.keys(values.sessionPlayerData.snapshotsByWindowId).length === 0) {
console.error('PostHog Recording Playback Error: No snapshots loaded')
- actions.setPlayerError('loadSnapshotsForSourceFailure')
+ actions.setPlayerError(
+ values.isSnapshotUnauthorized ? 'snapshotUnauthorized' : 'loadSnapshotsForSourceFailure'
+ )
}
},
loadSnapshotSourcesFailure: () => {
if (Object.keys(values.sessionPlayerData.snapshotsByWindowId).length === 0) {
console.error('PostHog Recording Playback Error: No snapshots loaded')
- actions.setPlayerError('loadSnapshotSourcesFailure')
+ actions.setPlayerError(
+ values.isSnapshotUnauthorized ? 'snapshotUnauthorized' : 'loadSnapshotSourcesFailure'
+ )
}
},
// Both are terminal give-ups: unlike the per-attempt failures above they fire even when other
// data already loaded, because the missing range would otherwise buffer forever with no error.
snapshotSourceLoadExhausted: () => {
console.error('PostHog Recording Playback Error: A snapshot source repeatedly failed to load')
- actions.setPlayerError('snapshotSourceLoadExhausted')
+ actions.setPlayerError(
+ values.isSnapshotUnauthorized ? 'snapshotUnauthorized' : 'snapshotSourceLoadExhausted'
+ )
},
snapshotProcessingFailed: () => {
console.error('PostHog Recording Playback Error: Snapshot processing repeatedly failed')
diff --git a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
index 8af959e2e2b2..02521cf24eac 100644
--- a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
@@ -3,7 +3,7 @@ import { EventType, IncrementalSource, NodeType, mutationData } from 'posthog-js
import { chunkMutationSnapshot, MUTATION_CHUNK_SIZE } from '@posthog/replay-shared'
-import { RecordingDeletedError } from 'lib/api'
+import { ApiError, RecordingDeletedError } from 'lib/api'
import { encodedWebSnapshotData } from 'scenes/session-recordings/player/__mocks__/encoded-snapshot-data'
import { parseEncodedSnapshots } from 'scenes/session-recordings/player/snapshot-processing/process-all-snapshots'
@@ -84,6 +84,41 @@ describe('snapshotDataLogic', () => {
}).toDispatchActions(['snapshotSourceLoadExhausted'])
consoleError.mockRestore()
})
+
+ it('does not grant a permanently-unauthorized source a fresh retry budget on a new seek target', async () => {
+ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
+ const error = new ApiError('Unauthorized', 401)
+ logic.actions.loadSnapshotsForSourceFailure('Unauthorized', error)
+ logic.actions.loadSnapshotsForSourceFailure('Unauthorized', error)
+ logic.actions.loadSnapshotsForSourceFailure('Unauthorized', error)
+
+ // Seeking to a genuinely new target would normally reset the retry budget, letting a
+ // permanently-failing 401 source buffer forever instead of ever reaching the cap.
+ logic.actions.setTargetTimestamp(123456, 1)
+
+ await expectLogic(logic, () => {
+ logic.actions.loadSnapshotsForSourceFailure('Unauthorized', error)
+ }).toDispatchActions(['snapshotSourceLoadExhausted'])
+ consoleError.mockRestore()
+ })
+ })
+
+ describe('isSnapshotUnauthorized', () => {
+ it('is false when no error', () => {
+ expect(logic.values.isSnapshotUnauthorized).toBe(false)
+ })
+
+ it('is true for a 401', () => {
+ logic.actions.loadSnapshotsForSourceFailure('Unauthorized', new ApiError('Unauthorized', 401))
+
+ expect(logic.values.isSnapshotUnauthorized).toBe(true)
+ })
+
+ it('is false for a non-401 error', () => {
+ logic.actions.loadSnapshotsForSourceFailure('Forbidden', new ApiError('Forbidden', 403))
+
+ expect(logic.values.isSnapshotUnauthorized).toBe(false)
+ })
})
describe('snapshot parsing', () => {
diff --git a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
index 1ef512ef2720..961c46f5e95f 100644
--- a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
+++ b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
@@ -20,7 +20,7 @@ import posthog from 'posthog-js'
import { keyForSource } from '@posthog/replay-shared'
import { SnapshotSourceType, SnapshotStore, SourceLoadingState } from '@posthog/replay-shared'
-import api, { RecordingDeletedError } from 'lib/api'
+import api, { ApiError, RecordingDeletedError } from 'lib/api'
import 'lib/dayjs'
import { parseEncodedSnapshots } from 'scenes/session-recordings/player/snapshot-processing/process-all-snapshots'
import { windowIdRegistryLogic } from 'scenes/session-recordings/player/windowIdRegistryLogic'
@@ -54,6 +54,7 @@ export interface snapshotDataLogicValues {
isLoadingSnapshots: boolean
isPolling: boolean
isRecordingDeleted: boolean
+ isSnapshotUnauthorized: boolean
loadAllMode: boolean
loadingSources: Pick<SessionRecordingSnapshotSource, 'blob_key' | 'end_timestamp' | 'source' | 'start_timestamp'>[]
pollingInterval: number
@@ -219,6 +220,7 @@ export interface snapshotDataLogicMeta {
isRecordingDeleted: (snapshotLoadError: Error | null) => boolean
recordingDeletedAt: (snapshotLoadError: Error | null) => number | null
recordingDeletedBy: (snapshotLoadError: Error | null) => string | null
+ isSnapshotUnauthorized: (snapshotLoadError: Error | null) => boolean
}
}
@@ -436,8 +438,11 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
cache.playbackPosition = timestamp
cache.playbackWindowId = windowId
const previousTarget = selectors.seekTarget(previousState)
- if (previousTarget?.timestamp !== timestamp || previousTarget?.windowId !== windowId) {
- // A genuinely new target grants fresh retries after the permanent-failure cap.
+ const targetChanged = previousTarget?.timestamp !== timestamp || previousTarget?.windowId !== windowId
+ // A genuinely new target grants fresh retries after the permanent-failure cap, unless the
+ // failure is a 401. Reseeking can never fix that, so it must keep counting toward the cap,
+ // otherwise a permanently-unauthorized source buffers forever.
+ if (targetChanged && !values.isSnapshotUnauthorized) {
cache.loadFailureCount = 0
}
actions.loadNextSnapshotSource()
@@ -728,6 +733,15 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
return null
},
],
+
+ // A missing session doesn't resolve by retrying, so a source failing this way should
+ // never be handed a fresh retry budget.
+ isSnapshotUnauthorized: [
+ (s) => [s.snapshotLoadError],
+ (snapshotLoadError: Error | null): boolean => {
+ return snapshotLoadError instanceof ApiError && snapshotLoadError.status === 401
+ },
+ ],
})),
afterMount(({ actions, cache }) => {
cache.playerActive = true