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(activity): disable recording btn for non-string session id (#73896)

Xander0d8ed6ba5ae4
diff --git a/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.test.tsx b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.test.tsx
new file mode 100644
index 000000000000..ba846236bac4
--- /dev/null
+++ b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.test.tsx
@@ -0,0 +1,30 @@
+import { recordingDisabledReason } from './ViewRecordingButton'
+
+describe('recordingDisabledReason', () => {
+ // Malformed SDK payloads can send $session_id as a non-string (dict/array/number). Such a value
+ // can't address a recording; without this guard the button stays enabled and links to
+ // /replay/[object Object]. See the events-query non-string $session_id fix.
+ it.each([
+ ['object', { bytes: { 0: 1 } }],
+ ['array', [1, 2, 3]],
+ ['number', 12345],
+ ])('disables with "No recording for this event" when $session_id is a %s', (_label, sessionId) => {
+ expect(recordingDisabledReason(sessionId as unknown as string, undefined, undefined)).toBe(
+ 'No recording for this event'
+ )
+ })
+
+ it('does not disable for a valid string session id with a recording', () => {
+ expect(recordingDisabledReason('0190-good-session', undefined, true)).toBeNull()
+ })
+
+ it('disables when the server reports no recording exists', () => {
+ expect(recordingDisabledReason('0190-good-session', undefined, false)).toBe('No recording for this event')
+ })
+
+ it('prompts to set a session id when it is genuinely absent', () => {
+ // Absent (not malformed) keeps the existing "no session id" guidance rather than "no recording".
+ expect(recordingDisabledReason(undefined, undefined, undefined)).not.toBeNull()
+ expect(typeof recordingDisabledReason(undefined, undefined, undefined)).not.toBe('string')
+ })
+})
diff --git a/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
index 86463c362acc..3de9478f866d 100644
--- a/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
+++ b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
@@ -78,6 +78,11 @@ export default function ViewRecordingButton({
noPadding = false,
...props
}: ViewRecordingButtonProps): JSX.Element {
+ // $session_id arrives from untyped event properties and can be a non-string (e.g. a malformed
+ // object from a broken SDK). Only a real string addresses a recording, so the raw value goes to
+ // the disabled-reason check while URL and key uses are gated on this validity flag.
+ const isValidSessionId = typeof sessionId === 'string' && sessionId !== ''
+
const { featureFlags } = useValues(featureFlagLogic)
const summaryFlagEnabled = !!featureFlags[FEATURE_FLAGS.REPLAY_VIDEO_BASED_SUMMARIZATION]
const summaryOutcomeEnabled = checkSummaryOutcome && summaryFlagEnabled
@@ -88,15 +93,15 @@ export default function ViewRecordingButton({
const { getRecordingExists, getSummaryOutcome } = useValues(sessionRecordingInfoLogic)
useEffect(() => {
- if (!sessionId) {
+ if (!isValidSessionId) {
return
}
if (checkRecordingExists || shouldFetchSummaryOutcome) {
checkRecordingInfo(sessionId, { includeOutcome: shouldFetchSummaryOutcome })
}
- }, [checkRecordingExists, shouldFetchSummaryOutcome, sessionId, checkRecordingInfo])
+ }, [checkRecordingExists, shouldFetchSummaryOutcome, isValidSessionId, sessionId, checkRecordingInfo])
- if (hasRecording === undefined && checkRecordingExists && sessionId) {
+ if (hasRecording === undefined && checkRecordingExists && isValidSessionId) {
hasRecording = getRecordingExists(sessionId)
}
@@ -113,8 +118,9 @@ export default function ViewRecordingButton({
// Outcome precedence: live progress beats parent-supplied prop beats persisted fetch.
// Live is freshest mid-summarisation; the prop is a parent-list short-circuit; persisted is the kea-cached fallback.
- const liveOutcome = summaryOutcomeEnabled && sessionId ? summaryBySessionId[sessionId]?.session_outcome : null
- const persistedOutcome = shouldFetchSummaryOutcome && sessionId ? getSummaryOutcome(sessionId) : null
+ const liveOutcome =
+ summaryOutcomeEnabled && isValidSessionId ? summaryBySessionId[sessionId]?.session_outcome : null
+ const persistedOutcome = shouldFetchSummaryOutcome && isValidSessionId ? getSummaryOutcome(sessionId) : null
const isInteractive = !disabledReason && !props.loading
const outcomeTooltip =
summaryOutcomeEnabled && isInteractive
@@ -122,9 +128,11 @@ export default function ViewRecordingButton({
: undefined
const { recordingViewed, recordingViewedLoading } = useValues(
- sessionRecordingViewedLogic({ sessionRecordingId: sessionId ?? '' })
+ sessionRecordingViewedLogic({ sessionRecordingId: isValidSessionId ? sessionId : '' })
+ )
+ const { loadRecordingViewed } = useActions(
+ sessionRecordingViewedLogic({ sessionRecordingId: isValidSessionId ? sessionId : '' })
)
- const { loadRecordingViewed } = useActions(sessionRecordingViewedLogic({ sessionRecordingId: sessionId ?? '' }))
useEffect(() => {
if (checkIfViewed && loadRecordingViewed) {
@@ -230,13 +238,17 @@ export default function ViewRecordingButton({
}
export const recordingDisabledReason = (
- sessionId: string | undefined,
+ sessionId: unknown,
recordingStatus: string | undefined,
hasRecording?: boolean
): JSX.Element | string | null => {
- if (!sessionId && hasRecording === false) {
+ if (sessionId != null && typeof sessionId !== 'string') {
return 'No recording for this event'
- } else if (!sessionId) {
+ }
+ const isValidSessionId = typeof sessionId === 'string' && sessionId !== ''
+ if (!isValidSessionId && hasRecording === false) {
+ return 'No recording for this event'
+ } else if (!isValidSessionId) {
return (
<>
No session ID associated with this event.{' '}
@@ -294,8 +306,11 @@ export function useRecordingButton({
disabledReason: JSX.Element | string | null
warningReason: string | undefined
} {
+ const isValidSessionId = typeof sessionId === 'string' && sessionId !== ''
const { openSessionPlayer } = useActions(sessionPlayerModalLogic)
- const { userClickedThrough } = useActions(sessionRecordingViewedLogic({ sessionRecordingId: sessionId ?? '' }))
+ const { userClickedThrough } = useActions(
+ sessionRecordingViewedLogic({ sessionRecordingId: isValidSessionId ? sessionId : '' })
+ )
const onClick = (): void => {
userClickedThrough()
@@ -303,13 +318,13 @@ export function useRecordingButton({
const fiveSecondsBeforeEvent = timestamp ? dayjs(timestamp).valueOf() - 5000 : 0
openSessionPlayer(
- { id: sessionId ?? '', matching_events: matchingEvents ?? undefined },
+ { id: isValidSessionId ? sessionId : '', matching_events: matchingEvents ?? undefined },
Math.max(fiveSecondsBeforeEvent, 0)
)
} else {
const timestampMs = timestamp ? dayjs(timestamp).valueOf() - 5000 : undefined
const urlParams = timestampMs ? { unixTimestampMillis: Math.max(timestampMs, 0) } : undefined
- newInternalTab(urls.replaySingle(sessionId ?? '', urlParams))
+ newInternalTab(urls.replaySingle(isValidSessionId ? sessionId : '', urlParams))
}
}