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(conversations): gate support ai suggestions by organization flag (#130154)

Alex V739ff36959e1
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 47faeae9b3e3..44f20df5bc5c 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -480,7 +480,7 @@ export const FEATURE_FLAGS = {
PRODUCT_ANALYTICS_RETENTION_AGGREGATION: 'retention-aggregation', // owner: @anirudhpillai #team-product-analytics
PRODUCT_AUTONOMY: 'product-autonomy', // owner: #team-self-driving
PRODUCT_BUSINESS_KNOWLEDGE: 'product-business-knowledge', // owner: @veryayskiy #team-conversations
- PRODUCT_SUPPORT_AI_SUGGESTION: 'product-support-ai-suggestion', // owner: @veryayskiy #team-conversations
+ PRODUCT_SUPPORT_AI_SUGGESTION_ORGS: 'product-support-ai-suggestion-orgs', // owner: @veryayskiy #team-conversations
PRODUCT_SUPPORT_GITHUB_CHANNEL: 'product-support-github-channel', // owner: @veryayskiy #team-conversations
PRODUCT_SUPPORT_IMPORT_TICKETS: 'product-support-import-tickets', // owner: @veryayskiy #team-conversations
PRODUCT_SUPPORT_REPLY_FILE_ATTACHMENTS: 'support-reply-file-attachments', // owner: #team-conversations, attach any file type to in-app ticket replies
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index fdee5781cf7c..2f167f381b60 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -1686,7 +1686,7 @@ export const SETTINGS_MAP: SettingSection[] = [
description:
'Automatically generate AI-powered reply suggestions grounded in your business knowledge sources.',
component: <AISection />,
- flag: 'PRODUCT_SUPPORT_AI_SUGGESTION',
+ flag: 'PRODUCT_SUPPORT_AI_SUGGESTION_ORGS',
allowForTeam: (t) => !!t?.conversations_enabled,
keywords: ['ai', 'agent', 'suggestion', 'auto', 'reply', 'support', 'conversation', 'beta'],
},
diff --git a/products/conversations/backend/temporal/coordinator.py b/products/conversations/backend/temporal/coordinator.py
index 4a21f5b4df93..ffbc8622c28c 100644
--- a/products/conversations/backend/temporal/coordinator.py
+++ b/products/conversations/backend/temporal/coordinator.py
@@ -54,7 +54,7 @@ TICKET_LOOKBACK_MINUTES = 5
MAX_TICKETS_PER_TEAM_PER_RUN = 10
MAX_TICKETS_PER_RUN = 50
-MASTER_FLAG = "product-support-ai-suggestion"
+MASTER_FLAG = "product-support-ai-suggestion-orgs"
# Minimum number of READY BK sources required before the coordinator will draft replies.
# Set to 0 locally to skip the BK readiness check entirely.
@@ -110,19 +110,16 @@ class CollectEligibleTicketsOutput:
def _is_master_flag_enabled(team: Team) -> bool:
- # The flag is targeted by project group; release conditions can match on the project's `uuid`,
- # so it must be in group_properties — the headless worker only sends what's listed here (unlike
- # posthog-js, which auto-attaches full group properties). Without it a uuid filter never matches.
+ # The flag is targeted by organization group, the same as `product-business-knowledge`. The headless
+ # worker only sends the group properties listed here (unlike posthog-js, which auto-attaches full
+ # group properties), so a release condition on any other organization property never matches.
try:
return bool(
posthoganalytics.feature_enabled(
MASTER_FLAG,
- str(team.uuid),
- groups={"organization": str(team.organization_id), "project": str(team.id)},
- group_properties={
- "organization": {"id": str(team.organization_id)},
- "project": {"id": str(team.id), "uuid": str(team.uuid)},
- },
+ str(team.organization_id),
+ groups={"organization": str(team.organization_id)},
+ group_properties={"organization": {"id": str(team.organization_id)}},
only_evaluate_locally=False,
send_feature_flag_events=False,
)
@@ -153,10 +150,15 @@ def _collect_eligible(lookback_minutes: int = TICKET_LOOKBACK_MINUTES) -> list[E
candidates: list[tuple[int, str, datetime, bool, int]] = []
untriaged_ticket_ids: set[str] = set()
skipped_ticket_ids_by_result: dict[str, list[str]] = {SKIPPED_TEAM_REPLIED: [], SKIPPED_CHANNEL_EXCLUDED: []}
+ # The flag is org-keyed, so evaluate it once per org per scan instead of once per ticket.
+ master_flag_by_org: dict[str, bool] = {}
for ticket in recent_tickets:
team = ticket.team
- if not _is_master_flag_enabled(team):
+ org_key = str(team.organization_id)
+ if org_key not in master_flag_by_org:
+ master_flag_by_org[org_key] = _is_master_flag_enabled(team)
+ if not master_flag_by_org[org_key]:
continue
settings_dict = team.conversations_settings or {}
diff --git a/products/conversations/backend/temporal/tests/test_coordinator.py b/products/conversations/backend/temporal/tests/test_coordinator.py
index 95b559dd0964..3a2fa49d8992 100644
--- a/products/conversations/backend/temporal/tests/test_coordinator.py
+++ b/products/conversations/backend/temporal/tests/test_coordinator.py
@@ -73,24 +73,16 @@ def _make_ticket(
class TestMasterFlagEnabled:
@patch(f"{COORD_MODULE}.posthoganalytics.feature_enabled", return_value=True)
- def test_evaluates_flag_with_team_uuid_and_groups(self, mock_feature_enabled):
+ def test_evaluates_flag_keyed_on_organization(self, mock_feature_enabled):
team = MagicMock()
- team.id = 2
- team.uuid = TEST_TEAM_UUID
team.organization_id = TEST_ORG_UUID
assert _is_master_flag_enabled(team) is True
mock_feature_enabled.assert_called_once_with(
- "product-support-ai-suggestion",
- str(TEST_TEAM_UUID),
- groups={
- "organization": str(TEST_ORG_UUID),
- "project": "2",
- },
- group_properties={
- "organization": {"id": str(TEST_ORG_UUID)},
- "project": {"id": "2", "uuid": str(TEST_TEAM_UUID)},
- },
+ "product-support-ai-suggestion-orgs",
+ str(TEST_ORG_UUID),
+ groups={"organization": str(TEST_ORG_UUID)},
+ group_properties={"organization": {"id": str(TEST_ORG_UUID)}},
only_evaluate_locally=False,
send_feature_flag_events=False,
)
@@ -177,6 +169,25 @@ class TestCollectEligible:
assert result[0].team_id == team.id
assert result[0].ticket_id == ticket_id
+ @patch(f"{COORD_MODULE}.has_ready_sources", return_value=True)
+ @patch(f"{COORD_MODULE}.Comment")
+ @patch(f"{COORD_MODULE}.Ticket")
+ @patch(f"{COORD_MODULE}._is_master_flag_enabled", return_value=True)
+ def test_master_flag_evaluated_once_per_org(
+ self,
+ mock_master_flag,
+ mock_ticket_model,
+ mock_comment_model,
+ mock_has_ready,
+ ):
+ tickets = [_make_ticket(team_id=team_id)[0] for team_id in (1, 1, 2)]
+ mock_ticket_model.objects.filter.return_value.select_related.return_value = tickets
+ mock_comment_model.objects.filter.return_value.values_list.return_value = []
+
+ result = _collect_eligible()
+ assert len(result) == 3
+ mock_master_flag.assert_called_once()
+
@parameterized.expand(
[
("channel_in_allowed_list", ["widget"], "widget"),