: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): name the readers mode 2 moves to flag_evaluations (#111090)
Phil Haack24f62b8568df
diff --git a/posthog/settings/dynamic_settings.py b/posthog/settings/dynamic_settings.pyindex 0e4035dcd071..15c8eb69a628 100644--- a/posthog/settings/dynamic_settings.py+++ b/posthog/settings/dynamic_settings.py@@ -341,7 +341,8 @@ CONSTANCE_CONFIG = {get_from_env("FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS", False, type_cast=str_to_bool),"When on, the feature flag Usage tab reads the events table for every organization on flag_evaluations ""mode 1. Use it when the flag_evaluations table stops receiving rows. Organizations on mode 2 keep reading "- "flag_evaluations, because once ingestion stops their events writes, events has none of their flag calls. "+ "flag_evaluations, because ingestion writes no flag calls to events for their teams in the ingestion "+ "allowlist. ""Stored modes and the flag_evaluations SQL table stay as they are, so turning it off restores every ""organization. Takes up to a minute to apply, and a page reload to show.",bool,diff --git a/posthog/settings/feature_flags.py b/posthog/settings/feature_flags.pyindex 5ea73e64c84e..4c297f0f709d 100644--- a/posthog/settings/feature_flags.py+++ b/posthog/settings/feature_flags.py@@ -168,8 +168,10 @@ TEAM_METADATA_CACHE_VERIFICATION_GRACE_PERIOD_MINUTES: int = get_from_env()# OrganizationFeatureFlagsConfig.flag_evaluations_mode for a new organization. 0 reads-# $feature_flag_called from events. 1 reads it from flag_evaluations. 2 also stops writing it to events.-# A change here never moves an existing organization.+# $feature_flag_called from events. 1 reads it from flag_evaluations for the flag Usage tab charts.+# 2 also reads it from flag_evaluations for the per-project counts on a flag's Projects tab and for+# events lists filtered to only $feature_flag_called, and stops writing it to events for teams in the+# ingestion allowlist. A change here never moves an existing organization.FLAG_EVALUATIONS_NEW_ORG_MODE: int = get_from_env("FLAG_EVALUATIONS_NEW_ORG_MODE", 0, type_cast=int)# Feature flag limits to prevent memory issues during flag evaluation/caching.diff --git a/products/feature_flags/backend/api/staff_team_config.py b/products/feature_flags/backend/api/staff_team_config.pyindex ae5a938b8a37..1d0396c8a68e 100644--- a/products/feature_flags/backend/api/staff_team_config.py+++ b/products/feature_flags/backend/api/staff_team_config.py@@ -111,9 +111,11 @@ class StaffTeamConfigSerializer(serializers.Serializer):choices=FlagEvaluationsMode.choices,help_text=("Which table the $feature_flag_called data of this team's organization is read from. Every team of "- "an organization shares one mode. 0 reads events, 1 and 2 read flag_evaluations. 2 also stops "- "ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations. This is "- "the stored mode: while the "+ "an organization shares one mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab "+ "charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's "+ "Projects tab and for events lists filtered to only $feature_flag_called, such as the Activity page and "+ "the Usage tab log. On 2, ingestion stops writing $feature_flag_called to events for the teams it "+ "writes to flag_evaluations. This is the stored mode: while the ""FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, an organization on 1 has its Usage tab ""read events anyway."),@@ -172,8 +174,10 @@ class StaffFlagEvaluationsModeMutationSerializer(serializers.Serializer):flag_evaluations_mode = serializers.ChoiceField(choices=FlagEvaluationsMode.choices,help_text=(- "Target flag_evaluations mode. 0 reads events, 1 reads flag_evaluations, 2 also stops ingestion "- "writing $feature_flag_called to events for the teams it writes to flag_evaluations."+ "Target flag_evaluations mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab "+ "charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's "+ "Projects tab and for events lists filtered to only $feature_flag_called, and stops ingestion writing "+ "$feature_flag_called to events for the teams it writes to flag_evaluations."),)team_ids = serializers.ListField(@@ -188,8 +192,9 @@ class StaffFlagEvaluationsModeMutationSerializer(serializers.Serializer):allow_downgrade = serializers.BooleanField(default=False,help_text=(- "Also lower organizations that are above the target mode. Once ingestion acts on mode 2, lowering "- "an organization from 2 leaves a gap in the events table for the time it spent on 2."+ "Also lower organizations that are above the target mode. Lowering an organization from 2 restarts "+ "the events writes that ingestion stopped for its teams in the ingestion allowlist. The events table "+ "keeps a gap for those teams for the time the organization spent on 2."),)dry_run = serializers.BooleanField(diff --git a/products/feature_flags/backend/facade/enums.py b/products/feature_flags/backend/facade/enums.pyindex 62e93e8bf249..163dd1502cd3 100644--- a/products/feature_flags/backend/facade/enums.py+++ b/products/feature_flags/backend/facade/enums.py@@ -13,10 +13,11 @@ class FlagEvaluationsMode(LabeledIntEnum):# The Usage tab reads the events table. The flag_evaluations HogQL table stays hidden unless# the flag-evaluations-hogql-table flag is on for the organization.EVENTS = 0, "Events"- # The Usage tab reads flag_evaluations, and the HogQL table is visible.+ # The Usage tab charts read flag_evaluations, and the HogQL table is visible.READ_FLAG_EVALUATIONS = 1, "Read flag evaluations"- # As READ_FLAG_EVALUATIONS, and ingestion stops writing $feature_flag_called to events. Some readers- # stay on events in READ_FLAG_EVALUATIONS and read flag_evaluations only in this mode. A team+ # As READ_FLAG_EVALUATIONS, and ingestion stops writing $feature_flag_called to events. These readers+ # stay on events in READ_FLAG_EVALUATIONS and read flag_evaluations only in this mode: the per-project+ # counts on a flag's Projects tab, and events lists filtered to only $feature_flag_called. A team# outside the ingestion allowlist still writes to events. INGESTION_FLAG_EVALUATIONS_ONLY_DISABLED# makes ingestion treat this mode as READ_FLAG_EVALUATIONS for every organization.FLAG_EVALUATIONS_ONLY = 2, "Flag evaluations only"diff --git a/products/feature_flags/backend/facade/flags.py b/products/feature_flags/backend/facade/flags.pyindex 3641c6036a45..5205c8d020a1 100644--- a/products/feature_flags/backend/facade/flags.py+++ b/products/feature_flags/backend/facade/flags.py@@ -35,7 +35,7 @@ def get_usage_tab_flag_evaluations_mode(organization_id: UUID) -> int:"""The mode that decides which table the flag Usage tab reads. FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS makesit EVENTS for an organization on READ_FLAG_EVALUATIONS and leaves the stored mode unchanged."""mode = get_organization_flag_evaluations_mode(organization_id)- # The switch skips FLAG_EVALUATIONS_ONLY. Once ingestion supports that mode, events holds none of the+ # The switch skips FLAG_EVALUATIONS_ONLY. For teams in the ingestion allowlist, events holds none of that# organization's flag calls, so the Usage tab would show empty days instead of the flag_evaluations rows.if mode == FlagEvaluationsMode.READ_FLAG_EVALUATIONS and get_instance_setting("FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS"diff --git a/products/feature_flags/backend/management/commands/set_flag_evaluations_mode.py b/products/feature_flags/backend/management/commands/set_flag_evaluations_mode.pyindex 8fa5a81d333b..90bff81ff2d2 100644--- a/products/feature_flags/backend/management/commands/set_flag_evaluations_mode.py+++ b/products/feature_flags/backend/management/commands/set_flag_evaluations_mode.py@@ -4,8 +4,8 @@ New organizations take FLAG_EVALUATIONS_NEW_ORG_MODE when they are created. Thisthe organizations that existed before that setting changed: a list of ids, or every organizationcreated after an instant.-Ingestion does not act on mode 2 yet. An organization set to 2 now behaves as mode 1, and it stops-writing $feature_flag_called to events on its own when that support deploys.+On mode 2, ingestion stops writing $feature_flag_called to events for the organization's teams in+the ingestion allowlist."""import argparse@@ -43,9 +43,11 @@ class Command(BaseCommand):required=True,choices=FlagEvaluationsMode.values,help=(- "0 reads events, 1 reads flag_evaluations, 2 also stops writing flag calls to events. "- "Ingestion does not act on mode 2 yet, so an organization on mode 2 behaves as mode 1 "- "until that ships. "+ "0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is "+ "available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for "+ "events lists filtered to only $feature_flag_called, such as the Activity page and the Usage tab "+ "log. On 2, ingestion stops writing $feature_flag_called to events for teams in the ingestion "+ "allowlist. ""flag_evaluations holds rows only from the day ingestion started writing them ""(2026-09-09 for PostHog Cloud), so on mode 1 or 2 the Usage tab shows no data for earlier days."),@@ -69,8 +71,9 @@ class Command(BaseCommand):"--allow-downgrade",action="store_true",help=(- "Also lower organizations that are above --mode. Once ingestion acts on mode 2, lowering "- "from mode 2 leaves a gap in the events table."+ "Also lower organizations that are above --mode. Lowering an organization from mode 2 restarts "+ "the events writes that ingestion stopped for its teams in the ingestion allowlist. The events "+ "table keeps a gap for those teams for the time the organization spent on 2."),)diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.tsindex 6006e8111d87..6c18f60b04fa 100644--- a/products/feature_flags/frontend/generated/api.schemas.ts+++ b/products/feature_flags/frontend/generated/api.schemas.ts@@ -209,7 +209,7 @@ export interface StaffTeamConfigApi {max_feature_flags_override: number | null/** The flag-count limit actually enforced for this team: the override when one is set, otherwise the global MAX_FEATURE_FLAGS_PER_TEAM setting. */effective_max_feature_flags: number- /** Which table the $feature_flag_called data of this team's organization is read from. Every team of an organization shares one mode. 0 reads events, 1 and 2 read flag_evaluations. 2 also stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations. This is the stored mode: while the FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, an organization on 1 has its Usage tab read events anyway.+ /** Which table the $feature_flag_called data of this team's organization is read from. Every team of an organization shares one mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for events lists filtered to only $feature_flag_called, such as the Activity page and the Usage tab log. On 2, ingestion stops writing $feature_flag_called to events for the teams it writes to flag_evaluations. This is the stored mode: while the FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, an organization on 1 has its Usage tab read events anyway.** * `0` - Events* * `1` - Read flag evaluations@@ -244,7 +244,7 @@ export interface StaffTeamConfigMutationApi {}export interface StaffFlagEvaluationsModeMutationApi {- /** Target flag_evaluations mode. 0 reads events, 1 reads flag_evaluations, 2 also stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.+ /** Target flag_evaluations mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for events lists filtered to only $feature_flag_called, and stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.** * `0` - Events* * `1` - Read flag evaluations@@ -256,7 +256,7 @@ export interface StaffFlagEvaluationsModeMutationApi {* @maxItems 50*/team_ids: number[]- /** Also lower organizations that are above the target mode. Once ingestion acts on mode 2, lowering an organization from 2 leaves a gap in the events table for the time it spent on 2. */+ /** Also lower organizations that are above the target mode. Lowering an organization from 2 restarts the events writes that ingestion stopped for its teams in the ingestion allowlist. The events table keeps a gap for those teams for the time the organization spent on 2. */allow_downgrade?: boolean/** Report what the write would change, and write nothing. */dry_run?: booleandiff --git a/products/feature_flags/frontend/generated/api.zod.ts b/products/feature_flags/frontend/generated/api.zod.tsindex bee3f415311b..1dbeaf8e3372 100644--- a/products/feature_flags/frontend/generated/api.zod.ts+++ b/products/feature_flags/frontend/generated/api.zod.ts@@ -139,7 +139,7 @@ export const FeatureFlagsStaffTeamConfigSetFlagEvaluationsModeCreateBody = /* @_flag_evaluations_mode: zod.union([zod.literal(0), zod.literal(1), zod.literal(2)]).describe(- 'Target flag_evaluations mode. 0 reads events, 1 reads flag_evaluations, 2 also stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.\n\n\* `0` - Events\n\* `1` - Read flag evaluations\n\* `2` - Flag evaluations only'+ "Target flag_evaluations mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for events lists filtered to only $feature_flag_called, and stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.\n\n\* `0` - Events\n\* `1` - Read flag evaluations\n\* `2` - Flag evaluations only"),team_ids: zod.array(zod.number())@@ -152,7 +152,7 @@ export const FeatureFlagsStaffTeamConfigSetFlagEvaluationsModeCreateBody = /* @_.boolean().default(featureFlagsStaffTeamConfigSetFlagEvaluationsModeCreateBodyAllowDowngradeDefault).describe(- 'Also lower organizations that are above the target mode. Once ingestion acts on mode 2, lowering an organization from 2 leaves a gap in the events table for the time it spent on 2.'+ 'Also lower organizations that are above the target mode. Lowering an organization from 2 restarts the events writes that ingestion stopped for its teams in the ingestion allowlist. The events table keeps a gap for those teams for the time the organization spent on 2.'),dry_run: zod.boolean()diff --git a/products/feature_flags/frontend/staff/StaffFlagEvaluationsModeModal.tsx b/products/feature_flags/frontend/staff/StaffFlagEvaluationsModeModal.tsxindex 71a365b4932c..5549eccaa382 100644--- a/products/feature_flags/frontend/staff/StaffFlagEvaluationsModeModal.tsx+++ b/products/feature_flags/frontend/staff/StaffFlagEvaluationsModeModal.tsx@@ -20,7 +20,7 @@ import { FLAG_EVALUATIONS_MODE_LABELS, featureFlagsStaffToolsLogic } from './feaconst MODE_DESCRIPTIONS: Record<FlagEvaluationsModeEnumApi, string> = {0: 'The Usage tab reads $feature_flag_called events from the events table.',1: 'The Usage tab reads the flag_evaluations table, and the table is available in SQL. While the FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, the Usage tab reads the events table instead.',- 2: 'The Usage tab and any events list filtered to $feature_flag_called read the flag_evaluations table, and the table is available in SQL. For teams in the ingestion allowlist, ingestion also stops writing $feature_flag_called to the events table.',+ 2: "The Usage tab, the per-project counts on a flag's Projects tab, and any events list filtered to $feature_flag_called read the flag_evaluations table, and the table is available in SQL. For teams in the ingestion allowlist, ingestion also stops writing $feature_flag_called to the events table.",}export function StaffFlagEvaluationsModeModal(): JSX.Element {diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 1e3d2c1de0a8..f0c38f7eb552 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -100878,7 +100878,7 @@ export namespace Schemas {}export interface StaffFlagEvaluationsModeMutation {- /** Target flag_evaluations mode. 0 reads events, 1 reads flag_evaluations, 2 also stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.+ /** Target flag_evaluations mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for events lists filtered to only $feature_flag_called, and stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations.** * `0` - Events* * `1` - Read flag evaluations@@ -100890,7 +100890,7 @@ export namespace Schemas {* @maxItems 50*/team_ids: number[];- /** Also lower organizations that are above the target mode. Once ingestion acts on mode 2, lowering an organization from 2 leaves a gap in the events table for the time it spent on 2. */+ /** Also lower organizations that are above the target mode. Lowering an organization from 2 restarts the events writes that ingestion stopped for its teams in the ingestion allowlist. The events table keeps a gap for those teams for the time the organization spent on 2. */allow_downgrade?: boolean;/** Report what the write would change, and write nothing. */dry_run?: boolean;@@ -100960,7 +100960,7 @@ export namespace Schemas {max_feature_flags_override: number | null;/** The flag-count limit actually enforced for this team: the override when one is set, otherwise the global MAX_FEATURE_FLAGS_PER_TEAM setting. */effective_max_feature_flags: number;- /** Which table the $feature_flag_called data of this team's organization is read from. Every team of an organization shares one mode. 0 reads events, 1 and 2 read flag_evaluations. 2 also stops ingestion writing $feature_flag_called to events for the teams it writes to flag_evaluations. This is the stored mode: while the FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, an organization on 1 has its Usage tab read events anyway.+ /** Which table the $feature_flag_called data of this team's organization is read from. Every team of an organization shares one mode. 0 reads events. 1 reads flag_evaluations for the flag Usage tab charts, and the table is available in SQL. 2 also reads it for the per-project counts on a flag's Projects tab and for events lists filtered to only $feature_flag_called, such as the Activity page and the Usage tab log. On 2, ingestion stops writing $feature_flag_called to events for the teams it writes to flag_evaluations. This is the stored mode: while the FLAG_EVALUATIONS_USAGE_TAB_FORCE_EVENTS instance setting is on, an organization on 1 has its Usage tab read events anyway.** * `0` - Events* * `1` - Read flag evaluations