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.

feat(experiments): raise the freeze cap to 200k and show its duration (#111758)

Marcel Poelker5bb54274dcd6
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
index 9ae5eaf6aced..ac12c4ea5177 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
@@ -48,6 +48,7 @@ import {
confirmUnfreezeExposure,
} from 'products/experiments/frontend/experimentActions'
import { isExperimentExposureFrozen, isExperimentPaused } from 'products/experiments/frontend/experimentStatus'
+import { getTotalExposures } from 'products/experiments/frontend/health/exposureHealth'
import { experimentLogic } from '../experimentLogic'
import { modalsLogic } from '../modalsLogic'
@@ -70,6 +71,7 @@ function ExperimentSceneMenuBarInner(): JSX.Element | null {
isExperimentLaunched,
isExperimentStopped,
isCreatingExperimentDashboard,
+ exposures,
freezeExposureLoading,
unfreezeExposureLoading,
showDebugPanel,
@@ -262,7 +264,9 @@ function ExperimentSceneMenuBarInner(): JSX.Element | null {
{showFreezeExposure && (
<SceneMenuBarItem
opensFloatingUi
- onClick={() => confirmFreezeExposure(() => freezeExposure())}
+ onClick={() =>
+ confirmFreezeExposure(() => freezeExposure(), getTotalExposures(exposures))
+ }
disabled={freezeExposureLoading}
tooltip={freezeExposureLoading ? 'Freezing exposure…' : undefined}
data-attr={`${RESOURCE_TYPE}-menubar-freeze-exposure`}
diff --git a/frontend/src/scenes/experiments/ExperimentView/useExperimentActions.tsx b/frontend/src/scenes/experiments/ExperimentView/useExperimentActions.tsx
index ee514039f752..51e59110d2ec 100644
--- a/frontend/src/scenes/experiments/ExperimentView/useExperimentActions.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/useExperimentActions.tsx
@@ -37,6 +37,7 @@ import {
confirmUnfreezeExposure,
} from 'products/experiments/frontend/experimentActions'
import { isExperimentExposureFrozen, isExperimentPaused } from 'products/experiments/frontend/experimentStatus'
+import { getTotalExposures } from 'products/experiments/frontend/health/exposureHealth'
import { experimentLogic } from '../experimentLogic'
import { modalsLogic } from '../modalsLogic'
@@ -59,6 +60,7 @@ export function useExperimentActions(dataAttrPrefix: string = ''): ExperimentAct
isExperimentLaunched,
isExperimentRunning,
isCreatingExperimentDashboard,
+ exposures,
freezeExposureLoading,
unfreezeExposureLoading,
} = useValues(experimentLogic)
@@ -166,7 +168,7 @@ export function useExperimentActions(dataAttrPrefix: string = ''): ExperimentAct
canFreezeExposure(experiment) && {
label: 'Freeze exposure',
icon: <IconLock />,
- onClick: () => confirmFreezeExposure(() => freezeExposure()),
+ onClick: () => confirmFreezeExposure(() => freezeExposure(), getTotalExposures(exposures)),
disabledReason: freezeExposureLoading ? 'Freezing exposure...' : undefined,
'data-attr': `${dataAttrPrefix}freeze-exposure`,
},
diff --git a/products/experiments/backend/experiment_service.py b/products/experiments/backend/experiment_service.py
index 903f7895764a..1959fde767a7 100644
--- a/products/experiments/backend/experiment_service.py
+++ b/products/experiments/backend/experiment_service.py
@@ -161,15 +161,29 @@ DEFAULT_VARIANTS = [
{"key": "test", "name": "Test Variant", "rollout_percentage": 50},
]
-# Synchronous freeze-exposure bounds. The snapshot is built inline in the request, so we cap both the
-# time spent scanning $feature_flag_called events (ClickHouse) and the number of exposed users we
-# materialize — the Postgres cohort sync is size-linear and is NOT covered by the query timeout.
-# The user cap is sized to the cohort insert (batches of 1000, sequential): 100k keeps the whole
-# freeze comfortably inside a web request. Long-running / very-high-traffic experiments that exceed
-# either bound are rejected rather than frozen synchronously (they would need a future async
-# populate path).
+# Synchronous freeze-exposure bounds. The freeze builds the snapshot inline in the web request, so the
+# request must finish before the ingress ends it at 120 seconds. After that the caller gets an error.
+#
+# The query timeout bounds the ClickHouse scan of the exposure events only. The user cap bounds the
+# two steps that the timeout does NOT cover. Both are linear in the number of exposed users, and
+# together they are almost all of the freeze duration:
+# - the personhog lookup: one RPC per PERSONHOG_BATCH_SIZE users, FREEZE_EXPOSURE_RESOLVE_CONCURRENCY at a time
+# - the cohort write: sequential batches of 1000, each with a ClickHouse read, a ClickHouse insert
+# and a personhog insert
+#
+# The cap is sized so that the slowest freeze stays below the ingress limit. As of October 2026 the
+# slowest measured cost in production is about 0.5 ms per exposed user, which is about 105 seconds
+# at the cap. Every freeze logs its user count and step durations as experiment_freeze_exposure_timing.
+# Read those logs and repeat this calculation before you raise the cap.
+#
+# A longer build also widens the gap between the scan and the flag save. A user who is first exposed
+# in that gap is not in the snapshot and loses their variant when the flag narrows.
+#
+# Flag evaluation does not depend on the cap. It does one indexed lookup per person, whatever the
+# cohort size. An experiment over either bound is rejected. To freeze such an experiment, populate
+# the cohort in a background task and narrow the flag only after the cohort is complete.
FREEZE_EXPOSURE_QUERY_TIMEOUT_SECONDS = 20
-FREEZE_EXPOSURE_MAX_EXPOSED_USERS = 100_000
+FREEZE_EXPOSURE_MAX_EXPOSED_USERS = 200_000
# Cohort membership is person-keyed, so exposed users without a person profile (anonymous
# "personless" traffic, or since-deleted persons) can never match the snapshot cohort and would
# silently lose their variant at freeze time. A small unresolvable share is tolerated as
diff --git a/products/experiments/frontend/experimentActions.tsx b/products/experiments/frontend/experimentActions.tsx
index 82ba6b30b0d2..1b1168c3ccc1 100644
--- a/products/experiments/frontend/experimentActions.tsx
+++ b/products/experiments/frontend/experimentActions.tsx
@@ -1,6 +1,8 @@
-import { LemonCheckbox, LemonDialog } from '@posthog/lemon-ui'
+import { IconClock } from '@posthog/icons'
+import { LemonBanner, LemonCheckbox, LemonDialog } from '@posthog/lemon-ui'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
import { Experiment } from '~/types'
@@ -10,6 +12,10 @@ import {
isExperimentPaused,
isLaunched,
} from 'products/experiments/frontend/experimentStatus'
+import {
+ estimateFreezeExposureSeconds,
+ formatFreezeExposureDuration,
+} from 'products/experiments/frontend/freezeExposureDuration'
/** Whether an experiment is in a state where it can be archived (ignoring permissions). */
export function canArchiveExperiment(
@@ -51,7 +57,8 @@ export function canFreezeExposure(
)
}
-export function confirmFreezeExposure(onConfirm: () => Promise<void>): void {
+/** `exposedUsers` is 0 when the exposure count has not loaded, and the dialog then shows no estimate. */
+export function confirmFreezeExposure(onConfirm: () => Promise<void>, exposedUsers: number): void {
LemonDialog.open({
title: 'Freeze exposure?',
content: (
@@ -69,7 +76,19 @@ export function confirmFreezeExposure(onConfirm: () => Promise<void>): void {
From a frozen state you can end an experiment or ship a variant at any time. You can unfreeze as
well to reopen enrollment.
</p>
- <p>Freezing can take a little while on projects with many users, so keep this dialog open.</p>
+ {exposedUsers > 0 ? (
+ <LemonBanner type="info" icon={<IconClock className="LemonBanner__icon" />}>
+ <div className="font-semibold">
+ Freezing takes {formatFreezeExposureDuration(estimateFreezeExposureSeconds(exposedUsers))}
+ </div>
+ <div className="font-normal">
+ {humanFriendlyNumber(exposedUsers)} exposed {exposedUsers === 1 ? 'user' : 'users'}. Keep
+ this dialog open until it finishes.
+ </div>
+ </LemonBanner>
+ ) : (
+ <p>Freezing can take a little while on projects with many users, so keep this dialog open.</p>
+ )}
</div>
),
shouldAwaitSubmit: true,
diff --git a/products/experiments/frontend/freezeExposureDuration.test.ts b/products/experiments/frontend/freezeExposureDuration.test.ts
new file mode 100644
index 000000000000..cfb18bef9bc3
--- /dev/null
+++ b/products/experiments/frontend/freezeExposureDuration.test.ts
@@ -0,0 +1,16 @@
+import { formatFreezeExposureDuration } from 'products/experiments/frontend/freezeExposureDuration'
+
+describe('formatFreezeExposureDuration', () => {
+ test.each([
+ [0.5, 'a few seconds'],
+ [4.9, 'a few seconds'],
+ [7.4, 'about 7 seconds'],
+ [9.6, 'about 10 seconds'],
+ [23, 'about 25 seconds'],
+ [58, 'about 1 minute'],
+ [73, 'about 1 minute 10 seconds'],
+ [122, 'about 2 minutes'],
+ ])('%s seconds reads as "%s"', (seconds, expected) => {
+ expect(formatFreezeExposureDuration(seconds)).toBe(expected)
+ })
+})
diff --git a/products/experiments/frontend/freezeExposureDuration.ts b/products/experiments/frontend/freezeExposureDuration.ts
new file mode 100644
index 000000000000..273885cc7e34
--- /dev/null
+++ b/products/experiments/frontend/freezeExposureDuration.ts
@@ -0,0 +1,25 @@
+// Fitted to the experiment_freeze_exposure_timing logs of US production as of October 2026: under one
+// second of fixed cost, plus 0.32 to 0.36 ms for each exposed user. Both values are rounded up, so the
+// estimate is a little long rather than short.
+const FIXED_SECONDS = 1
+const SECONDS_PER_EXPOSED_USER = 0.0004
+
+export function estimateFreezeExposureSeconds(exposedUsers: number): number {
+ return FIXED_SECONDS + exposedUsers * SECONDS_PER_EXPOSED_USER
+}
+
+/** Rounds more coarsely as the duration grows, so the text is never more precise than the estimate. */
+export function formatFreezeExposureDuration(seconds: number): string {
+ if (seconds < 5) {
+ return 'a few seconds'
+ }
+ const step = seconds < 10 ? 1 : seconds < 60 ? 5 : 10
+ const rounded = Math.round(seconds / step) * step
+ if (rounded < 60) {
+ return `about ${rounded} seconds`
+ }
+ const minutes = Math.floor(rounded / 60)
+ const remainder = rounded % 60
+ const minutesText = `${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`
+ return remainder === 0 ? `about ${minutesText}` : `about ${minutesText} ${remainder} seconds`
+}