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.

fix(feature-flags): remove warning for mixed-targeting conditions in feature flags (#57582)

Dylan Martina4c985b303de
diff --git a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts
index 7d99bde1fde7..bb60b1a4bfad 100644
--- a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.test.ts
@@ -157,6 +157,85 @@ describe('featureFlagIntentWarningLogic', () => {
groups: [{ properties: [], rollout_percentage: 100, variant: null }],
expectedUnreachable: [],
},
+ {
+ name: 'broad group-targeted condition does not shadow later user-targeted condition',
+ groups: [
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 0,
+ },
+ {
+ properties: [],
+ rollout_percentage: 0,
+ variant: null,
+ aggregation_group_type_index: null,
+ },
+ ],
+ expectedUnreachable: [],
+ },
+ {
+ name: 'broad user-targeted condition does not shadow later group-targeted condition',
+ groups: [
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: null,
+ },
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 0,
+ },
+ ],
+ expectedUnreachable: [],
+ },
+ {
+ name: 'broad group-targeted condition shadows later condition targeting the same group type',
+ groups: [
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 0,
+ },
+ {
+ properties: [
+ {
+ key: 'name',
+ type: PropertyFilterType.Group,
+ value: 'acme',
+ operator: PropertyOperator.Exact,
+ },
+ ],
+ rollout_percentage: 50,
+ variant: null,
+ aggregation_group_type_index: 0,
+ },
+ ],
+ expectedUnreachable: [1],
+ },
+ {
+ name: 'broad condition for group type 0 does not shadow later condition for group type 1',
+ groups: [
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 0,
+ },
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 1,
+ },
+ ],
+ expectedUnreachable: [],
+ },
])('$name', async ({ groups, expectedUnreachable }) => {
flagLogic.actions.setFeatureFlag({
...NEW_FLAG,
@@ -167,6 +246,37 @@ describe('featureFlagIntentWarningLogic', () => {
unreachableGroups: new Set(expectedUnreachable),
})
})
+
+ it('respects explicit null aggregation on a condition even when flag-level aggregation is set', async () => {
+ // Mixed flag: flag-level aggregation_group_type_index is 2, but condition 0 explicitly opts into
+ // user-targeting via aggregation_group_type_index: null. A broad user-targeted condition followed by a
+ // group-type-2 condition must not flag the group condition as unreachable.
+ flagLogic.actions.setFeatureFlag({
+ ...NEW_FLAG,
+ filters: {
+ ...NEW_FLAG.filters,
+ aggregation_group_type_index: 2,
+ groups: [
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: null,
+ },
+ {
+ properties: [],
+ rollout_percentage: 100,
+ variant: null,
+ aggregation_group_type_index: 2,
+ },
+ ] as FeatureFlagGroupType[],
+ },
+ })
+
+ await expectLogic(warningLogic).toMatchValues({
+ unreachableGroups: new Set(),
+ })
+ })
})
describe('local eval intent', () => {
diff --git a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.ts b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.ts
index 5c3da22f9004..65575b9328d1 100644
--- a/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagIntentWarningLogic.ts
@@ -77,13 +77,23 @@ export const featureFlagIntentWarningLogic = kea<featureFlagIntentWarningLogicTy
return new Set()
}
+ // A broad condition only shadows later conditions targeting the same entity type.
+ // Mixed-targeting flags can have condition sets aimed at users (null) or different
+ // group types, which are evaluated independently when their context is provided.
+ const flagAggregation = featureFlag?.filters?.aggregation_group_type_index ?? null
const unreachable = new Set<number>()
- let foundBroad = false
+ const broadAggregations = new Set<number | null>()
for (let i = 0; i < groups.length; i++) {
- if (foundBroad) {
+ const group = groups[i]
+ // Distinguish "not provided" (undefined → inherit flag-level) from "explicitly user-targeted" (null).
+ const aggregation =
+ group.aggregation_group_type_index !== undefined
+ ? group.aggregation_group_type_index
+ : flagAggregation
+ if (broadAggregations.has(aggregation)) {
unreachable.add(i)
- } else if (isGroupBroad(groups[i])) {
- foundBroad = true
+ } else if (isGroupBroad(group)) {
+ broadAggregations.add(aggregation)
}
}
return unreachable