: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(flags): describe the active filter and the status field in the schema (#108421)
James Gill51fd0cf25c29
diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.pyindex fca577c7b3cd..defbbada5c75 100644--- a/products/feature_flags/backend/api/feature_flag.py+++ b/products/feature_flags/backend/api/feature_flag.py@@ -141,6 +141,7 @@ from products.feature_flags.backend.filters_validation import collect_cross_fielfrom products.feature_flags.backend.flag_analytics import increment_request_countfrom products.feature_flags.backend.flag_limits import get_max_feature_flags_for_teamfrom products.feature_flags.backend.flag_status import (+ STALE_ACTIVE_PARAM_DESCRIPTION,FeatureFlagStatusChecker,exclude_archived_unless_requested,filter_flags_by_active_param,@@ -1304,7 +1305,13 @@ class FeatureFlagSerializer(# :TRICKY: Needed for backwards compatibilityfilters = serializers.DictField(source="get_filters", required=False)- status = serializers.SerializerMethodField()+ status = serializers.SerializerMethodField(+ help_text=(+ "Staleness classification: ACTIVE, STALE, ARCHIVED, DELETED or UNKNOWN. This is not the "+ "serving state. Read the `active` field for that. A disabled flag that is not archived or "+ "deleted reports ACTIVE, because disabled flags are not evaluated for staleness."+ )+ )ensure_experience_continuity = ClassicBehaviorBooleanFieldSerializer()has_enriched_analytics = ClassicBehaviorBooleanFieldSerializer()@@ -3215,9 +3222,11 @@ class FeatureFlagRolloutSummarySerializer(serializers.Serializer):class FeatureFlagStatusResponseSerializer(serializers.Serializer):status = serializers.CharField(help_text=(- "Flag staleness/evaluation status: active, stale, archived, deleted, or unknown. 'active' means the flag "- "was recently evaluated (or has no usage data yet) — it does NOT mean the flag is fully rolled "- "out. Use the `rollout` object to determine rollout completeness."+ "Staleness classification: active, stale, archived, deleted, or unknown. This is not the serving "+ "state, and this response carries no serving-state field: read the `active` field of the flag "+ "itself from the list or retrieve endpoint. A disabled flag that is not archived or deleted "+ "reports 'active', because disabled flags are not evaluated for staleness. 'active' also does "+ "NOT mean the flag is fully rolled out. Use the `rollout` object to determine rollout completeness."))reason = serializers.CharField(help_text="Human-readable explanation of the status")@@ -3522,7 +3531,7 @@ class BulkDeleteFiltersSerializer(serializers.Serializer):active = serializers.ChoiceField(choices=["true", "false", "STALE"],required=False,- help_text="Filter by active state.",+ help_text=STALE_ACTIVE_PARAM_DESCRIPTION,)created_by_id = serializers.IntegerField(required=False,@@ -4067,6 +4076,7 @@ class FeatureFlagViewSet(location=OpenApiParameter.QUERY,required=False,enum=["true", "false", "STALE"],+ description=STALE_ACTIVE_PARAM_DESCRIPTION,),OpenApiParameter("created_by_id",diff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.pyindex 19ef55036e3a..1c6bf7fb6b1f 100644--- a/products/feature_flags/backend/api/test/test_feature_flag.py+++ b/products/feature_flags/backend/api/test/test_feature_flag.py@@ -13481,6 +13481,60 @@ class TestFeatureFlagStatus(APIBaseTest, ClickhouseTestMixin):assert result["status"] == "STALE"+class TestFeatureFlagServingStateContract(APIBaseTest):+ def setUp(self):+ super().setUp()+ self.disabled_flag = FeatureFlag.objects.create(+ team=self.team,+ created_by=self.user,+ key="disabled-flag",+ active=False,+ )+ self.enabled_flag = FeatureFlag.objects.create(+ team=self.team,+ created_by=self.user,+ key="enabled-flag",+ active=True,+ )++ def test_active_false_filters_on_the_column_and_not_on_status(self):+ response = self.client.get(f"/api/projects/{self.team.id}/feature_flags?active=false")+ assert response.status_code == status.HTTP_200_OK++ results = response.json()["results"]+ assert [result["key"] for result in results] == ["disabled-flag"]+ assert results[0]["active"] is False+ assert results[0]["status"] == "ACTIVE"++ enabled = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{self.enabled_flag.id}").json()+ assert enabled["status"] == "ACTIVE"++ def test_stale_filter_skips_old_uncalled_flag_with_empty_groups(self):+ flag = FeatureFlag.objects.create(+ team=self.team,+ created_by=self.user,+ key="unconfigured-old-flag",+ active=True,+ filters={"groups": []},+ created_at=datetime.now(UTC) - timedelta(days=60),+ )+ stale = self.client.get(f"/api/projects/{self.team.id}/feature_flags?active=STALE").json()["results"]+ assert "unconfigured-old-flag" not in {r["key"] for r in stale}+ retrieved = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{flag.id}").json()+ assert retrieved["status"] == "STALE"++ def test_list_definition_and_status_endpoint_agree_on_a_disabled_flag(self):+ list_row = self.client.get(f"/api/projects/{self.team.id}/feature_flags?active=false").json()["results"][0]+ definition = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{self.disabled_flag.id}").json()+ staleness = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{self.disabled_flag.id}/status").json()++ assert list_row["active"] is False+ assert definition["active"] is False+ assert list_row["status"] == definition["status"] == "ACTIVE"+ assert staleness["status"] == "active"+ assert staleness["reason"] == "Flag is disabled (not evaluated for staleness)"++class TestFeatureFlagMatchingIds(APIBaseTest):def setUp(self):super().setUp()diff --git a/products/feature_flags/backend/flag_status.py b/products/feature_flags/backend/flag_status.pyindex 0faae66fc716..e431a1b4c18d 100644--- a/products/feature_flags/backend/flag_status.py+++ b/products/feature_flags/backend/flag_status.py@@ -111,7 +111,8 @@ def filter_stale_flags(queryset: QuerySet, *, stale_threshold: datetime | None =Set-based counterpart to `FeatureFlagStatusChecker.get_status`, which answers the samequestion for one flag and also produces the human-readable reason. The two are meant to- classify the same flags, so change them together.+ classify the same flags, so change them together. `STALE_ACTIVE_PARAM_DESCRIPTION` states+ these branches in prose for the published API schemas, so change it with them too.They do not agree on one shape: the checker calls a flag with no release conditions fullyrolled out, so `filters` of `{"groups": []}` (the model default) is STALE to the checker and@@ -221,6 +222,22 @@ def filter_effectively_full_rollout_flags(queryset: QuerySet) -> QuerySet:return queryset.extra(where=[_HAS_UNTARGETED_FULL_ROLLOUT_GROUP])+# Describes the `active` param for every published schema that accepts it: the list endpoint's+# OpenAPI parameter and the bulk-delete filter serializer. It states in prose what+# `filter_stale_flags` matches, so it has to change with that SQL.+STALE_ACTIVE_PARAM_DESCRIPTION = (+ "'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' "+ "returns enabled flags only, so a disabled flag is never STALE. An enabled flag "+ "matches when its last recorded `$feature_flag_called` event is more than "+ f"{STALE_FLAG_THRESHOLD_DAYS} days old. With no recorded event, it matches when it is "+ f"at least {STALE_FLAG_THRESHOLD_DAYS} days old and either stores `filters` as `{{}}` "+ "or serves one result to everyone through a release condition at 100% with no "+ "property filters. A flag with no recorded event and an empty `groups` list does not "+ "match, even when its `status` reads STALE. An SDK that sends no "+ "`$feature_flag_called` event leaves no record, so a STALE flag can still be in use."+)++def filter_flags_by_active_param(queryset: QuerySet, value: str | bool) -> QuerySet:"""Filter a FeatureFlag queryset by the `active` param (STALE / true / false).diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.tsindex e8e0d7dc11b4..f74dd729756e 100644--- a/products/feature_flags/frontend/generated/api.schemas.ts+++ b/products/feature_flags/frontend/generated/api.schemas.ts@@ -671,6 +671,7 @@ export interface FeatureFlagApi {is_remote_configuration?: boolean | null/** @nullable */has_encrypted_payloads?: boolean | null+ /** Staleness classification: ACTIVE, STALE, ARCHIVED, DELETED or UNKNOWN. This is not the serving state. Read the `active` field for that. A disabled flag that is not archived or deleted reports ACTIVE, because disabled flags are not evaluated for staleness. */readonly status: string/** Specifies where this feature flag should be evaluated*@@ -1418,7 +1419,7 @@ export interface FeatureFlagRolloutSummaryApi {}export interface FeatureFlagStatusResponseApi {- /** Flag staleness/evaluation status: active, stale, archived, deleted, or unknown. 'active' means the flag was recently evaluated (or has no usage data yet) — it does NOT mean the flag is fully rolled out. Use the `rollout` object to determine rollout completeness. */+ /** Staleness classification: active, stale, archived, deleted, or unknown. This is not the serving state, and this response carries no serving-state field: read the `active` field of the flag itself from the list or retrieve endpoint. A disabled flag that is not archived or deleted reports 'active', because disabled flags are not evaluated for staleness. 'active' also does NOT mean the flag is fully rolled out. Use the `rollout` object to determine rollout completeness. */status: string/** Human-readable explanation of the status */reason: string@@ -1606,7 +1607,7 @@ export const BulkDeleteFiltersTypeEnumApi = {* Allowed filter keys for bulk_delete — same shape as the list endpoint's query params.*/export interface BulkDeleteFiltersApi {- /** Filter by active state.+ /** 'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.** * `true` - true* * `false` - false@@ -2126,6 +2127,9 @@ export const FeatureFlagRequestUsageListTimeInterval = {} as constexport type FeatureFlagsListParams = {+ /**+ * 'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.+ */active?: FeatureFlagsListActive/*** Filter by archived state. When omitted, archived flags are excluded.diff --git a/products/feature_flags/frontend/generated/api.zod.ts b/products/feature_flags/frontend/generated/api.zod.tsindex 5130547f13d5..d871b32c8a9a 100644--- a/products/feature_flags/frontend/generated/api.zod.ts+++ b/products/feature_flags/frontend/generated/api.zod.ts@@ -1223,7 +1223,9 @@ export const FeatureFlagsBulkDeleteCreateBody = /* @__PURE__ */ zod.object({.enum(['true', 'false', 'STALE']).describe('\* `true` - true\n\* `false` - false\n\* `STALE` - STALE').optional()- .describe('Filter by active state.\n\n\* `true` - true\n\* `false` - false\n\* `STALE` - STALE'),+ .describe(+ "'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.\n\n\* `true` - true\n\* `false` - false\n\* `STALE` - STALE"+ ),created_by_id: zod.number().optional().describe('Filter to flags created by a specific user ID.'),search: zod.string().optional().describe('Search by feature flag key or name (case-insensitive).'),type: zoddiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 732a63d85a41..8012bddb7746 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -17282,7 +17282,7 @@ export namespace Schemas {* Allowed filter keys for bulk_delete — same shape as the list endpoint's query params.*/export interface BulkDeleteFilters {- /** Filter by active state.+ /** 'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.** * `true` - true* * `false` - false@@ -47177,6 +47177,7 @@ export namespace Schemas {is_remote_configuration?: boolean | null;/** @nullable */has_encrypted_payloads?: boolean | null;+ /** Staleness classification: ACTIVE, STALE, ARCHIVED, DELETED or UNKNOWN. This is not the serving state. Read the `active` field for that. A disabled flag that is not archived or deleted reports ACTIVE, because disabled flags are not evaluated for staleness. */readonly status: string;/** Specifies where this feature flag should be evaluated*@@ -47483,7 +47484,7 @@ export namespace Schemas {}export interface FeatureFlagStatusResponse {- /** Flag staleness/evaluation status: active, stale, archived, deleted, or unknown. 'active' means the flag was recently evaluated (or has no usage data yet) — it does NOT mean the flag is fully rolled out. Use the `rollout` object to determine rollout completeness. */+ /** Staleness classification: active, stale, archived, deleted, or unknown. This is not the serving state, and this response carries no serving-state field: read the `active` field of the flag itself from the list or retrieve endpoint. A disabled flag that is not archived or deleted reports 'active', because disabled flags are not evaluated for staleness. 'active' also does NOT mean the flag is fully rolled out. Use the `rollout` object to determine rollout completeness. */status: string;/** Human-readable explanation of the status */reason: string;@@ -114152,6 +114153,9 @@ export namespace Schemas {} as const;export type FeatureFlagsListParams = {+ /**+ * 'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.+ */active?: FeatureFlagsListActive;/*** Filter by archived state. When omitted, archived flags are excluded.diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.tsindex 04454b5714b9..14543617152a 100644--- a/services/mcp/src/generated/feature_flags/api.ts+++ b/services/mcp/src/generated/feature_flags/api.ts@@ -80,7 +80,12 @@ export const FeatureFlagsListParams = () => zod.object({})export const FeatureFlagsListQueryParams = () => zod.object({- active: zod.enum(['STALE', 'false', 'true']).optional(),+ active: zod+ .enum(['STALE', 'false', 'true'])+ .optional()+ .describe(+ "'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use."+ ),archived: zod.enum(['false', 'true']).optional()@@ -1172,7 +1177,9 @@ export const FeatureFlagsBulkDeleteCreateBody = () => zod.object({.enum(['true', 'false', 'STALE']).describe('\* `true` - true\n\* `false` - false\n\* `STALE` - STALE').optional()- .describe('Filter by active state.\n\n\* `true` - true\n\* `false` - false\n\* `STALE` - STALE'),+ .describe(+ "'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.\n\n\* `true` - true\n\* `false` - false\n\* `STALE` - STALE"+ ),created_by_id: zod.number().optional().describe('Filter to flags created by a specific user ID.'),search: zod.string().optional().describe('Search by feature flag key or name (case-insensitive).'),type: zoddiff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-bulk-delete-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-bulk-delete-create.jsonindex 4e6f76779235..af4964a6ce2b 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-bulk-delete-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/feature-flags-bulk-delete-create.json@@ -5,7 +5,7 @@"description": "Filter criteria — same shape as the list endpoint's query params. Mutually exclusive with `ids`. Use this to bulk-delete by search/active/tags/etc. instead of supplying explicit IDs.","properties": {"active": {- "description": "Filter by active state.\n\n* `true` - true\n* `false` - false\n* `STALE` - STALE",+ "description": "'true' and 'false' filter on serving state, the flag's `active` column. 'STALE' returns enabled flags only, so a disabled flag is never STALE. An enabled flag matches when its last recorded `$feature_flag_called` event is more than 30 days old. With no recorded event, it matches when it is at least 30 days old and either stores `filters` as `{}` or serves one result to everyone through a release condition at 100% with no property filters. A flag with no recorded event and an empty `groups` list does not match, even when its `status` reads STALE. An SDK that sends no `$feature_flag_called` event leaves no record, so a STALE flag can still be in use.\n\n* `true` - true\n* `false` - false\n* `STALE` - STALE","enum": ["true", "false", "STALE"],"type": "string"},