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.

chore(slack_app): retire the project-routing flag and drained patches (#103651)

Vojta Bartoš3d8156236fcd
diff --git a/posthog/temporal/ai/slack_app/activities/classifiers.py b/posthog/temporal/ai/slack_app/activities/classifiers.py
index dd712a18ee3d..6f9d122042c8 100644
--- a/posthog/temporal/ai/slack_app/activities/classifiers.py
+++ b/posthog/temporal/ai/slack_app/activities/classifiers.py
@@ -26,7 +26,6 @@ from products.slack_app.backend.facade.run_preferences import (
find_model_choice,
group_by_runtime,
)
-from products.slack_app.backend.feature_flags import is_slack_app_project_routing_enabled
from products.slack_app.backend.models import SlackThreadTaskMapping
from products.slack_app.backend.prompt_templates import PromptTemplates
from products.slack_app.backend.services.integration_resolver import format_project_candidate_list, routable_projects
@@ -645,7 +644,7 @@ def classify_slack_app_project_route_activity(input: SlackAppProjectRouteInput)
if not input.event_text.strip():
return None
# Cheapest gate first, and the one that answers most workspaces. Everything below is
- # two queries and a blocking flag call, and a workspace connected to one project has
+ # two queries and an access scan, and a workspace connected to one project has
# nothing to route between however they come out.
if Integration.objects.filter(kind="slack", integration_id=input.slack_team_id).count() < 2:
return None
@@ -658,8 +657,6 @@ def classify_slack_app_project_route_activity(input: SlackAppProjectRouteInput)
user = User.objects.filter(id=input.user_id).first()
if user is None:
return None
- if not is_slack_app_project_routing_enabled(integration, distinct_id=user.distinct_id):
- return None
projects = routable_projects(
slack_team_id=input.slack_team_id,
diff --git a/posthog/temporal/ai/slack_app/posthog_code_slack_mention.py b/posthog/temporal/ai/slack_app/posthog_code_slack_mention.py
index 4861296e24b7..2b97479e1485 100644
--- a/posthog/temporal/ai/slack_app/posthog_code_slack_mention.py
+++ b/posthog/temporal/ai/slack_app/posthog_code_slack_mention.py
@@ -33,18 +33,14 @@ from posthog.temporal.common.base import PostHogWorkflow
POSTHOG_CODE_SLACK_MENTION_TIMEOUT_SECONDS = 10 * 60
POSTHOG_CODE_SLACK_PICKER_TIMEOUT_MINUTES = 15
-# Temporal patch IDs — arbitrary strings recorded in workflow history. The pre-patch
-# histories behind the older ones have drained: this workflow's longest wait is the
-# 15-minute repo picker, and it is bounded at an hour as a child of the queue workflow.
-# Their gates are gone and only `deprecate_patch` remains, keeping the recorded marker
-# compatible for executions in flight across the deploy that removes them. Standard
-# two-step Temporal patch lifecycle: those calls come out once the histories that
-# recorded a plain marker have drained in turn. The younger ones stay full
-# `workflow.patched` branches until they drain too — grep a name to see which it is.
-_PATCH_ID_FILE_ONLY_FOLLOWUP_BYPASS = "slack-file-only-followup-bypass-v1"
+# Temporal patch IDs — arbitrary strings recorded in workflow history. Every gate below
+# has drained: this workflow's longest wait is the 15-minute repo picker, and it is
+# bounded at an hour as a child of the queue workflow, so the pre-patch histories are
+# gone within hours of a deploy. Each branch is gone and only `deprecate_patch` remains,
+# keeping the recorded marker compatible for executions in flight across the deploy that
+# removes the branch. Standard two-step Temporal patch lifecycle: these calls come out in
+# turn, once the histories that recorded a plain marker have drained as well.
_PATCH_ID_FOLLOWUP_MODEL_CLASSIFIER = "slack-app-followup-model-classifier-v1"
-_PATCH_ID_MODEL_CLASSIFIER = "slack-app-model-classifier-v1"
-_PATCH_ID_NO_PERSONAL_GITHUB_GATE = "slack-no-personal-github-gate-v1"
_PATCH_ID_PROJECT_ROUTE_CLASSIFIER = "slack-app-project-route-classifier-v1"
_PATCH_ID_PROJECT_ROUTE_QUOTA = "slack-app-project-route-quota-v1"
_PATCH_ID_UNTAGGED_FOLLOWUP_CONFIRMATION = "slack-untagged-followup-confirmation-v1"
@@ -111,32 +107,25 @@ class PostHogCodeSlackMentionWorkflow(PostHogWorkflow):
event_files = event.get("files")
event_has_files = isinstance(event_files, list) and len(event_files) > 0
file_only_followup = event_has_files and not (event.get("text") or "").strip()
- if inputs.untagged_followup and not inputs.untagged_followup_confirmed:
- if file_only_followup:
- # The gate this replaces was only ever reached behind both
- # flags, so only these histories carry the marker.
- workflow.deprecate_patch(_PATCH_ID_FILE_ONLY_FOLLOWUP_BYPASS)
- else:
- should_forward = await _execute_posthog_code_activity(
- classify_untagged_followup_activity,
- inputs,
- channel,
- thread_ts,
- slack_user_id,
- event.get("text", ""),
- )
- if not should_forward:
- return
+ unconfirmed_followup = inputs.untagged_followup and not inputs.untagged_followup_confirmed
+ if unconfirmed_followup and not file_only_followup:
+ should_forward = await _execute_posthog_code_activity(
+ classify_untagged_followup_activity,
+ inputs,
+ channel,
+ thread_ts,
+ slack_user_id,
+ event.get("text", ""),
+ )
+ if not should_forward:
+ return
# The reply is agent-directed. If the thread creator asked to be consulted
# about other people's replies, this is the moment to ask: the prompt now
# only interrupts someone over a message that would otherwise start work.
# A confirmed run skips it — the answer is what re-dispatched this.
- if (
- inputs.untagged_followup
- and not inputs.untagged_followup_confirmed
- and workflow.patched(_PATCH_ID_UNTAGGED_FOLLOWUP_CONFIRMATION)
- ):
+ if unconfirmed_followup:
+ workflow.deprecate_patch(_PATCH_ID_UNTAGGED_FOLLOWUP_CONFIRMATION)
awaiting_confirmation = await _execute_posthog_code_activity(
request_untagged_followup_confirmation_activity,
inputs,
@@ -152,43 +141,27 @@ class PostHogCodeSlackMentionWorkflow(PostHogWorkflow):
# split because the mapping lookup that tells the two apart lives inside the
# follow-up activity: one call here serves whichever path the message takes,
# and recording the choice in history once stops a retry of either activity
- # from landing on a different model than the first attempt announced. The
- # feature flag is checked inside the activity — branching the workflow on a
- # flag would be non-deterministic on replay.
- model_override: SlackAppModelOverride | None = None
- classified_before_split = workflow.patched(_PATCH_ID_FOLLOWUP_MODEL_CLASSIFIER)
- if classified_before_split:
- model_override = await _execute_posthog_code_activity(
- classify_slack_app_model_override_activity,
- SlackAppModelOverrideInput(
- integration_id=inputs.integration_id,
- slack_team_id=inputs.slack_team_id,
- event_text=event.get("text", ""),
- ),
- )
+ # from landing on a different model than the first attempt announced.
+ workflow.deprecate_patch(_PATCH_ID_FOLLOWUP_MODEL_CLASSIFIER)
+ model_override: SlackAppModelOverride | None = await _execute_posthog_code_activity(
+ classify_slack_app_model_override_activity,
+ SlackAppModelOverrideInput(
+ integration_id=inputs.integration_id,
+ slack_team_id=inputs.slack_team_id,
+ event_text=event.get("text", ""),
+ ),
+ )
- followup_handled = await _execute_posthog_code_activity(
- forward_posthog_code_followup_activity,
- inputs,
- channel,
- thread_ts,
- slack_user_id,
- event.get("text", ""),
- event.get("ts"),
- model_override,
- )
- else:
- # Pre-patch histories recorded this activity without the override, and
- # classified further down. Replaying them has to schedule the same call.
- followup_handled = await _execute_posthog_code_activity(
- forward_posthog_code_followup_activity,
- inputs,
- channel,
- thread_ts,
- slack_user_id,
- event.get("text", ""),
- event.get("ts"),
- )
+ followup_handled = await _execute_posthog_code_activity(
+ forward_posthog_code_followup_activity,
+ inputs,
+ channel,
+ thread_ts,
+ slack_user_id,
+ event.get("text", ""),
+ event.get("ts"),
+ model_override,
+ )
if followup_handled:
return
@@ -203,37 +176,34 @@ class PostHogCodeSlackMentionWorkflow(PostHogWorkflow):
# the forward activity found no task mapped to it. Only such a message may
# pick its own project, because a task, its mapping and its run all belong to
# one. Everything below reads the integration from `inputs`, so the switch
- # lands above the repo cascade. Eligibility and the flag are decided inside
- # the activity, since branching the workflow on a flag would break replay.
- if workflow.patched(_PATCH_ID_PROJECT_ROUTE_CLASSIFIER):
- project_route = await _execute_posthog_code_activity(
- classify_slack_app_project_route_activity,
- SlackAppProjectRouteInput(
- integration_id=inputs.integration_id,
- slack_team_id=inputs.slack_team_id,
- event_text=event.get("text", ""),
- user_id=inputs.user_id,
- slack_user_id=slack_user_id,
- ),
+ # lands above the repo cascade. Eligibility is decided inside the activity.
+ workflow.deprecate_patch(_PATCH_ID_PROJECT_ROUTE_CLASSIFIER)
+ project_route = await _execute_posthog_code_activity(
+ classify_slack_app_project_route_activity,
+ SlackAppProjectRouteInput(
+ integration_id=inputs.integration_id,
+ slack_team_id=inputs.slack_team_id,
+ event_text=event.get("text", ""),
+ user_id=inputs.user_id,
+ slack_user_id=slack_user_id,
+ ),
+ )
+ if project_route is not None:
+ inputs = replace(inputs, integration_id=project_route.integration_id)
+ # The gate at the top of the run checked the project routing had
+ # resolved, not the one the message named. Without this the run spends
+ # the thread fetch, the needs-repo classifier and possibly a discovery
+ # sandbox before task creation refuses on the same quota.
+ workflow.deprecate_patch(_PATCH_ID_PROJECT_ROUTE_QUOTA)
+ blocked = await _execute_posthog_code_activity(
+ enforce_posthog_code_billing_quota_activity,
+ inputs,
+ channel,
+ thread_ts,
+ slack_user_id,
)
- if project_route is not None:
- inputs = replace(inputs, integration_id=project_route.integration_id)
- # The gate at the top of the run checked the project routing had
- # resolved, not the one the message named. Without this the run
- # spends the thread fetch, the needs-repo classifier and possibly a
- # discovery sandbox before task creation refuses on the same quota.
- # Its own patch: a history that recorded the classifier marker above
- # would not have recorded this activity.
- if workflow.patched(_PATCH_ID_PROJECT_ROUTE_QUOTA):
- blocked = await _execute_posthog_code_activity(
- enforce_posthog_code_billing_quota_activity,
- inputs,
- channel,
- thread_ts,
- slack_user_id,
- )
- if blocked:
- return
+ if blocked:
+ return
user_id = inputs.user_id
@@ -278,7 +248,6 @@ class PostHogCodeSlackMentionWorkflow(PostHogWorkflow):
# that here meant a single false positive from the needs-repo classifier
# walled a plain analytics question behind a Connect button.
repository = None
- workflow.deprecate_patch(_PATCH_ID_NO_PERSONAL_GITHUB_GATE)
else:
# Multiple candidates and no explicit mention. Cheap Haiku
# check first to skip the agent entirely for analytics/config
@@ -334,21 +303,6 @@ class PostHogCodeSlackMentionWorkflow(PostHogWorkflow):
)
return
repository = self._selected_repo
- workflow.deprecate_patch(_PATCH_ID_MODEL_CLASSIFIER)
- if not classified_before_split:
- # Where pre-patch histories classify: past every gate that can still
- # abandon the mention, so the call is only spent on a task that gets
- # created. Newer executions trade that for one classification shared
- # with the follow-up path, which retries far more often than it is
- # abandoned here.
- model_override = await _execute_posthog_code_activity(
- classify_slack_app_model_override_activity,
- SlackAppModelOverrideInput(
- integration_id=inputs.integration_id,
- slack_team_id=inputs.slack_team_id,
- event_text=event.get("text", ""),
- ),
- )
await _execute_posthog_code_activity(
create_posthog_code_task_for_repo_activity,
diff --git a/posthog/temporal/tests/ai/slack_app/activities/test_project_route_activity.py b/posthog/temporal/tests/ai/slack_app/activities/test_project_route_activity.py
index d48878b488ed..e026cd163740 100644
--- a/posthog/temporal/tests/ai/slack_app/activities/test_project_route_activity.py
+++ b/posthog/temporal/tests/ai/slack_app/activities/test_project_route_activity.py
@@ -56,10 +56,9 @@ class TestClassifySlackAppProjectRouteActivity:
)
@contextmanager
- def _classifier(self, *, flag: bool = True, projects: list | None = None, **kwargs):
+ def _classifier(self, *, projects: list | None = None, **kwargs):
"""Run the activity with the LLM call stubbed, yielding the stub."""
with (
- patch(f"{ACTIVITY_MODULE}.is_slack_app_project_routing_enabled", return_value=flag),
patch(f"{ACTIVITY_MODULE}.routable_projects", return_value=self.offered if projects is None else projects),
patch(f"{ACTIVITY_MODULE}.classify_slack_app_project_route", **kwargs) as classify,
):
@@ -70,16 +69,12 @@ class TestClassifySlackAppProjectRouteActivity:
[
# A follow-up that is only an attachment carries no sentence to read.
"blank_text",
- "flag_is_off",
"no_eligible_projects",
],
)
def test_gates_return_no_route_without_calling_the_llm(self, reason):
text = " " if reason == "blank_text" else "how many signups on staging yesterday"
- with self._classifier(
- flag=reason != "flag_is_off",
- projects=[] if reason == "no_eligible_projects" else None,
- ) as classify:
+ with self._classifier(projects=[] if reason == "no_eligible_projects" else None) as classify:
assert classify_slack_app_project_route_activity(self._input(text)) is None
classify.assert_not_called()
diff --git a/posthog/temporal/tests/ai/test_posthog_code_slack_mention_workflow.py b/posthog/temporal/tests/ai/test_posthog_code_slack_mention_workflow.py
index 11b813adc177..0debc837d1c7 100644
--- a/posthog/temporal/tests/ai/test_posthog_code_slack_mention_workflow.py
+++ b/posthog/temporal/tests/ai/test_posthog_code_slack_mention_workflow.py
@@ -7,19 +7,15 @@ from posthog.temporal.ai.slack_app.types import PostHogCodeSlackMentionWorkflowI
@pytest.mark.asyncio
@pytest.mark.parametrize(
- "text,patched,expect_classifier",
+ "text,expect_classifier",
[
# File-only replies skip the classifier so the attachment isn't dropped.
- ("", True, False),
+ ("", False),
# Replies with text still face the classifier even when files are attached.
- ("nice weather today", True, True),
- # Replays of histories recorded before the confirmation patch skip the prompt.
- ("", False, False),
+ ("nice weather today", True),
],
)
-async def test_untagged_followup_with_files_classifier_gating(
- text: str, patched: bool, expect_classifier: bool
-) -> None:
+async def test_untagged_followup_with_files_classifier_gating(text: str, expect_classifier: bool) -> None:
workflow = posthog_code_slack_mention.PostHogCodeSlackMentionWorkflow()
calls: list[str] = []
inputs = PostHogCodeSlackMentionWorkflowInputs(
@@ -52,7 +48,6 @@ async def test_untagged_followup_with_files_classifier_gating(
raise AssertionError(f"unexpected activity: {activity_fn.__name__}")
with (
- patch.object(posthog_code_slack_mention.workflow, "patched", return_value=patched),
# Runs outside a workflow context, where the real marker call would raise.
patch.object(posthog_code_slack_mention.workflow, "deprecate_patch"),
patch.object(posthog_code_slack_mention, "_execute_posthog_code_activity", side_effect=fake_execute_activity),
@@ -62,12 +57,13 @@ async def test_untagged_followup_with_files_classifier_gating(
expected = ["enforce_posthog_code_billing_quota_activity"]
if expect_classifier:
expected.append("classify_untagged_followup_activity")
- if patched:
- expected.append("request_untagged_followup_confirmation_activity")
+ expected += [
+ "request_untagged_followup_confirmation_activity",
# The model-override classifier sits above the follow-up/new-task split, so it
- # runs for a reply too — but only for histories that recorded it there.
- expected.append("classify_slack_app_model_override_activity")
- expected.append("forward_posthog_code_followup_activity")
+ # runs for a reply too.
+ "classify_slack_app_model_override_activity",
+ "forward_posthog_code_followup_activity",
+ ]
assert calls == expected
@@ -97,7 +93,8 @@ async def test_confirmed_untagged_followup_skips_the_classifier_and_the_prompt()
raise AssertionError(f"unexpected activity: {activity_fn.__name__}")
with (
- patch.object(posthog_code_slack_mention.workflow, "patched", return_value=True),
+ # Runs outside a workflow context, where the real marker call would raise.
+ patch.object(posthog_code_slack_mention.workflow, "deprecate_patch"),
patch.object(posthog_code_slack_mention, "_execute_posthog_code_activity", side_effect=fake_execute_activity),
):
await workflow.run(inputs)
diff --git a/products/slack_app/backend/feature_flags.py b/products/slack_app/backend/feature_flags.py
index a848e4a4a200..b06b65b7d3f6 100644
--- a/products/slack_app/backend/feature_flags.py
+++ b/products/slack_app/backend/feature_flags.py
@@ -46,7 +46,6 @@ logger = structlog.get_logger(__name__)
SLACK_APP_AGENT_DESIGN_FLAG = "slack-app-agent-design"
SLACK_APP_FORKING_FLAG = "slack-app-forking"
-SLACK_APP_PROJECT_ROUTING_FLAG = "slack-app-project-routing"
# Linking a Slack identity to a PostHog user resolves the Slack profile and its email.
@@ -125,22 +124,6 @@ def is_slack_app_agent_design_enabled(integration: Integration, distinct_id: str
)
-def is_slack_app_project_routing_enabled(integration: Integration, distinct_id: str | None = None) -> bool:
- """Gate for reading a project out of the message that opens a thread, instead of
- always running against the saved default.
-
- Keyed on the person as well as the workspace: which projects are on offer is bounded
- by the mentioner's access, so the decision is about them and an internal rollout can
- name them the way every other one does.
- """
- return _workspace_flag_enabled(
- SLACK_APP_PROJECT_ROUTING_FLAG,
- integration,
- failure_log_key="slack_app_project_routing_feature_flag_check_failed",
- distinct_id=distinct_id,
- )
-
-
def is_slack_app_assistant_enabled(integration: Integration) -> bool:
"""Gate for the DM assistant: the install must hold the scopes the DM surface
calls — ``im:history`` in particular, without which the assistant would answer