: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): don't show terminal error for recent still-ingesting recordings (#65061)
posthog[bot]eb15ad91b106
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsxindex 63159b886a89..85f2aaf76da0 100644--- a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx@@ -69,7 +69,8 @@ const PlayerFrameOverlayActions = (): JSX.Element | null => {}const PlayerFrameOverlayContent = (): JSX.Element | null => {- const { currentPlayerState, endReached, logicProps, playerError } = useValues(sessionRecordingPlayerLogic)+ const { currentPlayerState, endReached, logicProps, playerError, isWaitingForIngestion } =+ useValues(sessionRecordingPlayerLogic)const { setPlay } = useActions(sessionRecordingPlayerLogic)const handlePlay = (e: MouseEvent): void => {@@ -120,7 +121,14 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {)}if (currentPlayerState === SessionPlayerState.BUFFER) {- content = (+ content = isWaitingForIngestion ? (+ <div className="SessionRecordingPlayer--buffering flex flex-col items-center gap-1 text-center text-white">+ <div className="text-3xl italic font-medium">Still processing…</div>+ <div className="text-sm max-w-100">+ This recording is finishing ingestion. It's usually ready to play within a few minutes.+ </div>+ </div>+ ) : (<div className="SessionRecordingPlayer--buffering text-3xl italic font-medium text-white">Buffering…</div>)}diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.tsindex 0c8c7025047b..e2863b5c27ce 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts@@ -43,6 +43,18 @@ export interface SessionRecordingDataCoordinatorLogicProps {accessToken?: string}+// For a short window after a recording starts it may still be ingesting, so a missing full+// snapshot is not yet definitive — late data (including the initial full snapshot) can still+// arrive. Past this grace period a missing full snapshot means the data never reached PostHog.+// NB: this clock is anchored on recording start, whereas snapshotDataLogic's+// POLLING_INACTIVITY_TIMEOUT_MS is anchored on the last source change — they both happen to be+// ~5 minutes but measure from different events, so tune them together, not in isolation.+export const INGESTION_GRACE_PERIOD_MINUTES = 5++export function isWithinIngestionGracePeriod(start: Dayjs | null): boolean {+ return start != null && now().diff(start, 'minute') <= INGESTION_GRACE_PERIOD_MINUTES+}+export const sessionRecordingDataCoordinatorLogic = kea<sessionRecordingDataCoordinatorLogicType>([path((key) => ['scenes', 'session-recordings', 'sessionRecordingDataCoordinatorLogic', key]),props({} as SessionRecordingDataCoordinatorLogicProps),@@ -442,8 +454,7 @@ export const sessionRecordingDataCoordinatorLogic = kea<sessionRecordingDataCoorisRecentAndInvalid: [(s) => [s.start, s.snapshotsInvalid],(start, snapshotsInvalid) => {- const lessThanFiveMinutesOld = dayjs().diff(start, 'minute') <= 5- return snapshotsInvalid && lessThanFiveMinutesOld+ return snapshotsInvalid && isWithinIngestionGracePeriod(start)},],diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.tsindex 7a26da1bc5a7..143f9bab24ee 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts@@ -6,6 +6,7 @@ import { EventType, IncrementalSource, eventWithTime } from 'posthog-js/rrweb-tyimport { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { playerSettingsLogic } from 'scenes/session-recordings/player/playerSettingsLogic'import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'+import * as sessionRecordingDataCoordinatorLogicModule from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'import {sessionRecordingPlayerLogic,SessionRecordingPlayerMode,@@ -564,6 +565,70 @@ describe('sessionRecordingPlayerLogic', () => {expect(logic.values.currentTimestamp).toBe(START + 61500)})+ // Same fully-loaded, no-full-snapshot-anywhere data as the "errors when fully loaded"+ // case above. Both sides of the ingestion grace boundary: while within it the missing+ // FullSnapshot may still arrive, so the seek buffers (and keeps loading sources) instead+ // of the terminal error; once past it the missing data is definitive and the seek errors.+ it.each([+ {+ description: 'buffers and keeps polling while a recent recording is still ingesting',+ withinGracePeriod: true,+ expectedError: null,+ expectedBuffering: true,+ expectedWaitingForIngestion: true,+ },+ {+ description: 'errors once the ingestion grace period has elapsed',+ withinGracePeriod: false,+ expectedError: 'noPlayableFullSnapshot',+ expectedBuffering: false,+ expectedWaitingForIngestion: false,+ },+ ])('$description', ({ withinGracePeriod, expectedError, expectedBuffering, expectedWaitingForIngestion }) => {+ const graceSpy = jest+ .spyOn(sessionRecordingDataCoordinatorLogicModule, 'isWithinIngestionGracePeriod')+ .mockReturnValue(withinGracePeriod)+ try {+ seedRecording([inc(START), inc(START + 1000)], [inc(START + 61000), inc(START + 62000)])+ logic.actions.setPause()++ logic.actions.seekToTimestamp(START + 61500)++ expect(logic.values.playerError).toBe(expectedError)+ expect(logic.values.isBuffering).toBe(expectedBuffering)+ expect(logic.values.isWaitingForIngestion).toBe(expectedWaitingForIngestion)+ expect(logic.values.currentTimestamp).toBe(START + 61500)+ } finally {+ graceSpy.mockRestore()+ }+ })++ it('flips a stuck still-ingesting recording to the terminal error once grace lapses', () => {+ // The afterMount BUFFERING_REEVALUATION_INTERVAL_MS interval re-runs checkBufferingCompleted;+ // this asserts that payload directly (no timer): a recording buffering on waitingForIngestion+ // transitions to the terminal error the next time checkBufferingCompleted runs after the grace+ // period has elapsed — without any new snapshot data arriving.+ const graceSpy = jest+ .spyOn(sessionRecordingDataCoordinatorLogicModule, 'isWithinIngestionGracePeriod')+ .mockReturnValue(true)+ try {+ seedRecording([inc(START), inc(START + 1000)], [inc(START + 61000), inc(START + 62000)])+ logic.actions.setPause()+ logic.actions.seekToTimestamp(START + 61500)+ expect(logic.values.isBuffering).toBe(true)+ expect(logic.values.playerError).toBeNull()++ // grace lapses, no new data arrives — the periodic nudge re-reads the now-definitive+ // verdict and surfaces the terminal error+ graceSpy.mockReturnValue(false)+ logic.actions.checkBufferingCompleted()++ expect(logic.values.playerError).toBe('noPlayableFullSnapshot')+ } finally {+ graceSpy.mockRestore()+ }+ })+it.each([{description: 'reports the leading unplayable span when the initial full snapshot is late',diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.tsindex a2d38fe1a27c..9c75a3fb57c2 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts@@ -43,6 +43,7 @@ import { ReplayIframeData } from 'scenes/heatmaps/components/heatmapsBrowserLogiimport { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'import { playerCommentModel } from 'scenes/session-recordings/player/commenting/playerCommentModel'import {+ isWithinIngestionGracePeriod,SessionRecordingDataCoordinatorLogicProps,sessionRecordingDataCoordinatorLogic,} from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'@@ -158,6 +159,17 @@ const MIN_CLAMPABLE_DEAD_ZONE_MS = 1000// marker); below it the dead-zone clamp handles things silently and a warning would be noiseconst LATE_FULL_SNAPSHOT_THRESHOLD_MS = 20000+// While buffering on a still-ingesting recording we may receive no new events to re-trigger a+// verdict re-evaluation: source polling can back off, and the grace check reads wall-clock time,+// which isn't reactive. Re-run checkBufferingCompleted on this cadence so a recording stuck+// buffering past the ingestion grace period still transitions to the terminal error rather than+// sitting on "Still processing…" forever. A tick is inert unless buffering has genuinely+// completed: checkBufferingCompleted early-returns when not buffering, and while still+// legitimately buffering it only ends buffering on a definitive verdict — so a mid-buffer tick+// never yanks the playhead. Cheap either way. The cadence is a deliberate safety-net interval,+// not a tuned value: worst case is ~2 min of "Still processing…" after grace has already lapsed.+const BUFFERING_REEVALUATION_INTERVAL_MS = 120000+export type SeekRenderability =// a FullSnapshot exists at or before the timestamp for its window| { kind: 'renderable' }@@ -166,10 +178,22 @@ export type SeekRenderability =| { kind: 'clampToFullSnapshot'; timestamp: number }// not determinable yet — data that could contain a FullSnapshot is still loading| { kind: 'waitingForData' }+ // everything currently loaded lacks a FullSnapshot, but the recording is still inside+ // the ingestion grace period — a late FullSnapshot may yet arrive, so keep buffering+ // and polling rather than declaring the seek unplayable+ | { kind: 'waitingForIngestion' }// everything is loaded and no FullSnapshot exists anywhere at or after the// timestamp — playback there can never work| { kind: 'unplayable' }+// Non-definitive verdicts where more data could still make the position renderable — playback+// should buffer and keep polling rather than play or error. Centralized so the buffer-entry+// (seekToTimestamp) and buffer-exit (checkBufferingCompleted) checks can't drift if a new+// still-loading kind is added.+export function isAwaitingMoreData(renderability: SeekRenderability): boolean {+ return renderability.kind === 'waitingForData' || renderability.kind === 'waitingForIngestion'+}+// weights should add up to 1const smoothingWeights = [0.07,@@ -1095,11 +1119,12 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(// how playback can recover (e.g. when the initial full snapshot was lost at// capture time, the recording is only playable from a later FullSnapshot).seekRenderability: [- (s) => [s.segmentForTimestamp, s.snapshotStore, s.allSourcesLoaded],+ (s) => [s.segmentForTimestamp, s.snapshotStore, s.allSourcesLoaded, s.sessionPlayerData],(segmentForTimestamp: (timestamp?: number) => RecordingSegment | null,snapshotStore: SnapshotStore,- allSourcesLoaded: boolean+ allSourcesLoaded: boolean,+ sessionPlayerData: SessionPlayerData) => {return (timestamp: number): SeekRenderability => {const segment = segmentForTimestamp(timestamp)@@ -1132,7 +1157,15 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(? { kind: 'renderable' }: { kind: 'clampToFullSnapshot', timestamp: recoveryTarget.timestamp }}- return allSourcesLoaded ? { kind: 'unplayable' } : { kind: 'waitingForData' }+ if (!allSourcesLoaded) {+ return { kind: 'waitingForData' }+ }+ // No FullSnapshot anywhere, everything loaded. Only definitive once the+ // ingestion grace period has passed — until then a late FullSnapshot may+ // still arrive, so keep buffering rather than showing a terminal error.+ return isWithinIngestionGracePeriod(sessionPlayerData.start)+ ? { kind: 'waitingForIngestion' }+ : { kind: 'unplayable' }}},],@@ -1168,6 +1201,25 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>((leadingUnplayableMs: number): boolean => leadingUnplayableMs > LATE_FULL_SNAPSHOT_THRESHOLD_MS,],+ // True while the player is buffering on a position whose FullSnapshot hasn't been+ // ingested yet but still might be (within the grace period). Lets the overlay show a+ // "still processing" message instead of the generic "Buffering…".+ // The grace check reads wall-clock `now()` at call time, so this value is intentionally+ // stale between recomputes — it only re-derives when seekRenderability/currentTimestamp+ // change, not when the grace period elapses. That's fine: it only drives the overlay+ // message, and the buffer machinery (seekToTimestamp, checkBufferingCompleted) re-reads+ // seekRenderability fresh at event time, so the actual ERROR transition isn't gated on it.+ // The afterMount BUFFERING_REEVALUATION_INTERVAL_MS nudge guarantees that re-read happens+ // even when no events fire, so a stuck-buffering recording still flips once grace lapses.+ isWaitingForIngestion: [+ (s) => [s.seekRenderability, s.currentTimestamp],+ (+ seekRenderability: (timestamp: number) => SeekRenderability,+ currentTimestamp: number | undefined+ ): boolean =>+ currentTimestamp != null && seekRenderability(currentTimestamp).kind === 'waitingForIngestion',+ ],+debugSnapshots: [(s) => [s.sessionPlayerData, s.debugSettings],(sessionPlayerData: SessionPlayerData, debugSettings): eventWithTime[] => {@@ -1623,9 +1675,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(renderability.kind === 'clampToFullSnapshot' || renderability.kind === 'unplayable'const stillBuffering =!hasDefinitiveVerdict &&- (isBufferingSegment ||- values.isWaitingForPlayableFullSnapshot ||- renderability.kind === 'waitingForData')+ (isBufferingSegment || values.isWaitingForPlayableFullSnapshot || isAwaitingMoreData(renderability))if (!stillBuffering) {actions.endBuffer()@@ -1883,10 +1933,13 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(// If next time is greater than last buffered time, set to buffering.// Also buffer while we can't yet tell whether this position has a// FullSnapshot to render from — playing would freeze on a blank frame.+ // `waitingForIngestion` lands here too: a recent recording missing its+ // FullSnapshot is still ingesting, so buffer and keep polling for late+ // sources rather than showing the terminal error.else if (segment?.kind === 'buffer' ||values.isWaitingForPlayableFullSnapshot ||- renderability.kind === 'waitingForData'+ isAwaitingMoreData(renderability)) {values.player?.replayer?.pause()actions.startBuffer()@@ -2507,6 +2560,15 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(return () => document.removeEventListener('fullscreenchange', fullScreenListener)}, 'fullscreenListener')+ // Safety net: re-evaluate the buffering verdict at least this often. A recording stuck+ // buffering on a still-ingesting position (waitingForIngestion) flips to the terminal+ // error once the grace period lapses — but only on a re-read of seekRenderability, which+ // otherwise happens solely on incoming events. Paused on hidden tabs by the plugin.+ cache.disposables.add(() => {+ const intervalId = setInterval(() => actions.checkBufferingCompleted(), BUFFERING_REEVALUATION_INTERVAL_MS)+ return () => clearInterval(intervalId)+ }, 'bufferingReevaluation')+if (props.sessionRecordingId) {actions.loadRecordingData()}