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): report broken flag variants + time the health request (#115784)

Marcel Poelker5595580165fa
diff --git a/frontend/src/scenes/experiments/experimentLogic.test.ts b/frontend/src/scenes/experiments/experimentLogic.test.ts
index 8d37697cac12..0ec9ba102572 100644
--- a/frontend/src/scenes/experiments/experimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/experimentLogic.test.ts
@@ -2490,10 +2490,18 @@ describe('experimentLogic', () => {
expect(logic.values.experimentWarning).toEqual(expected)
})
+ const healthUrl = '/api/projects/:team/experiments/7/health/'
+ const mountKeyedLogic = (): ReturnType<typeof experimentLogic.build> => {
+ const keyedLogic = experimentLogic({ experimentId: 7 })
+ keyedLogic.mount()
+ return keyedLogic
+ }
+
it.each<{
desc: string
overrides: Partial<Experiment>
- health: ExperimentHealthApi
+ // null makes the health request fail.
+ health: ExperimentHealthApi | null
expected: Record<string, unknown>
healthFindingsFlag?: boolean
}>([
@@ -2503,6 +2511,7 @@ describe('experimentLogic', () => {
health: { findings: [healthFinding('flag_off_while_running', 'running_but_flag_disabled')] },
expected: {
health_ui: 'panel',
+ request_failed: false,
health_finding_codes: ['flag_off_while_running'],
health_finding_subcodes: ['flag_off_while_running:running_but_flag_disabled'],
health_finding_count: 1,
@@ -2535,28 +2544,40 @@ describe('experimentLogic', () => {
flag_state_server: 'running_but_flag_disabled',
},
},
+ {
+ desc: 'a failed request, which leaves the server values empty',
+ overrides: { ...running, feature_flag: flag(false, multivariantFilters) },
+ health: null,
+ expected: {
+ request_failed: true,
+ health_finding_codes: null,
+ health_finding_count: null,
+ flag_state_browser: 'running_but_flag_disabled',
+ flag_state_server: null,
+ no_metric_server: null,
+ },
+ },
])(
'compares the local rules with the server checks when the health loads: $desc',
- ({ overrides, health, expected, healthFindingsFlag = true }) => {
+ async ({ overrides, health, expected, healthFindingsFlag = true }) => {
setHealthFindingsFlag(healthFindingsFlag)
+ useMocks({
+ get: { [healthUrl]: () => (health ? [200, health] : [500, { detail: 'Server error' }]) },
+ })
+ const keyedLogic = mountKeyedLogic()
const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ keyedLogic.actions.setExperiment(createExperiment({ id: 7, ...overrides }))
- logic.actions.setExperiment(createExperiment(overrides))
- logic.actions.loadExperimentHealthSuccess(health, 'experiment_load')
+ await expectLogic(keyedLogic, () => {
+ keyedLogic.actions.loadExperimentHealth('experiment_load')
+ }).toDispatchActions(['loadExperimentHealthSuccess'])
const checkedEvents = captureSpy.mock.calls.filter(([event]) => event === 'experiment health checked')
expect(checkedEvents).toHaveLength(1)
- expect(checkedEvents[0][1]).toMatchObject(expected)
+ expect(checkedEvents[0][1]).toMatchObject({ duration_ms: expect.any(Number), ...expected })
}
)
- const healthUrl = '/api/projects/:team/experiments/7/health/'
- const mountKeyedLogic = (): ReturnType<typeof experimentLogic.build> => {
- const keyedLogic = experimentLogic({ experimentId: 7 })
- keyedLogic.mount()
- return keyedLogic
- }
-
it('loads the health with each experiment load and after a changed input, comparing only once', async () => {
const health: ExperimentHealthApi = { findings: [] }
useMocks({ get: { [healthUrl]: () => [200, health] } })
diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsx
index a89f53002d65..459d3585ce8e 100644
--- a/frontend/src/scenes/experiments/experimentLogic.tsx
+++ b/frontend/src/scenes/experiments/experimentLogic.tsx
@@ -244,6 +244,7 @@ const HEALTH_CHECK_INPUTS = [
'start_date',
'end_date',
'archived',
+ 'stats_config',
] as const satisfies readonly (keyof Experiment)[]
function healthCheckInputs(experiment: Experiment): Partial<Experiment> {
@@ -1926,19 +1927,6 @@ export const experimentLogic = kea<experimentLogicType>([
reportHealthFindingActedOn: ({ finding, actionKind }) => {
captureExperimentHealthFindingActedOn(values.experiment, finding, values.healthUi, actionKind)
},
- loadExperimentHealthSuccess: ({ experimentHealth, payload }) => {
- // One comparison per experiment load. A reload after a write would compare unsaved edits in the
- // page with the saved experiment on the server.
- if (experimentHealth && payload === 'experiment_load') {
- captureExperimentHealthChecked(
- values.experiment,
- experimentHealth,
- values.healthUi,
- values.browserExperimentWarning,
- values.browserNoMetricsWarning
- )
- }
- },
setExperiment: () => {
// A save returns the whole experiment, so compare values: only a changed input makes the findings stale.
if (
@@ -2827,20 +2815,30 @@ export const experimentLogic = kea<experimentLogicType>([
await breakpoint(300)
}
cache.healthCheckInputs = healthCheckInputs(values.experiment)
+ // Timed here rather than in the success listener, which would have to read a start time off
+ // `cache` that a superseded request can overwrite.
+ const startedAt = performance.now()
+ let health: ExperimentHealthApi | null = null
try {
- const health = await experimentsHealthRetrieve(
- String(values.currentProjectId),
- values.experimentId
- )
- breakpoint()
- return health
- } catch (error) {
+ health = await experimentsHealthRetrieve(String(values.currentProjectId), values.experimentId)
+ } catch {
// The page applies its own rules without findings, so a failed request shows no error.
- if (isBreakpoint(error as Error)) {
- throw error
- }
- return null
}
+ // Kept outside the `try`: a superseded request throws here and is not a failure.
+ breakpoint()
+ // One comparison per experiment load. A reload after a write would compare unsaved edits in the
+ // page with the saved experiment on the server.
+ if (trigger === 'experiment_load') {
+ captureExperimentHealthChecked(
+ values.experiment,
+ health,
+ values.healthUi,
+ values.browserExperimentWarning,
+ values.browserNoMetricsWarning,
+ Math.round(performance.now() - startedAt)
+ )
+ }
+ return health
},
},
],
diff --git a/products/experiments/backend/facade/contracts.py b/products/experiments/backend/facade/contracts.py
index 6ac5ebd68961..6338d953096e 100644
--- a/products/experiments/backend/facade/contracts.py
+++ b/products/experiments/backend/facade/contracts.py
@@ -107,6 +107,7 @@ class ExperimentHealthFindingCode(LabeledStrEnum):
SRM = "srm", "Sample Ratio Mismatch"
ZERO_EXPOSURES = "zero_exposures"
FORCED_VARIANT_RELEASE_CONDITION = "forced_variant_release_condition"
+ FLAG_VARIANTS_MISMATCH = "flag_variants_mismatch"
class ExperimentHealthFindingSeverity(LabeledStrEnum):
diff --git a/products/experiments/backend/health/checks/flag_variants.py b/products/experiments/backend/health/checks/flag_variants.py
new file mode 100644
index 000000000000..5a3f6b177f44
--- /dev/null
+++ b/products/experiments/backend/health/checks/flag_variants.py
@@ -0,0 +1,70 @@
+"""
+The flag's variants against the variants the analysis needs. Pure functions, no I/O.
+
+The analysis reads its variants from the flag and compares each one with the baseline. Save and launch check
+both, but the flag can change after that, and experiments saved before those checks never had them.
+"""
+
+from products.experiments.backend.facade.contracts import (
+ ExperimentHealthFinding,
+ ExperimentHealthFindingActionKind,
+ ExperimentHealthFindingCode,
+ ExperimentHealthFindingSeverity,
+)
+from products.experiments.backend.health.context import HealthContext
+
+# pinned: the subcodes are sent as `finding_variant` on the health finding events, so insights group on them.
+FLAG_HAS_NO_VARIANTS = "flag_has_no_variants"
+NO_CONTROL_VARIANT = "no_control_variant"
+
+
+def flag_variants_mismatch(ctx: HealthContext) -> ExperimentHealthFinding | None:
+ flag = ctx.flag
+ # A deleted flag has a finding of its own, and the flag has to be restored first. After the end the flag
+ # can change for good reasons, for example to a boolean flag that keeps the shipped variant.
+ if flag is None or flag.deleted or ctx.has_ended or ctx.archived:
+ return None
+
+ variant_keys = {variant.key for variant in flag.variants if variant.key}
+ if not variant_keys:
+ # A draft without variants is not set up yet. A running experiment had at least two at launch.
+ if not ctx.is_running:
+ return None
+ return _finding(
+ subcode=FLAG_HAS_NO_VARIANTS,
+ title="The experiment is running, but its feature flag has no variants",
+ detail=(
+ "The linked feature flag has no variants, so the experiment can't count exposures or calculate "
+ "results. Open the feature flag and add the experiment's variants back."
+ ),
+ evidence={},
+ )
+
+ if ctx.baseline_variant_key is not None and ctx.baseline_variant_key not in variant_keys:
+ return _finding(
+ subcode=NO_CONTROL_VARIANT,
+ title="The baseline variant is not a variant of the feature flag",
+ detail=(
+ f'The baseline variant "{ctx.baseline_variant_key}" is not one of the linked feature flag\'s '
+ "variants, so the results can't be calculated. Add the variant to the feature flag, or pick "
+ "another baseline variant on the Settings tab."
+ ),
+ evidence={"baseline_variant_key": ctx.baseline_variant_key},
+ )
+
+ return None
+
+
+def _finding(
+ *, subcode: str, title: str, detail: str, evidence: dict[str, str | int | float | None]
+) -> ExperimentHealthFinding:
+ return ExperimentHealthFinding(
+ code=ExperimentHealthFindingCode.FLAG_VARIANTS_MISMATCH,
+ subcode=subcode,
+ severity=ExperimentHealthFindingSeverity.WARNING,
+ title=title,
+ detail=detail,
+ evidence=evidence,
+ actions=(ExperimentHealthFindingActionKind.OPEN_FEATURE_FLAG,),
+ diagnostic_ref="E4",
+ )
diff --git a/products/experiments/backend/health/context.py b/products/experiments/backend/health/context.py
index 00c5dc5df223..d48e3590ac51 100644
--- a/products/experiments/backend/health/context.py
+++ b/products/experiments/backend/health/context.py
@@ -57,6 +57,8 @@ class HealthContext:
is_paused: bool
archived: bool
flag: FlagState | None
+ # The baseline set in the experiment's settings. None when unset: the analysis then picks a variant of the flag.
+ baseline_variant_key: str | None
primary_metric_count: int
secondary_metric_count: int
exposures: ExposureTotals | None
@@ -131,6 +133,12 @@ def _load_flag_state(experiment: Experiment) -> FlagState | None:
)
+def _configured_baseline_variant_key(stats_config: object) -> str | None:
+ # An empty key counts as unset, as in `get_baseline_variant_key`.
+ key = stats_config.get("baseline_variant_key") if isinstance(stats_config, dict) else None
+ return key if isinstance(key, str) and key else None
+
+
def load_health_context(experiment: Experiment, exposures: ExposureTotals | None = None) -> HealthContext:
shared_metric_roles = [saved_metric_link_role(link) for link in saved_metric_links(experiment)]
return HealthContext(
@@ -140,6 +148,7 @@ def load_health_context(experiment: Experiment, exposures: ExposureTotals | None
is_paused=experiment.is_paused,
archived=experiment.archived,
flag=_load_flag_state(experiment),
+ baseline_variant_key=_configured_baseline_variant_key(experiment.stats_config),
primary_metric_count=len(experiment.metrics or []) + shared_metric_roles.count("primary"),
secondary_metric_count=len(experiment.metrics_secondary or []) + shared_metric_roles.count("secondary"),
exposures=exposures,
diff --git a/products/experiments/backend/health/registry.py b/products/experiments/backend/health/registry.py
index 5aea5ba3402b..f7fbe143f0cb 100644
--- a/products/experiments/backend/health/registry.py
+++ b/products/experiments/backend/health/registry.py
@@ -5,6 +5,7 @@ from posthog.exceptions_capture import capture_exception
from products.experiments.backend.facade.contracts import ExperimentHealthFinding
from products.experiments.backend.health.checks.bias_risk import bias_risk_multiple_excluded
from products.experiments.backend.health.checks.flag_state import flag_state
+from products.experiments.backend.health.checks.flag_variants import flag_variants_mismatch
from products.experiments.backend.health.checks.forced_variant import forced_variant_release_condition
from products.experiments.backend.health.checks.no_metric import no_metric
from products.experiments.backend.health.checks.srm import srm
@@ -13,7 +14,12 @@ from products.experiments.backend.health.context import HealthContext
HealthCheck = Callable[[HealthContext], ExperimentHealthFinding | None]
-EXPERIMENT_HEALTH_CHECKS: tuple[HealthCheck, ...] = (flag_state, forced_variant_release_condition, no_metric)
+EXPERIMENT_HEALTH_CHECKS: tuple[HealthCheck, ...] = (
+ flag_state,
+ flag_variants_mismatch,
+ forced_variant_release_condition,
+ no_metric,
+)
# The exposure query runs these on its answer. They must not include the checks above: the exposure answer
# is cached for a day, and a flag edit would not clear their findings.
diff --git a/products/experiments/backend/health/test/test_flag_state.py b/products/experiments/backend/health/test/test_flag_state.py
index 925919d53bb6..d70d8f08c9d8 100644
--- a/products/experiments/backend/health/test/test_flag_state.py
+++ b/products/experiments/backend/health/test/test_flag_state.py
@@ -58,6 +58,7 @@ def _context(
groups=filters.get("groups"),
variants=(filters.get("multivariate") or {}).get("variants"),
),
+ baseline_variant_key=None,
primary_metric_count=1,
secondary_metric_count=0,
exposures=None,
diff --git a/products/experiments/backend/health/test/test_flag_variants.py b/products/experiments/backend/health/test/test_flag_variants.py
new file mode 100644
index 000000000000..4e0a32375167
--- /dev/null
+++ b/products/experiments/backend/health/test/test_flag_variants.py
@@ -0,0 +1,68 @@
+from typing import Any
+
+from unittest import TestCase
+
+from parameterized import parameterized
+
+from products.experiments.backend.facade.contracts import ExperimentHealthFindingCode
+from products.experiments.backend.health.checks.flag_variants import flag_variants_mismatch
+from products.experiments.backend.health.context import HealthContext, parse_flag_state
+
+EVEN_SPLIT = [{"key": "control", "rollout_percentage": 50}, {"key": "test", "rollout_percentage": 50}]
+NO_CONTROL_SPLIT = [{"key": "a", "rollout_percentage": 50}, {"key": "b", "rollout_percentage": 50}]
+
+RUNNING = {"is_launched": True, "is_running": True, "has_ended": False}
+ENDED = {"is_launched": True, "is_running": False, "has_ended": True}
+DRAFT = {"is_launched": False, "is_running": False, "has_ended": False}
+
+
+def _context(
+ status: dict[str, bool],
+ *,
+ variants: list[dict[str, Any]] | None = EVEN_SPLIT,
+ baseline: str | None = None,
+ deleted: bool = False,
+ archived: bool = False,
+) -> HealthContext:
+ return HealthContext(
+ **status,
+ is_paused=False,
+ archived=archived,
+ flag=parse_flag_state(
+ active=True,
+ deleted=deleted,
+ groups=[{"properties": [], "rollout_percentage": 100}],
+ variants=variants,
+ ),
+ baseline_variant_key=baseline,
+ primary_metric_count=1,
+ secondary_metric_count=0,
+ exposures=None,
+ )
+
+
+class TestFlagVariantsMismatch(TestCase):
+ @parameterized.expand(
+ [
+ ("running_flag_without_variants", _context(RUNNING, variants=None), "flag_has_no_variants"),
+ ("draft_flag_without_variants", _context(DRAFT, variants=None), None),
+ ("running_baseline_not_a_variant", _context(RUNNING, baseline="holdout"), "no_control_variant"),
+ ("draft_baseline_not_a_variant", _context(DRAFT, baseline="holdout"), "no_control_variant"),
+ ("baseline_is_a_variant", _context(RUNNING, baseline="test"), None),
+ ("no_baseline_and_no_control_variant", _context(RUNNING, variants=NO_CONTROL_SPLIT), None),
+ ("ended_flag_changed_to_boolean", _context(ENDED, variants=None), None),
+ ("archived_draft_baseline_not_a_variant", _context(DRAFT, baseline="holdout", archived=True), None),
+ ("deleted_flag_without_variants", _context(RUNNING, variants=None, deleted=True), None),
+ ]
+ )
+ def test_flag_variants_mismatch(self, _name: str, ctx: HealthContext, expected_subcode: str | None) -> None:
+ finding = flag_variants_mismatch(ctx)
+
+ if expected_subcode is None:
+ self.assertIsNone(finding)
+ return
+ assert finding is not None
+ self.assertEqual(
+ (finding.code, finding.subcode), (ExperimentHealthFindingCode.FLAG_VARIANTS_MISMATCH, expected_subcode)
+ )
+ self.assertEqual(finding.evidence.get("baseline_variant_key"), ctx.baseline_variant_key)
diff --git a/products/experiments/backend/health/test/test_forced_variant.py b/products/experiments/backend/health/test/test_forced_variant.py
index e1ee053cd3c8..e4cc392425ec 100644
--- a/products/experiments/backend/health/test/test_forced_variant.py
+++ b/products/experiments/backend/health/test/test_forced_variant.py
@@ -38,6 +38,7 @@ def _context(
is_paused=False,
archived=False,
flag=parse_flag_state(active=True, deleted=deleted, groups=groups, variants=variants, early_exit=early_exit),
+ baseline_variant_key=None,
primary_metric_count=1,
secondary_metric_count=0,
exposures=None,
diff --git a/products/experiments/backend/health/test/test_no_metric.py b/products/experiments/backend/health/test/test_no_metric.py
index 9019f272d58f..d5a9938c3be2 100644
--- a/products/experiments/backend/health/test/test_no_metric.py
+++ b/products/experiments/backend/health/test/test_no_metric.py
@@ -17,6 +17,7 @@ def _context(**changes: Any) -> HealthContext:
"is_paused": False,
"archived": False,
"flag": None,
+ "baseline_variant_key": None,
"primary_metric_count": 0,
"secondary_metric_count": 0,
"exposures": None,
diff --git a/products/experiments/backend/health/test/test_registry.py b/products/experiments/backend/health/test/test_registry.py
index 4d27b728ac0e..df92398fade4 100644
--- a/products/experiments/backend/health/test/test_registry.py
+++ b/products/experiments/backend/health/test/test_registry.py
@@ -37,6 +37,7 @@ RUNNING_UNEVEN_SPLIT = HealthContext(
),
reachable_conditions=(),
),
+ baseline_variant_key=None,
primary_metric_count=1,
secondary_metric_count=0,
exposures=UNEVEN_SPLIT_TOTALS,
diff --git a/products/experiments/backend/test/test_presentation_api.py b/products/experiments/backend/test/test_presentation_api.py
index c83be8beb69a..cc573f2645a3 100644
--- a/products/experiments/backend/test/test_presentation_api.py
+++ b/products/experiments/backend/test/test_presentation_api.py
@@ -715,12 +715,18 @@ class TestExperimentCRUD(_HoistFlagConfigClientMixin, APILicensedTest):
("shared_primary_metric_counts", {}, {"metadata": {"type": "primary"}}, [_HEALTH_PAUSED]),
("shared_secondary_metric_counts", {}, {"metadata": {"type": "secondary"}}, [_HEALTH_PAUSED]),
("shared_metric_without_type_counts", {}, {}, [_HEALTH_PAUSED]),
+ (
+ "baseline_not_a_variant",
+ {"metrics": [_HEALTH_METRIC], "stats_config": {"baseline_variant_key": "holdout"}},
+ None,
+ [_HEALTH_PAUSED, ("flag_variants_mismatch", "no_control_variant")],
+ ),
]
)
def test_health_reports_findings(
self,
_name: str,
- inline_metrics: dict[str, list[dict[str, Any]]],
+ experiment_fields: dict[str, Any],
shared_metric_link: dict[str, Any] | None,
expected: list[tuple[str, str | None]],
) -> None:
@@ -743,8 +749,9 @@ class TestExperimentCRUD(_HoistFlagConfigClientMixin, APILicensedTest):
},
),
start_date=timezone.now() - timedelta(days=3),
- metrics=inline_metrics.get("metrics", []),
- metrics_secondary=inline_metrics.get("metrics_secondary", []),
+ metrics=experiment_fields.get("metrics", []),
+ metrics_secondary=experiment_fields.get("metrics_secondary", []),
+ stats_config=experiment_fields.get("stats_config", {}),
)
if shared_metric_link is not None:
saved_metric = ExperimentSavedMetric.objects.create(
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index 30844c3253fe..07a84a71bde0 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -2271,6 +2271,7 @@ export type _ExperimentApiMetricsListApi = ExperimentApiMetricApi[]
* * `srm` - Sample Ratio Mismatch
* * `zero_exposures` - Zero Exposures
* * `forced_variant_release_condition` - Forced Variant Release Condition
+ * * `flag_variants_mismatch` - Flag Variants Mismatch
*/
export type ExperimentHealthFindingCodeEnumApi =
(typeof ExperimentHealthFindingCodeEnumApi)[keyof typeof ExperimentHealthFindingCodeEnumApi]
@@ -2285,6 +2286,7 @@ export const ExperimentHealthFindingCodeEnumApi = {
Srm: 'srm',
ZeroExposures: 'zero_exposures',
ForcedVariantReleaseCondition: 'forced_variant_release_condition',
+ FlagVariantsMismatch: 'flag_variants_mismatch',
} as const
/**
@@ -2339,7 +2341,8 @@ export interface ExperimentHealthFindingApi {
* * `no_metric` - No Metric
* * `srm` - Sample Ratio Mismatch
* * `zero_exposures` - Zero Exposures
- * * `forced_variant_release_condition` - Forced Variant Release Condition */
+ * * `forced_variant_release_condition` - Forced Variant Release Condition
+ * * `flag_variants_mismatch` - Flag Variants Mismatch */
code: ExperimentHealthFindingCodeEnumApi
/**
* The case within the code, when a code covers several, for example 'running_but_no_rollout' within 'flag_off_while_running'. Null when the code has one case.
diff --git a/products/experiments/frontend/health/experimentHealthFindingEvents.ts b/products/experiments/frontend/health/experimentHealthFindingEvents.ts
index badca619e723..268126f3348c 100644
--- a/products/experiments/frontend/health/experimentHealthFindingEvents.ts
+++ b/products/experiments/frontend/health/experimentHealthFindingEvents.ts
@@ -22,6 +22,7 @@ export type ExperimentHealthFindingCode =
| 'zero_exposures'
| 'no_metric'
| 'forced_variant_release_condition'
+ | 'flag_variants_mismatch'
export interface ExperimentHealthFinding {
code: ExperimentHealthFindingCode
@@ -147,32 +148,39 @@ export function captureExperimentHealthFindingActedOn(
/**
* Compares the page's own rules with the server's checks for one experiment load. A `_browser` value is the
* result of the page's rule, and a `_server` value is the result of the server's check.
+ *
+ * `health` is null when the request failed. The event then has `request_failed` set, and its finding and
+ * `_server` values are null. A failed request still reports `duration_ms`, so a request that times out
+ * counts in the slow tail of the request time.
*/
export function captureExperimentHealthChecked(
experiment: Experiment,
- health: ExperimentHealthApi,
+ health: ExperimentHealthApi | null,
healthUi: ExperimentHealthUi,
browserWarning: ExperimentWarning | null,
- browserNoMetricsWarning: boolean
+ browserNoMetricsWarning: boolean,
+ durationMs: number
): void {
- const flagStateFinding = health.findings.find((finding) => FLAG_STATE_FINDING_CODES.has(finding.code))
+ const findings = health?.findings ?? null
+ const flagStateFinding = findings?.find((finding) => FLAG_STATE_FINDING_CODES.has(finding.code))
// pinned: analytics event name, so renaming it breaks insights
posthog.capture('experiment health checked', {
experiment_id: experiment.id,
experiment_status: getExperimentStatus(experiment),
health_ui: healthUi,
- health_finding_codes: health.findings.map((finding) => finding.code),
+ request_failed: health === null,
+ duration_ms: durationMs,
+ health_finding_codes: findings?.map((finding) => finding.code) ?? null,
// pinned: `code:subcode`, as on the server's `experiment launched`. The code prefix keeps a subcode
// unambiguous when two codes use the same subcode.
- health_finding_subcodes: health.findings.flatMap(({ code, subcode }) =>
- subcode ? [`${code}:${subcode}`] : []
- ),
- health_finding_count: health.findings.length,
+ health_finding_subcodes:
+ findings?.flatMap(({ code, subcode }) => (subcode ? [`${code}:${subcode}`] : [])) ?? null,
+ health_finding_count: findings?.length ?? null,
flag_state_browser: browserWarning?.key ?? null,
// The server sends the warning key as the subcode. A finding without one still differs from no finding.
flag_state_server: flagStateFinding ? (flagStateFinding.subcode ?? flagStateFinding.code) : null,
no_metric_browser: browserNoMetricsWarning,
- no_metric_server: health.findings.some((finding) => finding.code === 'no_metric'),
+ no_metric_server: findings ? findings.some((finding) => finding.code === 'no_metric') : null,
})
}
diff --git a/products/experiments/frontend/health/healthDebugReport.ts b/products/experiments/frontend/health/healthDebugReport.ts
index e93b223880c8..1f2a1f33003a 100644
--- a/products/experiments/frontend/health/healthDebugReport.ts
+++ b/products/experiments/frontend/health/healthDebugReport.ts
@@ -127,6 +127,18 @@ function noMetricChecks(input: HealthDebugInput): HealthDebugCheck[] {
]
}
+function flagVariantsChecks(input: HealthDebugInput): HealthDebugCheck[] {
+ return [
+ {
+ check: 'flag_variants_mismatch',
+ source: 'server',
+ result: serverResult(input.health, (code) => code === 'flag_variants_mismatch'),
+ note: null,
+ differs: false,
+ },
+ ]
+}
+
function forcedVariantChecks(input: HealthDebugInput): HealthDebugCheck[] {
const finding = input.health?.findings.find(({ code }) => code === 'forced_variant_release_condition')
return [
@@ -208,6 +220,7 @@ function exposureChecks(input: HealthDebugInput): HealthDebugCheck[] {
export function buildHealthDebugChecks(input: HealthDebugInput): HealthDebugCheck[] {
return [
...flagStateChecks(input),
+ ...flagVariantsChecks(input),
...forcedVariantChecks(input),
...noMetricChecks(input),
...exposureChecks(input),
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index a27477161733..88b454489a41 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -44258,6 +44258,7 @@ export namespace Schemas {
* * `srm` - Sample Ratio Mismatch
* * `zero_exposures` - Zero Exposures
* * `forced_variant_release_condition` - Forced Variant Release Condition
+ * * `flag_variants_mismatch` - Flag Variants Mismatch
*/
export type ExperimentHealthFindingCodeEnum = typeof ExperimentHealthFindingCodeEnum[keyof typeof ExperimentHealthFindingCodeEnum];
@@ -44272,6 +44273,7 @@ export namespace Schemas {
Srm: 'srm',
ZeroExposures: 'zero_exposures',
ForcedVariantReleaseCondition: 'forced_variant_release_condition',
+ FlagVariantsMismatch: 'flag_variants_mismatch',
} as const;
/**
@@ -44326,7 +44328,8 @@ export namespace Schemas {
* * `no_metric` - No Metric
* * `srm` - Sample Ratio Mismatch
* * `zero_exposures` - Zero Exposures
- * * `forced_variant_release_condition` - Forced Variant Release Condition */
+ * * `forced_variant_release_condition` - Forced Variant Release Condition
+ * * `flag_variants_mismatch` - Flag Variants Mismatch */
code: ExperimentHealthFindingCodeEnum;
/**
* The case within the code, when a code covers several, for example 'running_but_no_rollout' within 'flag_off_while_running'. Null when the code has one case.