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.

feat(flags): link to matching users and give PostHog AI the conditions (#79331)

posthog[bot]52c5fa3838c8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 75611d98aaed..4955f09b1e63 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6079,13 +6079,13 @@ snapshots:
scenes-app-feature-flags--feature-flags-list--light:
hash: v1.k794b7964.18d16a7559246445191198e9aa84e26c74f955bef153b9bdc1c8764478e24800.1_zbdiVOfqIetvE9g5QyjDcOA0JS7yQUsey5JNyoTAM
scenes-app-feature-flags--new-feature-flag--dark:
- hash: v1.k794b7964.c6ee9f73b8271c94a660d0545b0af273caa32694fef865203b08ae631c124e04.GpPjk_XVkt55IibjtehycEHD8-wRjSXz86y0ym0-IQs
+ hash: v1.k794b7964.70df3db2b33bd03ae45c4aac90d5db824f0640857b9029abca867a170a5f82c5.6nQgIAyy17NzNkvmvJdJ50-JxIZRrUiXcYkx7O1ukyQ
scenes-app-feature-flags--new-feature-flag--light:
- hash: v1.k794b7964.d8009a2da4b7b7557a6a963f0c6d76482eecbfd6042f0769eaba7f3eb64ad637.0wqb4NNMks7pszoSquUkRM1PFmMvUDIgC6YOHko_P7c
+ hash: v1.k794b7964.2d50bd19b5cdb52666bd2fc43bca72664f8bdfa989925b0454ffea8ebfa6df1b.yR5fkxwq8lbgPyAAnn8POP0NNKmqxwz-GEIMvpReiyw
scenes-app-feature-flags--new-multivariate-flag-variant-key-error--dark:
- hash: v1.k794b7964.d19e44f695b14c7aabfd2a256a11c5356ab6c5b39bbacc58534b98751806cd2e.Np4zb6r_aXGTDyi6AUP0tqQKKXhzNdU4aP6YktP9SEE
+ hash: v1.k794b7964.7aa10a5c4ca6fd392ce3b0e370d672b32ca04abe9ebaaedda7bbded75ff1cebd.63_aev7oWo3R-DB3v3GAfx6RxYrMcDPqYZtPNz-SHc0
scenes-app-feature-flags--new-multivariate-flag-variant-key-error--light:
- hash: v1.k794b7964.eb2d39f9267b6834b0f80a4f812558261ac46b82c3d0c678e8a539567ae4961b.upj7gQhT2vISF_511wekTjWuM4EnO7FOwsHjDstzIVQ
+ hash: v1.k794b7964.a0ce132dd53c5b6bb632616e5a5252a5adeb0004ec73f929347b1b327b7e21d8.P0wG2UE35QhA5Qz6ES_EXjZsyC_l7PJmTb2AlqUHy4E
scenes-app-feature-flags--new-remote-config-flag-payload-error--dark:
hash: v1.k794b7964.e08249de5d15170f153371d39a565900bb2bbfc88b8bfd3d38a2600cff9065e3.qDTsHl-ou0yZimNtzHHuM3R3c7N8zdSt0A8LUIMc2dc
scenes-app-feature-flags--new-remote-config-flag-payload-error--light:
@@ -7439,9 +7439,9 @@ snapshots:
scenes-app-surveys--new-survey-customisation-section--light:
hash: v1.k794b7964.339c3c78d35a293f9ad6f9523dab8728e4a3b627a164231c340ff08909964e05.l01MqFCkH2yV8pcwPmARadljXlVsY-B5n_64ICHhshM
scenes-app-surveys--new-survey-targeting-section--dark:
- hash: v1.k794b7964.6ce27fad0f643dd5b0049907cddc5b448e2d9cdb957c07c7cca584e2d436cd3d.UN9Qr_CqblK1Q2JYHtXs__8YntETBxJFHqjy77ULOsA
+ hash: v1.k794b7964.56d33084e4b801c43ec790d5f61b27701e0ee2f17fdcb92cf8558096373e978f.aZ2fXEHYXMEsGFU_QWn4S2_BXAaJEttc4CrklnVn4VA
scenes-app-surveys--new-survey-targeting-section--light:
- hash: v1.k794b7964.a978289c41618e1588e3119e5d92232568fcb58635c386a622c333a141604a61._XThypgeHY8ecXuZid3b7Bz7fmF1NkLnts4nKR1ebBw
+ hash: v1.k794b7964.751f6cd96d51519b47dcd64f7b6c9f24cc71a17acd3290bd3b4fe8acd25cb0b0.VT2rnqmAvRpIAW1jIZg-k2ZZeN153-8GZj-nzYtxyuU
scenes-app-surveys--new-survey-with-html-question-description--dark:
hash: v1.k794b7964.a574ed86e292ebc92b497686542327da0720d3ed1574c4a729d935bbe7877dd0.eqQXnqs8DOn2gZvkqXuppmNbOMx-y_73R2AJggWhbRc
scenes-app-surveys--new-survey-with-html-question-description--light:
diff --git a/frontend/src/scenes/feature-flags/FeatureFlag.tsx b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
index 33399a3f4c5b..17026b6336fc 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlag.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
@@ -2,7 +2,7 @@ import './FeatureFlag.scss'
import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
-import { Suspense, lazy, useEffect, useState } from 'react'
+import { Suspense, lazy, useEffect, useMemo, useState } from 'react'
import { IconArchive, IconCopy, IconPlusSmall, IconRewind, IconTrash } from '@posthog/icons'
import { LemonSkeleton } from '@posthog/lemon-ui'
@@ -79,6 +79,9 @@ import {
QueryBasedInsightModel,
} from '~/types'
+import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
+
+import { featureFlagContextItems } from './featureFlagAiContext'
import { openFeatureFlagArchiveDialog } from './featureFlagArchiveDialog'
import { openFeatureFlagDeleteDialog } from './featureFlagDeleteDialog'
import { FeatureFlagEvaluationContexts } from './FeatureFlagEvaluationContexts'
@@ -180,6 +183,15 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
const isNewFeatureFlag = id === 'new' || id === undefined
+ // Expose the flag's release conditions to PostHog AI so it can answer "who does this match?"
+ // and build an equivalent insight. The blast-radius endpoint only returns counts, so without
+ // this the agent on a flag page has no visibility into the targeting.
+ const featureFlagContext = useMemo(
+ () => (isNewFeatureFlag || !featureFlag?.key ? null : featureFlagContextItems(featureFlag)),
+ [isNewFeatureFlag, featureFlag]
+ )
+ useAttachedContext(featureFlagContext)
+
// Mounting the edit form is a multi-second render (Monaco editors + dnd-kit sortables). Mount it
// immediately when the scene first renders already in form mode (deep-link/new flag), but when the
// user clicks Edit on the readonly view, defer one frame so the click flips state and the loading
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx
new file mode 100644
index 000000000000..8a61d6a3b5da
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx
@@ -0,0 +1,122 @@
+import { MOCK_GROUP_TYPES } from '~/lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { cleanup, render, waitFor } from '@testing-library/react'
+import { Provider } from 'kea'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+import { mockGetEventDefinitions, mockGetPropertyDefinitions } from '~/test/mocks'
+import { FeatureFlagGroupType, FeatureFlagType, PropertyFilterType, PropertyOperator } from '~/types'
+
+import { FeatureFlagReleaseConditions } from './FeatureFlagReleaseConditions'
+import { FeatureFlagReleaseConditionsCollapsible } from './FeatureFlagReleaseConditionsCollapsible'
+
+jest.mock('lib/components/AutoSizer', () => ({
+ AutoSizer: ({ renderProp }: { renderProp: (size: { height: number; width: number }) => React.ReactNode }) =>
+ renderProp({ height: 400, width: 400 }),
+}))
+
+// `aggregation_group_type_index` is set at flag level only, so the condition has to inherit it. That
+// resolution happens at the call site and is invisible to `matchingActorsUrl`'s own tests.
+function buildFilters(aggregationGroupTypeIndex?: number): FeatureFlagType['filters'] {
+ const group: FeatureFlagGroupType = {
+ properties: [
+ {
+ key: 'email',
+ value: 'is_set',
+ operator: PropertyOperator.IsSet,
+ type: PropertyFilterType.Person,
+ },
+ ],
+ rollout_percentage: 100,
+ variant: null,
+ sort_key: 'group-1',
+ }
+ return {
+ groups: [group],
+ multivariate: null,
+ payloads: {},
+ aggregation_group_type_index: aggregationGroupTypeIndex,
+ }
+}
+
+describe('feature flag release conditions matching users link', () => {
+ beforeEach(() => {
+ initKeaTests()
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,
+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,
+ '/api/projects/:team/feature_flags/1234/': {
+ id: 1234,
+ key: 'test-flag',
+ filters: { groups: [], multivariate: null, payloads: {} },
+ },
+ '/api/projects/:team/actions': { results: [] },
+ '/api/projects/:team/groups_types': MOCK_GROUP_TYPES,
+ },
+ post: {
+ '/api/environments/:team/query': { results: [] },
+ '/api/projects/:team/feature_flags/user_blast_radius': () => [200, { affected: 0, total: 2 }],
+ },
+ })
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ const cases = [
+ [
+ 'FeatureFlagReleaseConditions',
+ <FeatureFlagReleaseConditions id="1234" filters={buildFilters()} onChange={jest.fn()} />,
+ 'View matching users',
+ '/persons',
+ ],
+ [
+ 'FeatureFlagReleaseConditionsCollapsible',
+ <FeatureFlagReleaseConditionsCollapsible
+ id="1234"
+ flagId={1234}
+ filters={buildFilters()}
+ onChange={jest.fn()}
+ />,
+ 'View matching users',
+ '/persons',
+ ],
+ [
+ 'FeatureFlagReleaseConditions, group-targeted',
+ <FeatureFlagReleaseConditions id="1234" filters={buildFilters(0)} onChange={jest.fn()} />,
+ 'View matching organizations',
+ '/groups/0',
+ ],
+ [
+ 'FeatureFlagReleaseConditionsCollapsible, group-targeted',
+ <FeatureFlagReleaseConditionsCollapsible
+ id="1234"
+ flagId={1234}
+ filters={buildFilters(0)}
+ onChange={jest.fn()}
+ />,
+ 'View matching organizations',
+ '/groups/0',
+ ],
+ ] as const
+
+ test.each(cases)(
+ '%s links a condition to the matching actors once counts load',
+ async (_name, component, linkText, expectedPath) => {
+ const { getByText } = render(<Provider>{component}</Provider>)
+
+ await waitFor(() => {
+ const link = getByText(linkText).closest('a')
+ expect(link).toBeInTheDocument()
+ expect(link).toHaveAttribute('href', expect.stringContaining(expectedPath))
+ // The condition's own properties have to reach the link, not just the actor list route.
+ expect(link).toHaveAttribute('href', expect.stringContaining('email'))
+ })
+ }
+ )
+})
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
index 061701009688..e71d0b532289 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
@@ -52,6 +52,7 @@ import {
isDistinctIdFilter,
withResolvedFlagLabels,
} from './featureFlagReleaseConditionsLogic'
+import { MatchingActorsLink } from './MatchingActorsLink'
import { getPropertySelectErrorMessages } from './propertySelectErrorMessages'
function PropertyValueComponent({
@@ -506,6 +507,11 @@ export function FeatureFlagReleaseConditions({
<b>~{pluralize(receivingFlag, singularName, pluralName)}</b> -{' '}
<b>{rolloutPct}%</b>
</span>
+ <MatchingActorsLink
+ properties={group.properties}
+ resolvedGroupTypeIndex={resolvedGroupTypeIndex}
+ targetName={pluralName}
+ />
</div>
)
})()}
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
index 12139173a5c5..f7cb1d00f5eb 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
@@ -86,6 +86,7 @@ import {
isDistinctIdFilter,
withResolvedFlagLabels,
} from './featureFlagReleaseConditionsLogic'
+import { MatchingActorsLink } from './MatchingActorsLink'
import { getPropertySelectErrorMessages, PropertySelectError } from './propertySelectErrorMessages'
interface FeatureFlagReleaseConditionsCollapsibleProps extends FeatureFlagReleaseConditionsLogicProps {
@@ -497,13 +498,11 @@ const ConditionContent = ({
}
const resolvedTargetName = aggregationTargetName(group.aggregation_group_type_index)
- const resolvedSingularTargetName = aggregationLabel(
- resolveAggregationGroupTypeIndex(
- group.aggregation_group_type_index,
- releaseFilters.aggregation_group_type_index
- ),
- true
- ).singular
+ const resolvedGroupTypeIndex = resolveAggregationGroupTypeIndex(
+ group.aggregation_group_type_index,
+ releaseFilters.aggregation_group_type_index
+ )
+ const resolvedSingularTargetName = aggregationLabel(resolvedGroupTypeIndex, true).singular
return (
<div
@@ -690,10 +689,7 @@ const ConditionContent = ({
calculateBlastRadiusForCondition(
group.sort_key,
group.properties,
- resolveAggregationGroupTypeIndex(
- group.aggregation_group_type_index,
- releaseFilters.aggregation_group_type_index
- )
+ resolvedGroupTypeIndex
)
}
>
@@ -732,10 +728,7 @@ const ConditionContent = ({
resolvedTargetName
)}
</b>
- {resolveAggregationGroupTypeIndex(
- group.aggregation_group_type_index,
- releaseFilters.aggregation_group_type_index
- ) == null && (
+ {resolvedGroupTypeIndex == null && (
<Tooltip
title={MATCHING_ESTIMATE_TOOLTIP}
interactive
@@ -756,6 +749,11 @@ const ConditionContent = ({
</b>{' '}
- <b className="tabular-nums">{rolloutPct}%</b>
</span>
+ <MatchingActorsLink
+ properties={group.properties}
+ resolvedGroupTypeIndex={resolvedGroupTypeIndex}
+ targetName={resolvedTargetName}
+ />
</div>
)
})()}
diff --git a/frontend/src/scenes/feature-flags/MatchingActorsLink.tsx b/frontend/src/scenes/feature-flags/MatchingActorsLink.tsx
new file mode 100644
index 000000000000..2fd04cff8ab2
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/MatchingActorsLink.tsx
@@ -0,0 +1,34 @@
+import { IconOpenInNew } from 'lib/lemon-ui/icons'
+import { Link } from 'lib/lemon-ui/Link'
+
+import { AnyPropertyFilter } from '~/types'
+
+import { matchingActorsUrl } from './matchingActorsUrl'
+
+export interface MatchingActorsLinkProps {
+ properties: AnyPropertyFilter[] | undefined
+ resolvedGroupTypeIndex: number | null
+ /** Plural aggregation target name, e.g. "users" or "organizations". */
+ targetName: string
+}
+
+/**
+ * Drills from a release condition's blast-radius count into the actors it matches. Both release
+ * condition editors render it, so a change here lands in the plain editor and the collapsible one.
+ */
+export function MatchingActorsLink({
+ properties,
+ resolvedGroupTypeIndex,
+ targetName,
+}: MatchingActorsLinkProps): JSX.Element {
+ return (
+ <Link
+ to={matchingActorsUrl(properties, resolvedGroupTypeIndex)}
+ target="_blank"
+ className="flex items-center gap-1 w-fit mt-1"
+ >
+ View matching {targetName}
+ <IconOpenInNew />
+ </Link>
+ )
+}
diff --git a/frontend/src/scenes/feature-flags/featureFlagAiContext.test.ts b/frontend/src/scenes/feature-flags/featureFlagAiContext.test.ts
new file mode 100644
index 000000000000..32a0be657bfe
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagAiContext.test.ts
@@ -0,0 +1,135 @@
+import {
+ AccessControlLevel,
+ FeatureFlagBucketingIdentifier,
+ FeatureFlagEvaluationRuntime,
+ FeatureFlagGroupType,
+ FeatureFlagType,
+ PropertyFilterType,
+ PropertyOperator,
+} from '~/types'
+
+import { wrapWithPosthogContext } from 'products/posthog_ai/frontend/utils/posthogContextBlock'
+
+import { featureFlagContextItems } from './featureFlagAiContext'
+
+// The backend's own cap on a text attachment (MAX_TEXT_LENGTH in the posthog_ai backend). Asserting
+// the literal rather than importing the frontend constant is deliberate: raising the frontend cap
+// past what the backend accepts is exactly the regression these cases guard against.
+const MAX_BACKEND_TEXT_LENGTH = 4096
+
+describe('featureFlagContextItems', () => {
+ const baseFeatureFlag: FeatureFlagType = {
+ id: 1,
+ key: 'test-flag',
+ name: '',
+ created_at: '2021-01-01',
+ updated_at: '2021-01-01',
+ created_by: null,
+ is_remote_configuration: false,
+ filters: { groups: [], payloads: {}, multivariate: null },
+ deleted: false,
+ archived: false,
+ active: true,
+ experiment_set: null,
+ experiment_set_metadata: null,
+ features: null,
+ surveys: null,
+ can_edit: true,
+ tags: [],
+ ensure_experience_continuity: null,
+ user_access_level: AccessControlLevel.Admin,
+ status: 'ACTIVE',
+ has_encrypted_payloads: false,
+ version: 0,
+ last_modified_by: null,
+ evaluation_runtime: FeatureFlagEvaluationRuntime.ALL,
+ evaluation_contexts: [],
+ bucketing_identifier: FeatureFlagBucketingIdentifier.DISTINCT_ID,
+ }
+
+ const personCondition: FeatureFlagGroupType = {
+ properties: [
+ { key: 'email', value: 'is_set', operator: PropertyOperator.IsSet, type: PropertyFilterType.Person },
+ ],
+ rollout_percentage: 50,
+ variant: null,
+ }
+
+ function withFilters(filters: Partial<FeatureFlagType['filters']>): FeatureFlagType {
+ return { ...baseFeatureFlag, filters: { ...baseFeatureFlag.filters, ...filters } }
+ }
+
+ function targetingValue(featureFlag: FeatureFlagType): string {
+ const item = featureFlagContextItems(featureFlag).find((item) => item.type === 'feature_flag_targeting')
+ if (!item?.value) {
+ throw new Error('no targeting item')
+ }
+ return item.value
+ }
+
+ it('renders the release conditions into the context block the agent reads', () => {
+ const block = wrapWithPosthogContext(
+ 'who matches this flag?',
+ featureFlagContextItems(withFilters({ groups: [personCondition] }))
+ )
+
+ expect(block).toContain('feature_flag test-flag')
+ expect(block).toContain('release_conditions')
+ expect(block).toContain('email')
+ })
+
+ it('carries the targeting a group-targeted multivariate flag needs beyond its release conditions', () => {
+ const targeting = JSON.parse(
+ targetingValue(
+ withFilters({
+ groups: [personCondition],
+ aggregation_group_type_index: 0,
+ multivariate: { variants: [{ key: 'control', rollout_percentage: 50 }] },
+ holdout_groups: [personCondition],
+ })
+ )
+ )
+
+ expect(targeting.aggregation_group_type_index).toBe(0)
+ expect(targeting.multivariate.variants[0].key).toBe('control')
+ expect(targeting.holdout_groups).toHaveLength(1)
+ })
+
+ const flagWithPastedValues = withFilters({
+ groups: [
+ {
+ properties: [
+ {
+ key: 'email',
+ value: Array.from({ length: 500 }, (_, index) => `person${index}@example.com`),
+ operator: PropertyOperator.Exact,
+ type: PropertyFilterType.Person,
+ },
+ ],
+ rollout_percentage: 100,
+ variant: null,
+ },
+ ],
+ })
+
+ const oversized: [string, FeatureFlagType][] = [
+ ['a condition holding hundreds of pasted values', flagWithPastedValues],
+ ['a very long description', { ...withFilters({ groups: [personCondition] }), name: 'x'.repeat(20000) }],
+ ]
+
+ test.each(oversized)('keeps the attachment under the backend limit with %s', (_name, featureFlag) => {
+ const value = targetingValue(featureFlag)
+
+ expect(value.length).toBeLessThanOrEqual(MAX_BACKEND_TEXT_LENGTH)
+ expect(() => JSON.parse(value)).not.toThrow()
+ })
+
+ it('summarizes the release conditions it drops to fit', () => {
+ const value = targetingValue(flagWithPastedValues)
+
+ expect(value).not.toContain('[email protected]')
+ // Without the count the agent can't tell a flag with no targeting from one whose targeting
+ // was too large to send.
+ expect(JSON.parse(value).release_condition_count).toBe(1)
+ })
+})
diff --git a/frontend/src/scenes/feature-flags/featureFlagAiContext.ts b/frontend/src/scenes/feature-flags/featureFlagAiContext.ts
new file mode 100644
index 000000000000..926660bae143
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagAiContext.ts
@@ -0,0 +1,65 @@
+import { FeatureFlagType } from '~/types'
+
+import type { AttachedContextItem } from 'products/posthog_ai/frontend/api/types'
+
+// The backend rejects a text attachment longer than this and fails the whole send with a 400
+// (MAX_TEXT_LENGTH in products/posthog_ai/backend/context_wrapper.py), so an oversized flag has to
+// lose detail here rather than break the user's message.
+const MAX_TARGETING_VALUE_LENGTH = 4096
+
+// A flag's description is free text with no length limit of its own, so it could otherwise eat the
+// whole budget above on its own.
+const MAX_DESCRIPTION_LENGTH = 400
+
+/**
+ * Describes a saved flag to PostHog AI: a keyed reference that renders as the composer chip, plus a
+ * separate keyless item carrying the targeting as JSON.
+ *
+ * These have to stay two items. `formatItem` in posthogContextBlock renders a keyed item as its
+ * type, key, and label alone and never reads `value`, so folding the JSON into the reference would
+ * drop the targeting before it reached the agent.
+ */
+export function featureFlagContextItems(featureFlag: FeatureFlagType): AttachedContextItem[] {
+ return [
+ // `name` on a flag is the description, so the key is the only display name available here.
+ { type: 'feature_flag', key: featureFlag.key, label: featureFlag.key },
+ { type: 'feature_flag_targeting', label: 'Release conditions', value: targetingValue(featureFlag) },
+ ]
+}
+
+function targetingValue(featureFlag: FeatureFlagType): string {
+ const filters = featureFlag.filters
+ const identity = {
+ key: featureFlag.key,
+ description: featureFlag.name.slice(0, MAX_DESCRIPTION_LENGTH),
+ active: featureFlag.active,
+ // Whether the flag counts persons or a group type, which decides what "who matches?" means.
+ aggregation_group_type_index: filters?.aggregation_group_type_index ?? null,
+ // The matcher evaluates all three ahead of the release conditions, so an agent reading only
+ // those overcounts a flag behind a holdout or an early access gate.
+ holdout: filters?.holdout ?? null,
+ }
+
+ const full = JSON.stringify({
+ ...identity,
+ multivariate: filters?.multivariate ?? null,
+ super_groups: filters?.super_groups ?? null,
+ holdout_groups: filters?.holdout_groups ?? null,
+ release_conditions: filters?.groups ?? [],
+ })
+ if (full.length <= MAX_TARGETING_VALUE_LENGTH) {
+ return full
+ }
+
+ // Property filters are what blow the budget, because a single condition can hold hundreds of
+ // pasted values. Variant keys and the condition counts still describe the flag's shape, and the
+ // agent can read the saved flag by key when it needs the filters themselves.
+ return JSON.stringify({
+ ...identity,
+ variant_keys: filters?.multivariate?.variants.map((variant) => variant.key) ?? null,
+ release_condition_count: filters?.groups?.length ?? 0,
+ super_condition_count: filters?.super_groups?.length ?? 0,
+ holdout_condition_count: filters?.holdout_groups?.length ?? 0,
+ conditions_omitted: 'Too large to attach. Read the saved flag to see the property filters.',
+ })
+}
diff --git a/frontend/src/scenes/feature-flags/matchingActorsUrl.test.ts b/frontend/src/scenes/feature-flags/matchingActorsUrl.test.ts
new file mode 100644
index 000000000000..ed6ef38b6089
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/matchingActorsUrl.test.ts
@@ -0,0 +1,41 @@
+import { combineUrl } from 'kea-router'
+
+import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'
+
+import { matchingActorsUrl } from './matchingActorsUrl'
+
+describe('matchingActorsUrl', () => {
+ const personProperty: AnyPropertyFilter = {
+ key: 'email',
+ value: 'is_set',
+ operator: PropertyOperator.IsSet,
+ type: PropertyFilterType.Person,
+ }
+ const flagDependency: AnyPropertyFilter = {
+ key: '123',
+ value: true,
+ operator: PropertyOperator.FlagEvaluatesTo,
+ type: PropertyFilterType.Flag,
+ }
+
+ it('links a person-targeted condition to the persons list with the filters in the query', () => {
+ const parsed = combineUrl(matchingActorsUrl([personProperty], null))
+ expect(parsed.pathname).toBe('/persons')
+ expect(parsed.hashParams.q.source.kind).toBe('ActorsQuery')
+ expect(parsed.hashParams.q.source.properties).toEqual([personProperty])
+ })
+
+ it('links a group-targeted condition to that group type list with the filters', () => {
+ const parsed = combineUrl(matchingActorsUrl([personProperty], 1))
+ expect(parsed.pathname).toBe('/groups/1')
+ expect(JSON.parse(parsed.searchParams.properties_1)).toEqual([personProperty])
+ })
+
+ it('strips flag-dependency filters the actor lists cannot evaluate', () => {
+ const persons = combineUrl(matchingActorsUrl([personProperty, flagDependency], null))
+ expect(persons.hashParams.q.source.properties).toEqual([personProperty])
+
+ const groups = combineUrl(matchingActorsUrl([personProperty, flagDependency], 0))
+ expect(JSON.parse(groups.searchParams.properties_0)).toEqual([personProperty])
+ })
+})
diff --git a/frontend/src/scenes/feature-flags/matchingActorsUrl.ts b/frontend/src/scenes/feature-flags/matchingActorsUrl.ts
new file mode 100644
index 000000000000..7dd4c72a669f
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/matchingActorsUrl.ts
@@ -0,0 +1,46 @@
+import { combineUrl } from 'kea-router'
+
+import { isFlagPropertyFilter } from 'lib/components/PropertyFilters/utils'
+import { urls } from 'scenes/urls'
+
+import { DataTableNode, NodeKind } from '~/queries/schema/schema-general'
+import { AnyPersonScopeFilter, AnyPropertyFilter } from '~/types'
+
+// Flag-dependency filters (type: 'flag') aren't property filters the persons/groups lists can
+// evaluate, so drop them before linking, matching how the backend blast radius skips them.
+function toActorFilters(properties: AnyPropertyFilter[] | undefined): AnyPropertyFilter[] {
+ return (properties ?? []).filter((property) => !isFlagPropertyFilter(property))
+}
+
+/**
+ * Links to the list of actors matching a release condition set's properties: the groups list for a
+ * group-targeted condition, otherwise the persons list.
+ *
+ * The param names belong to the consuming scenes and have to stay in sync with them:
+ * `personsSceneLogic` reads `q` from the hash, `groupsListLogic` reads `properties_<index>` from the
+ * query. Renaming either one leaves this file compiling and silently produces an unfiltered list.
+ */
+export function matchingActorsUrl(
+ properties: AnyPropertyFilter[] | undefined,
+ resolvedGroupTypeIndex: number | null
+): string {
+ const actorFilters = toActorFilters(properties)
+
+ if (resolvedGroupTypeIndex != null) {
+ return combineUrl(urls.groups(resolvedGroupTypeIndex), {
+ [`properties_${resolvedGroupTypeIndex}`]: JSON.stringify(actorFilters),
+ }).url
+ }
+
+ const query: DataTableNode = {
+ kind: NodeKind.DataTableNode,
+ source: {
+ kind: NodeKind.ActorsQuery,
+ // A person-targeted condition (resolvedGroupTypeIndex null) only carries person and
+ // cohort filters, which are person-scoped; the group-targeted case takes the branch above.
+ properties: actorFilters as AnyPersonScopeFilter[],
+ },
+ full: true,
+ }
+ return combineUrl(urls.persons(), {}, { q: query }).url
+}