: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(experiments): hide idle recalculation status and 0/0 rows flash (#72119)
Rodrigo Iloro4e66be35a1f4
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsxindex 49ee216ce36e..9f98ef84ef0b 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx@@ -90,11 +90,7 @@ const MetricsTab = (): JSX.Element => {<MultiVariantBiasWarning /></div>- {showRecalculationStatus && (- <div className="mb-2">- <RecalculationStatus experiment={experiment} />- </div>- )}+ {showRecalculationStatus && <RecalculationStatus experiment={experiment} />}{/* Modern metrics view */}{!hasMetrics ? (diff --git a/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx b/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsxindex e17bd8655cac..b3de78f85dc8 100644--- a/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx+++ b/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx@@ -4,10 +4,8 @@ import { IconBell, IconCheck, IconInfo } from '@posthog/icons'import { LemonButton, Tooltip } from '@posthog/lemon-ui'import { useAnimatedNumber } from '@posthog/quill-charts'-import { LemonDivider } from 'lib/lemon-ui/LemonDivider'import { Spinner } from 'lib/lemon-ui/Spinner'import { humanFriendlyNumber } from 'lib/utils/numbers'-import { ExperimentLastRefreshText } from 'scenes/experiments/ExperimentView/ExperimentReloadAction'import { experimentMetricsLogic } from '~/scenes/experiments/experimentMetricsLogic'import { experimentResultsNotificationLogic } from '~/scenes/experiments/experimentResultsNotificationLogic'@@ -16,80 +14,47 @@ import { Experiment } from '~/types'import type { ExperimentMetricsRecalculationApi } from 'products/experiments/frontend/generated/api.schemas'/**- * Always-on status line for the recalculation flow. Renders exactly one state from- * `recalculationDisplayState`; the in-flight states read live ClickHouse progress off the poll.- * Only rendered behind EXPERIMENTS_METRICS_RECALCULATION (see ExperimentView).+ * Status line for an in-flight recalculation. Renders only while a run is actually executing+ * (`cold` / `refreshing`); loading-from-latest and terminal states show nothing — the metric rows+ * carry their own loading and error affordances. Only rendered behind+ * EXPERIMENTS_METRICS_RECALCULATION (see ExperimentView).*/-export function RecalculationStatus({ experiment }: { experiment: Experiment }): JSX.Element {- const { recalculationDisplayState, currentRecalculation, totalMetricsCount } = useValues(+export function RecalculationStatus({ experiment }: { experiment: Experiment }): JSX.Element | null {+ const { recalculationDisplayState, currentRecalculation, liveRowsProgress } = useValues(experimentMetricsLogic({ experiment }))/*** Mounted here rather than inside the in-flight branch so the finish-edge subscription that- * fires the browser notification is still alive when the bar swaps to a terminal state.+ * fires the browser notification is still alive when the bar disappears on the terminal state.*/const notificationLogic = experimentResultsNotificationLogic({ experiment })const { notifyWhenResultsReady } = useValues(notificationLogic)const { subscribeToResultsNotification } = useActions(notificationLogic)- switch (recalculationDisplayState) {- case 'initial':- return (- <StatusBar>- <span className="flex items-center gap-1.5 whitespace-nowrap">- <Spinner textColored className="text-sm text-accent" />- <span className="font-medium">Loading metrics…</span>- </span>- </StatusBar>- )- case 'cold':- case 'refreshing':- return (- <InFlightStatus- recalculation={currentRecalculation}- notifyWhenResultsReady={notifyWhenResultsReady}- onSubscribe={subscribeToResultsNotification}- />- )- case 'partial':- case 'resting':- return (- <StatusBar>- <span className="flex items-center gap-1.5 whitespace-nowrap">- <IconCheck className="text-success text-sm" />- <span className="font-medium">- {totalMetricsCount} {totalMetricsCount === 1 ? 'metric' : 'metrics'}- </span>- {recalculationDisplayState === 'partial' && (- <span className="text-danger font-medium">- · {currentRecalculation?.failed_metrics} failed- </span>- )}- </span>- {currentRecalculation?.completed_at && (- <>- <LemonDivider vertical className="h-3.5 self-center" />- <span className="flex items-center gap-1 whitespace-nowrap text-muted text-xs [&_span]:align-baseline">- <span>Results calculated </span>- <ExperimentLastRefreshText lastRefresh={currentRecalculation.completed_at} />- </span>- </>- )}- </StatusBar>- )+ if (recalculationDisplayState !== 'cold' && recalculationDisplayState !== 'refreshing') {+ return null}+ return (+ <InFlightStatus+ recalculation={currentRecalculation}+ liveRowsProgress={liveRowsProgress}+ notifyWhenResultsReady={notifyWhenResultsReady}+ onSubscribe={subscribeToResultsNotification}+ />+ )}function InFlightStatus({recalculation,+ liveRowsProgress,notifyWhenResultsReady,onSubscribe,}: {recalculation: ExperimentMetricsRecalculationApi | null+ liveRowsProgress: { recalculationId: string; rowsRead: number; estimatedRows: number } | nullnotifyWhenResultsReady: booleanonSubscribe: () => void}): JSX.Element {- const rowsRead = recalculation?.rows_read ?? undefinedconst succeeded = recalculation?.completed_metrics ?? 0const failed = recalculation?.failed_metrics ?? 0const total = recalculation?.total_metrics ?? 0@@ -106,10 +71,10 @@ function InFlightStatus({<Tooltip title="We're computing each metric against the latest data. This runs server-side so you can leave this page; results appear as each metric finishes."><IconInfo className="text-muted text-xs" /></Tooltip>- {rowsRead !== undefined && (+ {liveRowsProgress && liveRowsProgress.recalculationId === recalculation?.id && (<ClimbingRows- rowsRead={rowsRead}- estimatedRows={recalculation?.estimated_rows_total ?? undefined}+ rowsRead={liveRowsProgress.rowsRead}+ estimatedRows={liveRowsProgress.estimatedRows || undefined}/>)}</span>@@ -133,7 +98,7 @@ function InFlightStatus({function StatusBar({ children }: { children: React.ReactNode }): JSX.Element {return (- <div className="flex min-h-8 w-full flex-wrap items-center gap-2.5 rounded border border-primary bg-surface-secondary px-2.5 py-1 text-sm">+ <div className="mb-2 flex min-h-8 w-full flex-wrap items-center gap-2.5 rounded border border-primary bg-surface-secondary px-2.5 py-1 text-sm">{children}</div>)diff --git a/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts b/frontend/src/scenes/experiments/experimentMetricsLogic.test.tsindex 76e967d8b8a8..76af5c6c5824 100644--- a/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts+++ b/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts@@ -11,6 +11,8 @@ import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { Experiment } from '~/types'+import type { ExperimentMetricsRecalculationApi } from 'products/experiments/frontend/generated/api.schemas'+import { experimentMetricsLogic } from './experimentMetricsLogic'jest.mock('@posthog/lemon-ui', () => ({@@ -737,6 +739,40 @@ describe('experimentMetricsLogic', () => {})})+ describe('liveRowsProgress', () => {+ const asRecalc = (obj: Record<string, unknown>): ExperimentMetricsRecalculationApi =>+ obj as unknown as ExperimentMetricsRecalculationApi++ it('retains the last nonzero sample within a run and clears on a new run', () => {+ // Draft experiment: afterMount no-ops, so the reducer can be driven directly.+ const draft = { ...EXPERIMENT, status: undefined, start_date: null, end_date: null } as Experiment+ logic = experimentMetricsLogic({ experiment: draft })+ logic.mount()++ logic.actions.setCurrentRecalculation(+ asRecalc({ ...inProgressRecalculation, rows_read: 500, estimated_rows_total: 1000 })+ )+ expect(logic.values.liveRowsProgress).toEqual({+ recalculationId: 'recalc-2',+ rowsRead: 500,+ estimatedRows: 1000,+ })++ // A poll without a live sample (all-zeros gap) must not wipe the last value — the 0/0 flash.+ logic.actions.setCurrentRecalculation(+ asRecalc({ ...inProgressRecalculation, rows_read: 0, estimated_rows_total: 0 })+ )+ expect(logic.values.liveRowsProgress).toEqual({+ recalculationId: 'recalc-2',+ rowsRead: 500,+ estimatedRows: 1000,+ })++ logic.actions.setCurrentRecalculation(asRecalc({ ...inProgressRecalculation, id: 'recalc-3' }))+ expect(logic.values.liveRowsProgress).toBeNull()+ })+ })+describe('tab focus does not clobber a loaded run', () => {it('does not reload latest on focus once a run is already loaded', async () => {const latestMock = jest.fn(() => [200, completedRecalculation])diff --git a/frontend/src/scenes/experiments/experimentMetricsLogic.ts b/frontend/src/scenes/experiments/experimentMetricsLogic.tsindex 5a2846c30c5d..3e81896ae367 100644--- a/frontend/src/scenes/experiments/experimentMetricsLogic.ts+++ b/frontend/src/scenes/experiments/experimentMetricsLogic.ts@@ -145,6 +145,11 @@ export interface experimentMetricsLogicValues {isMetricRecalculating: (metricUuid: string | undefined) => booleanisRecalculating: booleanlastRefresh: string | null+ liveRowsProgress: {+ estimatedRows: number+ recalculationId: string+ rowsRead: number+ } | nullprimaryMetricsResults: CachedNewExperimentQueryResponse[]primaryMetricsResultsErrors: (unknown | null)[]recalculatingMetricUuids: string[]@@ -332,6 +337,25 @@ export const experimentMetricsLogic = kea<experimentMetricsLogicType>([setRecalculatingMetricUuids: (_, { uuids }) => uuids,},],+ liveRowsProgress: [+ null as { recalculationId: string; rowsRead: number; estimatedRows: number } | null,+ {+ setCurrentRecalculation: (state, { recalculation }) => {+ if (!recalculation) {+ return null+ }+ const rowsRead = recalculation.rows_read ?? 0+ if (rowsRead > 0) {+ return {+ recalculationId: recalculation.id,+ rowsRead,+ estimatedRows: recalculation.estimated_rows_total ?? 0,+ }+ }+ return state?.recalculationId === recalculation.id ? state : null+ },+ },+ ],}),selectors({// True while a recalculation is being fetched or is still running.