: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): allow setting multiple_variant_handling via experiment-update (#66260)
Anders394caf00e389
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 14ee78c6369a..561cb42a198f 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -19129,6 +19129,11 @@},"filterTestAccounts": {"type": "boolean"+ },+ "multiple_variant_handling": {+ "description": "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure.",+ "enum": ["exclude", "first_seen"],+ "type": "string"}},"type": "object"diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 2804f48a558f..f1ae5672ff35 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -4119,6 +4119,9 @@ export interface ExperimentApiExposureConfig {export interface ExperimentApiExposureCriteria {filterTestAccounts?: booleanexposure_config?: ExperimentApiExposureConfig+ /** How to handle entities exposed to multiple variants. 'exclude' (default) drops them from+ * the analysis; 'first_seen' assigns them to the variant from their earliest exposure. */+ multiple_variant_handling?: 'exclude' | 'first_seen'}export const enum ExperimentMetricType {diff --git a/posthog/schema.py b/posthog/schema.pyindex 08868d32733f..355d159c2071 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -4966,6 +4966,14 @@ class ExperimentApiExposureCriteria(BaseModel):)exposure_config: ExperimentApiExposureConfig | None = NonefilterTestAccounts: bool | None = None+ multiple_variant_handling: MultipleVariantHandling | None = Field(+ default=None,+ description=(+ "How to handle entities exposed to multiple variants. 'exclude' (default)"+ " drops them from the analysis; 'first_seen' assigns them to the variant"+ " from their earliest exposure."+ ),+ )class ExperimentApiMetric(BaseModel):diff --git a/products/experiments/backend/test/test_presentation_api.py b/products/experiments/backend/test/test_presentation_api.pyindex 5b0ca026ea38..a7ec6c281d3c 100644--- a/products/experiments/backend/test/test_presentation_api.py+++ b/products/experiments/backend/test/test_presentation_api.py@@ -7538,3 +7538,28 @@ class TestExperimentSerializerSuperset(unittest.TestCase):mismatches,"Shared fields have mismatched read_only/required between serializers:\n" + "\n".join(mismatches),)+++class TestExperimentApiExposureCriteriaParity(unittest.TestCase):+ """Structural guard: the slim API exposure-criteria schema must expose every writable field.++ ``exposure_criteria`` is stored as a plain JSONField, so the backend accepts any field at+ runtime. ``ExperimentApiExposureCriteria`` is the slim type that drives the OpenAPI spec and,+ downstream, the MCP tool / frontend write schema. A field honored at runtime (read from+ ``ExperimentExposureCriteria``) but missing from the slim type is silently stripped by the+ generated client before it ever reaches the API — which is how ``multiple_variant_handling``+ looked settable via ``experiment-get`` yet never saved via ``experiment-update``.+ """++ def test_api_schema_exposes_every_runtime_field(self) -> None:+ from posthog.schema import ExperimentApiExposureCriteria, ExperimentExposureCriteria++ runtime_fields = set(ExperimentExposureCriteria.model_fields)+ api_fields = set(ExperimentApiExposureCriteria.model_fields)+ dropped = runtime_fields - api_fields+ self.assertFalse(+ dropped,+ f"ExperimentApiExposureCriteria omits exposure_criteria fields the runtime honors: {dropped}. "+ "Generated write clients (MCP, frontend) strip these silently — add them to the slim API "+ "type in frontend/src/queries/schema/schema-general.ts and rerun hogli build:schema.",+ )diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.tsindex 7326b64ed8e4..7f58e325bb3d 100644--- a/products/experiments/frontend/generated/api.schemas.ts+++ b/products/experiments/frontend/generated/api.schemas.ts@@ -513,9 +513,18 @@ export interface ExperimentApiExposureConfigApi {properties: EventPropertyFilterApi[]}+export type MultipleVariantHandlingApi = (typeof MultipleVariantHandlingApi)[keyof typeof MultipleVariantHandlingApi]++export const MultipleVariantHandlingApi = {+ Exclude: 'exclude',+ FirstSeen: 'first_seen',+} as const+export interface ExperimentApiExposureCriteriaApi {exposure_config?: ExperimentApiExposureConfigApi | nullfilterTestAccounts?: boolean | null+ /** How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure. */+ multiple_variant_handling?: MultipleVariantHandlingApi | null}export type KindApi = (typeof KindApi)[keyof typeof KindApi]diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex abfc33531d38..2e3bbf1e6eea 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -21066,6 +21066,8 @@ export namespace Schemas {export interface ExperimentApiExposureCriteria {exposure_config?: ExperimentApiExposureConfig | null;filterTestAccounts?: boolean | null;+ /** How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure. */+ multiple_variant_handling?: MultipleVariantHandling | null;}export type Kind = typeof Kind[keyof typeof Kind];diff --git a/services/mcp/src/generated/experiments/api.ts b/services/mcp/src/generated/experiments/api.tsindex 29b1dbd3f1d9..45da22976a7f 100644--- a/services/mcp/src/generated/experiments/api.ts+++ b/services/mcp/src/generated/experiments/api.ts@@ -494,6 +494,12 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod]).optional(),filterTestAccounts: zod.union([zod.boolean(), zod.null()]).optional(),+ multiple_variant_handling: zod+ .union([zod.enum(['exclude', 'first_seen']), zod.null()])+ .optional()+ .describe(+ "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure."+ ),}),zod.null(),])@@ -2879,6 +2885,12 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod]).optional(),filterTestAccounts: zod.union([zod.boolean(), zod.null()]).optional(),+ multiple_variant_handling: zod+ .union([zod.enum(['exclude', 'first_seen']), zod.null()])+ .optional()+ .describe(+ "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure."+ ),}),zod.null(),])@@ -5329,6 +5341,12 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod]).optional(),filterTestAccounts: zod.union([zod.boolean(), zod.null()]).optional(),+ multiple_variant_handling: zod+ .union([zod.enum(['exclude', 'first_seen']), zod.null()])+ .optional()+ .describe(+ "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure."+ ),}),zod.null(),])diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.jsonindex e8d9b2995181..e61d56890f74 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json@@ -186,6 +186,18 @@"type": "null"}]+ },+ "multiple_variant_handling": {+ "anyOf": [+ {+ "enum": ["exclude", "first_seen"],+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure."}},"type": "object"diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.jsonindex 1afdc5279736..349a8b9957f2 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json@@ -214,6 +214,18 @@"type": "null"}]+ },+ "multiple_variant_handling": {+ "anyOf": [+ {+ "enum": ["exclude", "first_seen"],+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "How to handle entities exposed to multiple variants. 'exclude' (default) drops them from the analysis; 'first_seen' assigns them to the variant from their earliest exposure."}},"type": "object"