: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): handle count-query failures on "what to watch" tab (#61191)
posthog[bot]6f1f5fddf823
diff --git a/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsx b/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsxindex f14921d86bac..0f8f7de65ead 100644--- a/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsx+++ b/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsx@@ -11,7 +11,9 @@ import { urls } from 'scenes/urls'import { FilterLogicalOperator, PropertyFilterType, PropertyOperator, ReplayTabs } from '~/types'export const ReplayActiveScreensTable = (): JSX.Element => {- const { countedScreens, countedScreensLoading } = useValues(replayActiveScreensTableLogic({ scene: 'templates' }))+ const { countedScreens, countedScreensLoading, countedScreensError } = useValues(+ replayActiveScreensTableLogic({ scene: 'templates' })+ )return (<div className="flex flex-col border rounded bg-surface-primary w-full px-4 py-2">@@ -36,6 +38,11 @@ export const ReplayActiveScreensTable = (): JSX.Element => {]}dataSource={countedScreens || []}loading={countedScreensLoading}+ emptyState={+ countedScreensError+ ? "Couldn't load most active pages right now. Please try again later."+ : undefined+ }onRow={(record) => {return {className: 'cursor-pointer hover:bg-surface-secondary',diff --git a/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsx b/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsxindex ae950298553e..e8aba32d1d9a 100644--- a/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsx+++ b/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsx@@ -13,7 +13,9 @@ import { PersonType } from '~/types'import { replayActiveUsersTableLogic } from './replayActiveUsersTableLogic'export const ReplayActiveUsersTable = (): JSX.Element => {- const { countedUsers, countedUsersLoading } = useValues(replayActiveUsersTableLogic({ scene: 'templates' }))+ const { countedUsers, countedUsersLoading, countedUsersError } = useValues(+ replayActiveUsersTableLogic({ scene: 'templates' })+ )return (<div className="flex flex-col border rounded bg-surface-primary w-full px-4 py-2">@@ -38,6 +40,9 @@ export const ReplayActiveUsersTable = (): JSX.Element => {]}dataSource={countedUsers || []}loading={countedUsersLoading}+ emptyState={+ countedUsersError ? "Couldn't load most active users right now. Please try again later." : undefined+ }onRow={(record) => {return {className: 'cursor-pointer hover:bg-surface-secondary',diff --git a/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.ts b/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.tsindex e660a81fec5f..77437de711d6 100644--- a/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.ts+++ b/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.ts@@ -1,4 +1,4 @@-import { defaults, kea, key, path, props } from 'kea'+import { actions, defaults, isBreakpoint, kea, key, path, props, reducers } from 'kea'import { lazyLoaders } from 'kea-loaders'import api from 'lib/api'@@ -15,10 +15,21 @@ export const replayActiveScreensTableLogic = kea<replayActiveScreensTableLogicTypath(['scenes', 'session-recordings', 'components', 'replayActiveScreensTableLogic']),props({} as ReplayActiveScreensTableLogicProps),key((props) => props.scene || 'default'),+ actions({+ setCountedScreensError: (hasError: boolean) => ({ hasError }),+ }),defaults({countedScreens: [] as { screen: string; count: number }[],}),- lazyLoaders(() => ({+ reducers({+ countedScreensError: [+ false,+ {+ setCountedScreensError: (_, { hasError }) => hasError,+ },+ ],+ }),+ lazyLoaders(({ actions }) => ({countedScreens: {loadCountedScreens: async (_, breakpoint): Promise<{ screen: string; count: number }[]> => {const q = hogql`@@ -40,16 +51,28 @@ export const replayActiveScreensTableLogic = kea<replayActiveScreensTableLogicTyLIMIT 10`- const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })+ try {+ const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })- breakpoint()+ breakpoint()- return (qResponse.results || []).map((row) => {- return {- screen: row[0] as string,- count: row[1] as number,+ actions.setCountedScreensError(false)+ return (qResponse.results || []).map((row) => {+ return {+ screen: row[0] as string,+ count: row[1] as number,+ }+ }) as { screen: string; count: number }[]+ } catch (e: any) {+ // a breakpoint cancellation means a newer load superseded this one, let it propagate+ if (isBreakpoint(e)) {+ throw e}- }) as { screen: string; count: number }[]+ // the count query can time out or be rejected when ClickHouse is busy,+ // degrade to an empty/error state rather than an uncaught exception+ actions.setCountedScreensError(true)+ return []+ }},},})),diff --git a/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.ts b/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.tsindex 541a616b61d5..3145d8343ba6 100644--- a/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.ts+++ b/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.ts@@ -1,4 +1,4 @@-import { defaults, kea, key, path, props } from 'kea'+import { actions, defaults, isBreakpoint, kea, key, path, props, reducers } from 'kea'import { lazyLoaders } from 'kea-loaders'import api from 'lib/api'@@ -16,10 +16,21 @@ export const replayActiveUsersTableLogic = kea<replayActiveUsersTableLogicType>(path(['scenes', 'session-recordings', 'components', 'replayActiveUsersTableLogic']),props({} as ReplayActiveUsersTableLogicProps),key((props) => props.scene || 'default'),+ actions({+ setCountedUsersError: (hasError: boolean) => ({ hasError }),+ }),defaults({countedUsers: [] as { person: PersonType; count: number }[],}),- lazyLoaders(() => ({+ reducers({+ countedUsersError: [+ false,+ {+ setCountedUsersError: (_, { hasError }) => hasError,+ },+ ],+ }),+ lazyLoaders(({ actions }) => ({countedUsers: {loadCountedUsers: async (_, breakpoint): Promise<{ person: PersonType; count: number }[]> => {const q = hogql`@@ -67,16 +78,29 @@ export const replayActiveUsersTableLogic = kea<replayActiveUsersTableLogicType>(LIMIT 10`- const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })+ try {+ const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })- breakpoint()+ breakpoint()- return (qResponse.results || []).map((row) => {- return {- person: { id: row[0] as string, properties: JSON.parse(row[1]) as Record<string, any> },- count: row[2] as number,+ actions.setCountedUsersError(false)+ return (qResponse.results || []).map((row) => {+ return {+ person: { id: row[0] as string, properties: JSON.parse(row[1]) as Record<string, any> },+ count: row[2] as number,+ }+ }) as { person: PersonType; count: number }[]+ } catch (e: any) {+ // a breakpoint cancellation means a newer load superseded this one, let it propagate+ if (isBreakpoint(e)) {+ throw e}- }) as { person: PersonType; count: number }[]+ // this is the heaviest of the "what to watch" count queries and the most likely to+ // time out or be rejected under load, degrade to an empty/error state rather than+ // an uncaught exception+ actions.setCountedUsersError(true)+ return []+ }},},})),