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): mark release conditions on deleted cohorts (#119792)

Phil Haack8796800befde
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 11138e3d3a70..3665f8af3657 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -11006,10 +11006,14 @@ snapshots:
hash: v1.k794b7964.4f1e063fd0ea193507fc461100835138a210c677172cf02c4e6a1d3ca85053af.QLMBnXZd8GFY-ERfzWmRUW-eFybjMBVuSeT9PLkOnzI
scenes-app-feature-flags--feature-flag-not-found--light:
hash: v1.k794b7964.9760899dc54ed1457b2f2790151da4dced7ce03ba2db211fc8987584331225f7.NwLOFpddIBI2MKFCF_nA7ICbR7JCJISgydgqg4pdPWg
+ scenes-app-feature-flags--feature-flag-targeting-deleted-cohort--dark:
+ hash: v1.k794b7964.be241f83e9227c00e65ff3f6e59f13d7b3e7400f96b8408783fe1461c707d2a6.r3nSp3zq0MFuOWkbEOmZQUW2PSeIkHCWymkVybops-0
+ scenes-app-feature-flags--feature-flag-targeting-deleted-cohort--light:
+ hash: v1.k794b7964.090b542a2d7598e04f1ecfbe374f32989f1bc9af1dbfcac3f5dd1c933e8f5e1f.USVIt7dRohg5cqqz1Ve78diPqV9Id5F085nIKUwW5DE
scenes-app-feature-flags--feature-flags-list--dark:
- hash: v1.k794b7964.a087e78f1796f558317749366d298c4fae57e1cd70c71fbb847a044857d32ae5.Z4aXxGLFnh8STT3wzwSMS_xREn7xxXo8GPOiJ4_x--s
+ hash: v1.k794b7964.ef6d876e7bbde904ffd1c020aa944c6e1f6859a6ec1a5e1b46f8a0be4954a4c3.KDMu6OHIcXbDZkp3HqawyB3AjfUmiDiIG7mgYmgll6M
scenes-app-feature-flags--feature-flags-list--light:
- hash: v1.k794b7964.9ee4d2d17d2e30904e95417a18880fddb8901a67eeebadb88c59977be4da3499.7ukvP36WfqxLU9CYStToepJdMa38vSMLDdlw5htt2wo
+ hash: v1.k794b7964.7e6a9320d1a30d42d360787c03b5130b5211557fcaa04d52c08ef2966ea5e168.eh5DZ_B67GZS0UOQz5FX9yZO2p4Y7NjBHilaJAcD3cE
scenes-app-feature-flags--feature-flags-list-with-rules-v-2-flag--dark:
hash: v1.k794b7964.1727ef0eabfc4ce85f096027de08767cfb1d4a7df8524b865fce0db25ff31748.AZGib3Lsi5vEz7bWNkHr_Qa4LBmhuQwTuh4R5D-N8Zc
scenes-app-feature-flags--feature-flags-list-with-rules-v-2-flag--light:
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index 3971854b99ce..73130e348e34 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -1402,6 +1402,10 @@ export interface PersonPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
index 392ec41f3e76..5fd3e7c27188 100644
--- a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
@@ -4,13 +4,16 @@ import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import { useId } from 'react'
-import { IconPlusSmall } from '@posthog/icons'
+import { IconPlusSmall, IconWarning } from '@posthog/icons'
import { LemonButton, LemonDropdown, Link } from '@posthog/lemon-ui'
import { OperatorValueSelect } from 'lib/components/PropertyFilters/components/OperatorValueSelect'
import { PropertyFilterInternalProps } from 'lib/components/PropertyFilters/types'
import {
PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE,
+ cohortAnnotations,
+ cohortFilterName,
+ isCohortPropertyFilter,
isGroupPropertyFilter,
isPropertyGroupFilterLike,
propertyFilterTypeToTaxonomicFilterType,
@@ -234,7 +237,7 @@ export function TaxonomicPropertyFilter({
type: filter?.type,
label: filter?.label,
...(isGroupPropertyFilter(filter) ? { group_type_index: filter.group_type_index } : {}),
- ...(filter.type === PropertyFilterType.Cohort ? { cohort_name: filter.cohort_name } : {}),
+ ...(isCohortPropertyFilter(filter) ? cohortAnnotations(filter) : {}),
} as AnyPropertyFilter)
}
if (newOperator && newValue && !isOperatorMulti(newOperator) && !isOperatorRegex(newOperator)) {
@@ -271,7 +274,11 @@ export function TaxonomicPropertyFilter({
// The button truncates its label, so its tooltip is how a long cohort name is read in full. The
// wrapper below cannot do that job: it clips rather than wraps, and it would nest the tag's own
// tooltip inside the button's. So the tooltip gets the plain string.
- const cohortLabel = filter?.type === 'cohort' ? cohortName || `Cohort #${filter?.value}` : undefined
+ const cohortLabel = isCohortPropertyFilter(filter)
+ ? filter.cohort_deleted
+ ? cohortFilterName(filter, cohort?.name)
+ : cohortName || `Cohort #${filter.value}`
+ : undefined
const nestedGroupLabel = nestedGroup ? propertyGroupSummary(nestedGroup, cohortsById) : undefined
@@ -279,6 +286,10 @@ export function TaxonomicPropertyFilter({
<span className="truncate">{nestedGroupLabel || 'Grouped filters'}</span>
) : filter?.type === 'cohort' ? (
<span className="flex items-center gap-2 min-w-0">
+ {/* The label truncates from the end and can hide its "(deleted)" or "(missing)" suffix. The icon stays visible. */}
+ {isCohortPropertyFilter(filter) && filter.cohort_deleted && (
+ <IconWarning className="shrink-0 text-danger" data-attr="property-filter-deleted-cohort-icon" />
+ )}
<span className="truncate">{cohortLabel}</span>
{showCohortFlagTargeting && <CohortRealtimeTag realtime={cohort?.realtime} />}
</span>
diff --git a/frontend/src/lib/components/PropertyFilters/utils.test.ts b/frontend/src/lib/components/PropertyFilters/utils.test.ts
index 8a5d15c6b457..a77be5ec70ce 100644
--- a/frontend/src/lib/components/PropertyFilters/utils.test.ts
+++ b/frontend/src/lib/components/PropertyFilters/utils.test.ts
@@ -23,6 +23,7 @@ import {
BehavioralEventType,
BehavioralPropertyFilter,
CohortPropertyFilter,
+ CohortType,
ElementPropertyFilter,
EmptyPropertyFilter,
FilterLogicalOperator,
@@ -156,6 +157,31 @@ describe('formatPropertyLabel() for behavioral filters', () => {
})
})
+describe('formatPropertyLabel() for cohort filters', () => {
+ const cohortsById = { 42: { id: 42, name: 'Known cohort' } as CohortType }
+
+ it.each<[string, Partial<CohortPropertyFilter>, string]>([
+ ['live cohort named by the flag API', { cohort_name: 'Beta testers' }, 'User in Beta testers'],
+ ['live cohort named by the cohorts model', {}, 'User in Known cohort'],
+ [
+ 'deleted cohort with a name',
+ { cohort_name: 'Beta testers', cohort_deleted: true },
+ 'User in Beta testers (deleted)',
+ ],
+ ['deleted cohort without a name', { value: 7, cohort_deleted: true }, 'User in Deleted cohort (ID 7)'],
+ ['missing cohort', { value: 7, cohort_deleted: true, cohort_missing: true }, 'User in Missing cohort (ID 7)'],
+ ])('formats a %s', (_, overrides, expected) => {
+ const filter: CohortPropertyFilter = {
+ key: 'id',
+ type: PropertyFilterType.Cohort,
+ operator: PropertyOperator.In,
+ value: 42,
+ ...overrides,
+ }
+ expect(formatPropertyLabel(filter, cohortsById)).toEqual(expected)
+ })
+})
+
describe('formatPropertyLabel() for account date filters', () => {
it.each([
['-14d', 'created_at > 14 days ago'],
diff --git a/frontend/src/lib/components/PropertyFilters/utils.ts b/frontend/src/lib/components/PropertyFilters/utils.ts
index 9addb1059450..1388daf8a18a 100644
--- a/frontend/src/lib/components/PropertyFilters/utils.ts
+++ b/frontend/src/lib/components/PropertyFilters/utils.ts
@@ -176,7 +176,6 @@ export function formatPropertyLabel(
const { value, key, type } = item
const label = 'label' in item ? item.label : undefined
const operator = 'operator' in item ? item.operator : undefined
- const cohortName = 'cohort_name' in item ? item.cohort_name : undefined
const resolvedType = (type ?? PropertyFilterType.Event) as PropertyFilterType
const resolvedOperator = operator ?? PropertyOperator.Exact
const taxonomicFilterGroupType = PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE[resolvedType]
@@ -191,10 +190,10 @@ export function formatPropertyLabel(
? formatRelativeDateValue(relativeDateValue)
: undefined
- if (resolvedType === PropertyFilterType.Cohort) {
+ if (isCohortPropertyFilter(item)) {
return (
`${capitalizeFirstLetter(cohortOperatorMap[resolvedOperator] || 'user in')} ` +
- (cohortName || (typeof value === 'number' ? cohortsById[value]?.name : undefined) || `ID ${value}`)
+ cohortFilterName(item, typeof value === 'number' ? cohortsById[value]?.name : undefined)
)
}
@@ -259,6 +258,24 @@ export function isCohortPropertyFilter(filter?: AnyFilterLike | null): filter is
return filter?.type === PropertyFilterType.Cohort
}
+export function cohortFilterName(filter: CohortPropertyFilter, fallbackName?: string | null): string {
+ const name = filter.cohort_name || fallbackName
+ if (filter.cohort_missing) {
+ return name ? `${name} (missing)` : `Missing cohort (ID ${filter.value})`
+ }
+ if (filter.cohort_deleted) {
+ return name ? `${name} (deleted)` : `Deleted cohort (ID ${filter.value})`
+ }
+ return name || `ID ${filter.value}`
+}
+
+// The flag API reads these keys from the cohort table on every response. Nobody edits them.
+export const COHORT_ANNOTATION_KEYS = ['cohort_name', 'cohort_deleted', 'cohort_missing'] as const
+
+export function cohortAnnotations(filter: CohortPropertyFilter): Partial<CohortPropertyFilter> {
+ return Object.fromEntries(COHORT_ANNOTATION_KEYS.map((key) => [key, filter[key]])) as Partial<CohortPropertyFilter>
+}
+
export function isBehavioralPropertyFilter(filter?: AnyFilterLike | null): filter is BehavioralPropertyFilter {
return filter?.type === PropertyFilterType.Behavioral
}
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 7d0216739520..8948f6814fd5 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -17694,6 +17694,14 @@
"additionalProperties": false,
"description": "Sync with nodejs/src/types.ts",
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
diff --git a/frontend/src/queries/validators.js b/frontend/src/queries/validators.js
index 9e54aa5b3632..bf9cc96c0ae8 100644
--- a/frontend/src/queries/validators.js
+++ b/frontend/src/queries/validators.js
@@ -1709,6 +1709,14 @@ const schema28 = {
additionalProperties: false,
description: 'Sync with nodejs/src/types.ts',
properties: {
+ cohort_deleted: {
+ description: 'Set by the feature flag API when the cohort is deleted or does not exist.',
+ type: 'boolean',
+ },
+ cohort_missing: {
+ description: 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.',
+ type: 'boolean',
+ },
cohort_name: { type: 'string' },
key: { const: 'id', type: 'string' },
label: { type: 'string' },
@@ -1746,6 +1754,8 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
for (const key0 in data) {
if (
!(
+ key0 === 'cohort_deleted' ||
+ key0 === 'cohort_missing' ||
key0 === 'cohort_name' ||
key0 === 'key' ||
key0 === 'label' ||
@@ -1768,16 +1778,16 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
}
}
if (_errs1 === errors) {
- if (data.cohort_name !== undefined) {
+ if (data.cohort_deleted !== undefined) {
const _errs2 = errors
- if (typeof data.cohort_name !== 'string') {
+ if (typeof data.cohort_deleted !== 'boolean') {
validate31.errors = [
{
- instancePath: instancePath + '/cohort_name',
- schemaPath: '#/properties/cohort_name/type',
+ instancePath: instancePath + '/cohort_deleted',
+ schemaPath: '#/properties/cohort_deleted/type',
keyword: 'type',
- params: { type: 'string' },
- message: 'must be string',
+ params: { type: 'boolean' },
+ message: 'must be boolean',
},
]
return false
@@ -1787,29 +1797,16 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
var valid0 = true
}
if (valid0) {
- if (data.key !== undefined) {
- let data1 = data.key
+ if (data.cohort_missing !== undefined) {
const _errs4 = errors
- if (typeof data1 !== 'string') {
+ if (typeof data.cohort_missing !== 'boolean') {
validate31.errors = [
{
- instancePath: instancePath + '/key',
- schemaPath: '#/properties/key/type',
+ instancePath: instancePath + '/cohort_missing',
+ schemaPath: '#/properties/cohort_missing/type',
keyword: 'type',
- params: { type: 'string' },
- message: 'must be string',
- },
- ]
- return false
- }
- if ('id' !== data1) {
- validate31.errors = [
- {
- instancePath: instancePath + '/key',
- schemaPath: '#/properties/key/const',
- keyword: 'const',
- params: { allowedValue: 'id' },
- message: 'must be equal to constant',
+ params: { type: 'boolean' },
+ message: 'must be boolean',
},
]
return false
@@ -1819,13 +1816,13 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
var valid0 = true
}
if (valid0) {
- if (data.label !== undefined) {
+ if (data.cohort_name !== undefined) {
const _errs6 = errors
- if (typeof data.label !== 'string') {
+ if (typeof data.cohort_name !== 'string') {
validate31.errors = [
{
- instancePath: instancePath + '/label',
- schemaPath: '#/properties/label/type',
+ instancePath: instancePath + '/cohort_name',
+ schemaPath: '#/properties/cohort_name/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -1838,14 +1835,14 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
var valid0 = true
}
if (valid0) {
- if (data.operator !== undefined) {
- let data3 = data.operator
+ if (data.key !== undefined) {
+ let data3 = data.key
const _errs8 = errors
if (typeof data3 !== 'string') {
validate31.errors = [
{
- instancePath: instancePath + '/operator',
- schemaPath: '#/definitions/PropertyOperator/type',
+ instancePath: instancePath + '/key',
+ schemaPath: '#/properties/key/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -1853,56 +1850,14 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
]
return false
}
- if (
- !(
- data3 === 'exact' ||
- data3 === 'is_not' ||
- data3 === 'icontains' ||
- data3 === 'not_icontains' ||
- data3 === 'starts_with' ||
- data3 === 'not_starts_with' ||
- data3 === 'ends_with' ||
- data3 === 'not_ends_with' ||
- data3 === 'regex' ||
- data3 === 'not_regex' ||
- data3 === 'gt' ||
- data3 === 'gte' ||
- data3 === 'lt' ||
- data3 === 'lte' ||
- data3 === 'is_set' ||
- data3 === 'is_not_set' ||
- data3 === 'is_date_exact' ||
- data3 === 'is_date_before' ||
- data3 === 'is_date_after' ||
- data3 === 'between' ||
- data3 === 'not_between' ||
- data3 === 'min' ||
- data3 === 'max' ||
- data3 === 'in' ||
- data3 === 'not_in' ||
- data3 === 'is_cleaned_path_exact' ||
- data3 === 'is_cleaned_path_not_exact' ||
- data3 === 'flag_evaluates_to' ||
- data3 === 'semver_eq' ||
- data3 === 'semver_neq' ||
- data3 === 'semver_gt' ||
- data3 === 'semver_gte' ||
- data3 === 'semver_lt' ||
- data3 === 'semver_lte' ||
- data3 === 'semver_tilde' ||
- data3 === 'semver_caret' ||
- data3 === 'semver_wildcard' ||
- data3 === 'icontains_multi' ||
- data3 === 'not_icontains_multi'
- )
- ) {
+ if ('id' !== data3) {
validate31.errors = [
{
- instancePath: instancePath + '/operator',
- schemaPath: '#/definitions/PropertyOperator/enum',
- keyword: 'enum',
- params: { allowedValues: schema14.enum },
- message: 'must be equal to one of the allowed values',
+ instancePath: instancePath + '/key',
+ schemaPath: '#/properties/key/const',
+ keyword: 'const',
+ params: { allowedValue: 'id' },
+ message: 'must be equal to constant',
},
]
return false
@@ -1912,14 +1867,13 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
var valid0 = true
}
if (valid0) {
- if (data.type !== undefined) {
- let data4 = data.type
- const _errs11 = errors
- if (typeof data4 !== 'string') {
+ if (data.label !== undefined) {
+ const _errs10 = errors
+ if (typeof data.label !== 'string') {
validate31.errors = [
{
- instancePath: instancePath + '/type',
- schemaPath: '#/properties/type/type',
+ instancePath: instancePath + '/label',
+ schemaPath: '#/properties/label/type',
keyword: 'type',
params: { type: 'string' },
message: 'must be string',
@@ -1927,49 +1881,145 @@ function validate31(data, { instancePath = '', parentData, parentDataProperty, r
]
return false
}
- if ('cohort' !== data4) {
- validate31.errors = [
- {
- instancePath: instancePath + '/type',
- schemaPath: '#/properties/type/const',
- keyword: 'const',
- params: { allowedValue: 'cohort' },
- message: 'must be equal to constant',
- },
- ]
- return false
- }
- var valid0 = _errs11 === errors
+ var valid0 = _errs10 === errors
} else {
var valid0 = true
}
if (valid0) {
- if (data.value !== undefined) {
- let data5 = data.value
- const _errs13 = errors
+ if (data.operator !== undefined) {
+ let data5 = data.operator
+ const _errs12 = errors
+ if (typeof data5 !== 'string') {
+ validate31.errors = [
+ {
+ instancePath: instancePath + '/operator',
+ schemaPath: '#/definitions/PropertyOperator/type',
+ keyword: 'type',
+ params: { type: 'string' },
+ message: 'must be string',
+ },
+ ]
+ return false
+ }
if (
!(
- typeof data5 == 'number' &&
- !(data5 % 1) &&
- !isNaN(data5) &&
- isFinite(data5)
+ data5 === 'exact' ||
+ data5 === 'is_not' ||
+ data5 === 'icontains' ||
+ data5 === 'not_icontains' ||
+ data5 === 'starts_with' ||
+ data5 === 'not_starts_with' ||
+ data5 === 'ends_with' ||
+ data5 === 'not_ends_with' ||
+ data5 === 'regex' ||
+ data5 === 'not_regex' ||
+ data5 === 'gt' ||
+ data5 === 'gte' ||
+ data5 === 'lt' ||
+ data5 === 'lte' ||
+ data5 === 'is_set' ||
+ data5 === 'is_not_set' ||
+ data5 === 'is_date_exact' ||
+ data5 === 'is_date_before' ||
+ data5 === 'is_date_after' ||
+ data5 === 'between' ||
+ data5 === 'not_between' ||
+ data5 === 'min' ||
+ data5 === 'max' ||
+ data5 === 'in' ||
+ data5 === 'not_in' ||
+ data5 === 'is_cleaned_path_exact' ||
+ data5 === 'is_cleaned_path_not_exact' ||
+ data5 === 'flag_evaluates_to' ||
+ data5 === 'semver_eq' ||
+ data5 === 'semver_neq' ||
+ data5 === 'semver_gt' ||
+ data5 === 'semver_gte' ||
+ data5 === 'semver_lt' ||
+ data5 === 'semver_lte' ||
+ data5 === 'semver_tilde' ||
+ data5 === 'semver_caret' ||
+ data5 === 'semver_wildcard' ||
+ data5 === 'icontains_multi' ||
+ data5 === 'not_icontains_multi'
)
) {
validate31.errors = [
{
- instancePath: instancePath + '/value',
- schemaPath: '#/properties/value/type',
- keyword: 'type',
- params: { type: 'integer' },
- message: 'must be integer',
+ instancePath: instancePath + '/operator',
+ schemaPath: '#/definitions/PropertyOperator/enum',
+ keyword: 'enum',
+ params: { allowedValues: schema14.enum },
+ message: 'must be equal to one of the allowed values',
},
]
return false
}
- var valid0 = _errs13 === errors
+ var valid0 = _errs12 === errors
} else {
var valid0 = true
}
+ if (valid0) {
+ if (data.type !== undefined) {
+ let data6 = data.type
+ const _errs15 = errors
+ if (typeof data6 !== 'string') {
+ validate31.errors = [
+ {
+ instancePath: instancePath + '/type',
+ schemaPath: '#/properties/type/type',
+ keyword: 'type',
+ params: { type: 'string' },
+ message: 'must be string',
+ },
+ ]
+ return false
+ }
+ if ('cohort' !== data6) {
+ validate31.errors = [
+ {
+ instancePath: instancePath + '/type',
+ schemaPath: '#/properties/type/const',
+ keyword: 'const',
+ params: { allowedValue: 'cohort' },
+ message: 'must be equal to constant',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs15 === errors
+ } else {
+ var valid0 = true
+ }
+ if (valid0) {
+ if (data.value !== undefined) {
+ let data7 = data.value
+ const _errs17 = errors
+ if (
+ !(
+ typeof data7 == 'number' &&
+ !(data7 % 1) &&
+ !isNaN(data7) &&
+ isFinite(data7)
+ )
+ ) {
+ validate31.errors = [
+ {
+ instancePath: instancePath + '/value',
+ schemaPath: '#/properties/value/type',
+ keyword: 'type',
+ params: { type: 'integer' },
+ message: 'must be integer',
+ },
+ ]
+ return false
+ }
+ var valid0 = _errs17 === errors
+ } else {
+ var valid0 = true
+ }
+ }
+ }
}
}
}
diff --git a/frontend/src/scenes/feature-flags/FeatureFlag.tsx b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
index 270b7a420aea..69dcd89043c2 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlag.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
@@ -81,6 +81,7 @@ import {
PropertyOperator,
} from '~/types'
+import { deletedCohortDisabledReason, restoreChecksCohorts } from 'products/feature_flags/frontend/deletedCohortFilters'
import {
ARCHIVE_UNAVAILABLE_DISABLED_REASON,
RESTORE_UNAVAILABLE_DISABLED_REASON,
@@ -89,6 +90,7 @@ import {
featureFlagConfigFormatLabel,
isRulesV2EditableConfig,
} from 'products/feature_flags/frontend/featureFlagConfigFormat'
+import { FeatureFlagDeletedCohortBanner } from 'products/feature_flags/frontend/FeatureFlagDeletedCohortBanner'
import { FeatureFlagStaleBanner } from 'products/feature_flags/frontend/FeatureFlagStaleBanner'
import { AGENT_TOOL_APPLY_BACK_CONTEXT_ITEM, useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
@@ -159,11 +161,14 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
dependentFlags,
configFormat,
editorKind,
+ deletedCohortFilters,
broadcastCohortLoading,
} = useValues(featureFlagLogic)
const isV1Config = configFormat === 'v1'
const canRestore = canRestoreFeatureFlag(featureFlag.filters)
const restoreUnavailable = !!featureFlag.deleted && !canRestore
+ const deletedCohortReason = deletedCohortDisabledReason(deletedCohortFilters)
+ const restoreBlockedReason = restoreChecksCohorts(featureFlag) ? deletedCohortReason : undefined
const { featureFlags } = useValues(enabledFeaturesLogic)
const {
deleteFeatureFlag,
@@ -511,6 +516,9 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
[ARCHIVE_UNAVAILABLE_DISABLED_REASON]: !canArchiveFeatureFlag(
featureFlag.filters
),
+ ...(featureFlag.archived && deletedCohortReason
+ ? { [deletedCohortReason]: true }
+ : {}),
'Updating…': featureFlagActiveUpdateLoading,
}}
>
@@ -546,6 +554,7 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
"You have only 'View' access for this feature flag. To make changes, please contact the flag's creator.":
!featureFlag.can_edit,
[RESTORE_UNAVAILABLE_DISABLED_REASON]: restoreUnavailable,
+ ...(restoreBlockedReason ? { [restoreBlockedReason]: true } : {}),
'Restoring…': featureFlagRestoreLoading,
}}
>
@@ -571,6 +580,7 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
children: 'Restore',
onClick: () => restoreFeatureFlag(featureFlag),
loading: featureFlagRestoreLoading,
+ disabledReason: restoreBlockedReason,
'data-attr': 'restore-feature-flag-banner',
}
: undefined
@@ -592,7 +602,9 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
? {
children: 'Unarchive',
onClick: () => updateFeatureFlagArchived({ archived: false }),
- disabledReason: featureFlagActiveUpdateLoading ? 'Updating…' : undefined,
+ disabledReason: featureFlagActiveUpdateLoading
+ ? 'Updating…'
+ : deletedCohortReason,
}
: undefined
}
@@ -601,6 +613,7 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
experiments and surveys keep their data.
</LemonBanner>
)}
+ {isV1Config && <FeatureFlagDeletedCohortBanner />}
{isV1Config && <FeatureFlagStaleBanner />}
{earlyAccessFeature && earlyAccessFeature.stage === EarlyAccessFeatureStage.Concept && (
<LemonBanner type="info">
@@ -673,12 +686,13 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
disabled={
!!disabledReason ||
featureFlagRestoreLoading ||
- restoreUnavailable
+ restoreUnavailable ||
+ !!restoreBlockedReason
}
tooltip={
restoreUnavailable
? RESTORE_UNAVAILABLE_DISABLED_REASON
- : undefined
+ : restoreBlockedReason
}
data-attr={
featureFlag.deleted
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagOverview.tsx b/frontend/src/scenes/feature-flags/FeatureFlagOverview.tsx
index f1e4cba31f47..2b52d0bd02df 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagOverview.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagOverview.tsx
@@ -13,6 +13,7 @@ import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagL
import { AccessControlLevel, AccessControlResourceType, FeatureFlagEvaluationRuntime, FeatureFlagType } from '~/types'
+import { deletedCohortDisabledReason } from 'products/feature_flags/frontend/deletedCohortFilters'
import {
UNSUPPORTED_CONFIG_DISABLED_REASON,
featureFlagConfigFormat,
@@ -66,7 +67,7 @@ function TagsDisplay({ tags, evaluationContexts, flagId, hasEvaluationContexts }
*/
export function FeatureFlagOverview({ featureFlag }: FeatureFlagOverviewProps): JSX.Element {
const { featureFlags } = useValues(enabledFeaturesLogic)
- const { recordingFilterForFlag, featureFlagActiveUpdateLoading } = useValues(featureFlagLogic)
+ const { recordingFilterForFlag, featureFlagActiveUpdateLoading, deletedCohortFilters } = useValues(featureFlagLogic)
const { toggleFeatureFlagActive } = useActions(featureFlagLogic)
const hasEvaluationContexts = !!featureFlags[FEATURE_FLAGS.FLAG_EVALUATION_TAGS] // NB: the tag was named "flag-evaluation-tags" before we renamed the concept – i.e. this powers evaluation contexts even though the name implies tags
@@ -168,7 +169,9 @@ export function FeatureFlagOverview({ featureFlag }: FeatureFlagOverviewProps):
? "You only have view access to this feature flag. To make changes, contact the flag's creator."
: featureFlagConfigFormat(featureFlag.filters) === 'unsupported'
? UNSUPPORTED_CONFIG_DISABLED_REASON
- : null
+ : !featureFlag.active
+ ? deletedCohortDisabledReason(deletedCohortFilters)
+ : null
}
label="Enable feature flag"
bordered
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx
index 657e009f609a..df49d1b25500 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom'
-import { cleanup, render, waitFor } from '@testing-library/react'
+import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { useMocks } from '~/mocks/jest'
@@ -38,9 +39,9 @@ const cohortFilter: CohortPropertyFilter = {
cohort_name: 'Power Users',
}
-function buildFilters(): FeatureFlagFilters {
+function buildFilters(property: CohortPropertyFilter = cohortFilter): FeatureFlagFilters {
const group: FeatureFlagGroupType = {
- properties: [cohortFilter],
+ properties: [property],
rollout_percentage: 100,
variant: null,
sort_key: 'group-1',
@@ -104,4 +105,39 @@ describe('feature flag release conditions cohort operator', () => {
expect(document.querySelector('[data-attr="taxonomic-operator"]')).toBeInTheDocument()
})
})
+
+ it.each([
+ { state: 'a deleted cohort', markers: { cohort_deleted: true }, label: 'Power Users (deleted)' },
+ {
+ state: 'a missing cohort',
+ markers: { cohort_deleted: true, cohort_missing: true },
+ label: 'Power Users (missing)',
+ },
+ ])('keeps $state marked when the operator changes', async ({ markers, label }) => {
+ const onChange = jest.fn()
+ render(
+ <Provider>
+ <FeatureFlagReleaseConditions
+ id="1234"
+ filters={buildFilters({ ...cohortFilter, ...markers })}
+ onChange={onChange}
+ />
+ </Provider>
+ )
+
+ await waitFor(() => {
+ expect(screen.getByText(label)).toBeInTheDocument()
+ })
+ expect(document.querySelector('[data-attr="property-filter-deleted-cohort-icon"]')).toBeInTheDocument()
+ await userEvent.click(document.querySelector('[data-attr="taxonomic-operator"] button')!)
+ await userEvent.click(await screen.findByText('user in'))
+
+ await waitFor(() => {
+ expect(onChange.mock.lastCall?.[0].groups[0].properties[0]).toMatchObject({
+ operator: PropertyOperator.In,
+ cohort_name: 'Power Users',
+ ...markers,
+ })
+ })
+ })
})
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
index 754b777f8bee..87d947a4dff1 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
@@ -43,7 +43,7 @@ import {
import { allOperatorsToHumanName } from 'lib/components/DefinitionPopover/utils'
import { EditableField } from 'lib/components/EditableField/EditableField'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
-import { isPropertyFilterWithOperator } from 'lib/components/PropertyFilters/utils'
+import { cohortFilterName, isPropertyFilterWithOperator } from 'lib/components/PropertyFilters/utils'
import { TaxonomicFilterGroupType, TaxonomicFilterProps } from 'lib/components/TaxonomicFilter/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
@@ -165,7 +165,7 @@ function summarizeProperties(
let value: string | number
if (property.type === PropertyFilterType.Cohort) {
- value = property.cohort_name || `ID ${property.value}`
+ value = cohortFilterName(property)
} else if (Array.isArray(property.value)) {
const displayValues = property.value.map(resolveValue)
value = displayValues.slice(0, 2).join(', ') + (displayValues.length > 2 ? '...' : '')
diff --git a/frontend/src/scenes/feature-flags/FeatureFlags.stories.tsx b/frontend/src/scenes/feature-flags/FeatureFlags.stories.tsx
index 3d529885efef..c3a74e7e36b8 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlags.stories.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlags.stories.tsx
@@ -15,6 +15,7 @@ import { featureFlagLogic } from './featureFlagLogic'
const STALE_FLAG_ID = 1498
const RULES_V2_FLAG_ID = 1802
const DELETED_FLAG_ID = 1526
+const DELETED_COHORT_FLAG_ID = 1803
const meta: Meta = {
component: App,
@@ -261,6 +262,12 @@ export const DeletedFeatureFlag: Story = {
},
}
+export const FeatureFlagTargetingDeletedCohort: Story = {
+ parameters: {
+ pageUrl: urls.featureFlag(DELETED_COHORT_FLAG_ID),
+ },
+}
+
// The banner has no Restore button, because the server refuses to restore a flag in another config version.
export const DeletedRulesV2FeatureFlag: Story = {
parameters: {
diff --git a/frontend/src/scenes/feature-flags/FeatureFlags.tsx b/frontend/src/scenes/feature-flags/FeatureFlags.tsx
index 450a32787788..c4898984142f 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlags.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlags.tsx
@@ -57,6 +57,11 @@ import {
FeatureFlagType,
} from '~/types'
+import {
+ cohortCanBeRestored,
+ deletedCohortDisabledReason,
+ deletedCohortFilters,
+} from 'products/feature_flags/frontend/deletedCohortFilters'
import { featureFlagsEmptyState } from 'products/feature_flags/frontend/emptyState/featureFlagsEmptyState'
import {
ARCHIVE_UNAVAILABLE_DISABLED_REASON,
@@ -112,9 +117,11 @@ function FeatureFlagStatusCell({ featureFlag }: { featureFlag: FeatureFlagType }
const { featureFlagsUpdating } = useValues(flagLogic)
const isUpdating = featureFlag.id ? featureFlagsUpdating[featureFlag.id] : false
+ const deletedCohorts = deletedCohortFilters(featureFlag.filters)
+ const cohortMissing = !deletedCohorts.every(cohortCanBeRestored)
return (
- <div className="flex justify-start gap-1">
+ <div className="flex flex-wrap justify-start gap-1">
{isUpdating ? (
<LemonTag type="muted" className="uppercase">
<span className="inline-flex items-center gap-1">
@@ -139,30 +146,48 @@ function FeatureFlagStatusCell({ featureFlag }: { featureFlag: FeatureFlagType }
Disabled
</LemonTag>
)}
- {featureFlag.status === 'STALE' && (
- <Tooltip
- title={
- <>
- <div className="text-sm">This flag is likely safe to remove</div>
- <div className="text-xs">
- Not called in 30+ days or fully rolled out. Make sure to remove any references in your
- code before deleting it.
- </div>
- </>
+ {deletedCohorts.length > 0 && (
+ <WarningStatusTag
+ label={cohortMissing ? 'Missing cohort' : 'Deleted cohort'}
+ heading={
+ cohortMissing
+ ? 'A release condition targets a cohort that does not exist in this project'
+ : 'A release condition targets a deleted cohort'
}
- placement="left"
- >
- <span>
- <LemonTag type="warning" className="uppercase cursor-default">
- Stale
- </LemonTag>
- </span>
- </Tooltip>
+ detail="The flag can't evaluate that condition. Open the flag to update its release conditions."
+ />
+ )}
+ {featureFlag.status === 'STALE' && (
+ <WarningStatusTag
+ label="Stale"
+ heading="This flag is likely safe to remove"
+ detail="Not called in 30+ days or fully rolled out. Make sure to remove any references in your code before deleting it."
+ />
)}
</div>
)
}
+function WarningStatusTag({ label, heading, detail }: { label: string; heading: string; detail: string }): JSX.Element {
+ return (
+ <Tooltip
+ title={
+ <>
+ <div className="text-sm">{heading}</div>
+ <div className="text-xs">{detail}</div>
+ </>
+ }
+ placement="left"
+ >
+ <span>
+ <LemonTag type="warning" className="uppercase cursor-default">
+ {label}
+ </LemonTag>
+ </span>
+ </Tooltip>
+ )
+}
+
// Component for feature flag row actions that needs to use hooks
function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }): JSX.Element {
const { currentProjectId } = useValues(projectLogic)
@@ -174,6 +199,7 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
const [isQuickSurveyModalOpen, setIsQuickSurveyModalOpen] = useState(false)
const configFormat = featureFlagConfigFormat(featureFlag.filters)
const isV1Config = configFormat === 'v1'
+ const deletedCohortReason = deletedCohortDisabledReason(deletedCohortFilters(featureFlag.filters))
const tryInInsightsUrl = (featureFlag: FeatureFlagType): string => {
const query: InsightVizNode = {
@@ -281,7 +307,9 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
? 'Unarchive this flag before enabling it.'
: configFormat === 'unsupported'
? UNSUPPORTED_CONFIG_DISABLED_REASON
- : undefined
+ : !featureFlag.active
+ ? deletedCohortReason
+ : undefined
}
>
{featureFlag.active ? 'Disable' : 'Enable'}
@@ -318,7 +346,9 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
? 'Updating…'
: !canArchiveFeatureFlag(featureFlag.filters)
? ARCHIVE_UNAVAILABLE_DISABLED_REASON
- : undefined
+ : featureFlag.archived
+ ? deletedCohortReason
+ : undefined
}
>
{featureFlag.archived ? 'Unarchive' : 'Archive'}
diff --git a/frontend/src/scenes/feature-flags/__mocks__/feature_flags.json b/frontend/src/scenes/feature-flags/__mocks__/feature_flags.json
index 140d32c71a9e..0b49667105dc 100644
--- a/frontend/src/scenes/feature-flags/__mocks__/feature_flags.json
+++ b/frontend/src/scenes/feature-flags/__mocks__/feature_flags.json
@@ -1,5 +1,5 @@
{
- "count": 8,
+ "count": 9,
"next": null,
"previous": null,
"results": [
@@ -47,6 +47,48 @@
"created_at": "2022-03-16T18:01:41.362030Z",
"updated_at": "2022-03-16T18:01:41.362030Z"
},
+ {
+ "id": 1803,
+ "name": "Show the loyalty program banner",
+ "key": "loyalty-program-banner",
+ "filters": {
+ "groups": [
+ {
+ "properties": [
+ {
+ "key": "id",
+ "type": "cohort",
+ "value": 1,
+ "operator": "in",
+ "cohort_name": "Viewed pricing this week"
+ },
+ {
+ "key": "id",
+ "type": "cohort",
+ "value": 2,
+ "operator": "in",
+ "cohort_name": "Frequent buyers",
+ "cohort_deleted": true
+ }
+ ],
+ "rollout_percentage": 100
+ }
+ ],
+ "multivariate": null
+ },
+ "deleted": false,
+ "active": true,
+ "can_edit": true,
+ "created_by": {
+ "id": 4765,
+ "uuid": "4609ea95-6a1c-4577-bc5d-00ded02ffca9",
+ "distinct_id": "98ca6644-43b2-4d78-a35b-0cb1cc520e35",
+ "first_name": "Rick",
+ "email": "[email protected]"
+ },
+ "created_at": "2022-03-20T10:12:05.000000Z",
+ "updated_at": "2022-03-20T10:12:05.000000Z"
+ },
{
"id": 1526,
"name": "",
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
index 4ee3c5085201..57131a015d94 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
@@ -35,6 +35,7 @@ import { deleteFromTree, refreshTreeItem } from '~/layout/panel-layout/ProjectTr
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import {
+ CohortPropertyFilter,
CohortType,
FeatureFlagGroupType,
FeatureFlagType,
@@ -291,44 +292,86 @@ describe('featureFlagLogic', () => {
})
describe('stale list-cache reconciliation on mount', () => {
- it('refreshes a cache-painted flag so active reflects the server, not the stale list cache', async () => {
- logic.unmount()
+ it.each([
+ {
+ cohortChange: 'deleted',
+ listMarkers: {},
+ serverMarkers: { cohort_name: 'Frequent buyers', cohort_deleted: true },
+ expectedDeletedCohortFilters: [
+ expect.objectContaining({ value: 5, cohort_name: 'Frequent buyers', cohort_deleted: true }),
+ ],
+ },
+ {
+ cohortChange: 'restored',
+ listMarkers: { cohort_name: 'Frequent buyers', cohort_deleted: true },
+ serverMarkers: { cohort_name: 'Frequent buyers' },
+ expectedDeletedCohortFilters: [],
+ },
+ ])(
+ 'refreshes a cache-painted flag so active and cohort markers reflect the server after the cohort was $cohortChange',
+ async ({ listMarkers, serverMarkers, expectedDeletedCohortFilters }) => {
+ logic.unmount()
- useMocks({
- get: {
- '/api/projects/:projectId/feature_flags/': () => [
- 200,
- { results: [{ ...MOCK_FEATURE_FLAG, active: false }], count: 1 },
- ],
- [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${MOCK_FEATURE_FLAG.id}/`]: () => [
- 200,
- { ...MOCK_FEATURE_FLAG, active: true },
- ],
- [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${MOCK_FEATURE_FLAG.id}/status`]: () => [
- 200,
- MOCK_FEATURE_FLAG_STATUS,
- ],
- },
- })
+ // The cohort changed after the list loaded, so the list copy and the server copy mark it differently.
+ const cohortCondition: CohortPropertyFilter = {
+ key: 'id',
+ type: PropertyFilterType.Cohort,
+ value: 5,
+ operator: PropertyOperator.In,
+ }
+ const withCohortCondition = (properties: CohortPropertyFilter[]): FeatureFlagFilters => ({
+ ...MOCK_FEATURE_FLAG.filters,
+ groups: [{ properties, rollout_percentage: 100, variant: null }],
+ })
+ useMocks({
+ get: {
+ '/api/projects/:projectId/feature_flags/': () => [
+ 200,
+ {
+ results: [
+ {
+ ...MOCK_FEATURE_FLAG,
+ active: false,
+ filters: withCohortCondition([{ ...cohortCondition, ...listMarkers }]),
+ },
+ ],
+ count: 1,
+ },
+ ],
+ [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${MOCK_FEATURE_FLAG.id}/`]: () => [
+ 200,
+ {
+ ...MOCK_FEATURE_FLAG,
+ active: true,
+ filters: withCohortCondition([{ ...cohortCondition, ...serverMarkers }]),
+ },
+ ],
+ [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${MOCK_FEATURE_FLAG.id}/status`]:
+ () => [200, MOCK_FEATURE_FLAG_STATUS],
+ },
+ })
- featureFlagsLogic.mount()
- featureFlagsLogic.actions.loadFeatureFlags()
- await expectLogic(featureFlagsLogic).toFinishAllListeners()
- expect(featureFlagsLogic.values.featureFlags.results[0].active).toBe(false)
+ featureFlagsLogic.mount()
+ featureFlagsLogic.actions.loadFeatureFlags()
+ await expectLogic(featureFlagsLogic).toFinishAllListeners()
+ expect(featureFlagsLogic.values.featureFlags.results[0].active).toBe(false)
- logic = featureFlagLogic({ id: 1 })
- logic.mount()
+ logic = featureFlagLogic({ id: 1 })
+ logic.mount()
- await expectLogic(logic)
- .toDispatchActions(['setFeatureFlag', 'refreshFeatureFlag', 'refreshFeatureFlagSuccess'])
- .toFinishAllListeners()
+ await expectLogic(logic)
+ .toDispatchActions(['setFeatureFlag', 'refreshFeatureFlag', 'refreshFeatureFlagSuccess'])
+ .toFinishAllListeners()
- expect(logic.values.featureFlag.active).toBe(true)
- expect(featureFlagsLogic.values.featureFlags.results[0].active).toBe(true)
- expect(lemonToast.info).not.toHaveBeenCalled()
+ expect(logic.values.featureFlag.active).toBe(true)
+ expect(logic.values.deletedCohortFilters).toEqual(expectedDeletedCohortFilters)
+ expect(logic.values.isFormDirty).toBe(false)
+ expect(featureFlagsLogic.values.featureFlags.results[0].active).toBe(true)
+ expect(lemonToast.info).not.toHaveBeenCalled()
- featureFlagsLogic.unmount()
- })
+ featureFlagsLogic.unmount()
+ }
+ )
// The agent path surfaces its failures through this same loader, so its rethrow must not
// reach this one.
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
index 356ca27a5c2c..fc6b5507dfef 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
@@ -62,6 +62,7 @@ import {
ActivityScope,
AvailableFeature,
Breadcrumb,
+ CohortPropertyFilter,
CohortType,
EarlyAccessFeatureType,
FeatureFlagBucketingIdentifier,
@@ -93,6 +94,7 @@ import { cohortsList, cohortsRetrieve } from 'products/cohorts/frontend/generate
import { cohortsActivityRetrieve } from 'products/cohorts/frontend/generated/api'
import type { CohortApi } from 'products/cohorts/frontend/generated/api.schemas'
import { NEW_EARLY_ACCESS_FEATURE } from 'products/early_access_features/frontend/earlyAccessFeatureLogic'
+import { deletedCohortFilters, withCohortAnnotationsFrom } from 'products/feature_flags/frontend/deletedCohortFilters'
import {
FeatureFlagConfigFormat,
featureFlagConfigFormat,
@@ -334,6 +336,25 @@ function reportFeatureFlagScheduleSuccess(): void {
posthog.capture('feature flag scheduled')
}
+// A flag opened from the list arrives through refreshFeatureFlag, not loadFeatureFlag.
+// Clicking Edit loads the flag again. The cache entry limits the event to one capture per mount.
+function reportFlagWithDeletedCohortLoaded(featureFlag: FeatureFlagType | null, cache: Record<string, any>): void {
+ if (!featureFlag?.id || cache.hasCapturedDeletedCohortLoad) {
+ return
+ }
+ const filters = deletedCohortFilters(featureFlag.filters)
+ if (filters.length === 0) {
+ return
+ }
+ cache.hasCapturedDeletedCohortLoad = true
+ posthog.capture('feature flag with deleted cohort loaded', {
+ active: featureFlag.active,
+ archived: featureFlag.archived,
+ deleted: featureFlag.deleted,
+ deleted_cohort_count: filters.length,
+ })
+}
+
// A collapsed condition-set panel renders none of its children, so an inline release-condition
// error has no element to render into and `scrollToFormError` has nothing to scroll to. Open every
// set that holds a blocking error before the scroll runs.
@@ -1221,6 +1242,7 @@ export interface featureFlagLogicValues {
customPairDisableCronPreview: string | null
customPairEnableCron: string
customPairEnableCronPreview: string | null
+ deletedCohortFilters: CohortPropertyFilter[]
dependentFlags: DependentFlag[]
dependentFlagsLoading: boolean
disableCopiedFlag: boolean
@@ -2516,6 +2538,7 @@ export interface featureFlagLogicMeta {
hasEncryptedPayloadBeenSaved: (featureFlag: FeatureFlagType, props: any) => boolean | undefined
hasExperiment: (featureFlag: FeatureFlagType) => boolean | null
showStaleFlagBanner: (featureFlag: FeatureFlagType, flagStatus: FeatureFlagStatusResponseApi | null) => boolean
+ deletedCohortFilters: (featureFlag: FeatureFlagType) => CohortPropertyFilter[]
isDraftExperiment: (experiment: any) => boolean
properties: (featureFlag: FeatureFlagType) => AnyPropertyFilter[]
savedVariantKeys: (originalFeatureFlag: FeatureFlagType | null) => string[]
@@ -4659,6 +4682,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
if (!featureFlagRefresh) {
return
}
+ reportFlagWithDeletedCohortLoaded(featureFlagRefresh, cache)
const afterAgentChange = !!payload?.afterAgentChange
if (afterAgentChange && cache.agentRefreshFailedToastId) {
// This response carries what the failed one missed, so its notice is now wrong.
@@ -4690,8 +4714,13 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
...(isEditedLocally('archived') ? {} : { archived: featureFlagRefresh.archived }),
...(afterAgentChange ? {} : { version: featureFlagRefresh.version }),
}
- actions.setFeatureFlag({ ...values.featureFlag, ...persisted })
- actions.setOriginalFeatureFlag({ ...baseline, ...persisted })
+ // A list-cached flag can carry cohort markers from before a cohort was deleted or restored.
+ actions.setFeatureFlag(
+ withCohortAnnotationsFrom({ ...values.featureFlag, ...persisted }, featureFlagRefresh)
+ )
+ actions.setOriginalFeatureFlag(
+ withCohortAnnotationsFrom({ ...baseline, ...persisted }, featureFlagRefresh)
+ )
if (afterAgentChange) {
lemonToast.info(
'PostHog AI changed this flag. The page kept your unsaved edits, so it does not show the saved version.',
@@ -4869,6 +4898,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
}
actions.loadRelatedInsights()
actions.loadDependentFlags()
+ reportFlagWithDeletedCohortLoaded(featureFlag, cache)
// Experiment is now loaded inline during loadFeatureFlag, not here
// Auto-apply template from URL param on first load
@@ -5603,6 +5633,10 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
)
},
],
+ deletedCohortFilters: [
+ (s) => [s.featureFlag],
+ (featureFlag: FeatureFlagType): CohortPropertyFilter[] => deletedCohortFilters(featureFlag.filters),
+ ],
isDraftExperiment: [
(s) => [s.experiment],
(experiment) => {
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index c32be4f233ec..b6766bf92905 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -1307,6 +1307,10 @@ export interface CohortPropertyFilter extends BasePropertyFilter {
/** @default 'in' */
operator: PropertyOperator
cohort_name?: string
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean
}
export interface GroupPropertyFilter extends BasePropertyFilter {
diff --git a/posthog/api/documentation.py b/posthog/api/documentation.py
index 5a12cd13f51c..9f871a0551f4 100644
--- a/posthog/api/documentation.py
+++ b/posthog/api/documentation.py
@@ -513,6 +513,16 @@ class FeatureFlagFilterPropertyCohortInSchemaSerializer(_FeatureFlagFilterProper
required=True,
help_text="Cohort comparison value (single or list, depending on usage).",
)
+ cohort_deleted = serializers.BooleanField(
+ required=False,
+ help_text="Set to true in responses when the cohort is deleted or does not exist. "
+ "The flag cannot evaluate this condition. Ignored on write.",
+ )
+ cohort_missing = serializers.BooleanField(
+ required=False,
+ help_text="Set to true in responses when no cohort with this id exists in the project, so it cannot be "
+ "restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ )
class FeatureFlagFilterPropertyFlagEvaluatesSchemaSerializer(_FeatureFlagFilterPropertyBaseSerializer):
diff --git a/posthog/schema.py b/posthog/schema.py
index 53b87b7905a5..ea5eaace3341 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -5360,6 +5360,14 @@ class CohortPropertyFilter(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ cohort_deleted: bool | None = Field(
+ default=None,
+ description=("Set by the feature flag API when the cohort is deleted or does not exist."),
+ )
+ cohort_missing: bool | None = Field(
+ default=None,
+ description=("Set by the feature flag API when the cohort does not exist, so it cannot be restored."),
+ )
cohort_name: str | None = None
key: Literal["id"] = "id"
label: str | None = None
diff --git a/products/alerts_platform/frontend/generated/api.schemas.ts b/products/alerts_platform/frontend/generated/api.schemas.ts
index c7031029f8ac..3d1b29acf6e6 100644
--- a/products/alerts_platform/frontend/generated/api.schemas.ts
+++ b/products/alerts_platform/frontend/generated/api.schemas.ts
@@ -366,6 +366,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.ts
index fef61c790b2f..bc511e2ddd39 100644
--- a/products/customer_analytics/frontend/generated/api.schemas.ts
+++ b/products/customer_analytics/frontend/generated/api.schemas.ts
@@ -2343,6 +2343,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index d248b9cbf568..1c141e01cd94 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -1319,6 +1319,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.ts
index eab5e774172c..68b3abc1bd19 100644
--- a/products/desktop/packages/api-client/src/generated.ts
+++ b/products/desktop/packages/api-client/src/generated.ts
@@ -852,6 +852,8 @@ export namespace Schemas {
| undefined;
};
export type CohortPropertyFilter = {
+ cohort_deleted?: (boolean | null) | undefined;
+ cohort_missing?: (boolean | null) | undefined;
cohort_name?: (string | null) | undefined;
key?: string | undefined;
label?: (string | null) | undefined;
@@ -9444,6 +9446,8 @@ export namespace Schemas {
* Cohort comparison value (single or list, depending on usage).
*/
value: unknown;
+ cohort_deleted?: boolean | undefined;
+ cohort_missing?: boolean | undefined;
};
/**
* * `flag` - flag
diff --git a/products/endpoints/frontend/generated/api.schemas.ts b/products/endpoints/frontend/generated/api.schemas.ts
index 405425c83e68..729e9d054ae9 100644
--- a/products/endpoints/frontend/generated/api.schemas.ts
+++ b/products/endpoints/frontend/generated/api.schemas.ts
@@ -816,6 +816,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/error_tracking/frontend/generated/api.schemas.ts b/products/error_tracking/frontend/generated/api.schemas.ts
index 9285fa2de52f..e93707b0ab0b 100644
--- a/products/error_tracking/frontend/generated/api.schemas.ts
+++ b/products/error_tracking/frontend/generated/api.schemas.ts
@@ -335,6 +335,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index 4ada98e070eb..ff600815881d 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -324,6 +324,10 @@ export interface FeatureFlagFilterPropertyCohortInSchemaApi {
operator: FeatureFlagFilterPropertyCohortInSchemaOperatorEnumApi
/** Cohort comparison value (single or list, depending on usage). */
value: unknown
+ /** Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write. */
+ cohort_deleted?: boolean
+ /** Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write. */
+ cohort_missing?: boolean
}
/**
@@ -1116,6 +1120,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/experiments/frontend/generated/api.zod.ts b/products/experiments/frontend/generated/api.zod.ts
index e9a0d17ae4aa..0487fdc28d3f 100644
--- a/products/experiments/frontend/generated/api.zod.ts
+++ b/products/experiments/frontend/generated/api.zod.ts
@@ -239,6 +239,18 @@ export const ExperimentHoldoutsCreateBody = /* @__PURE__ */ zod
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -518,6 +530,18 @@ export const ExperimentHoldoutsUpdateBody = /* @__PURE__ */ zod
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -798,6 +822,18 @@ export const ExperimentHoldoutsPartialUpdateBody = /* @__PURE__ */ zod
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.py
index a4e9dfe8b072..7882ffac178b 100644
--- a/products/feature_flags/backend/api/feature_flag.py
+++ b/products/feature_flags/backend/api/feature_flag.py
@@ -1182,6 +1182,27 @@ def _iter_flag_filter_properties(groups: Any) -> Iterator[_FlagFilterProperty]:
)
+def _condition_cohort_id(value: Any) -> int | None:
+ """Return the cohort id a condition's value names, or None when the value is not an id."""
+ # The Rust flag evaluator (PropertyFilter::get_cohort_id) accepts only a JSON integer or a string that
+ # parse::<i32>() accepts (ASCII digits with an optional sign), and only when the id fits in 32 bits.
+ # It rejects a float such as 42.5, which int() would truncate to a live cohort's id.
+ # A JSON true is the Python integer 1, so the bool check must come before the int check.
+ if isinstance(value, bool):
+ return None
+ if isinstance(value, str):
+ if not re.fullmatch(r"[+-]?[0-9]+", value):
+ return None
+ try:
+ value = int(value)
+ except ValueError:
+ # Python refuses to convert a string with more digits than sys.get_int_max_str_digits().
+ return None
+ if isinstance(value, int) and -(2**31) <= value < 2**31:
+ return value
+ return None
+
+
def _validate_cohort_reference(cohort_id: Any, project_id: int) -> Cohort:
"""Return the cohort a release condition targets, or raise if the flag cannot evaluate it.
@@ -1189,12 +1210,9 @@ def _validate_cohort_reference(cohort_id: Any, project_id: int) -> Cohort:
deleted cohort therefore fails the whole flag. The lookup includes deleted cohorts so that the
error can name the cohort.
"""
- try:
- # A JSON true is the Python integer 1, so the lookup would match the cohort with id 1.
- if isinstance(cohort_id, bool):
- raise TypeError(cohort_id)
- cohort = Cohort.objects.get(pk=cast(str | int, cohort_id), team__project_id=project_id)
- except (Cohort.DoesNotExist, ValueError, TypeError):
+ parsed_id = _condition_cohort_id(cohort_id)
+ cohort = Cohort.objects.filter(pk=parsed_id, team__project_id=project_id).first() if parsed_id is not None else None
+ if cohort is None:
raise serializers.ValidationError(
detail=f"Cohort with id {cohort_id} does not exist",
code="cohort_does_not_exist",
@@ -1208,14 +1226,20 @@ def _validate_cohort_reference(cohort_id: Any, project_id: int) -> Cohort:
return cohort
+def _cohort_properties(groups: Any) -> Iterator[dict[str, Any]]:
+ """Yield the cohort properties in a v1 document's release condition groups."""
+ for located in _iter_flag_filter_properties(groups):
+ if located.prop.get("type") == PropertyFilterType.COHORT:
+ yield located.prop
+
+
def validate_stored_cohort_references(flag: FeatureFlag) -> None:
"""Raise if a stored release condition targets a cohort the flag cannot evaluate."""
# Only config version 1 can reference a cohort.
if detect_config_format(flag.filters).kind != "v1":
return
- for located in _iter_flag_filter_properties(flag.conditions):
- if located.prop.get("type") == "cohort":
- _validate_cohort_reference(located.prop.get("value"), flag.team.project_id)
+ for prop in _cohort_properties(flag.conditions):
+ _validate_cohort_reference(prop.get("value"), flag.team.project_id)
class FeatureFlagCreateRequestSchemaSerializer(serializers.Serializer):
@@ -1327,11 +1351,41 @@ class FeatureFlagExperimentSetMetadataSerializer(serializers.Serializer):
)
-COHORT_NAMES_CONTEXT_KEY = "feature_flag_cohort_names"
+CONDITION_COHORTS_CONTEXT_KEY = "feature_flag_condition_cohorts"
+
+
+@frozen
+class _ConditionCohort:
+ name: str | None
+ deleted: bool
+
+
+def _load_condition_cohorts(flags: Iterable[FeatureFlag], project_id: int) -> dict[int, _ConditionCohort]:
+ """Load the cohorts that the flags' release conditions target, keyed by id.
+
+ Deleted cohorts are included so that a condition on one can show its name. An id with no
+ cohort in the project has no entry.
+ """
+ cohort_ids: set[int] = set()
+ for flag in flags:
+ if detect_config_format(flag.filters).kind != "v1":
+ continue
+ for cohort_prop in _cohort_properties(flag.conditions):
+ cohort_id = _condition_cohort_id(cohort_prop.get("value"))
+ if cohort_id is not None:
+ cohort_ids.add(cohort_id)
+ if not cohort_ids:
+ return {}
+ return {
+ cohort_id: _ConditionCohort(name=name, deleted=deleted)
+ for cohort_id, name, deleted in Cohort.objects.filter(
+ id__in=cohort_ids, team__project_id=project_id
+ ).values_list("id", "name", "deleted")
+ }
class FeatureFlagListSerializer(serializers.ListSerializer):
- """Resolves the cohort names of every flag on a page in one query, instead of one query per flag.
+ """Loads the condition cohorts of every flag on a page in one query, instead of one query per flag.
The cohort ids live in each flag's JSON filters, so a queryset prefetch cannot select them. This is
the only hook DRF gives that sees the whole page.
@@ -1340,26 +1394,13 @@ class FeatureFlagListSerializer(serializers.ListSerializer):
def to_representation(self, data: Any) -> Any:
flags = list(data)
assert isinstance(self.child, FeatureFlagSerializer)
- cohort_ids: set[int] = set()
- for flag in flags:
- config = decode_config(flag.get_filters())
- # A document no reader can parse has no cohort names to show, and must not fail the page.
- if isinstance(config, UnsupportedConfig):
- continue
- cohort_ids.update(references(config).cohort_ids)
- cohort_names: dict[str, str | None] = {}
- if cohort_ids:
- cohort_names = {
- str(cohort_id): name
- for cohort_id, name in Cohort.objects.filter(
- id__in=cohort_ids, team__project_id=self.child.context["project_id"], deleted=False
- ).values_list("id", "name")
- }
- self.child.context[COHORT_NAMES_CONTEXT_KEY] = cohort_names
+ self.child.context[CONDITION_COHORTS_CONTEXT_KEY] = _load_condition_cohorts(
+ flags, self.child.context["project_id"]
+ )
try:
return super().to_representation(flags)
finally:
- self.child.context.pop(COHORT_NAMES_CONTEXT_KEY, None)
+ self.child.context.pop(CONDITION_COHORTS_CONTEXT_KEY, None)
class FeatureFlagSerializer(
@@ -2445,10 +2486,6 @@ class FeatureFlagSerializer(
if property_type is None or prop.get("type") == property_type:
yield prop
- def _get_cohort_properties_from_filters(self, filters: dict):
- """Extract cohort properties from filters."""
- return list(self._get_properties_from_filters(filters, PropertyFilterType.COHORT))
-
def _get_group_key_properties_from_filters(self, filters: dict):
"""Extract $group_key properties from group-type filters."""
return [
@@ -3018,22 +3055,39 @@ class FeatureFlagSerializer(
flag_status, _ = checker.get_status()
return flag_status.name
+ def _annotate_condition_cohorts(self, instance: FeatureFlag, filters: dict[str, Any]) -> None:
+ # A document in another config version can still hold `groups`. Annotating it would mark its live
+ # cohorts as deleted.
+ if detect_config_format(filters).kind != "v1":
+ return
+ cohort_props = list(_cohort_properties((filters or {}).get("groups")))
+ if not cohort_props:
+ return
+
+ # FeatureFlagListSerializer loads the cohorts of a whole page. Retrieve and writes serialize one flag.
+ cohorts = self.context.get(CONDITION_COHORTS_CONTEXT_KEY)
+ if cohorts is None:
+ cohorts = _load_condition_cohorts([instance], self.context["project_id"])
+
+ for cohort_prop in cohort_props:
+ cohort_id = _condition_cohort_id(cohort_prop.get("value"))
+ cohort = cohorts.get(cohort_id) if cohort_id is not None else None
+ cohort_prop["cohort_name"] = cohort.name if cohort else None
+ # The flag evaluator loads only non-deleted cohorts. A condition on a deleted or missing
+ # cohort fails the flag. A client that echoes these keys back can store them. Removing a
+ # key here hides that stale value on a live cohort.
+ markers = {"cohort_deleted": cohort is None or cohort.deleted, "cohort_missing": cohort is None}
+ for key, marked in markers.items():
+ if marked:
+ cohort_prop[key] = True
+ else:
+ cohort_prop.pop(key, None)
+
def to_representation(self, instance):
representation = super().to_representation(instance)
filters = representation.get("filters", {})
- # FeatureFlagListSerializer resolves the names of a whole page. Retrieve and writes serialize one flag.
- cohorts = self.context.get(COHORT_NAMES_CONTEXT_KEY)
- if cohorts is None:
- cohort_ids = {cohort_prop.get("value") for cohort_prop in self._get_cohort_properties_from_filters(filters)}
- cohorts = {
- str(cohort.id): cohort.name
- for cohort in Cohort.objects.filter(id__in=cohort_ids, team__project_id=self.context["project_id"])
- }
-
- # Add cohort names to the response
- for cohort_prop in self._get_cohort_properties_from_filters(filters):
- cohort_prop["cohort_name"] = cohorts.get(str(cohort_prop.get("value")))
+ self._annotate_condition_cohorts(instance, filters)
# Resolve group key display names for $group_key filters. Check both
# the flag-level and per-condition-set aggregation_group_type_index to
diff --git a/products/feature_flags/backend/api/filters_schema.py b/products/feature_flags/backend/api/filters_schema.py
index cf37d6eab660..1625caf3d46e 100644
--- a/products/feature_flags/backend/api/filters_schema.py
+++ b/products/feature_flags/backend/api/filters_schema.py
@@ -320,6 +320,17 @@ class FlagPropertySerializer(DropsUnknownKeysMixin, serializers.Serializer):
allow_blank=True,
help_text="Display name of the referenced cohort. Injected on read and echoed back by clients.",
)
+ # Declared so that DropsUnknownKeysMixin treats an echoed value as known. A read-only field
+ # never reaches validated_data. A structurally valid write therefore drops the value, even
+ # while unknown keys are preserved.
+ cohort_deleted = serializers.BooleanField(
+ read_only=True,
+ help_text="True when the referenced cohort is deleted or does not exist. Injected on read and ignored on write.",
+ )
+ cohort_missing = serializers.BooleanField(
+ read_only=True,
+ help_text="True when no cohort with the referenced id exists in the project. Injected on read and ignored on write.",
+ )
group_key_names = serializers.JSONField(
required=False,
allow_null=True,
diff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.py
index 4086666e3c39..e5f71cd83070 100644
--- a/products/feature_flags/backend/api/test/test_feature_flag.py
+++ b/products/feature_flags/backend/api/test/test_feature_flag.py
@@ -5072,7 +5072,7 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
expected_status=status.HTTP_201_CREATED,
)
- def _unusable_cohort_id(self, cohort_state: str) -> int | str:
+ def _unusable_cohort_id(self, cohort_state: str) -> int | float | str:
if cohort_state == "missing":
return (Cohort.objects.order_by("-id").values_list("id", flat=True).first() or 0) + 1
if cohort_state == "malformed":
@@ -5081,6 +5081,9 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
# A live cohort with id 1 is what a boolean value would wrongly resolve to.
Cohort.objects.update_or_create(pk=1, defaults={"team": self.team, "name": "First cohort"})
return True
+ if cohort_state == "fractional":
+ # int() would truncate the value to this live cohort's id.
+ return Cohort.objects.create(team=self.team, name="Live cohort").id + 0.5
return Cohort.objects.create(
team=self.team,
name=None if cohort_state == "deleted_unnamed" else "Retired cohort",
@@ -5094,12 +5097,12 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
).id
@staticmethod
- def _cohort_condition_filters(cohort_id: int | str) -> dict[str, Any]:
+ def _cohort_condition_filters(cohort_id: int | float | str) -> dict[str, Any]:
return {"groups": [{"properties": [{"key": "id", "type": "cohort", "value": cohort_id}]}]}
@staticmethod
- def _unusable_cohort_detail(cohort_state: str, cohort_id: int | str) -> str:
- if cohort_state in ("missing", "malformed", "boolean"):
+ def _unusable_cohort_detail(cohort_state: str, cohort_id: int | float | str) -> str:
+ if cohort_state in ("missing", "malformed", "boolean", "fractional"):
return f"Cohort with id {cohort_id} does not exist"
label = (
f"Cohort with id {cohort_id}"
@@ -5111,6 +5114,7 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
@parameterized.expand(
[
("missing_post", "missing", "post"),
+ ("fractional_post", "fractional", "post"),
("deleted_post", "deleted", "post"),
("deleted_patch", "deleted", "patch"),
("deleted_unnamed_post", "deleted_unnamed", "post"),
@@ -5203,6 +5207,27 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
+ def test_deleted_flag_restores_after_its_missing_cohort_condition_is_removed(self) -> None:
+ flag = FeatureFlag.objects.create(
+ team=self.team,
+ created_by=self.user,
+ key="cohort-flag",
+ filters=self._cohort_condition_filters(self._unusable_cohort_id("missing")),
+ active=True,
+ deleted=True,
+ )
+ url = f"/api/projects/{self.team.id}/feature_flags/{flag.id}/"
+
+ edit = self.client.patch(
+ url, {"filters": {"groups": [{"properties": [], "rollout_percentage": 100}]}}, format="json"
+ )
+ self.assertEqual(edit.status_code, status.HTTP_200_OK, edit.content)
+ restore = self.client.patch(url, {"deleted": False}, format="json")
+ self.assertEqual(restore.status_code, status.HTTP_200_OK, restore.content)
+
+ flag.refresh_from_db()
+ self.assertFalse(flag.deleted)
+
def test_validation_payloads(self):
self._create_flag_with_properties(
"person-flag",
@@ -7351,6 +7376,8 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
def test_feature_flag_includes_cohort_names(self, endpoint: str):
groups = [{"properties": [{"key": "email", "value": "@posthog.com", "type": "person"}]}]
cohort = Cohort.objects.create(team=self.team, name="test_cohort", groups=groups)
+ deleted_cohort = Cohort.objects.create(team=self.team, name="deleted_cohort", groups=groups, deleted=True)
+ nameless_deleted_cohort = Cohort.objects.create(team=self.team, name=None, groups=groups, deleted=True)
other_project_team = Team.objects.create(organization=self.organization, name="Other project")
other_project_cohort = Cohort.objects.create(team=other_project_team, name="other_cohort", groups=groups)
flag = FeatureFlag.objects.create(
@@ -7360,35 +7387,90 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
filters={
"groups": [
{"properties": [{"key": "id", "type": "cohort", "value": cohort.pk}]},
- {"properties": [{"key": "id", "type": "cohort", "value": str(cohort.pk)}]},
+ {
+ "properties": [
+ {
+ "key": "id",
+ "type": "cohort",
+ "value": str(cohort.pk),
+ "cohort_deleted": True,
+ "cohort_missing": True,
+ }
+ ]
+ },
+ {"properties": [{"key": "id", "type": "cohort", "value": deleted_cohort.pk}]},
+ {"properties": [{"key": "id", "type": "cohort", "value": nameless_deleted_cohort.pk}]},
{"properties": [{"key": "id", "type": "cohort", "value": other_project_cohort.pk}]},
]
},
)
- FeatureFlag.objects.create(
+ malformed_flag = FeatureFlag.objects.create(
team=self.team,
created_by=self.user,
key="legacy-malformed-cohort-value",
- filters={"groups": [{"properties": [{"key": "id", "type": "cohort", "value": "not-a-cohort-id"}]}]},
+ filters={
+ "groups": [
+ {"properties": [{"key": "id", "type": "cohort", "value": "not-a-cohort-id"}]},
+ {"properties": [{"key": "id", "type": "cohort", "value": True}]},
+ {"properties": [{"key": "id", "type": "cohort", "value": cohort.pk + 0.5}]},
+ {"properties": [{"key": "id", "type": "cohort", "value": "9" * 5000}]},
+ ]
+ },
+ )
+ # A live cohort with id 1 is what a boolean value would wrongly resolve to.
+ Cohort.objects.get_or_create(pk=1, defaults={"team": self.team, "name": "First cohort", "groups": groups})
+ unsupported_flag = FeatureFlag.objects.create(
+ team=self.team,
+ created_by=self.user,
+ key="unsupported-config-version",
+ filters={"version": 3, "groups": [{"properties": [{"key": "id", "type": "cohort", "value": cohort.pk}]}]},
)
- if endpoint == "list":
- response = self.client.get(f"/api/projects/{self.team.id}/feature_flags/")
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- filters = next(result for result in response.json()["results"] if result["id"] == flag.id)["filters"]
- else:
- response = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{flag.id}/")
+ def get_filters(flag_id: int) -> dict[str, Any]:
+ if endpoint == "list":
+ response = self.client.get(f"/api/projects/{self.team.id}/feature_flags/")
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ return next(result for result in response.json()["results"] if result["id"] == flag_id)["filters"]
+ response = self.client.get(f"/api/projects/{self.team.id}/feature_flags/{flag_id}/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
- filters = response.json()["filters"]
+ return response.json()["filters"]
+ missing = {"cohort_name": None, "cohort_deleted": True, "cohort_missing": True}
self.assertEqual(
- [group["properties"][0] for group in filters["groups"]],
+ [group["properties"][0] for group in get_filters(flag.id)["groups"]],
[
{"key": "id", "type": "cohort", "value": cohort.pk, "cohort_name": "test_cohort"},
{"key": "id", "type": "cohort", "value": str(cohort.pk), "cohort_name": "test_cohort"},
- {"key": "id", "type": "cohort", "value": other_project_cohort.pk, "cohort_name": None},
+ {
+ "key": "id",
+ "type": "cohort",
+ "value": deleted_cohort.pk,
+ "cohort_name": "deleted_cohort",
+ "cohort_deleted": True,
+ },
+ {
+ "key": "id",
+ "type": "cohort",
+ "value": nameless_deleted_cohort.pk,
+ "cohort_name": None,
+ "cohort_deleted": True,
+ },
+ {"key": "id", "type": "cohort", "value": other_project_cohort.pk, **missing},
],
)
+ self.assertEqual(
+ [group["properties"][0] for group in get_filters(malformed_flag.id)["groups"]],
+ [
+ {"key": "id", "type": "cohort", "value": "not-a-cohort-id", **missing},
+ {"key": "id", "type": "cohort", "value": True, **missing},
+ {"key": "id", "type": "cohort", "value": cohort.pk + 0.5, **missing},
+ {"key": "id", "type": "cohort", "value": "9" * 5000, **missing},
+ ],
+ )
+ self.assertEqual(
+ get_filters(unsupported_flag.id)["groups"][0]["properties"][0],
+ {"key": "id", "type": "cohort", "value": cohort.pk},
+ )
def test_feature_flag_includes_group_key_names(self):
create_group_type_mapping(
diff --git a/products/feature_flags/backend/api/test/test_filters_schema.py b/products/feature_flags/backend/api/test/test_filters_schema.py
index bf779a61982c..016fcc1194ac 100644
--- a/products/feature_flags/backend/api/test/test_filters_schema.py
+++ b/products/feature_flags/backend/api/test/test_filters_schema.py
@@ -330,7 +330,14 @@ class TestFiltersSchema(SimpleTestCase):
def test_log_only_mode_preserves_non_legacy_unknown_keys_at_every_level(self) -> None:
filters = {
- "groups": [{"properties": [{**VALID_PROPERTY, "property_extra": {"a": 1}}], "group_extra": "g"}],
+ "groups": [
+ {
+ "properties": [
+ {**VALID_PROPERTY, "property_extra": {"a": 1}, "cohort_deleted": True, "cohort_missing": True}
+ ],
+ "group_extra": "g",
+ }
+ ],
"multivariate": {
"variants": [{"key": "a", "rollout_percentage": 100, "variant_extra": [1]}],
"multivariate_extra": True,
@@ -349,6 +356,8 @@ class TestFiltersSchema(SimpleTestCase):
assert validated["filters_extra"] == "f"
assert validated["groups"][0]["group_extra"] == "g"
assert validated["groups"][0]["properties"][0]["property_extra"] == {"a": 1}
+ assert "cohort_deleted" not in validated["groups"][0]["properties"][0]
+ assert "cohort_missing" not in validated["groups"][0]["properties"][0]
assert validated["multivariate"]["multivariate_extra"] is True
assert validated["multivariate"]["variants"][0]["variant_extra"] == [1]
assert validated["holdout"]["holdout_extra"] == "h"
diff --git a/products/feature_flags/frontend/CohortConditionLink.tsx b/products/feature_flags/frontend/CohortConditionLink.tsx
index 66b3d108aa9f..1f8a57c9728a 100644
--- a/products/feature_flags/frontend/CohortConditionLink.tsx
+++ b/products/feature_flags/frontend/CohortConditionLink.tsx
@@ -1,8 +1,9 @@
import { useValues } from 'kea'
-import { IconBolt } from '@posthog/icons'
+import { IconBolt, IconWarning } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
+import { cohortFilterName } from 'lib/components/PropertyFilters/utils'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { urls } from 'scenes/urls'
@@ -10,12 +11,42 @@ import { urls } from 'scenes/urls'
import { cohortsModel } from '~/models/cohortsModel'
import { CohortPropertyFilter } from '~/types'
-/** The cohort a flag condition targets, linked, with a bolt when flags read its membership in realtime. */
+import { cohortCanBeRestored } from './deletedCohortFilters'
+
+/**
+ * The cohort a flag condition targets, linked, with a bolt when flags read its membership in realtime.
+ * A deleted or missing cohort renders as a warning instead.
+ */
export function CohortConditionLink({ property }: { property: CohortPropertyFilter }): JSX.Element {
const { cohortsById } = useValues(cohortsModel)
const realtimeTargetingEnabled = useFeatureFlag('REALTIME_COHORT_FLAG_TARGETING')
const isRealtime = realtimeTargetingEnabled && cohortsById[property.value]?.realtime?.state === 'ready'
+ if (property.cohort_deleted) {
+ // A missing cohort has no page to open. A soft-deleted cohort's page has a restore action.
+ const restorable = cohortCanBeRestored(property)
+ const name = cohortFilterName(property)
+ const explanation = restorable
+ ? "This cohort was deleted, so the flag can't evaluate this condition. Restore the cohort, choose another cohort, or remove the condition."
+ : "This cohort does not exist in this project, so the flag can't evaluate this condition. Choose another cohort or remove the condition."
+ return (
+ <LemonButton
+ type="secondary"
+ status="danger"
+ size="xsmall"
+ to={restorable ? urls.cohort(property.value) : undefined}
+ icon={<IconWarning />}
+ tooltip={explanation}
+ // Without a `to`, LemonButton renders a plain button and uses a string tooltip as its whole
+ // accessible name. The label leads with the cohort name so screen readers still announce it.
+ aria-label={restorable ? undefined : `${name}. ${explanation}`}
+ sideIcon={restorable ? <IconOpenInNew /> : undefined}
+ >
+ {name}
+ </LemonButton>
+ )
+ }
+
return (
<LemonButton
type="secondary"
@@ -27,7 +58,7 @@ export function CohortConditionLink({ property }: { property: CohortPropertyFilt
}
sideIcon={<IconOpenInNew />}
>
- {property.cohort_name || `ID ${property.value}`}
+ {cohortFilterName(property)}
</LemonButton>
)
}
diff --git a/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.test.tsx b/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.test.tsx
new file mode 100644
index 000000000000..f757763861de
--- /dev/null
+++ b/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.test.tsx
@@ -0,0 +1,254 @@
+import { MOCK_DEFAULT_PROJECT } from 'lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { BindLogic, Provider } from 'kea'
+import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
+
+import { NEW_FLAG, featureFlagLogic } from 'scenes/feature-flags/featureFlagLogic'
+
+import { useMocks } from '~/mocks/jest'
+import type { Mocks } from '~/mocks/utils'
+import { initKeaTests } from '~/test/init'
+import { AnyPropertyFilter, FeatureFlagType, PropertyFilterType, PropertyOperator } from '~/types'
+
+import { FeatureFlagDeletedCohortBanner } from './FeatureFlagDeletedCohortBanner'
+
+jest.mock('posthog-js')
+
+const FLAG_ID = 1
+const EDIT_SELECTOR = '[data-attr="feature-flag-deleted-cohort-banner-edit"]'
+
+function cohortProperty(value: number | string, overrides: Record<string, unknown> = {}): AnyPropertyFilter {
+ return {
+ key: 'id',
+ type: PropertyFilterType.Cohort,
+ operator: PropertyOperator.In,
+ value,
+ cohort_name: 'Frequent buyers',
+ ...overrides,
+ } as AnyPropertyFilter
+}
+
+function buildFlag(
+ overrides: Partial<FeatureFlagType> = {},
+ cohortOverrides: Record<string, unknown> = {}
+): FeatureFlagType {
+ return {
+ ...NEW_FLAG,
+ id: FLAG_ID,
+ key: 'test-flag',
+ can_edit: true,
+ filters: {
+ groups: [
+ {
+ properties: [cohortProperty(5, { cohort_deleted: true, ...cohortOverrides })],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ ...overrides,
+ }
+}
+
+describe('FeatureFlagDeletedCohortBanner', () => {
+ function endpointMocks(flag: FeatureFlagType): Mocks {
+ return {
+ get: {
+ [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${FLAG_ID}/`]: () => [200, flag],
+ [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${FLAG_ID}/status`]: () => [
+ 200,
+ { status: 'active', reason: '', reason_states_rollout: false },
+ ],
+ [`/api/projects/${MOCK_DEFAULT_PROJECT.id}/feature_flags/${FLAG_ID}/dependent_flags/`]: () => [200, []],
+ },
+ }
+ }
+
+ async function renderBanner(): Promise<ReturnType<typeof featureFlagLogic.build>> {
+ const logicProps = { id: FLAG_ID }
+ const logic = featureFlagLogic(logicProps)
+ logic.mount()
+ render(
+ <Provider>
+ <BindLogic logic={featureFlagLogic} props={logicProps}>
+ <FeatureFlagDeletedCohortBanner />
+ </BindLogic>
+ </Provider>
+ )
+ await act(async () => {
+ await expectLogic(logic).toFinishAllListeners()
+ })
+ return logic
+ }
+
+ beforeEach(() => {
+ initKeaTests()
+ jest.mocked(posthog.capture).mockClear()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it.each([
+ {
+ state: 'an active flag',
+ flag: buildFlag({ active: true }),
+ says: /^Cohort 'Frequent buyers' was deleted\. The flag fails to evaluate for anyone who reaches a release condition that targets it\. Restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a disabled flag',
+ flag: buildFlag({ active: false }),
+ says: /You can't enable the flag until you restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'an archived flag',
+ flag: buildFlag({ active: false, archived: true }),
+ says: /You can't unarchive the flag until you restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a deleted flag',
+ flag: buildFlag({ active: true, deleted: true }),
+ says: /You can't restore the flag until you restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ // Restoring leaves the flag archived, so the flag API skips the cohort check until the flag is unarchived.
+ state: 'a deleted and archived flag',
+ flag: buildFlag({ active: false, deleted: true, archived: true }),
+ says: /You can't unarchive the flag until you restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a flag the user cannot edit',
+ flag: buildFlag({ active: true, can_edit: false }),
+ says: /Restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: false,
+ },
+ {
+ state: 'a flag whose deleted cohort has no name',
+ flag: buildFlag({ active: true }, { cohort_name: undefined }),
+ says: /^Cohort ID 5 was deleted\. .* Restore the cohort or update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a flag whose cohort no longer exists',
+ flag: buildFlag({ active: true }, { cohort_name: undefined, cohort_missing: true }),
+ says: /^Cohort ID 5 does not exist in this project\. The flag fails to evaluate for anyone who reaches a release condition that targets it\. Update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a deleted flag whose cohort no longer exists',
+ flag: buildFlag({ active: true, deleted: true }, { cohort_name: undefined, cohort_missing: true }),
+ says: /You can't restore the flag until you update the release conditions to remove it\.$/,
+ showsEdit: true,
+ },
+ {
+ state: 'a flag with two deleted cohorts where one no longer exists',
+ flag: buildFlag({
+ active: true,
+ filters: {
+ groups: [
+ {
+ properties: [
+ cohortProperty(5, { cohort_deleted: true }),
+ cohortProperty(6, {
+ cohort_deleted: true,
+ cohort_name: undefined,
+ cohort_missing: true,
+ }),
+ ],
+ rollout_percentage: 100,
+ },
+ ],
+ },
+ }),
+ says: /^Cohort 'Frequent buyers' was deleted\. Cohort ID 6 does not exist in this project\. .* Update the release conditions to remove them\.$/,
+ showsEdit: true,
+ },
+ ])('gives the next step for $state', async ({ flag, says, showsEdit }) => {
+ useMocks(endpointMocks(flag))
+ await renderBanner()
+
+ expect(screen.getByText(/^Cohorts? /)).toHaveTextContent(says)
+ expect(document.querySelectorAll(EDIT_SELECTOR).length > 0).toBe(showsEdit)
+ })
+
+ it('reports a flag with a deleted cohort once when the user starts editing it', async () => {
+ useMocks(endpointMocks(buildFlag({ active: true })))
+ const logic = await renderBanner()
+
+ await act(async () => {
+ fireEvent.click(document.querySelector(EDIT_SELECTOR)!)
+ await expectLogic(logic).toFinishAllListeners()
+ })
+
+ expect(logic.values.isEditingFlag).toBe(true)
+ expect(posthog.capture).toHaveBeenCalledWith('feature flag deleted cohort banner edit clicked')
+ const loadedCaptures = jest
+ .mocked(posthog.capture)
+ .mock.calls.filter(([event]) => event === 'feature flag with deleted cohort loaded')
+ expect(loadedCaptures).toHaveLength(1)
+ })
+
+ const deletedCohort = (value: number | string): AnyPropertyFilter => cohortProperty(value, { cohort_deleted: true })
+ const missingCohort = (value: number): AnyPropertyFilter =>
+ cohortProperty(value, { cohort_deleted: true, cohort_missing: true, cohort_name: undefined })
+
+ it.each([
+ {
+ name: 'one cohort stored as a number and as a string',
+ properties: [deletedCohort(5), deletedCohort('5')],
+ heading: 'This flag targets a deleted cohort',
+ },
+ {
+ name: 'two deleted cohorts',
+ properties: [deletedCohort(5), deletedCohort(6)],
+ heading: 'This flag targets deleted cohorts',
+ },
+ { name: 'a missing cohort', properties: [missingCohort(5)], heading: 'This flag targets a missing cohort' },
+ {
+ name: 'a deleted and a missing cohort',
+ properties: [deletedCohort(5), missingCohort(6)],
+ heading: 'This flag targets deleted and missing cohorts',
+ },
+ ])('gives the heading for $name', async ({ properties, heading }) => {
+ useMocks(
+ endpointMocks(
+ buildFlag({
+ filters: {
+ groups: properties.map((property) => ({ properties: [property], rollout_percentage: 100 })),
+ },
+ })
+ )
+ )
+ await renderBanner()
+
+ expect(screen.getByText(heading)).toBeInTheDocument()
+ })
+
+ it.each([
+ {
+ name: 'no condition targets a deleted cohort',
+ filters: { groups: [{ properties: [cohortProperty(5)], rollout_percentage: 100 }] },
+ },
+ {
+ name: 'the flag is in an unsupported config version',
+ filters: {
+ version: 3,
+ groups: [{ properties: [cohortProperty(5, { cohort_deleted: true })], rollout_percentage: 100 }],
+ } as unknown as FeatureFlagType['filters'],
+ },
+ ])('renders nothing when $name', async ({ filters }) => {
+ useMocks(endpointMocks(buildFlag({ filters })))
+ await renderBanner()
+
+ expect(screen.queryByText(/deleted cohort/)).not.toBeInTheDocument()
+ })
+})
diff --git a/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.tsx b/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.tsx
new file mode 100644
index 000000000000..f59f3d5529ab
--- /dev/null
+++ b/products/feature_flags/frontend/FeatureFlagDeletedCohortBanner.tsx
@@ -0,0 +1,81 @@
+import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
+
+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { capitalizeFirstLetter, humanList } from 'lib/utils/strings'
+import { featureFlagLogic } from 'scenes/feature-flags/featureFlagLogic'
+
+import { CohortPropertyFilter } from '~/types'
+
+import { cohortCanBeRestored, restoreChecksCohorts } from './deletedCohortFilters'
+
+function cohortName(property: CohortPropertyFilter): string {
+ return property.cohort_name ? `'${property.cohort_name}'` : `ID ${property.value}`
+}
+
+function describeCohorts(names: string[], singular: string, plural: string): string[] {
+ if (names.length === 0) {
+ return []
+ }
+ return [names.length === 1 ? `Cohort ${names[0]} ${singular}.` : `Cohorts ${humanList(names)} ${plural}.`]
+}
+
+/** Warns that release conditions target a cohort the flag evaluator cannot load, so the flag fails to evaluate. */
+export function FeatureFlagDeletedCohortBanner(): JSX.Element | null {
+ const { featureFlag, deletedCohortFilters } = useValues(featureFlagLogic)
+ const { editFeatureFlag } = useActions(featureFlagLogic)
+
+ if (!featureFlag.id || deletedCohortFilters.length === 0) {
+ return null
+ }
+
+ const deletedNames = deletedCohortFilters.filter(cohortCanBeRestored).map(cohortName)
+ const missingNames = deletedCohortFilters.filter((property) => !cohortCanBeRestored(property)).map(cohortName)
+ const single = deletedCohortFilters.length === 1
+ const them = single ? 'it' : 'them'
+ const theCohorts = single ? 'the cohort' : 'the cohorts'
+ const kinds = humanList([...(deletedNames.length ? ['deleted'] : []), ...(missingNames.length ? ['missing'] : [])])
+ const whatHappened = [
+ ...describeCohorts(deletedNames, 'was deleted', 'were deleted'),
+ ...describeCohorts(missingNames, 'does not exist in this project', 'do not exist in this project'),
+ ].join(' ')
+ const restorable = missingNames.length === 0
+ const removeThem = `update the release conditions to remove ${them}`
+ const fix = restorable ? `restore ${theCohorts} or ${removeThem}` : removeThem
+ // The flag API refuses to restore, unarchive or enable a flag while a condition targets a deleted cohort.
+ let consequence: string
+ if (restoreChecksCohorts(featureFlag)) {
+ consequence = `You can't restore the flag until you ${fix}.`
+ } else if (featureFlag.archived) {
+ consequence = `You can't unarchive the flag until you ${fix}.`
+ } else if (featureFlag.active) {
+ consequence = `The flag fails to evaluate for anyone who reaches a release condition that targets ${them}. ${capitalizeFirstLetter(fix)}.`
+ } else {
+ consequence = `You can't enable the flag until you ${fix}.`
+ }
+
+ return (
+ <LemonBanner type="warning">
+ <div className="flex flex-col gap-1">
+ <strong>{single ? `This flag targets a ${kinds} cohort` : `This flag targets ${kinds} cohorts`}</strong>
+ <span>{`${whatHappened} ${consequence}`}</span>
+ {featureFlag.can_edit && (
+ <div className="flex flex-wrap gap-2 mt-1">
+ <LemonButton
+ type="secondary"
+ size="small"
+ data-attr="feature-flag-deleted-cohort-banner-edit"
+ onClick={() => {
+ posthog.capture('feature flag deleted cohort banner edit clicked')
+ editFeatureFlag(true)
+ }}
+ >
+ Edit release conditions
+ </LemonButton>
+ </div>
+ )}
+ </div>
+ </LemonBanner>
+ )
+}
diff --git a/products/feature_flags/frontend/deletedCohortFilters.test.ts b/products/feature_flags/frontend/deletedCohortFilters.test.ts
new file mode 100644
index 000000000000..ecd9f84985fb
--- /dev/null
+++ b/products/feature_flags/frontend/deletedCohortFilters.test.ts
@@ -0,0 +1,62 @@
+import {
+ CohortPropertyFilter,
+ FeatureFlagFilters,
+ FeatureFlagType,
+ PropertyFilterType,
+ PropertyOperator,
+} from '~/types'
+
+import { deletedCohortDisabledReason, deletedCohortFilters, withCohortAnnotationsFrom } from './deletedCohortFilters'
+
+function deletedCohort(value: number, overrides: Partial<CohortPropertyFilter> = {}): CohortPropertyFilter {
+ return {
+ key: 'id',
+ type: PropertyFilterType.Cohort,
+ operator: PropertyOperator.In,
+ value,
+ cohort_deleted: true,
+ ...overrides,
+ }
+}
+
+// A legacy flag can store a group whose `properties` is not a list. The flag API skips such a group.
+const malformedFilters = {
+ groups: [{ properties: {}, rollout_percentage: 100 }, null, { properties: [null, deletedCohort(5)] }],
+} as unknown as FeatureFlagFilters
+
+describe('deletedCohortFilters', () => {
+ it.each([
+ { name: 'no condition targets a deleted cohort', filters: [], reason: undefined },
+ {
+ name: 'every deleted cohort can be restored',
+ filters: [deletedCohort(5)],
+ reason: 'A release condition targets a deleted cohort. Restore the cohort or update the release conditions first.',
+ },
+ {
+ name: 'one deleted cohort no longer exists',
+ filters: [deletedCohort(5), deletedCohort(6, { cohort_missing: true })],
+ reason: 'A release condition targets a cohort that does not exist in this project. Update the release conditions first.',
+ },
+ ])('explains the disabled control when $name', ({ filters, reason }) => {
+ expect(deletedCohortDisabledReason(filters)).toBe(reason)
+ })
+
+ it('finds the deleted cohort in a flag whose other groups are malformed', () => {
+ expect(deletedCohortFilters(malformedFilters)).toEqual([deletedCohort(5)])
+ })
+
+ it('copies cohort annotations into a flag whose other groups are malformed', () => {
+ const flag = { filters: malformedFilters } as FeatureFlagType
+ const source = {
+ filters: { groups: [{ properties: [deletedCohort(5, { cohort_name: 'Frequent buyers' })] }] },
+ } as FeatureFlagType
+
+ expect(withCohortAnnotationsFrom(flag, source).filters).toEqual({
+ groups: [
+ { properties: {}, rollout_percentage: 100 },
+ null,
+ { properties: [null, deletedCohort(5, { cohort_name: 'Frequent buyers' })] },
+ ],
+ })
+ })
+})
diff --git a/products/feature_flags/frontend/deletedCohortFilters.ts b/products/feature_flags/frontend/deletedCohortFilters.ts
new file mode 100644
index 000000000000..3fbd59f9f5dd
--- /dev/null
+++ b/products/feature_flags/frontend/deletedCohortFilters.ts
@@ -0,0 +1,109 @@
+import { COHORT_ANNOTATION_KEYS, isCohortPropertyFilter } from 'lib/components/PropertyFilters/utils'
+
+import {
+ AnyPropertyFilter,
+ CohortPropertyFilter,
+ FeatureFlagConfig,
+ FeatureFlagFilters,
+ FeatureFlagType,
+} from '~/types'
+
+import { isV1FeatureFlagConfig } from './featureFlagConfigFormat'
+
+/** Whether a condition's deleted cohort still exists, so that its page can restore it. */
+export function cohortCanBeRestored(property: CohortPropertyFilter): boolean {
+ return !property.cohort_missing
+}
+
+/**
+ * Whether restoring the flag runs the flag API's cohort check.
+ * A restore that leaves the flag archived skips the check, because unarchiving the flag runs it.
+ */
+export function restoreChecksCohorts(flag: Pick<FeatureFlagType, 'deleted' | 'archived'>): boolean {
+ return !!flag.deleted && !flag.archived
+}
+
+/**
+ * Why a control that enables, unarchives or restores the flag is disabled, given the flag's `deletedCohortFilters`.
+ * The flag API refuses those writes while a release condition targets a deleted cohort.
+ * Returns undefined when `conditions` is empty, so the control stays enabled.
+ */
+export function deletedCohortDisabledReason(conditions: CohortPropertyFilter[]): string | undefined {
+ if (conditions.length === 0) {
+ return undefined
+ }
+ const theCohorts = conditions.length === 1 ? 'the cohort' : 'the cohorts'
+ return conditions.every(cohortCanBeRestored)
+ ? `A release condition targets a deleted cohort. Restore ${theCohorts} or update the release conditions first.`
+ : 'A release condition targets a cohort that does not exist in this project. Update the release conditions first.'
+}
+
+/**
+ * The properties in a v1 config's release conditions.
+ * It skips a group whose `properties` is not a list, as the flag API does.
+ * One malformed flag therefore cannot break the flag list, which reads every flag.
+ */
+function releaseConditionProperties(filters: FeatureFlagFilters): (AnyPropertyFilter | null)[] {
+ const groups: unknown = filters.groups
+ if (!Array.isArray(groups)) {
+ return []
+ }
+ return groups.flatMap((group) => (Array.isArray(group?.properties) ? group.properties : []))
+}
+
+/** The release conditions that target a deleted or missing cohort, one per cohort. */
+export function deletedCohortFilters(filters: FeatureFlagConfig | null | undefined): CohortPropertyFilter[] {
+ if (!filters || !isV1FeatureFlagConfig(filters)) {
+ return []
+ }
+ // Stored cohort values can be numbers or numeric strings. `5` and `"5"` name the same cohort.
+ const byCohort = new Map<string, CohortPropertyFilter>()
+ for (const property of releaseConditionProperties(filters)) {
+ if (isCohortPropertyFilter(property) && property.cohort_deleted && !byCohort.has(String(property.value))) {
+ byCohort.set(String(property.value), property)
+ }
+ }
+ return [...byCohort.values()]
+}
+
+/** Copies `source`'s cohort annotations onto `flag`'s cohort conditions that name the same cohort. */
+export function withCohortAnnotationsFrom(flag: FeatureFlagType, source: FeatureFlagType): FeatureFlagType {
+ if (!isV1FeatureFlagConfig(flag.filters) || !isV1FeatureFlagConfig(source.filters)) {
+ return flag
+ }
+ const annotatedByCohort = new Map<string, CohortPropertyFilter>()
+ for (const property of releaseConditionProperties(source.filters)) {
+ if (isCohortPropertyFilter(property)) {
+ annotatedByCohort.set(String(property.value), property)
+ }
+ }
+ const reannotate = (property: AnyPropertyFilter): AnyPropertyFilter => {
+ const annotated = isCohortPropertyFilter(property) ? annotatedByCohort.get(String(property.value)) : undefined
+ if (!annotated) {
+ return property
+ }
+ const updated: Record<string, unknown> = { ...property }
+ for (const key of COHORT_ANNOTATION_KEYS) {
+ if (annotated[key] === undefined) {
+ delete updated[key]
+ } else {
+ updated[key] = annotated[key]
+ }
+ }
+ return updated as AnyPropertyFilter
+ }
+ const groups: unknown = flag.filters.groups
+ if (!Array.isArray(groups)) {
+ return flag
+ }
+ return {
+ ...flag,
+ filters: {
+ ...flag.filters,
+ // A malformed group keeps its stored shape, so that saving the flag writes it back unchanged.
+ groups: groups.map((group) =>
+ Array.isArray(group?.properties) ? { ...group, properties: group.properties.map(reannotate) } : group
+ ),
+ },
+ }
+}
diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.ts
index ed87c6c001e9..9badadc628a6 100644
--- a/products/feature_flags/frontend/generated/api.schemas.ts
+++ b/products/feature_flags/frontend/generated/api.schemas.ts
@@ -1024,6 +1024,10 @@ export interface FeatureFlagFilterPropertyCohortInSchemaApi {
operator: FeatureFlagFilterPropertyCohortInSchemaOperatorEnumApi
/** Cohort comparison value (single or list, depending on usage). */
value: unknown
+ /** Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write. */
+ cohort_deleted?: boolean
+ /** Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write. */
+ cohort_missing?: boolean
}
/**
diff --git a/products/feature_flags/frontend/generated/api.zod.ts b/products/feature_flags/frontend/generated/api.zod.ts
index 07ad8f69fc4c..40c339e10b01 100644
--- a/products/feature_flags/frontend/generated/api.zod.ts
+++ b/products/feature_flags/frontend/generated/api.zod.ts
@@ -446,6 +446,18 @@ export const FeatureFlagsCreateBody = /* @__PURE__ */ zod.object({
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -882,6 +894,18 @@ export const FeatureFlagsPartialUpdateBody = /* @__PURE__ */ zod.object({
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
diff --git a/products/logs/frontend/generated/api.schemas.ts b/products/logs/frontend/generated/api.schemas.ts
index 56db74a0d251..78b41a4bf036 100644
--- a/products/logs/frontend/generated/api.schemas.ts
+++ b/products/logs/frontend/generated/api.schemas.ts
@@ -165,6 +165,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/marketing_analytics/frontend/generated/api.schemas.ts b/products/marketing_analytics/frontend/generated/api.schemas.ts
index 9dd378ef1386..051e83f51d90 100644
--- a/products/marketing_analytics/frontend/generated/api.schemas.ts
+++ b/products/marketing_analytics/frontend/generated/api.schemas.ts
@@ -225,6 +225,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/persons/frontend/generated/api.schemas.ts b/products/persons/frontend/generated/api.schemas.ts
index bfb87ed27258..2a8fcdb7a1a5 100644
--- a/products/persons/frontend/generated/api.schemas.ts
+++ b/products/persons/frontend/generated/api.schemas.ts
@@ -890,6 +890,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index e6ddda0b1be3..39e40f8b75fb 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -367,6 +367,10 @@ export interface SessionPropertyFilterApi {
}
export interface CohortPropertyFilterApi {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null
cohort_name?: string | null
key?: 'id'
label?: string | null
diff --git a/products/surveys/frontend/generated/api.schemas.ts b/products/surveys/frontend/generated/api.schemas.ts
index 4c1d498a49e6..6a321d2db1d2 100644
--- a/products/surveys/frontend/generated/api.schemas.ts
+++ b/products/surveys/frontend/generated/api.schemas.ts
@@ -807,6 +807,10 @@ export interface FeatureFlagFilterPropertyCohortInSchemaApi {
operator: FeatureFlagFilterPropertyCohortInSchemaOperatorEnumApi
/** Cohort comparison value (single or list, depending on usage). */
value: unknown
+ /** Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write. */
+ cohort_deleted?: boolean
+ /** Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write. */
+ cohort_missing?: boolean
}
/**
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index d88ef8268b00..77938f14a06b 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -3533,6 +3533,10 @@ export namespace Schemas {
}
export interface CohortPropertyFilter {
+ /** Set by the feature flag API when the cohort is deleted or does not exist. */
+ cohort_deleted?: boolean | null;
+ /** Set by the feature flag API when the cohort does not exist, so it cannot be restored. */
+ cohort_missing?: boolean | null;
cohort_name?: string | null;
key?: 'id';
label?: string | null;
@@ -44236,6 +44240,10 @@ export namespace Schemas {
operator: FeatureFlagFilterPropertyCohortInSchemaOperatorEnum;
/** Cohort comparison value (single or list, depending on usage). */
value: unknown;
+ /** Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write. */
+ cohort_deleted?: boolean;
+ /** Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write. */
+ cohort_missing?: boolean;
}
/**
diff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.ts
index 118c352b1031..5b909a313c5f 100644
--- a/services/mcp/src/generated/core/api.ts
+++ b/services/mcp/src/generated/core/api.ts
@@ -1149,6 +1149,18 @@ export const OrganizationsProjectsCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -1786,6 +1798,18 @@ export const OrganizationsProjectsCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -2426,6 +2450,18 @@ export const OrganizationsProjectsCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -3926,6 +3962,18 @@ export const OrganizationsProjectsPartialUpdateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -4563,6 +4611,18 @@ export const OrganizationsProjectsPartialUpdateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -5203,6 +5263,18 @@ export const OrganizationsProjectsPartialUpdateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/endpoints/api.ts b/services/mcp/src/generated/endpoints/api.ts
index 7b24a4bef50b..1870f9137db8 100644
--- a/services/mcp/src/generated/endpoints/api.ts
+++ b/services/mcp/src/generated/endpoints/api.ts
@@ -899,6 +899,18 @@ export const EndpointsRunCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/error_tracking/api.ts b/services/mcp/src/generated/error_tracking/api.ts
index be665d6d64cd..1f5541f8c37c 100644
--- a/services/mcp/src/generated/error_tracking/api.ts
+++ b/services/mcp/src/generated/error_tracking/api.ts
@@ -421,6 +421,16 @@ export const ErrorTrackingAssignmentRulesCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -2050,6 +2060,16 @@ export const ErrorTrackingBypassRulesCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -3650,6 +3670,16 @@ export const ErrorTrackingBypassRulesUpdateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -5282,6 +5312,16 @@ export const ErrorTrackingGroupingRulesCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -6904,6 +6944,16 @@ export const ErrorTrackingGroupingRulesUpdateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -9169,6 +9219,16 @@ export const ErrorTrackingSeverityRulesCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -10777,6 +10837,16 @@ export const ErrorTrackingSeverityRulesUpdateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -12398,6 +12468,16 @@ export const ErrorTrackingSuppressionRulesCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -14009,6 +14089,16 @@ export const ErrorTrackingSuppressionRulesUpdateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.'),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/experiments/api.ts b/services/mcp/src/generated/experiments/api.ts
index 9b28d245aabc..a6db2dbf5b68 100644
--- a/services/mcp/src/generated/experiments/api.ts
+++ b/services/mcp/src/generated/experiments/api.ts
@@ -262,6 +262,18 @@ export const ExperimentHoldoutsCreateBody = () => zod
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -563,6 +575,18 @@ export const ExperimentHoldoutsPartialUpdateBody = () => zod
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -1587,6 +1611,18 @@ export const ExperimentsCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -3318,6 +3354,18 @@ export const ExperimentsCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -7778,6 +7826,18 @@ export const ExperimentsPartialUpdateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -9509,6 +9569,18 @@ export const ExperimentsPartialUpdateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -13948,6 +14020,18 @@ export const ExperimentsDuplicateCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -15679,6 +15763,18 @@ export const ExperimentsDuplicateCreateBody = () => zod
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/feature_flags/api.ts b/services/mcp/src/generated/feature_flags/api.ts
index 8c4c41d45543..b910ded60064 100644
--- a/services/mcp/src/generated/feature_flags/api.ts
+++ b/services/mcp/src/generated/feature_flags/api.ts
@@ -368,6 +368,18 @@ export const FeatureFlagsCreateBody = () => zod.object({
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
@@ -750,6 +762,18 @@ export const FeatureFlagsPartialUpdateBody = () => zod.object({
value: zod
.unknown()
.describe('Cohort comparison value (single or list, depending on usage).'),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod.string().describe('Property key used in this feature flag condition.'),
diff --git a/services/mcp/src/generated/logs/api.ts b/services/mcp/src/generated/logs/api.ts
index 5a741eaf6683..25e7f1169703 100644
--- a/services/mcp/src/generated/logs/api.ts
+++ b/services/mcp/src/generated/logs/api.ts
@@ -473,6 +473,18 @@ export const LogsAlertsCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -2325,6 +2337,18 @@ export const LogsAlertsPartialUpdateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -4252,6 +4276,18 @@ export const LogsAlertsSimulateCreateBody = () => zod.object({
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/marketing_analytics/api.ts b/services/mcp/src/generated/marketing_analytics/api.ts
index a89ecf88f4c2..cafada6c711f 100644
--- a/services/mcp/src/generated/marketing_analytics/api.ts
+++ b/services/mcp/src/generated/marketing_analytics/api.ts
@@ -625,6 +625,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -2506,6 +2518,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -4173,6 +4197,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -6053,6 +6089,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -7722,6 +7770,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -9603,6 +9663,18 @@ export const MarketingAnalyticsConversionGoalsUpdatePartialUpdateBody = () => zo
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -11501,6 +11573,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -13374,6 +13458,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -15041,6 +15137,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -16910,6 +17018,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -18579,6 +18699,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
@@ -20449,6 +20581,18 @@ export const MarketingAnalyticsConversionGoalsCreateCreateBody = () => zod.objec
.optional(),
}),
zod.object({
+ cohort_deleted: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort is deleted or does not exist.'
+ ),
+ cohort_missing: zod
+ .union([zod.boolean(), zod.null()])
+ .optional()
+ .describe(
+ 'Set by the feature flag API when the cohort does not exist, so it cannot be restored.'
+ ),
cohort_name: zod.union([zod.string(), zod.null()]).optional(),
key: zod
.literal('id')
diff --git a/services/mcp/src/generated/surveys/api.ts b/services/mcp/src/generated/surveys/api.ts
index 3c619465bcc7..05b216ace3b7 100644
--- a/services/mcp/src/generated/surveys/api.ts
+++ b/services/mcp/src/generated/surveys/api.ts
@@ -387,6 +387,18 @@ export const SurveysCreateBody = () => zod.object({
.describe(
'Cohort comparison value (single or list, depending on usage).'
),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod
@@ -1629,6 +1641,18 @@ export const SurveysPartialUpdateBody = () => zod.object({
.describe(
'Cohort comparison value (single or list, depending on usage).'
),
+ cohort_deleted: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.'
+ ),
+ cohort_missing: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.'
+ ),
}),
zod.object({
key: zod
diff --git a/services/mcp/src/tools/generated/web_analytics.ts b/services/mcp/src/tools/generated/web_analytics.ts
index 88bb22b93556..ca4137460115 100644
--- a/services/mcp/src/tools/generated/web_analytics.ts
+++ b/services/mcp/src/tools/generated/web_analytics.ts
@@ -471,6 +471,14 @@ const SessionPropertyFilter = z.object({
})
const CohortPropertyFilter = z.object({
+ cohort_deleted: z.coerce
+ .boolean()
+ .describe('Set by the feature flag API when the cohort is deleted or does not exist.')
+ .optional(),
+ cohort_missing: z.coerce
+ .boolean()
+ .describe('Set by the feature flag API when the cohort does not exist, so it cannot be restored.')
+ .optional(),
cohort_name: z.string().optional(),
key: z.literal('id').default('id'),
label: z.string().optional(),
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json
index 3e8d23f5e73e..161aa000e1c9 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/create-feature-flag.json
@@ -356,6 +356,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-assignment-rules-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-assignment-rules-create.json
index e92cf2987ec2..1a436d73b0c2 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-assignment-rules-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-assignment-rules-create.json
@@ -649,6 +649,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-create.json
index 875365cd9734..ba4306f1317b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-create.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-update.json
index 384f9a5419fa..d52ff50eebea 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-bypass-rules-update.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-create.json
index 4407a6b17a12..24a2d7f03373 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-create.json
@@ -667,6 +667,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-update.json
index d33f85534185..a75b46e2ec60 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-grouping-rules-update.json
@@ -627,6 +627,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-create.json
index bc2f058cce19..852908eec6ce 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-create.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-update.json
index 5a4d3e065fe8..bb573de30469 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-severity-rules-update.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-create.json
index 79f2861617ca..ba96d9ff2f4a 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-create.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-update.json
index 92918995b976..2dd790cf6062 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-suppression-rules-update.json
@@ -626,6 +626,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
index 224076d29490..7f061d890542 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-create.json
@@ -678,6 +678,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
@@ -3531,6 +3553,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-create.json
index c8cef9ae48ef..38f8800bb643 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-create.json
@@ -290,6 +290,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-partial-update.json
index 2f55da419766..6468b3c195a0 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-holdouts-partial-update.json
@@ -290,6 +290,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
index 7b1add3015b9..4aebc3960828 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/experiment-update.json
@@ -720,6 +720,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
@@ -3573,6 +3595,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-create.json
index 69883ef1fe2b..6c529adc3c2b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-create.json
@@ -662,6 +662,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-partial-update.json
index e91f49d10f0a..6a670be27a49 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-partial-update.json
@@ -658,6 +658,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-simulate-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-simulate-create.json
index ec9d35c20ea8..a84e3ad7a1aa 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-simulate-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-alerts-simulate-create.json
@@ -668,6 +668,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
index ec7c27758d91..a1fb78b71248 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/project-settings-update.json
@@ -1216,6 +1216,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
@@ -2239,6 +2261,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
@@ -3279,6 +3323,28 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist."
+ },
+ "cohort_missing": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored."
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-overview.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-overview.json
index 8cc90af68ce6..7abe5a3f74d6 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-overview.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-overview.json
@@ -326,6 +326,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
@@ -708,6 +716,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
@@ -1145,6 +1161,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-stats.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-stats.json
index 650cf047d3b2..69eccc4162aa 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-stats.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-web-stats.json
@@ -366,6 +366,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
@@ -748,6 +756,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
@@ -1212,6 +1228,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set by the feature flag API when the cohort is deleted or does not exist.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set by the feature flag API when the cohort does not exist, so it cannot be restored.",
+ "type": "boolean"
+ },
"cohort_name": {
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
index b3a8cb9a7f27..ad843698625e 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json
@@ -1494,6 +1494,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
index e137a17653b5..5c2d393805c5 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json
@@ -1525,6 +1525,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json
index 9b1b54f9dd06..a0a52bda37b8 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/update-feature-flag.json
@@ -360,6 +360,14 @@
},
{
"properties": {
+ "cohort_deleted": {
+ "description": "Set to true in responses when the cohort is deleted or does not exist. The flag cannot evaluate this condition. Ignored on write.",
+ "type": "boolean"
+ },
+ "cohort_missing": {
+ "description": "Set to true in responses when no cohort with this id exists in the project, so it cannot be restored. `cohort_deleted` is also true. Absent for a soft-deleted cohort. Ignored on write.",
+ "type": "boolean"
+ },
"cohort_name": {
"anyOf": [
{