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(flags): respect explicit user targeting in mixed condition sets (#65926)

Steven Shultsaa1143b5d680
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
index db3969d1cda5..cca9e880a2c3 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
@@ -44,6 +44,7 @@ import {
PropertyOperator,
} from '~/types'
+import { resolveAggregationGroupTypeIndex } from './aggregation'
import { MATCHING_ESTIMATE_TOOLTIP } from './constants'
import { featureFlagLogic } from './featureFlagLogic'
import {
@@ -460,7 +461,10 @@ export function FeatureFlagReleaseConditions({
const targetIndex = group.aggregation_group_type_index
const pluralName = aggregationTargetName(targetIndex)
const singularName = aggregationLabel(
- targetIndex ?? filters.aggregation_group_type_index,
+ resolveAggregationGroupTypeIndex(
+ targetIndex,
+ filters.aggregation_group_type_index
+ ),
true
).singular
const affected = group.sort_key ? affectedCounts[group.sort_key] : undefined
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
index 33ec5a713bae..48515b620e8d 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
@@ -72,6 +72,7 @@ import {
import { INTENT_METADATA } from 'products/feature_flags/frontend/featureFlagTemplateConstants'
+import { resolveAggregationGroupTypeIndex } from './aggregation'
import { MATCHING_ESTIMATE_TOOLTIP } from './constants'
import { EarlyExitIndicator } from './EarlyExitIndicator'
import { FeatureFlagConditionDragHandle } from './FeatureFlagConditionDragHandle'
@@ -478,7 +479,10 @@ const ConditionContent = ({
const resolvedTargetName = aggregationTargetName(group.aggregation_group_type_index)
const resolvedSingularTargetName = aggregationLabel(
- group.aggregation_group_type_index ?? releaseFilters.aggregation_group_type_index,
+ resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ releaseFilters.aggregation_group_type_index
+ ),
true
).singular
@@ -607,8 +611,7 @@ const ConditionContent = ({
updateConditionSet(index, undefined, properties)
}}
taxonomicGroupTypes={taxonomicGroupTypesForCondition(
- group.aggregation_group_type_index ??
- releaseFilters.aggregation_group_type_index
+ group.aggregation_group_type_index
)}
taxonomicFilterOptionsFromProp={filtersTaxonomicOptions}
hasRowOperator={false}
@@ -683,9 +686,10 @@ const ConditionContent = ({
resolvedTargetName
)}
</b>
- {(group.aggregation_group_type_index ??
- releaseFilters.aggregation_group_type_index) ==
- null && (
+ {resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ releaseFilters.aggregation_group_type_index
+ ) == null && (
<Tooltip
title={MATCHING_ESTIMATE_TOOLTIP}
interactive
diff --git a/frontend/src/scenes/feature-flags/aggregation.ts b/frontend/src/scenes/feature-flags/aggregation.ts
new file mode 100644
index 000000000000..1f627b1aa84d
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/aggregation.ts
@@ -0,0 +1,14 @@
+/**
+ * Resolves a condition set's effective aggregation group type index, mirroring the backend's
+ * `effective_aggregation` (rust/feature-flags/src/flags/flag_property_group.rs). The per-condition
+ * field has three states that must stay distinct — `??` would wrongly collapse the first two:
+ * - `undefined` — not set, inherit the flag-level (global) index
+ * - `null` — explicitly target users, overriding the global group index
+ * - number — explicitly target that group type
+ */
+export function resolveAggregationGroupTypeIndex(
+ conditionGroupTypeIndex: number | null | undefined,
+ flagLevelGroupTypeIndex: number | null | undefined
+): number | null {
+ return (conditionGroupTypeIndex !== undefined ? conditionGroupTypeIndex : flagLevelGroupTypeIndex) ?? null
+}
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
index c4e6bde5f8c7..442b0b423f02 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
@@ -2,6 +2,7 @@ import { expectLogic } from 'kea-test-utils'
import { v4 as uuidv4 } from 'uuid'
import api from 'lib/api'
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
@@ -14,6 +15,7 @@ import {
PropertyOperator,
} from '~/types'
+import { resolveAggregationGroupTypeIndex } from './aggregation'
import { featureFlagReleaseConditionsLogic } from './featureFlagReleaseConditionsLogic'
jest.mock('uuid', () => ({
@@ -439,6 +441,53 @@ describe('the feature flag release conditions logic', () => {
}
})
+ it('sends user scope to blast radius when a condition explicitly targets users over a flag-level group', async () => {
+ logic?.unmount()
+
+ const createSpy = jest.spyOn(api, 'create').mockResolvedValue({ affected: 10, total: 100 })
+
+ try {
+ logic = featureFlagReleaseConditionsLogic({
+ id: 'condition-null-override-test',
+ filters: {
+ ...generateFeatureFlagFilters([
+ {
+ properties: [
+ {
+ key: 'email',
+ value: 'test',
+ type: PropertyFilterType.Person,
+ operator: PropertyOperator.Exact,
+ },
+ ],
+ rollout_percentage: 100,
+ variant: null,
+ sort_key: 'A',
+ // Explicit null = "users", must override the flag-level group index below
+ aggregation_group_type_index: null,
+ },
+ ]),
+ aggregation_group_type_index: 0,
+ },
+ })
+
+ await expectLogic(logic, () => {
+ logic.mount()
+ }).toFinishAllListeners()
+
+ expect(createSpy).toHaveBeenCalledWith(
+ expect.stringContaining('user_blast_radius'),
+ expect.objectContaining({ group_type_index: null })
+ )
+ expect(createSpy).not.toHaveBeenCalledWith(
+ expect.stringContaining('user_blast_radius'),
+ expect.objectContaining({ group_type_index: 0 })
+ )
+ } finally {
+ createSpy.mockRestore()
+ }
+ })
+
it('stores counts from group-aggregated blast radius response', async () => {
logic?.unmount()
@@ -1153,6 +1202,53 @@ describe('the feature flag release conditions logic', () => {
})
})
+ it("keeps an explicit-user condition's properties when the flag-level index is a group", async () => {
+ logic?.unmount()
+
+ logic = featureFlagReleaseConditionsLogic({
+ id: 'transition-user-cond-under-group-flag',
+ filters: {
+ ...generateFeatureFlagFilters([
+ {
+ properties: userProperties,
+ rollout_percentage: 50,
+ variant: null,
+ sort_key: 'user-cond',
+ aggregation_group_type_index: null,
+ },
+ {
+ properties: groupProperties,
+ rollout_percentage: 30,
+ variant: 'test',
+ sort_key: 'group-cond',
+ aggregation_group_type_index: 0,
+ },
+ ]),
+ // Flag-level index is a group (a number). This is what makes the resolver
+ // differ from `??`: the explicit-null user condition must resolve to users,
+ // not collapse into this group index, so toggling to users leaves its
+ // properties untouched (under the old `??` they were wrongly wiped).
+ aggregation_group_type_index: 1,
+ },
+ })
+
+ await expectLogic(logic, () => {
+ logic.mount()
+ })
+
+ await expectLogic(logic, () => {
+ logic.actions.setAggregationGroupTypeIndex(null)
+ }).toMatchValues({
+ filters: expect.objectContaining({
+ aggregation_group_type_index: null,
+ groups: [
+ expect.objectContaining({ sort_key: 'user-cond', properties: userProperties }),
+ expect.objectContaining({ sort_key: 'group-cond', properties: [] }),
+ ],
+ }),
+ })
+ })
+
// v2 Properties → Device: the UI calls setAggregationGroupTypeIndex(null) when switching
// to Device mode. Group-scoped condition properties are dropped (incompatible with
// distinct_id bucketing) while person-scoped condition properties are preserved.
@@ -1452,4 +1548,45 @@ describe('the feature flag release conditions logic', () => {
expect(logic.values.distinctIds).toEqual([])
})
})
+
+ describe('per-condition aggregation scope resolution', () => {
+ // Mirrors the backend's effective_aggregation (rust/feature-flags/src/flags/flag_property_group.rs):
+ // a condition's explicit null ("users") must win over a flag-level group index, while an
+ // absent (undefined) value inherits the flag-level index.
+ it.each([
+ // [conditionLevel, flagLevel, expected]
+ [undefined, 1, 1], // absent → inherit flag-level group
+ [undefined, null, null], // absent → inherit flag-level user
+ [null, 1, null], // explicit user wins over flag-level group
+ [2, null, 2], // explicit group wins over flag-level user
+ [2, 1, 2], // explicit group wins over flag-level group
+ ])('resolveAggregationGroupTypeIndex(%p, %p) === %p', (conditionLevel, flagLevel, expected) => {
+ expect(resolveAggregationGroupTypeIndex(conditionLevel, flagLevel)).toEqual(expected)
+ })
+
+ it('resolves an explicit-user condition to users even when the flag targets a group', async () => {
+ logic?.unmount()
+
+ logic = featureFlagReleaseConditionsLogic({
+ id: 'scope-resolution-test',
+ filters: {
+ ...generateFeatureFlagFilters([
+ { properties: [], rollout_percentage: 100, variant: null, sort_key: 'A' },
+ ]),
+ aggregation_group_type_index: 0,
+ },
+ })
+ logic.mount()
+
+ // Explicit null = users, despite the flag-level group index of 0
+ expect(logic.values.aggregationTargetName(null)).toEqual('users')
+ expect(logic.values.taxonomicGroupTypesForCondition(null)).toContain(
+ TaxonomicFilterGroupType.PersonProperties
+ )
+ // An absent value still inherits the flag-level group scope (not user properties)
+ expect(logic.values.taxonomicGroupTypesForCondition(undefined)).not.toContain(
+ TaxonomicFilterGroupType.PersonProperties
+ )
+ })
+ })
})
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
index 7a856d9fa52b..ac07ac887da1 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
@@ -33,6 +33,7 @@ import {
UserBlastRadiusType,
} from '~/types'
+import { resolveAggregationGroupTypeIndex } from './aggregation'
import type { featureFlagReleaseConditionsLogicType } from './featureFlagReleaseConditionsLogicType'
// A property filter targets people by their raw distinct id.
@@ -187,8 +188,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
...state,
aggregation_group_type_index: value,
groups: state.groups.map((group) => {
- const previousEffective =
- group.aggregation_group_type_index ?? state.aggregation_group_type_index ?? null
+ const previousEffective = resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ state.aggregation_group_type_index
+ )
// Use == to treat null and undefined equivalently
const scopeChanged = previousEffective != value
return {
@@ -456,8 +459,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
}
await breakpoint(1000) // in ms
- const groupTypeIndex =
- group.aggregation_group_type_index ?? values.filters?.aggregation_group_type_index ?? null
+ const groupTypeIndex = resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ values.filters?.aggregation_group_type_index
+ )
const response: UserBlastRadiusType = await api.create(
`api/projects/${values.currentProjectId}/feature_flags/user_blast_radius`,
{
@@ -472,8 +477,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
setConditionAggregation: ({ index }) => {
const group = values.filters.groups[index]
if (group?.sort_key) {
- const groupTypeIndex =
- group.aggregation_group_type_index ?? values.filters?.aggregation_group_type_index ?? null
+ const groupTypeIndex = resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ values.filters?.aggregation_group_type_index
+ )
actions.calculateBlastRadiusForCondition(group.sort_key, group.properties, groupTypeIndex)
}
},
@@ -481,8 +488,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
const newGroup = values.filters.groups[values.filters.groups.length - 1]
if (newGroup.sort_key) {
actions.openCondition(newGroup.sort_key)
- const groupTypeIndex =
- newGroup.aggregation_group_type_index ?? values.filters?.aggregation_group_type_index ?? null
+ const groupTypeIndex = resolveAggregationGroupTypeIndex(
+ newGroup.aggregation_group_type_index,
+ values.filters?.aggregation_group_type_index
+ )
actions.calculateBlastRadiusForCondition(newGroup.sort_key, newGroup.properties, groupTypeIndex)
}
},
@@ -545,8 +554,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
},
calculateBlastRadius: () => {
values.filters.groups.forEach((condition: FeatureFlagGroupTypeWithSortKey) => {
- const groupTypeIndex =
- condition.aggregation_group_type_index ?? values.filters?.aggregation_group_type_index ?? null
+ const groupTypeIndex = resolveAggregationGroupTypeIndex(
+ condition.aggregation_group_type_index,
+ values.filters?.aggregation_group_type_index
+ )
actions.calculateBlastRadiusForCondition(condition.sort_key, condition.properties, groupTypeIndex)
})
},
@@ -691,7 +702,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
(s) => [s.filters, s.aggregationLabel],
(filters, aggregationLabel) =>
(conditionGroupTypeIndex?: number | null): string => {
- const effectiveIndex = conditionGroupTypeIndex ?? filters.aggregation_group_type_index
+ const effectiveIndex = resolveAggregationGroupTypeIndex(
+ conditionGroupTypeIndex,
+ filters.aggregation_group_type_index
+ )
if (effectiveIndex != null) {
return aggregationLabel(effectiveIndex).plural
}
@@ -702,7 +716,10 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
(s) => [s.filters, s.groupTypes],
(filters, groupTypes) =>
(conditionGroupTypeIndex: number | null | undefined): TaxonomicFilterGroupType[] => {
- const effectiveIndex = conditionGroupTypeIndex ?? filters?.aggregation_group_type_index
+ const effectiveIndex = resolveAggregationGroupTypeIndex(
+ conditionGroupTypeIndex,
+ filters?.aggregation_group_type_index
+ )
const targetGroupTypes: TaxonomicFilterGroupType[] = []
if (effectiveIndex != null) {