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(experiments): don't treat completed experiment results as stale (#88219)

Juraj Majerik793bbe39a5e0
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx
index 6ac1de26f211..afca3cb3b146 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx
@@ -14,6 +14,7 @@ import { Label } from 'lib/ui/Label/Label'
import { humanFriendlyDuration } from 'lib/utils/durations'
import { experimentLogic } from '../experimentLogic'
+import { hasEnded } from '../experimentStatus'
/**
* Hook to check if experiment data is stale and trigger refresh if needed.
@@ -65,14 +66,21 @@ function useStaleDataCheck({
}, [lastRefresh, enabled, intervalSeconds, onRefresh])
}
-export const ExperimentLastRefreshText = ({ lastRefresh }: { lastRefresh: string | null }): JSX.Element => {
- const colorClass = lastRefresh
- ? dayjs().diff(dayjs(lastRefresh), 'hours') > 12
- ? 'text-danger'
- : dayjs().diff(dayjs(lastRefresh), 'hours') > 6
- ? 'text-warning'
- : ''
- : ''
+export const ExperimentLastRefreshText = ({
+ lastRefresh,
+ showStaleness = true,
+}: {
+ lastRefresh: string | null
+ showStaleness?: boolean
+}): JSX.Element => {
+ const colorClass =
+ showStaleness && lastRefresh
+ ? dayjs().diff(dayjs(lastRefresh), 'hours') > 12
+ ? 'text-danger'
+ : dayjs().diff(dayjs(lastRefresh), 'hours') > 6
+ ? 'text-warning'
+ : ''
+ : ''
return <span className={colorClass}>{lastRefresh ? <TZLabel time={lastRefresh} /> : 'a while ago'}</span>
}
@@ -100,13 +108,16 @@ export const ExperimentReloadAction = ({
onClick: () => void
progress?: { completed: number; total: number }
}): JSX.Element => {
- const { autoRefresh } = useValues(experimentLogic)
+ const { autoRefresh, experiment } = useValues(experimentLogic)
const { setAutoRefresh, setPageVisibility, stopAutoRefreshInterval } = useActions(experimentLogic)
+ // Completed experiments have final results: no staleness warning, no auto refresh
+ const ended = hasEnded(experiment)
+
// Check if data is stale on mount or when page becomes visible
useStaleDataCheck({
lastRefresh,
- enabled: autoRefresh.enabled,
+ enabled: autoRefresh.enabled && !ended,
intervalSeconds: autoRefresh.interval,
onRefresh: onClick,
})
@@ -147,55 +158,63 @@ export const ExperimentReloadAction = ({
icon={isRefreshing ? <Spinner textColored /> : <IconRefresh />}
data-attr="refresh-experiment"
disabledReason={isRefreshing ? 'Loading...' : null}
- sideAction={{
- 'data-attr': 'refresh-experiment-dropdown',
- dropdown: {
- closeOnClickInside: false,
- placement: 'bottom-end',
- overlay: (
- <LemonMenuOverlay
- items={[
- {
- label: () => (
- <LemonSwitch
- onChange={(checked) =>
- setAutoRefresh(checked, autoRefresh.interval)
- }
- label="Auto refresh while on page"
- checked={autoRefresh.enabled}
- fullWidth
- className="mt-1 mb-2"
- />
- ),
- },
- ...(autoRefresh.enabled
- ? [
+ sideAction={
+ ended
+ ? undefined
+ : {
+ 'data-attr': 'refresh-experiment-dropdown',
+ dropdown: {
+ closeOnClickInside: false,
+ placement: 'bottom-end',
+ overlay: (
+ <LemonMenuOverlay
+ items={[
{
- title: 'Refresh interval',
- items: [
- {
- label: () => (
- <LemonRadio
- value={autoRefresh.interval}
- options={options}
- onChange={(value: number) => {
- setAutoRefresh(true, value)
- }}
- className="mx-2 mb-1"
- />
- ),
- },
- ],
+ label: () => (
+ <LemonSwitch
+ onChange={(checked) =>
+ setAutoRefresh(checked, autoRefresh.interval)
+ }
+ label="Auto refresh while on page"
+ checked={autoRefresh.enabled}
+ fullWidth
+ className="mt-1 mb-2"
+ />
+ ),
},
- ]
- : []),
- ]}
- />
- ),
- },
- }}
+ ...(autoRefresh.enabled
+ ? [
+ {
+ title: 'Refresh interval',
+ items: [
+ {
+ label: () => (
+ <LemonRadio
+ value={autoRefresh.interval}
+ options={options}
+ onChange={(value: number) => {
+ setAutoRefresh(true, value)
+ }}
+ className="mx-2 mb-1"
+ />
+ ),
+ },
+ ],
+ },
+ ]
+ : []),
+ ]}
+ />
+ ),
+ },
+ }
+ }
>
- {isRefreshing ? loadingText : <ExperimentLastRefreshText lastRefresh={lastRefresh} />}
+ {isRefreshing ? (
+ loadingText
+ ) : (
+ <ExperimentLastRefreshText lastRefresh={lastRefresh} showStaleness={!ended} />
+ )}
</LemonButton>
<LemonBadge
size="small"
@@ -204,7 +223,7 @@ export const ExperimentReloadAction = ({
<IconRefresh className="mr-0" /> {humanFriendlyDuration(autoRefresh.interval)}
</>
}
- visible={autoRefresh.enabled}
+ visible={autoRefresh.enabled && !ended}
position="top-right"
status="muted"
/>
diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsx
index a506300c6c81..cf73c09446c0 100644
--- a/frontend/src/scenes/experiments/experimentLogic.tsx
+++ b/frontend/src/scenes/experiments/experimentLogic.tsx
@@ -3923,9 +3923,15 @@ export const experimentLogic = kea<experimentLogicType>([
// Clear any existing interval first
cache.disposables.dispose('autoRefreshInterval')
- if (values.autoRefresh.enabled) {
+ // Completed experiments have final results — never poll them
+ if (values.autoRefresh.enabled && !hasEnded(values.experiment)) {
cache.disposables.add(() => {
const intervalId = window.setInterval(() => {
+ // The experiment may have ended while the interval was running
+ if (hasEnded(values.experiment)) {
+ cache.disposables.dispose('autoRefreshInterval')
+ return
+ }
// Track auto-refresh trigger
actions.reportExperimentMetricsRefreshed(values.experiment, true, {
triggered_by: 'auto-refresh',