: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(slack-app): show one feature tip under an answer (#122538)
Vojta Bartošefbb6497cac0
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex b622485e247b..f7d947f534dd 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -54,6 +54,9 @@ from products.slack_app.backend.feature_flags import ()from products.slack_app.backend.helpers import local_dev_slack_emailfrom products.slack_app.backend.logic import reply_suggestions+from products.slack_app.backend.logic.feature_tips import interactivity as feature_tip_interactivity+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.logic.untagged_question import is_untagged_question_candidatefrom products.slack_app.backend.models import (ChannelWelcomeMode,@@ -4552,6 +4555,7 @@ def _handle_untagged_followup_run(payload: dict) -> HttpResponse:slack_channel_id=context.get("slack_channel_id"),slack_user_id=clicker_slack_user_id,)+ record_feature_used(slack_team_id, clicker_slack_user_id, SlackFeature.THREAD_FOLLOWUP)capture_slack_event(integration,"slack app untagged followup confirmed",@@ -4728,6 +4732,7 @@ def _handle_reply_suggestion_click(payload: dict, clicked: reply_suggestions.Clilogger.warning("slack_app_reply_suggestion_delete_failed", integration_id=integration.id)raise+ record_feature_used(slack_team_id, clicker_slack_user_id, SlackFeature.REPLY_SUGGESTIONS)capture_slack_event(integration,"slack app reply suggestion clicked",@@ -4813,6 +4818,9 @@ def _report_slack_mention_received(if posthog_user is not None and identified_distinct_id is not None:properties["$set"] = posthog_user.get_analytics_metadata()+ if event.get("files"):+ record_feature_used(slack_team_id, slack_user_id, SlackFeature.FILE_ATTACHMENTS)+posthoganalytics.capture(distinct_id=distinct_id,event="posthog code slack mention received",@@ -6292,6 +6300,7 @@ def posthog_code_interactivity_handler(request: HttpRequest) -> HttpResponse:or _extract_action_value_hints(payload, TURN_FEEDBACK_ACTION_ID)[0]or turn_feedback.extract_modal_hint(payload)or (clicked_reply_suggestion.integration_id if clicked_reply_suggestion else None)+ or feature_tip_interactivity.feature_tip_integration_hint(payload))requesting_user = payload.get("user", {}).get("id", "")slack_team_id = payload.get("team", {}).get("id")@@ -6457,6 +6466,8 @@ def posthog_code_interactivity_handler(request: HttpRequest) -> HttpResponse:return _handle_fork_thread_submit(payload)if action_id == TURN_FEEDBACK_ACTION_ID:return turn_feedback.handle_turn_feedback_click(payload)+ if feature_tip_interactivity.is_feature_tip_action(action_id):+ return feature_tip_interactivity.handle_feature_tip_action(payload)if reply_suggestions.is_reply_suggestion_action(action_id) and clicked_reply_suggestion:return _handle_reply_suggestion_click(payload, clicked_reply_suggestion)if action_id == CHANNEL_APPROVAL_ACTION_APPROVE:diff --git a/products/slack_app/backend/facade/api.py b/products/slack_app/backend/facade/api.pyindex d8a132442b3a..ffec8de22b22 100644--- a/products/slack_app/backend/facade/api.py+++ b/products/slack_app/backend/facade/api.py@@ -4,12 +4,12 @@ The ONLY module other products are allowed to import. Keep the surface narrow:every function here lives behind a tach contract check, so each addition has acost in cross-product coupling.-Today the facade exists for four jobs: letting core's OAuth callback invalidate+Today the facade exists for five jobs: letting core's OAuth callback invalidatethe per-integration auth-state cache when a Slack install is reconnected,answering whether a channel has been approved for PostHog to speak in,telling a product that posts a report whether the bot can answer a follow-up,-and turning an agent's tool calls into the progress lines of a streamed Slack-reply. All are stable re-exports so the implementations can move around inside+turning an agent's tool calls into the progress lines of a streamed Slack+reply, and recording that a Slack user used a feature, so feature tips skip it. All are stable re-exports so the implementations can move around insideslack_app without breaking their callers.This module's import graph must not reach ``products.signals``. That product now imports this@@ -22,9 +22,13 @@ from __future__ import annotationsfrom typing import Any+import structlog+from posthog.models.integration import Integrationfrom products.slack_app.backend.feature_flags import is_slack_app_chart_links_enabled+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.logic.progress_phases import (ANSWER_LINE_TITLE,OTHER_WORK,@@ -45,7 +49,7 @@ from products.slack_app.backend.logic.progress_phases import (from products.slack_app.backend.models import SlackChannelfrom products.slack_app.backend.services.followup_invite import build_followup_invite, build_followup_invite_textfrom products.slack_app.backend.services.slack_auth import invalidate_auth_state-from products.slack_app.backend.services.slack_scopes import has_scopes+from products.slack_app.backend.services.slack_scopes import SLACK_CANVAS_SCOPE, SLACK_FILE_SCOPE, has_scopesfrom products.slack_app.backend.services.slack_user_info import invalidate_workspace_bot_user_id__all__ = [@@ -55,6 +59,7 @@ __all__ = ["PLAN_TITLE_WORKING","PREPARING_LINE_TITLE","SLACK_STEP_STATUSES",+ "SlackFeature","THINKING_LINE_TITLE","ProgressPhase","agent_plan_steps",@@ -65,13 +70,16 @@ __all__ = ["phase_line_title","tool_call_from_acp_update","invalidate_slack_integration_auth_state",+ "record_slack_feature_used","slack_artifact_delivery_state_updates","slack_channel_is_approved","slack_followup_invite","slack_followup_invite_text",]-_SLACK_CANVAS_FILE_ADAPTER_SCOPES = frozenset({"canvases:write", "files:write"})+logger = structlog.get_logger(__name__)++_SLACK_CANVAS_FILE_ADAPTER_SCOPES = frozenset({SLACK_CANVAS_SCOPE, SLACK_FILE_SCOPE})def invalidate_slack_integration_auth_state(integration_id: int) -> None:@@ -134,3 +142,18 @@ def slack_followup_invite_text(integration: Integration | None, *, utm_tags: strdef slack_followup_invite(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> dict[str, Any] | None:"""``slack_followup_invite_text`` as a Slack context block, for a caller that appends blocks."""return build_followup_invite(integration, utm_tags=utm_tags, ai_enabled=ai_enabled)+++def record_slack_feature_used(integration_id: int, slack_user_id: str | None, feature: SlackFeature) -> None:+ """Never raises, so a caller can record use from inside the feature's own code path."""+ try:+ slack_workspace_id = (+ Integration.objects.filter(id=integration_id, kind="slack") # nosemgrep: idor-lookup-without-team+ .values_list("integration_id", flat=True)+ .first()+ )+ except Exception:+ logger.warning("slack_app_feature_used_lookup_failed", integration_id=integration_id, exc_info=True)+ return+ if slack_workspace_id:+ record_feature_used(slack_workspace_id, slack_user_id, feature)diff --git a/products/slack_app/backend/feature_flags.py b/products/slack_app/backend/feature_flags.pyindex c92a01aa054a..38615173fb15 100644--- a/products/slack_app/backend/feature_flags.py+++ b/products/slack_app/backend/feature_flags.py@@ -47,6 +47,7 @@ logger = structlog.get_logger(__name__)SLACK_APP_AGENT_DESIGN_FLAG = "slack-app-agent-design"SLACK_APP_CHART_LINKS_FLAG = "slack-app-chart-links"+SLACK_APP_FEATURE_TIPS_FLAG = "slack-app-feature-tips"SLACK_APP_FORKING_FLAG = "slack-app-forking"SLACK_APP_MULTIPLAYER_APPROVALS_FLAG = "slack-app-multiplayer-approvals"SLACK_APP_BYOS_FLAG = "slack-app-byos"@@ -140,6 +141,21 @@ def is_slack_app_chart_links_enabled(integration: Integration) -> bool:)+def is_slack_app_feature_tips_enabled(integration: Integration, distinct_id: str) -> bool:+ """Gate for the one-line feature tip under an answer.++ ``distinct_id`` is the reader's PostHog distinct id, or their Slack-derived id when no+ PostHog user is linked. A tip is a per-person decision, so a percentage rollout splits+ people and a holdout group can measure what tips change.+ """+ return _workspace_flag_enabled(+ SLACK_APP_FEATURE_TIPS_FLAG,+ integration,+ failure_log_key="slack_app_feature_tips_feature_flag_check_failed",+ distinct_id=distinct_id,+ )++def is_slack_app_multiplayer_approvals_enabled(integration: Integration, distinct_id: str | None) -> bool:"""Gate for the thread creator's choice of who may join their threads.diff --git a/products/slack_app/backend/logic/feature_tips/__init__.py b/products/slack_app/backend/logic/feature_tips/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/slack_app/backend/logic/feature_tips/catalog.py b/products/slack_app/backend/logic/feature_tips/catalog.pynew file mode 100644index 000000000000..d847e971fc12--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/catalog.py@@ -0,0 +1,536 @@+"""The Slack app features that a tip can promote.++Each feature answers two questions about one Slack user: ``is_eligible`` (can this person use+the feature now) and ``was_used`` (does this person already use it).++``was_used`` reads stored state where the feature leaves some, such as a setting or a connected+account, so a user who started before tips existed is judged the same way as a new user. Some+features leave no state, such as a rating or a fork. The code path of such a feature calls+``record_feature_used`` instead, so their use counts only from the release of tips onward.++``is_eligible`` can make a network call, such as a feature flag check, so the caller runs it+outside any database lock.+"""++from __future__ import annotations++from functools import cached_property++from posthog.dataclasses import frozen+from posthog.models.integration import Integration, SlackIntegration+from posthog.models.user_integration import UserIntegration+from posthog.slack.formatting import channel_id_from_target++from products.mcp_store.backend.facade.api import get_active_installations+from products.slack_app.backend.feature_flags import (+ is_slack_app_assistant_enabled,+ is_slack_app_forking_enabled,+ is_slack_app_unprompted_answers_enabled,+)+from products.slack_app.backend.inbox_channel import (+ _get_team_channel,+ channel_name_from_target,+ ensure_inbox_channel,+ has_inbox_scopes,+ invite_user_to_inbox,+)+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.models import SlackSettings, SlackThreadTaskMapping, UntaggedFollowupMode+from products.slack_app.backend.services.slack_conversations import resolve_conversation_type+from products.slack_app.backend.services.slack_messages import app_home_url, personal_integrations_url, project_web_url+from products.slack_app.backend.services.slack_scopes import SLACK_CANVAS_SCOPE, SLACK_FILE_SCOPE, has_scopes+from products.slack_app.backend.services.slack_settings import (+ set_auto_model_choice,+ set_untagged_followup_mode,+ set_untagged_question_mode,+)+from products.subscriptions.backend.facade.api import user_has_slack_subscription+++@frozen(slots=False)+class TipContext:+ integration: Integration+ slack_user_id: str+ posthog_user_id: int | None+ channel: str+ settings: SlackSettings++ @property+ def team_id(self) -> int:+ return self.integration.team_id++ @property+ def in_direct_message(self) -> bool:+ # Slack gives every direct message conversation an id that starts with "D".+ return self.channel.startswith("D")++ @cached_property+ def team_has_github(self) -> bool:+ return Integration.objects.filter(team_id=self.team_id, kind="github").exists()++ @cached_property+ def workspace_has_several_projects(self) -> bool:+ # Every PostHog project connected to this Slack workspace has its own Slack integration row.+ return (+ Integration.objects.filter( # nosemgrep: idor-lookup-without-team+ kind="slack", integration_id=self.integration.integration_id+ ).count()+ > 1+ )++ @cached_property+ def inbox_channel_target(self) -> str | None:+ if not has_inbox_scopes(self.integration):+ return None+ target = _get_team_channel(self.team_id)+ if target is None:+ return None+ # A tip names the channel and invites the reader, so a private or unknown channel would+ # leak its name or add someone who was not meant to join it.+ return target if _is_public_channel(self.integration, channel_id_from_target(target)) else None++ @cached_property+ def app_home_url(self) -> str | None:+ return app_home_url(self.integration)+++def _is_public_channel(integration: Integration, channel_id: str) -> bool:+ conversation_type = resolve_conversation_type(SlackIntegration(integration), {}, channel_id)+ return conversation_type == SlackThreadTaskMapping.ConversationType.PUBLIC_CHANNEL+++@frozen+class TipCta:+ label: str+ # Without a URL, the button runs ``apply_action``.+ url: str | None = None+++def _home_tab_cta(ctx: TipContext) -> TipCta | None:+ if ctx.app_home_url is None:+ return None+ return TipCta(label="Open the Home tab", url=ctx.app_home_url)+++class TipFeature:+ feature: SlackFeature+ # Lower comes first when nothing in the message points at one feature.+ rank: int+ emoji: str+ title: str+ text: str+ choice_criteria: str+ has_action: bool = False++ def is_eligible(self, ctx: TipContext) -> bool:+ return True++ def was_used(self, ctx: TipContext) -> bool:+ """``False`` for a feature without stored state. Its code path records use instead."""+ return False++ def render_text(self, ctx: TipContext) -> str:+ return self.text++ def cta(self, ctx: TipContext) -> TipCta | None:+ return None++ def apply_action(self, integration: Integration, slack_user_id: str) -> str:+ raise NotImplementedError+++class ThreadFollowupTip(TipFeature):+ feature = SlackFeature.THREAD_FOLLOWUP+ rank = 10+ has_action = True+ emoji = "💬"+ title = "Reply without tagging me"+ text = "In threads you start with me, you can reply without tagging me. I ask before I pick up the reply, or I can always pick it up."+ choice_criteria = (+ "Replying in a thread without tagging the assistant. Fits a message that continues a conversation "+ 'or asks a follow-up question about an earlier answer, such as one that starts with "and" or asks '+ 'about "the same numbers", "that chart" or "those users".'+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ # In a direct message every reply already goes to PostHog.+ return not ctx.in_direct_message++ def was_used(self, ctx: TipContext) -> bool:+ # Any stored choice means the person found the setting.+ return ctx.settings.untagged_followup_mode is not None++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Always pick up my replies")++ def apply_action(self, integration: Integration, slack_user_id: str) -> str:+ set_untagged_followup_mode(integration.integration_id, slack_user_id, UntaggedFollowupMode.AUTO)+ return (+ "✅ Done. I'll pick up your replies in threads you start with me. "+ "You can change this in the PostHog app Home tab."+ )+++class SubscriptionTip(TipFeature):+ feature = SlackFeature.SUBSCRIPTION+ rank = 20+ emoji = "📬"+ title = "Get reports on a schedule"+ text = "I can send you a report in Slack on a schedule. For example: _@PostHog send me our weekly signups every Monday at 9:00_."+ choice_criteria = (+ "Scheduled reports posted to Slack. Fits a message about a number the person checks again and again, "+ "such as weekly signups, a recurring report, or a metric they track over time."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.posthog_user_id is not None++ def was_used(self, ctx: TipContext) -> bool:+ if ctx.posthog_user_id is None:+ return False+ return user_has_slack_subscription(team_id=ctx.team_id, user_id=ctx.posthog_user_id)+++class CodeChangePrTip(TipFeature):+ feature = SlackFeature.CODE_CHANGE_PR+ rank = 30+ emoji = "🛠️"+ title = "I can change code too"+ text = "Ask me to fix a bug or add an event, and I open a pull request for you to review."+ choice_criteria = (+ "The person asks to change their product's code: fix a bug or an error, add or change an event or "+ "tracking, or open a pull request."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.posthog_user_id is not None and ctx.team_has_github++ def was_used(self, ctx: TipContext) -> bool:+ if ctx.posthog_user_id is None:+ return False+ return UserIntegration.objects.filter(+ user_id=ctx.posthog_user_id, kind=UserIntegration.IntegrationKind.GITHUB+ ).exists()++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Connect your GitHub", url=personal_integrations_url(ctx.team_id))+++class McpToolTip(TipFeature):+ feature = SlackFeature.MCP_TOOL+ rank = 40+ emoji = "🔌"+ title = "Connect MCP servers"+ text = (+ "I can also use MCP servers, such as Linear or Notion. "+ "Connect them in PostHog, and I use them with your own access."+ )+ choice_criteria = (+ "Connecting other work tools such as Linear, Jira, Notion or Google Drive. Fits a message that mentions "+ "tickets, issues, docs, specs or another work tool."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.posthog_user_id is not None++ def was_used(self, ctx: TipContext) -> bool:+ if ctx.posthog_user_id is None:+ return False+ return bool(get_active_installations(ctx.team_id, ctx.posthog_user_id))++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Connect an MCP server", url=f"{project_web_url(ctx.team_id)}/mcp-servers")+++class DirectMessageTip(TipFeature):+ feature = SlackFeature.DIRECT_MESSAGE+ rank = 50+ emoji = "🔒"+ title = "Ask me in private"+ text = "You can also send me a direct message, for questions you want to keep to yourself."+ choice_criteria = (+ "Private direct messages with the assistant. Fits a message about a sensitive topic, such as one customer, "+ "revenue, salaries, or the person's own work."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return not ctx.in_direct_message and is_slack_app_assistant_enabled(ctx.integration)++ def was_used(self, ctx: TipContext) -> bool:+ return SlackThreadTaskMapping.objects.filter(+ slack_workspace_id=ctx.integration.integration_id,+ mentioning_slack_user_id=ctx.slack_user_id,+ conversation_type=SlackThreadTaskMapping.ConversationType.IM,+ ).exists()++ def cta(self, ctx: TipContext) -> TipCta | None:+ url = app_home_url(ctx.integration, tab="messages")+ if url is None:+ return None+ return TipCta(label="Open a direct message", url=url)+++class FileAttachmentsTip(TipFeature):+ feature = SlackFeature.FILE_ATTACHMENTS+ rank = 60+ emoji = "📎"+ title = "Send me screenshots and files"+ text = "Attach a screenshot or a file to your message, and I read it together with your question."+ choice_criteria = (+ "Sending screenshots and files to the assistant. Fits a message that describes something on screen, "+ "a design, a spreadsheet, a log file, or an error the person sees."+ )+++class FileOutputsTip(TipFeature):+ feature = SlackFeature.FILE_OUTPUTS+ rank = 70+ emoji = "📊"+ title = "Get files back"+ text = "Ask me for a CSV or a chart, and I add it to the thread as a file."+ choice_criteria = (+ "Files and Slack canvases made by the assistant. Fits a message that asks for an export, a list of rows, "+ "a chart to share, or a long report."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return has_scopes(ctx.integration, {SLACK_FILE_SCOPE})++ def render_text(self, ctx: TipContext) -> str:+ if has_scopes(ctx.integration, {SLACK_CANVAS_SCOPE}):+ return (+ "Ask me for a CSV, a chart, or a long report, and I add it to the thread as a file or a Slack canvas."+ )+ return self.text+++class InboxChannelTip(TipFeature):+ feature = SlackFeature.INBOX_CHANNEL+ rank = 80+ has_action = True+ emoji = "📥"+ title = "See what PostHog finds"+ text = "Join the PostHog inbox channel to see the problems that PostHog finds in your product."+ choice_criteria = (+ "A Slack channel with reports about problems PostHog finds on its own, such as new or spiking errors. "+ "Fits a message about errors, regressions, incidents, or keeping watch on the product."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.inbox_channel_target is not None++ def render_text(self, ctx: TipContext) -> str:+ if ctx.inbox_channel_target is None:+ return self.text+ name = channel_name_from_target(ctx.inbox_channel_target)+ return f"Join {name} to see the problems that PostHog finds in your product, such as new errors."++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Join the channel")++ def apply_action(self, integration: Integration, slack_user_id: str) -> str:+ channel = ensure_inbox_channel(integration)+ # Checked again on click, because the channel can turn private after the tip was shown.+ if channel is None or not _is_public_channel(integration, channel[0]):+ return "I couldn't add you to the channel. Ask a Slack admin to add you."+ if not invite_user_to_inbox(integration, channel[0], slack_user_id):+ return "I couldn't add you to the channel. Try again later, or ask a Slack admin to add you."+ return f"✅ Done. You're in {channel[1]}."+++class ProjectInMentionTip(TipFeature):+ feature = SlackFeature.PROJECT_IN_MENTION+ rank = 90+ emoji = "🗂️"+ title = "Pick a project in your message"+ text = "Name a project in your message, and I use it for that request. For example: _@PostHog in the website project, why did signups drop?_"+ choice_criteria = (+ "Naming a PostHog project in one request. Fits a message that names which of several apps, sites or "+ 'environments to look in, such as "in the mobile app" or "on staging". A platform used as a filter '+ 'or breakdown, such as "for mobile", or a mention of "the app", names no project.'+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.workspace_has_several_projects+++class AppHomeProjectTip(TipFeature):+ feature = SlackFeature.APP_HOME_PROJECT+ rank = 100+ emoji = "🏠"+ title = "Choose your default project"+ text = "You can choose your default project in the Home tab of the PostHog app."+ choice_criteria = (+ "Changing the default PostHog project. Fits a message that asks to switch projects, or says the "+ "person usually works in a project other than the one the assistant used."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.workspace_has_several_projects++ def was_used(self, ctx: TipContext) -> bool:+ return ctx.settings.default_integration_id is not None++ def cta(self, ctx: TipContext) -> TipCta | None:+ return _home_tab_cta(ctx)+++class ModelInMentionTip(TipFeature):+ feature = SlackFeature.MODEL_IN_MENTION+ rank = 110+ emoji = "🧠"+ title = "Pick a model for one request"+ text = "Name the model in your message. For example: _@PostHog use sonnet and fix the flaky checkout test_."+ choice_criteria = (+ "Choosing an AI model or effort level for one request. Fits a hard or long task, such as a deep "+ "investigation or a large code change, or a message about speed or quality of answers."+ )+++class AutoModelChoiceTip(TipFeature):+ feature = SlackFeature.AUTO_MODEL_CHOICE+ rank = 120+ has_action = True+ emoji = "⚡"+ title = "Let me pick the model"+ text = "I can choose the model for each task you start: a faster one for short questions and a stronger one for code changes."+ choice_criteria = (+ "Letting the assistant choose the AI model for each task. Fits a message about answer speed, cost, "+ "or a mix of quick questions and large tasks."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ # Without a linked PostHog user the router cannot run, so the setting would do nothing.+ return ctx.posthog_user_id is not None++ def was_used(self, ctx: TipContext) -> bool:+ return ctx.settings.auto_model_choice is not None++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Turn it on")++ def apply_action(self, integration: Integration, slack_user_id: str) -> str:+ set_auto_model_choice(integration.integration_id, slack_user_id, True)+ return "✅ Done. I'll choose the model for each new task you start. You can change this in the PostHog app Home tab."+++class AppHomeTasksTip(TipFeature):+ feature = SlackFeature.APP_HOME_TASKS+ rank = 130+ emoji = "📋"+ title = "See all your tasks"+ text = "The Home tab of the PostHog app lists your tasks and their status."+ choice_criteria = (+ "A list of the person's tasks and their status. Fits a message that asks about an earlier request, "+ "a pull request in progress, or what the assistant is working on."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return ctx.app_home_url is not None++ def cta(self, ctx: TipContext) -> TipCta | None:+ return _home_tab_cta(ctx)+++class InsightUnfurlTip(TipFeature):+ feature = SlackFeature.INSIGHT_UNFURL+ rank = 140+ emoji = "🔗"+ title = "Share insight links"+ text = "Paste a link to a PostHog insight in Slack, and I show a preview of it."+ choice_criteria = (+ "Previews of PostHog links pasted in Slack. Fits a message that shares or mentions an insight, "+ "a dashboard, or a chart with the team."+ )+++class ForkThreadTip(TipFeature):+ feature = SlackFeature.FORK_THREAD+ rank = 150+ emoji = "🍴"+ title = "Continue in private"+ text = 'To continue a thread in private, use "Fork to DM" in the menu on my answer.'+ choice_criteria = (+ "Moving a channel conversation into a private direct message. Fits a message in a busy channel, "+ "or about a topic the person wants to explore alone."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return not ctx.in_direct_message and is_slack_app_forking_enabled(ctx.integration)+++class UnpromptedAnswersTip(TipFeature):+ feature = SlackFeature.UNPROMPTED_ANSWERS+ rank = 160+ has_action = True+ emoji = "🙋"+ title = "Ask without tagging me"+ text = "When you ask about PostHog in a channel without tagging me, I can offer to answer."+ choice_criteria = (+ "Answers to channel questions that do not tag the assistant. Fits a message that the person could "+ "have asked the whole channel, such as a quick data question."+ )++ def is_eligible(self, ctx: TipContext) -> bool:+ return not ctx.in_direct_message and is_slack_app_unprompted_answers_enabled(ctx.integration)++ def was_used(self, ctx: TipContext) -> bool:+ return ctx.settings.untagged_question_mode is not None++ def cta(self, ctx: TipContext) -> TipCta | None:+ return TipCta(label="Always answer my questions")++ def apply_action(self, integration: Integration, slack_user_id: str) -> str:+ set_untagged_question_mode(integration.integration_id, slack_user_id, UntaggedFollowupMode.AUTO)+ return (+ "✅ Done. I'll answer your questions about PostHog in channels, also when you don't tag me. "+ "You can change this in the PostHog app Home tab."+ )+++class AnswerRatingTip(TipFeature):+ feature = SlackFeature.ANSWER_RATING+ rank = 170+ emoji = "👍"+ title = "Rate my answers"+ text = "Use the 👍 and 👎 buttons under my answers. This helps us make them better."+ choice_criteria = (+ "Rating the assistant's answers. Fits a message that says an earlier answer was wrong, "+ "incomplete, or very helpful."+ )+++class ReplySuggestionsTip(TipFeature):+ feature = SlackFeature.REPLY_SUGGESTIONS+ rank = 180+ emoji = "👆"+ title = "Ask the next question in one click"+ text = "Click a suggested reply under my answer to ask your next question."+ choice_criteria = (+ "Suggested follow-up replies under an answer. Fits a short follow-up question that continues an earlier answer."+ )+++CATALOG: dict[SlackFeature, TipFeature] = {+ tip.feature: tip+ for tip in (+ ThreadFollowupTip(),+ SubscriptionTip(),+ CodeChangePrTip(),+ McpToolTip(),+ DirectMessageTip(),+ FileAttachmentsTip(),+ FileOutputsTip(),+ InboxChannelTip(),+ ProjectInMentionTip(),+ AppHomeProjectTip(),+ ModelInMentionTip(),+ AutoModelChoiceTip(),+ AppHomeTasksTip(),+ InsightUnfurlTip(),+ ForkThreadTip(),+ UnpromptedAnswersTip(),+ AnswerRatingTip(),+ ReplySuggestionsTip(),+ )+}diff --git a/products/slack_app/backend/logic/feature_tips/features.py b/products/slack_app/backend/logic/feature_tips/features.pynew file mode 100644index 000000000000..e59e57400df3--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/features.py@@ -0,0 +1,22 @@+from enum import StrEnum+++class SlackFeature(StrEnum):+ THREAD_FOLLOWUP = "thread_followup"+ SUBSCRIPTION = "subscription"+ CODE_CHANGE_PR = "code_change_pr"+ MCP_TOOL = "mcp_tool"+ DIRECT_MESSAGE = "direct_message"+ FILE_ATTACHMENTS = "file_attachments"+ FILE_OUTPUTS = "file_outputs"+ INBOX_CHANNEL = "inbox_channel"+ PROJECT_IN_MENTION = "project_in_mention"+ APP_HOME_PROJECT = "app_home_project"+ MODEL_IN_MENTION = "model_in_mention"+ AUTO_MODEL_CHOICE = "auto_model_choice"+ APP_HOME_TASKS = "app_home_tasks"+ INSIGHT_UNFURL = "insight_unfurl"+ FORK_THREAD = "fork_thread"+ UNPROMPTED_ANSWERS = "unprompted_answers"+ ANSWER_RATING = "answer_rating"+ REPLY_SUGGESTIONS = "reply_suggestions"diff --git a/products/slack_app/backend/logic/feature_tips/interactivity.py b/products/slack_app/backend/logic/feature_tips/interactivity.pynew file mode 100644index 000000000000..91fdf1e4d834--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/interactivity.py@@ -0,0 +1,119 @@+"""What a click on a tip's buttons does. Only the reader sees the tip, so the clicker is the reader."""++from __future__ import annotations++import json+from typing import Any++from django.http import HttpResponse+from django.utils import timezone++import structlog++from posthog.dataclasses import frozen+from posthog.models.integration import Integration++from products.slack_app.backend.analytics import capture_slack_event+from products.slack_app.backend.logic.feature_tips.catalog import CATALOG+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.offer import (+ FEATURE_TIP_ACTION_IDS,+ FEATURE_TIP_CTA_ACTION_ID,+ FEATURE_TIP_DISMISS_ACTION_ID,+ FEATURE_TIP_OPT_OUT_ACTION_ID,+)+from products.slack_app.backend.logic.feature_tips.state import FeatureTipsState, TipRecord, update_state+from products.slack_app.backend.services.inbox_interactivity import post_response_url++logger = structlog.get_logger(__name__)++TIPS_OFF_TEXT = "👋 Got it. I won't show you more tips."+++@frozen+class _TipClick:+ action_id: str+ value: dict[str, Any]+++def _tip_action(payload: dict[str, Any]) -> _TipClick | None:+ for action in payload.get("actions", []):+ if action.get("action_id") not in FEATURE_TIP_ACTION_IDS:+ continue+ try:+ value = json.loads(action.get("value") or "")+ except json.JSONDecodeError:+ return None+ if isinstance(value, dict):+ return _TipClick(action_id=action["action_id"], value=value)+ return None+++def is_feature_tip_action(action_id: object) -> bool:+ return action_id in FEATURE_TIP_ACTION_IDS+++def _integration_id(value: dict[str, Any]) -> int | None:+ integration_id = value.get("integration_id")+ return integration_id if isinstance(integration_id, int) else None+++def feature_tip_integration_hint(payload: dict[str, Any]) -> int | None:+ found = _tip_action(payload)+ return _integration_id(found.value) if found is not None else None+++def handle_feature_tip_action(payload: dict[str, Any]) -> HttpResponse:+ response_url = payload.get("response_url", "")+ found = _tip_action(payload)+ integration_id = _integration_id(found.value) if found is not None else None+ slack_user_id = payload.get("user", {}).get("id")+ slack_team_id = payload.get("team", {}).get("id")+ if found is None or integration_id is None or not slack_user_id or not slack_team_id:+ post_response_url(response_url, {"delete_original": True})+ return HttpResponse(status=200)+ value = found.value+ integration = Integration.objects.filter( # nosemgrep: idor-lookup-without-team+ id=integration_id, # nosemgrep: idor-taint-user-input-to-model-get+ kind="slack",+ integration_id=slack_team_id,+ ).first()+ if integration is None or value.get("feature") not in SlackFeature:+ post_response_url(response_url, {"delete_original": True})+ return HttpResponse(status=200)+ feature = SlackFeature(value["feature"])++ action_id = found.action_id+ tip = CATALOG[feature]+ runs_action = action_id == FEATURE_TIP_CTA_ACTION_ID and tip.has_action+ now = timezone.now()++ def change(state: FeatureTipsState) -> None:+ record = state.shown.setdefault(feature.value, TipRecord(first_shown_at=now))+ if action_id == FEATURE_TIP_CTA_ACTION_ID:+ record.clicked_at = now+ elif action_id == FEATURE_TIP_DISMISS_ACTION_ID:+ record.dismissed_at = now+ elif action_id == FEATURE_TIP_OPT_OUT_ACTION_ID:+ record.dismissed_at = now+ state.opted_out_at = now+ if runs_action:+ state.used.setdefault(feature.value, now)++ update_state(integration.integration_id, slack_user_id, change)++ if action_id == FEATURE_TIP_CTA_ACTION_ID:+ event = "slack app feature tip clicked"+ if runs_action:+ text = tip.apply_action(integration, slack_user_id)+ post_response_url(response_url, {"replace_original": True, "text": text})+ else:+ post_response_url(response_url, {"delete_original": True})+ elif action_id == FEATURE_TIP_OPT_OUT_ACTION_ID:+ event = "slack app feature tips turned off"+ post_response_url(response_url, {"replace_original": True, "text": TIPS_OFF_TEXT})+ else:+ event = "slack app feature tip dismissed"+ post_response_url(response_url, {"delete_original": True})+ capture_slack_event(integration, event, slack_user_id=slack_user_id, feature=feature.value)+ return HttpResponse(status=200)diff --git a/products/slack_app/backend/logic/feature_tips/offer.py b/products/slack_app/backend/logic/feature_tips/offer.pynew file mode 100644index 000000000000..cc8525c8dc4b--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/offer.py@@ -0,0 +1,264 @@+"""Whether a tip goes under an answer, which one, and how it reaches the reader.++The work runs in three steps, so no network call ever holds the lock on the reader's settings row:++1. Under the lock: count this interaction and run the cheap gates (opt-out, the number of earlier+ interactions, the daily limit).+2. Without the lock: run the feature checks. Some of them check a feature flag over the network.+3. Under the lock again: record what the checks found and hold today's tip slot.++Then, with two or more candidates, the decision model picks one, and the tip posts.+"""++from __future__ import annotations++import json+from datetime import datetime, timedelta+from typing import TYPE_CHECKING, Any++from django.db import transaction+from django.utils import timezone++import structlog++from posthog.dataclasses import frozen+from posthog.models.integration import Integration, SlackIntegration++from products.slack_app.backend.analytics import capture_slack_event, slack_distinct_id+from products.slack_app.backend.feature_flags import is_slack_app_feature_tips_enabled+from products.slack_app.backend.logic.feature_tips.catalog import CATALOG, TipContext, TipFeature+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.picker import choose_tip+from products.slack_app.backend.logic.feature_tips.state import FeatureTipsState, mark_shown, parse_state+from products.slack_app.backend.models import SlackSettings, SlackThreadTaskMapping+from products.slack_app.backend.services.slack_messages import post_slack_ephemeral, section_block++if TYPE_CHECKING:+ from posthog.models.user import User++logger = structlog.get_logger(__name__)++# A first-time reader gets answers before any tip, so the tip does not crowd their first impression.+MIN_INTERACTIONS = 3+TIP_INTERVAL = timedelta(hours=24)++FEATURE_TIP_CTA_ACTION_ID = "slack_app_feature_tip_cta"+FEATURE_TIP_DISMISS_ACTION_ID = "slack_app_feature_tip_dismiss"+FEATURE_TIP_OPT_OUT_ACTION_ID = "slack_app_feature_tip_opt_out"+FEATURE_TIP_ACTION_IDS = frozenset(+ {FEATURE_TIP_CTA_ACTION_ID, FEATURE_TIP_DISMISS_ACTION_ID, FEATURE_TIP_OPT_OUT_ACTION_ID}+)+++@frozen+class TipRequest:+ integration: Integration+ slack_user_id: str+ posthog_user: User | None+ channel: str+ thread_ts: str+ person_message: str | None = None+ trace_id: str | None = None+++@frozen(slots=False)+class _Reservation:+ candidates: list[TipFeature]+ ctx: TipContext+ interaction_count: int+++def offer_feature_tip(request: TipRequest) -> SlackFeature | None:+ integration = request.integration+ stored = list(+ SlackSettings.objects.filter(+ slack_workspace_id=integration.integration_id, slack_user_id=request.slack_user_id+ ).values_list("feature_tips", flat=True)[:1]+ )+ # Most answers come from a reader who opted out or already got today's tip. They stop here,+ # before the flag call and the lock. Their interaction count no longer gates anything.+ if stored and _skip_without_counting(parse_state(stored[0]), timezone.now()):+ return None+ distinct_id = (+ request.posthog_user.distinct_id+ if request.posthog_user is not None and request.posthog_user.distinct_id+ else slack_distinct_id(integration, request.slack_user_id)+ )+ if not is_slack_app_feature_tips_enabled(integration, distinct_id):+ return None+ if not stored:+ SlackSettings.objects.get_or_create(+ slack_workspace_id=integration.integration_id, slack_user_id=request.slack_user_id+ )+ # Counted before the lock, so a reader with a long thread history never holds the row during the scan.+ history_count = (+ _thread_count(integration.integration_id, request.slack_user_id)+ if not stored or parse_state(stored[0]).backfilled_at is None+ else None+ )+ reservation = _reserve_candidates(request, history_count)+ if reservation is None:+ return None+ choice = choose_tip(+ reservation.candidates,+ request.person_message,+ team_id=integration.team_id,+ distinct_id=distinct_id,+ trace_id=request.trace_id,+ )+ if choice is None:+ return None+ tip = CATALOG[choice.feature]+ body = tip.render_text(reservation.ctx)+ try:+ post_slack_ephemeral(+ SlackIntegration(integration).client,+ channel=request.channel,+ user=request.slack_user_id,+ thread_ts=request.thread_ts,+ text=f"💡 Tip: {tip.title}. {body}",+ blocks=tip_blocks(integration.id, tip, reservation.ctx, body),+ )+ except Exception:+ logger.warning("slack_app_feature_tip_post_failed", feature=choice.feature, exc_info=True)+ return None+ mark_shown(integration.integration_id, request.slack_user_id, choice.feature.value, "tip")+ capture_slack_event(+ integration,+ "slack app feature tip shown",+ slack_user_id=request.slack_user_id,+ posthog_user=request.posthog_user,+ feature=choice.feature.value,+ pick_source=choice.source,+ pick_confidence=choice.confidence,+ candidate_count=len(reservation.candidates),+ interaction_count=reservation.interaction_count,+ in_direct_message=reservation.ctx.in_direct_message,+ )+ return choice.feature+++def _skip_without_counting(state: FeatureTipsState, now: datetime) -> bool:+ if state.opted_out_at is not None:+ return True+ return (+ state.interaction_count >= MIN_INTERACTIONS+ and state.last_shown_at is not None+ and now - state.last_shown_at < TIP_INTERVAL+ )+++def _is_due(state: FeatureTipsState, now: datetime) -> bool:+ return (+ state.opted_out_at is None+ and state.interaction_count >= MIN_INTERACTIONS+ and (state.last_shown_at is None or now - state.last_shown_at >= TIP_INTERVAL)+ )+++def _locked_settings(workspace_id: str, slack_user_id: str) -> SlackSettings | None:+ # Another answer for this reader holds the row when this returns None. That answer decides about today's tip.+ return (+ SlackSettings.objects.filter(slack_workspace_id=workspace_id, slack_user_id=slack_user_id)+ .select_for_update(skip_locked=True)+ .first()+ )+++def _save(settings: SlackSettings, state: FeatureTipsState) -> None:+ settings.feature_tips = state.model_dump(mode="json")+ settings.save(update_fields=["feature_tips", "updated_at"])+++def _thread_count(workspace_id: str, slack_user_id: str) -> int:+ return SlackThreadTaskMapping.objects.filter(+ slack_workspace_id=workspace_id, mentioning_slack_user_id=slack_user_id+ ).count()+++def _reserve_candidates(request: TipRequest, history_count: int | None) -> _Reservation | None:+ """Count this interaction, run the gates and the feature checks, and hold today's tip slot.++ The slot is held before the tip posts, so two answers that finish together cannot both send+ one. A post that then fails gives up the tip for that day, which is the cheaper mistake.+ """+ workspace_id = request.integration.integration_id+ slack_user_id = request.slack_user_id+ now = timezone.now()++ with transaction.atomic():+ settings = _locked_settings(workspace_id, slack_user_id)+ if settings is None:+ return None+ state = parse_state(settings.feature_tips)+ if state.backfilled_at is None:+ # The history already holds the thread of this answer, so it is not counted again.+ state.interaction_count = (+ history_count if history_count is not None else _thread_count(workspace_id, slack_user_id)+ )+ state.backfilled_at = now+ else:+ state.interaction_count += 1+ _save(settings, state)+ if not _is_due(state, now):+ return None++ ctx = TipContext(+ integration=request.integration,+ slack_user_id=slack_user_id,+ posthog_user_id=request.posthog_user.id if request.posthog_user is not None else None,+ channel=request.channel,+ settings=settings,+ )+ newly_used: list[SlackFeature] = []+ candidates: list[TipFeature] = []+ for feature, tip in CATALOG.items():+ if feature.value in state.used or feature.value in state.shown:+ continue+ if tip.was_used(ctx):+ newly_used.append(feature)+ elif tip.is_eligible(ctx):+ candidates.append(tip)++ with transaction.atomic():+ settings = _locked_settings(workspace_id, slack_user_id)+ if settings is None:+ return None+ state = parse_state(settings.feature_tips)+ for feature in newly_used:+ state.used.setdefault(feature.value, now)+ # A tip that another answer sent while the checks ran is already counted. Do not send a second one.+ candidates = [tip for tip in candidates if tip.feature.value not in state.shown]+ reserved = bool(candidates) and _is_due(state, now)+ if reserved:+ state.last_shown_at = now+ _save(settings, state)+ if not reserved:+ return None+ return _Reservation(candidates=candidates, ctx=ctx, interaction_count=state.interaction_count)+++def _button(action_id: str, label: str, value: str, **extra: str) -> dict[str, Any]:+ return {+ "type": "button",+ "action_id": action_id,+ "text": {"type": "plain_text", "text": label},+ "value": value,+ **extra,+ }+++def tip_blocks(integration_id: int, tip: TipFeature, ctx: TipContext, body: str) -> list[dict[str, Any]]:+ # The integration id lets the cross-region interactivity router find the region that owns the click.+ value = json.dumps({"integration_id": integration_id, "feature": tip.feature.value})+ buttons: list[dict[str, Any]] = []+ cta = tip.cta(ctx)+ if cta is not None:+ extra = {"style": "primary", **({"url": cta.url} if cta.url else {})}+ buttons.append(_button(FEATURE_TIP_CTA_ACTION_ID, cta.label, value, **extra))+ buttons.append(_button(FEATURE_TIP_DISMISS_ACTION_ID, "Not now", value))+ buttons.append(_button(FEATURE_TIP_OPT_OUT_ACTION_ID, "Don't show tips", value))+ return [+ section_block(f"💡 *Tip: {tip.title}*\n{tip.emoji} {body}"),+ {"type": "actions", "elements": buttons},+ ]diff --git a/products/slack_app/backend/logic/feature_tips/picker.py b/products/slack_app/backend/logic/feature_tips/picker.pynew file mode 100644index 000000000000..6ecc05bb6b9d--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/picker.py@@ -0,0 +1,135 @@+"""Which feature a tip promotes, when more than one is a candidate.++Jev, a System One decision model, reads the person's message and picks the feature that fits it,+or ``none``. Below the confidence threshold, on ``none``, or on any failure, the candidate with+the lowest rank wins. A tip does not have to match the message, so the model only orders the+candidates and never decides whether a tip goes out.+"""++from __future__ import annotations++from collections.abc import Sequence+from typing import Literal++import structlog++from posthog.dataclasses import frozen+from posthog.llm.managed_decision_model import DEFAULT_DECISION_MODEL+from posthog.llm.system_one import ChoiceAnswer, ChoiceQuestion+from posthog.llm.system_one_client import GATEWAY_MAX_CHOICE_OPTIONS, build_system_one_client++from products.slack_app.backend.logic.feature_tips.catalog import TipFeature+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.temporal.activities.classifiers import CLASSIFIER_PROPERTY++logger = structlog.get_logger(__name__)++FEATURE_TIP_DECISION_MODEL = DEFAULT_DECISION_MODEL+# Not the `slack_app` product the other classifiers bill under: a tip promotes PostHog, so it+# must not spend the team's AI credits.+FEATURE_TIP_AI_PRODUCT = "slack_app_feature_tip"+# The answer is already in the thread. A slow call only delays the tip, so it is not worth waiting for.+FEATURE_TIP_TIMEOUT_SECONDS = 5.0+# Tuned in products/slack_app/evals/eval_feature_tip_picker.py.+FEATURE_TIP_MIN_CONFIDENCE = 0.6+FEATURE_TIP_QUESTION_ID = "feature_tip"+NO_FEATURE = "none"+# The model needs the request, not the whole message. This also keeps pasted logs out of the call.+FEATURE_TIP_MESSAGE_MAX_CHARS = 500+# `none` takes one of the options the gateway accepts.+FEATURE_TIP_MAX_CANDIDATES = GATEWAY_MAX_CHOICE_OPTIONS - 1++FEATURE_TIP_INSTRUCTIONS = (+ "`message` is what a person asked the PostHog assistant in Slack. "+ "Pick the assistant feature that would help this person most with this kind of request. "+ "Pick `none` when no feature in the list relates to the message. "+ "Do not pick a feature only because it is generally useful."+)+NO_FEATURE_CRITERIA = "No feature in the list relates to what the message asks for."+++@frozen+class FeatureTipVerdict:+ choice: str+ confidence: float+++@frozen+class TipChoice:+ feature: SlackFeature+ source: Literal["contextual", "ranked"]+ confidence: float | None = None+++def classify_feature_tip(+ message: str,+ candidates: Sequence[TipFeature],+ *,+ team_id: int,+ distinct_id: str | None,+ trace_id: str | None = None,+) -> FeatureTipVerdict | None:+ """Ask the decision model which candidate fits the message. ``None`` means no verdict.++ Raises when no System One server is configured or the call fails, so the caller can tell+ an outage from a refusal.+ """+ text = message.strip()[:FEATURE_TIP_MESSAGE_MAX_CHARS]+ if not text or not candidates:+ return None+ candidates = sorted(candidates, key=lambda tip: tip.rank)[:FEATURE_TIP_MAX_CANDIDATES]+ # No TypeSafe fallback: the message is customer text, and TypeSafe is a third party.+ client = build_system_one_client(+ model=FEATURE_TIP_DECISION_MODEL,+ ai_product=FEATURE_TIP_AI_PRODUCT,+ team_id=team_id,+ distinct_id=distinct_id,+ trace_id=trace_id,+ properties={CLASSIFIER_PROPERTY: "feature_tip"},+ timeout=FEATURE_TIP_TIMEOUT_SECONDS,+ )+ result = client.decide(+ state={"message": text},+ questions={+ FEATURE_TIP_QUESTION_ID: ChoiceQuestion(+ instructions=FEATURE_TIP_INSTRUCTIONS,+ criteria={+ **{tip.feature.value: tip.choice_criteria for tip in candidates},+ NO_FEATURE: NO_FEATURE_CRITERIA,+ },+ )+ },+ )+ answer = result.answers.get(FEATURE_TIP_QUESTION_ID)+ if not isinstance(answer, ChoiceAnswer):+ logger.info("slack_app_feature_tip_refused")+ return None+ return FeatureTipVerdict(choice=answer.choice, confidence=answer.confidence)+++def choose_tip(+ candidates: Sequence[TipFeature],+ message: str | None,+ *,+ team_id: int,+ distinct_id: str | None,+ trace_id: str | None = None,+) -> TipChoice | None:+ if not candidates:+ return None+ ranked = min(candidates, key=lambda tip: tip.rank)+ if len(candidates) == 1 or not message:+ return TipChoice(feature=ranked.feature, source="ranked")+ try:+ verdict = classify_feature_tip(message, candidates, team_id=team_id, distinct_id=distinct_id, trace_id=trace_id)+ except Exception:+ logger.warning("slack_app_feature_tip_classifier_failed", exc_info=True)+ verdict = None+ by_value = {tip.feature.value: tip for tip in candidates}+ if verdict is not None and verdict.choice in by_value and verdict.confidence >= FEATURE_TIP_MIN_CONFIDENCE:+ return TipChoice(feature=by_value[verdict.choice].feature, source="contextual", confidence=verdict.confidence)+ return TipChoice(+ feature=ranked.feature,+ source="ranked",+ confidence=verdict.confidence if verdict is not None else None,+ )diff --git a/products/slack_app/backend/logic/feature_tips/state.py b/products/slack_app/backend/logic/feature_tips/state.pynew file mode 100644index 000000000000..521d9f5b9901--- /dev/null+++ b/products/slack_app/backend/logic/feature_tips/state.py@@ -0,0 +1,124 @@+"""What one Slack user did with the Slack app features: used them, saw a tip, or dismissed it.++The state lives in ``SlackSettings.feature_tips`` on the user's personal row, so it exists before+the user links a PostHog account.+"""++from __future__ import annotations++from collections.abc import Callable+from datetime import datetime+from typing import Literal++from django.db import transaction+from django.utils import timezone++import structlog+from pydantic import BaseModel, ValidationError++from products.slack_app.backend.models import SlackSettings++logger = structlog.get_logger(__name__)++TipSource = Literal["tip", "onboarding"]+++class TipRecord(BaseModel):+ first_shown_at: datetime+ times_shown: int = 1+ source: TipSource = "tip"+ clicked_at: datetime | None = None+ dismissed_at: datetime | None = None+++class FeatureTipsState(BaseModel):+ version: int = 1+ backfilled_at: datetime | None = None+ interaction_count: int = 0+ # Keys are ``SlackFeature`` values. Plain strings, so a feature removed from the catalog+ # does not make the stored state fail to parse.+ used: dict[str, datetime] = {}+ shown: dict[str, TipRecord] = {}+ opted_out_at: datetime | None = None+ last_shown_at: datetime | None = None+++def parse_state(raw: object) -> FeatureTipsState:+ if not raw:+ return FeatureTipsState()+ try:+ return FeatureTipsState.model_validate(raw)+ except ValidationError:+ # A broken row must not block tips forever. Starting again shows a tip at most once more.+ logger.warning("slack_app_feature_tips_state_invalid")+ return FeatureTipsState()+++def get_state(slack_workspace_id: str, slack_user_id: str) -> FeatureTipsState:+ raw = (+ SlackSettings.objects.filter(slack_workspace_id=slack_workspace_id, slack_user_id=slack_user_id)+ .values_list("feature_tips", flat=True)+ .first()+ )+ return parse_state(raw)+++def update_state(+ slack_workspace_id: str, slack_user_id: str, change: Callable[[FeatureTipsState], None]+) -> FeatureTipsState:+ """Apply ``change`` to the stored state under a row lock, so two writers never lose an update.++ The lock is on the user's own settings row. Keep ``change`` free of network calls, because+ the row stays locked until it returns.+ """+ with transaction.atomic():+ settings, _ = SlackSettings.objects.select_for_update().get_or_create(+ slack_workspace_id=slack_workspace_id, slack_user_id=slack_user_id+ )+ state = parse_state(settings.feature_tips)+ change(state)+ settings.feature_tips = state.model_dump(mode="json")+ settings.save(update_fields=["feature_tips", "updated_at"])+ return state+++def mark_used(slack_workspace_id: str, slack_user_id: str, feature: str) -> None:+ def change(state: FeatureTipsState) -> None:+ state.used.setdefault(feature, timezone.now())++ update_state(slack_workspace_id, slack_user_id, change)+++def record_feature_used(slack_workspace_id: str, slack_user_id: str | None, feature: str) -> None:+ """Never raises, because it runs inside the code path of the feature itself.++ Checks the key in SQL first, so a feature used every day costs one indexed read after its first+ use, not a locked write.+ """+ if not slack_user_id:+ return+ try:+ if SlackSettings.objects.filter(+ slack_workspace_id=slack_workspace_id, slack_user_id=slack_user_id, feature_tips__used__has_key=feature+ ).exists():+ return+ mark_used(slack_workspace_id, slack_user_id, feature)+ except Exception:+ logger.warning("slack_app_feature_tips_record_used_failed", feature=feature, exc_info=True)+++def mark_shown(slack_workspace_id: str, slack_user_id: str, feature: str, source: TipSource) -> None:+ def change(state: FeatureTipsState) -> None:+ record_shown(state, feature, source, timezone.now())++ update_state(slack_workspace_id, slack_user_id, change)+++def record_shown(state: FeatureTipsState, feature: str, source: TipSource, now: datetime) -> None:+ record = state.shown.get(feature)+ if record is None:+ state.shown[feature] = TipRecord(first_shown_at=now, source=source)+ else:+ record.times_shown += 1+ if source == "tip":+ state.last_shown_at = nowdiff --git a/products/slack_app/backend/migrations/0023_slacksettings_feature_tips.py b/products/slack_app/backend/migrations/0023_slacksettings_feature_tips.pynew file mode 100644index 000000000000..3f998d4acbee--- /dev/null+++ b/products/slack_app/backend/migrations/0023_slacksettings_feature_tips.py@@ -0,0 +1,21 @@+# Generated by Django 5.2.18 on 2026-10-23 08:01++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("slack_app", "0022_thread_join_mode"),+ ]++ operations = [+ migrations.AddField(+ model_name="slacksettings",+ name="feature_tips",+ field=models.JSONField(+ blank=True,+ help_text="Which Slack app features this user used, saw as a tip, or dismissed.",+ null=True,+ ),+ ),+ ]diff --git a/products/slack_app/backend/migrations/max_migration.txt b/products/slack_app/backend/migrations/max_migration.txtindex 28808c951e4d..054ba3619f39 100644--- a/products/slack_app/backend/migrations/max_migration.txt+++ b/products/slack_app/backend/migrations/max_migration.txt@@ -1 +1 @@-0022_thread_join_mode+0023_slacksettings_feature_tipsdiff --git a/products/slack_app/backend/models.py b/products/slack_app/backend/models.pyindex dd9cea8def0f..c3c1fc7ec2d5 100644--- a/products/slack_app/backend/models.py+++ b/products/slack_app/backend/models.py@@ -250,6 +250,13 @@ class SlackSettings(UUIDModel):blank=True,help_text="Let PostHog pick the model for each new task this user starts from Slack.",)+ # Only read on a personal row. NULL means feature tips never evaluated this user.+ # The shape is ``FeatureTipsState`` in ``logic/feature_tips/state.py``.+ feature_tips = models.JSONField(+ null=True,+ blank=True,+ help_text="Which Slack app features this user used, saw as a tip, or dismissed.",+ )created_at = models.DateTimeField(auto_now_add=True)updated_at = models.DateTimeField(auto_now=True)diff --git a/products/slack_app/backend/services/inbox_interactivity.py b/products/slack_app/backend/services/inbox_interactivity.pyindex f03ac6fc0526..0d1f0e104071 100644--- a/products/slack_app/backend/services/inbox_interactivity.py+++ b/products/slack_app/backend/services/inbox_interactivity.py@@ -18,6 +18,8 @@ import structlogfrom posthog.models.integration import Integrationfrom products.slack_app.backend import inbox_channel, onboarding+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.services import slack_welcome_messageslogger = structlog.get_logger(__name__)@@ -134,6 +136,7 @@ def handle_inbox_join(payload: dict) -> HttpResponse:return HttpResponse(status=200)if inbox_channel.invite_user_to_inbox(integration, channel[0], slack_user_id):+ record_feature_used(integration.integration_id, slack_user_id, SlackFeature.INBOX_CHANNEL)dm_channel = payload.get("channel", {}).get("id") or payload.get("container", {}).get("channel_id")message_ts = payload.get("message", {}).get("ts")if dm_channel and message_ts:diff --git a/products/slack_app/backend/services/slack_app_home.py b/products/slack_app/backend/services/slack_app_home.pyindex 8b4cacbcc74f..f7602ed0112b 100644--- a/products/slack_app/backend/services/slack_app_home.py+++ b/products/slack_app/backend/services/slack_app_home.py@@ -39,6 +39,8 @@ from products.slack_app.backend.feature_flags import (is_slack_app_oauth_enabled,is_slack_app_unprompted_answers_enabled,)+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.models import (ChannelWelcomeMode,SlackSettings,@@ -1740,6 +1742,7 @@ def handle_app_home_opened(event: dict, slack_team_id: str, *, integration: Inteslack_user_id=slack_user_id,slack_team_id=slack_team_id,)+ record_feature_used(slack_team_id, slack_user_id, SlackFeature.APP_HOME_TASKS)capture_slack_event(integration,"slack app home opened",diff --git a/products/slack_app/backend/services/slack_messages.py b/products/slack_app/backend/services/slack_messages.pyindex 890fe8f3020d..56fa486630a5 100644--- a/products/slack_app/backend/services/slack_messages.py+++ b/products/slack_app/backend/services/slack_messages.py@@ -1007,7 +1007,7 @@ def context_block(text: str) -> dict[str, Any]:return {"type": "context", "elements": [{"type": "mrkdwn", "text": text}]}-def app_home_url(integration: Integration) -> str | None:+def app_home_url(integration: Integration, *, tab: str = "home") -> str | None:"""Deep link to this install's Home tab, where the model picker lives.The native `slack://` form rather than the https `app_redirect` one: the reader is@@ -1021,7 +1021,7 @@ def app_home_url(integration: Integration) -> str | None:app_id = (integration.config or {}).get("app_id")if not app_id or not integration.integration_id:return None- return f"slack://app?team={integration.integration_id}&id={app_id}&tab=home"+ return f"slack://app?team={integration.integration_id}&id={app_id}&tab={tab}"def personal_integrations_url(team_id: int) -> str:diff --git a/products/slack_app/backend/services/slack_scopes.py b/products/slack_app/backend/services/slack_scopes.pyindex 0d13cebcef90..d691ba8369d9 100644--- a/products/slack_app/backend/services/slack_scopes.py+++ b/products/slack_app/backend/services/slack_scopes.py@@ -33,6 +33,10 @@ REQUIRED_SLACK_SCOPES: frozenset[str] = frozenset()+SLACK_FILE_SCOPE = "files:write"+SLACK_CANVAS_SCOPE = "canvases:write"++def has_scopes(integration: Integration, required: Iterable[str]) -> bool:"""Whether the install granted these bot scopes. Fails closed, so an install whosegranted set can't be read never enables anything."""diff --git a/products/slack_app/backend/services/turn_feedback.py b/products/slack_app/backend/services/turn_feedback.pyindex 253a2db14372..41badbba9a14 100644--- a/products/slack_app/backend/services/turn_feedback.py+++ b/products/slack_app/backend/services/turn_feedback.py@@ -32,6 +32,8 @@ from posthog.event_usage import groupsfrom posthog.models.integration import Integration, SlackIntegrationfrom products.slack_app.backend.analytics import slack_event_props+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.services.slack_messages import SLACK_WEBHOOK_TIMEOUT_SECONDS, TURN_FEEDBACK_ACTION_IDfrom products.slack_app.backend.services.slack_user_info import get_cached_bot_user_id@@ -388,6 +390,9 @@ def handle_turn_feedback_click(payload: dict) -> HttpResponse:# resolves the clicker's identity against the database on its way out.if sentiment == "negative":_open_reason_modal(payload, target)+ record_feature_used(+ target.integration.integration_id, payload.get("user", {}).get("id"), SlackFeature.ANSWER_RATING+ )_capture(target,"$ai_metric",@@ -557,4 +562,5 @@ def handle_reaction_added(event: dict, slack_team_id: str, workspace_integration"reaction": _reaction_base(reaction),},)+ record_feature_used(integration.integration_id, event.get("user"), SlackFeature.ANSWER_RATING)return REACTION_HANDLEDdiff --git a/products/slack_app/backend/slack_link_unfurl.py b/products/slack_app/backend/slack_link_unfurl.pyindex 7adc6e8347f1..d6c36d4c83fa 100644--- a/products/slack_app/backend/slack_link_unfurl.py+++ b/products/slack_app/backend/slack_link_unfurl.py@@ -55,6 +55,8 @@ from products.product_analytics.backend.facade.models import Insightfrom products.signals.backend.models import SignalReportfrom products.signals.backend.report_access import may_read_reportsfrom products.slack_app.backend.analytics import capture_slack_event+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.logic.link_unfurl_charts import (UNFURL_IMAGE_ASSET_TTL,UNFURL_IMAGE_URL_TTL,@@ -1364,7 +1366,8 @@ def handle_posthog_link_unfurl(event: dict, integration: Integration) -> None:from products.slack_app.backend.api import SLACK_PLACEHOLDER_USER_ID, resolve_slack_userbot_authors = {SLACK_PLACEHOLDER_USER_ID, get_cached_bot_user_id(slack, integration)}- bot_reply_actor = _bot_reply_actor(integration, event) if slack_user_id in bot_authors else None+ shared_by_person = slack_user_id not in bot_authors+ bot_reply_actor = None if shared_by_person else _bot_reply_actor(integration, event)if bot_reply_actor:slack_user_id = bot_reply_actor# Everything downstream, the chart workflow included, reads the sharer from the event.@@ -1505,6 +1508,8 @@ def handle_posthog_link_unfurl(event: dict, integration: Integration) -> None:integration=integration, user=user, event=event, unfurls=unfurls, url=first_url, title=first_card.title))+ if shared_by_person:+ record_feature_used(integration.integration_id, slack_user_id, SlackFeature.INSIGHT_UNFURL)capture_slack_event(integration,"slack app link unfurled",diff --git a/products/slack_app/backend/slack_thread.py b/products/slack_app/backend/slack_thread.pyindex 2503c5772067..a421ed54dcd7 100644--- a/products/slack_app/backend/slack_thread.py+++ b/products/slack_app/backend/slack_thread.py@@ -16,6 +16,7 @@ from posthog.slack.markdown import SLACK_MARKDOWN_TEXT_MAX_LEN, slack_markdown_bfrom products.slack_app.backend.analytics import capture_slack_event, slack_session_idfrom products.slack_app.backend.feature_flags import is_slack_app_forking_enabled+from products.slack_app.backend.logic.feature_tips.offer import TipRequest, offer_feature_tipfrom products.slack_app.backend.logic.reply_suggestions import (ReplySuggestionAttribution,SuggestedReply,@@ -555,7 +556,7 @@ class SlackThreadHandler:append_attachments: Callable[[], None] | None = None,mention_sent: bool = False,reply_suggestions_for: str | None = None,- ) -> None:+ ) -> bool:"""Final flush: mark the last plan-block step complete, stream the answer, then chat.stopStream.The answer starts with the @-mention, so the one notification lands with it. With no@@ -566,15 +567,19 @@ class SlackThreadHandler:With no stream timestamp, the answer goes out as an ordinary thread reply.When Slack already closed the stream, the answer also goes out as a plain thread reply,- and nothing else is sent to the closed stream."""+ and nothing else is sent to the closed stream.++ Returns whether the answer reached the thread.+ """if ts is None:self.stream_ended = True+ delivered = Falseif final_markdown:delivered = self._post_answer_outside_stream(final_markdown)if delivered:self.offer_reply_suggestions(reply_suggestions_for)self.capture_reply_posted(ReplyKind.ANSWER, delivered=delivered)- return+ return deliveredanswer_chunks: list[dict[str, Any]] = []if plan_title:answer_chunks.append(_plan_update_chunk(plan_title))@@ -600,6 +605,7 @@ class SlackThreadHandler:# A turn stopped before it answered still closes its stream, which then holds only status lines.if final_markdown or mention_sent:self.capture_reply_posted(ReplyKind.ANSWER, delivered=answer_delivered)+ return answer_delivereddef _close_stream(self,@@ -1121,6 +1127,24 @@ class SlackThreadHandler:run_id=self.run_footer.run_id,)+ def offer_feature_tip(self) -> None:+ if not self.actor_slack_user_id:+ return+ try:+ offer_feature_tip(+ TipRequest(+ integration=self._get_integration(),+ slack_user_id=self.actor_slack_user_id,+ posthog_user=self._actor_posthog_user,+ channel=self.context.channel,+ thread_ts=self.context.thread_ts,+ person_message=self.turn_person_message,+ trace_id=self.turn_trace_id,+ )+ )+ except Exception:+ logger.warning("slack_app_feature_tip_failed", exc_info=True)+def capture_reply_posted(self, reply_kind: ReplyKind, *, delivered: bool) -> None:"""Capture a reply the run posted to this thread, so a mention can be followed to its answer.diff --git a/products/slack_app/backend/temporal/activities/classifiers.py b/products/slack_app/backend/temporal/activities/classifiers.pyindex dd44c89206c0..0b4db1c9d1f6 100644--- a/products/slack_app/backend/temporal/activities/classifiers.py+++ b/products/slack_app/backend/temporal/activities/classifiers.py@@ -19,6 +19,8 @@ from products.slack_app.backend.facade.run_preferences import (find_model_choice,group_by_runtime,)+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.models import SlackThreadTaskMappingfrom products.slack_app.backend.prompt_templates import PromptTemplatesfrom products.slack_app.backend.services.integration_resolver import format_project_candidate_list, routable_projects@@ -619,6 +621,7 @@ def classify_slack_app_model_override_activity(input: SlackAppModelOverrideInput)if override is None:return None+ record_feature_used(input.slack_team_id, input.slack_user_id, SlackFeature.MODEL_IN_MENTION)logger.info("slack_app_model_override_classified",@@ -776,6 +779,7 @@ def classify_slack_app_project_route_activity(input: SlackAppProjectRouteInput)if chosen is None or chosen.id == integration.id:return None+ record_feature_used(input.slack_team_id, input.slack_user_id, SlackFeature.PROJECT_IN_MENTION)logger.info("slack_app_project_route_classified",integration_id=integration.id,diff --git a/products/slack_app/backend/temporal/activities/fork.py b/products/slack_app/backend/temporal/activities/fork.pyindex fe40af9e6bc9..5c6579de5037 100644--- a/products/slack_app/backend/temporal/activities/fork.py+++ b/products/slack_app/backend/temporal/activities/fork.py@@ -68,6 +68,8 @@ def process_slack_app_fork_thread_payload(payload: dict[str, Any]) -> None:from products.slack_app.backend.analytics import capture_slack_eventfrom products.slack_app.backend.api import SLACK_INTEGRATION_KIND, _channel_is_approvedfrom products.slack_app.backend.feature_flags import is_slack_app_forking_enabled+ from products.slack_app.backend.logic.feature_tips.features import SlackFeature+ from products.slack_app.backend.logic.feature_tips.state import record_feature_usedfrom products.slack_app.backend.models import SlackThreadTaskMappingfrom products.slack_app.backend.services.integration_resolver import load_integrations, resolve_user_for_workspacefrom products.slack_app.backend.services.slack_fork_context import PendingFork, store_pending_fork@@ -255,6 +257,7 @@ def process_slack_app_fork_thread_payload(payload: dict[str, Any]) -> None:# Reported as its own event rather than folded into the mention funnel: a fork is a# different intent and would otherwise inflate mention counts.+ record_feature_used(slack_team_id, slack_user_id, SlackFeature.FORK_THREAD)capture_slack_event(integration,"slack app fork created",diff --git a/products/slack_app/backend/temporal/slack_app_mention_processing.py b/products/slack_app/backend/temporal/slack_app_mention_processing.pyindex f09c2a7abb9a..476d2ab3219b 100644--- a/products/slack_app/backend/temporal/slack_app_mention_processing.py+++ b/products/slack_app/backend/temporal/slack_app_mention_processing.py@@ -266,6 +266,7 @@ def _model_override_input(inputs: PostHogCodeSlackMentionWorkflowInputs, thread_slack_team_id=inputs.slack_team_id,event_text=inputs.event.get("text", ""),thread_ts=thread_ts,+ slack_user_id=inputs.event.get("user") or None,)diff --git a/products/slack_app/backend/temporal/types.py b/products/slack_app/backend/temporal/types.pyindex 00c849024d96..e1c1bed84e93 100644--- a/products/slack_app/backend/temporal/types.py+++ b/products/slack_app/backend/temporal/types.py@@ -231,6 +231,9 @@ class SlackAppModelOverrideInput(BaseModel):slack_team_id: strevent_text: strthread_ts: str | None = None+ # Who sent the message, so a model named in it counts as a use of that feature. Trailing and+ # defaulted, so a task queued before this field existed still decodes.+ slack_user_id: str | None = Noneclass SlackAppModelOverride(BaseModel):diff --git a/products/slack_app/backend/tests/logic/test_feature_tips.py b/products/slack_app/backend/tests/logic/test_feature_tips.pynew file mode 100644index 000000000000..b4886d6cc862--- /dev/null+++ b/products/slack_app/backend/tests/logic/test_feature_tips.py@@ -0,0 +1,290 @@+import json+from datetime import timedelta++import pytest+from unittest.mock import MagicMock, patch++from django.apps import apps+from django.test import SimpleTestCase+from django.utils import timezone++from parameterized import parameterized++from posthog.llm.system_one import ChoiceAnswer, RefusalAnswer, SystemOneResult+from posthog.models.integration import Integration+from posthog.models.organization import Organization+from posthog.models.team.team import Team++from products.slack_app.backend.logic.feature_tips import catalog, interactivity, offer, picker+from products.slack_app.backend.logic.feature_tips.catalog import CATALOG+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.backend.logic.feature_tips.offer import TipRequest, offer_feature_tip+from products.slack_app.backend.logic.feature_tips.state import get_state, parse_state+from products.slack_app.backend.models import SlackSettings, SlackThreadTaskMapping, UntaggedFollowupMode++WORKSPACE = "T_TIPS"+SLACK_USER = "U_READER"+++class TestOfferFeatureTip:+ @pytest.fixture(autouse=True)+ def setup(self):+ organization = Organization.objects.create(name="Org")+ self.team = Team.objects.create(organization=organization, name="Team")+ # No linked PostHog user and no optional scopes, so the thread follow-up tip ranks first.+ self.integration = Integration.objects.create(+ team=self.team, kind="slack", integration_id=WORKSPACE, sensitive_config={"access_token": "xoxb-test"}+ )+ with (+ patch.object(offer, "is_slack_app_feature_tips_enabled", return_value=True) as self.flag,+ patch.object(offer, "post_slack_ephemeral") as self.post,+ patch.object(offer, "SlackIntegration"),+ patch.object(catalog, "is_slack_app_unprompted_answers_enabled", return_value=False),+ # The decision model is not reachable here, so every pick falls back to the ranked order.+ patch.object(picker, "build_system_one_client", side_effect=RuntimeError("no gateway")),+ ):+ yield++ def _threads(self, count: int) -> None:+ Task = apps.get_model("tasks", "Task")+ TaskRun = apps.get_model("tasks", "TaskRun")+ for index in range(count):+ task = Task.objects.create(team=self.team, title="t")+ SlackThreadTaskMapping.objects.create(+ team=self.team,+ integration=self.integration,+ slack_workspace_id=WORKSPACE,+ channel="C1",+ thread_ts=f"{index}.1",+ task=task,+ task_run=TaskRun.objects.create(team=self.team, task=task),+ mentioning_slack_user_id=SLACK_USER,+ )++ def _offer(self) -> SlackFeature | None:+ return offer_feature_tip(+ TipRequest(+ integration=self.integration,+ slack_user_id=SLACK_USER,+ posthog_user=None,+ channel="C1",+ thread_ts="1.1",+ person_message="how many signups last week?",+ )+ )++ def test_existing_user_gets_a_tip_at_the_first_answer_after_launch(self):+ self._threads(3)++ assert self._offer() == SlackFeature.THREAD_FOLLOWUP+ self.post.assert_called_once()+ assert get_state(WORKSPACE, SLACK_USER).shown[SlackFeature.THREAD_FOLLOWUP.value].times_shown == 1++ def test_new_user_gets_no_tip_before_the_third_interaction(self):+ self._threads(1)++ assert [self._offer(), self._offer(), self._offer()] == [None, None, SlackFeature.THREAD_FOLLOWUP]++ def test_at_most_one_tip_a_day_and_each_tip_only_once(self):+ self._threads(3)+ assert self._offer() == SlackFeature.THREAD_FOLLOWUP++ assert self._offer() is None+ state = get_state(WORKSPACE, SLACK_USER)+ state.last_shown_at = timezone.now() - timedelta(days=2)+ SlackSettings.objects.filter(slack_workspace_id=WORKSPACE, slack_user_id=SLACK_USER).update(+ feature_tips=state.model_dump(mode="json")+ )+ second = self._offer()+ assert second is not None and second != SlackFeature.THREAD_FOLLOWUP+ assert self.post.call_count == 2++ @parameterized.expand(+ [+ ("opted out", {"opted_out_at": "2026-01-01T00:00:00Z"}, None, None),+ (+ "chose a follow-up mode before tips existed",+ {},+ UntaggedFollowupMode.NEVER,+ SlackFeature.FILE_ATTACHMENTS,+ ),+ (+ "used a feature that leaves no setting",+ {"used": {"file_attachments": "2026-01-01T00:00:00Z"}},+ UntaggedFollowupMode.NEVER,+ SlackFeature.MODEL_IN_MENTION,+ ),+ ]+ )+ def test_skips_what_the_reader_turned_off_or_already_uses(self, _name, stored_state, followup_mode, expected):+ self._threads(3)+ SlackSettings.objects.create(+ slack_workspace_id=WORKSPACE,+ slack_user_id=SLACK_USER,+ untagged_followup_mode=followup_mode,+ feature_tips={"backfilled_at": "2026-01-01T00:00:00Z", "interaction_count": 5, **stored_state},+ )++ assert self._offer() == expected++ def test_flag_off_writes_nothing(self):+ self._threads(3)+ self.flag.return_value = False++ assert self._offer() is None+ assert not SlackSettings.objects.filter(slack_workspace_id=WORKSPACE, slack_user_id=SLACK_USER).exists()+++class TestCatalog(SimpleTestCase):+ def test_every_feature_has_a_tip_and_a_unique_rank(self):+ assert set(CATALOG) == set(SlackFeature)+ assert len({tip.rank for tip in CATALOG.values()}) == len(CATALOG)+ assert all(tip.emoji and tip.title for tip in CATALOG.values())+++class TestInboxChannelTarget(SimpleTestCase):+ @parameterized.expand(+ [+ (SlackThreadTaskMapping.ConversationType.PUBLIC_CHANNEL, "C1|#posthog-inbox"),+ (SlackThreadTaskMapping.ConversationType.PRIVATE_CHANNEL, None),+ (SlackThreadTaskMapping.ConversationType.UNKNOWN, None),+ ]+ )+ def test_only_a_public_inbox_channel_is_named_in_a_tip(self, conversation_type, expected):+ ctx = catalog.TipContext(+ integration=MagicMock(team_id=1),+ slack_user_id=SLACK_USER,+ posthog_user_id=None,+ channel="C2",+ settings=MagicMock(),+ )+ with (+ patch.object(catalog, "has_inbox_scopes", return_value=True),+ patch.object(catalog, "_get_team_channel", return_value="C1|#posthog-inbox"),+ patch.object(catalog, "SlackIntegration"),+ patch.object(catalog, "resolve_conversation_type", return_value=conversation_type),+ ):+ assert ctx.inbox_channel_target == expected+++class TestInboxChannelJoin(SimpleTestCase):+ @parameterized.expand(+ [+ (SlackThreadTaskMapping.ConversationType.PUBLIC_CHANNEL, True),+ (SlackThreadTaskMapping.ConversationType.PRIVATE_CHANNEL, False),+ ]+ )+ def test_join_rechecks_that_the_channel_is_still_public(self, conversation_type, invited):+ with (+ patch.object(catalog, "ensure_inbox_channel", return_value=("C1", "#posthog-inbox")),+ patch.object(catalog, "SlackIntegration"),+ patch.object(catalog, "resolve_conversation_type", return_value=conversation_type),+ patch.object(catalog, "invite_user_to_inbox", return_value=True) as invite,+ ):+ CATALOG[SlackFeature.INBOX_CHANNEL].apply_action(MagicMock(), SLACK_USER)++ assert invite.called is invited+++class TestChooseTip(SimpleTestCase):+ candidates = [CATALOG[SlackFeature.SUBSCRIPTION], CATALOG[SlackFeature.CODE_CHANGE_PR]]++ @parameterized.expand(+ [+ (+ "confident match",+ ChoiceAnswer(choice="code_change_pr", confidence=0.9, probabilities={}),+ "code_change_pr",+ "contextual",+ ),+ (+ "low confidence",+ ChoiceAnswer(choice="code_change_pr", confidence=0.3, probabilities={}),+ "subscription",+ "ranked",+ ),+ ("no match", ChoiceAnswer(choice="none", confidence=0.95, probabilities={}), "subscription", "ranked"),+ (+ "not a candidate",+ ChoiceAnswer(choice="mcp_tool", confidence=0.95, probabilities={}),+ "subscription",+ "ranked",+ ),+ ("refusal", RefusalAnswer(), "subscription", "ranked"),+ ]+ )+ def test_the_model_orders_but_never_blocks(self, _name, answer, expected_feature, expected_source):+ client = MagicMock()+ client.decide.return_value = SystemOneResult(+ model="jev", answers={picker.FEATURE_TIP_QUESTION_ID: answer}, input_tokens=None+ )+ with patch.object(picker, "build_system_one_client", return_value=client):+ choice = picker.choose_tip(self.candidates, "fix the checkout error", team_id=1, distinct_id=None)++ assert choice is not None+ assert (choice.feature.value, choice.source) == (expected_feature, expected_source)++ def test_an_outage_falls_back_to_the_ranked_tip(self):+ with patch.object(picker, "build_system_one_client", side_effect=RuntimeError("gateway down")):+ choice = picker.choose_tip(self.candidates, "fix the checkout error", team_id=1, distinct_id=None)++ assert choice is not None+ assert (choice.feature, choice.source) == (SlackFeature.SUBSCRIPTION, "ranked")+++class TestFeatureTipClicks:+ @pytest.fixture(autouse=True)+ def setup(self):+ organization = Organization.objects.create(name="Org")+ team = Team.objects.create(organization=organization, name="Team")+ self.integration = Integration.objects.create(+ team=team, kind="slack", integration_id=WORKSPACE, sensitive_config={"access_token": "xoxb-test"}+ )+ with patch.object(interactivity, "post_response_url") as self.respond:+ yield++ def _click(self, action_id: str, feature: str, slack_team_id: str = WORKSPACE) -> None:+ interactivity.handle_feature_tip_action(+ {+ "user": {"id": SLACK_USER},+ "team": {"id": slack_team_id},+ "response_url": "https://hooks.slack.com/actions/x",+ "actions": [+ {+ "action_id": action_id,+ "value": json.dumps({"integration_id": self.integration.id, "feature": feature}),+ }+ ],+ }+ )++ def _settings(self) -> SlackSettings | None:+ return SlackSettings.objects.filter(slack_workspace_id=WORKSPACE, slack_user_id=SLACK_USER).first()++ @parameterized.expand(+ [+ (SlackFeature.THREAD_FOLLOWUP, "untagged_followup_mode", UntaggedFollowupMode.AUTO),+ (SlackFeature.AUTO_MODEL_CHOICE, "auto_model_choice", True),+ (SlackFeature.UNPROMPTED_ANSWERS, "untagged_question_mode", UntaggedFollowupMode.AUTO),+ ]+ )+ def test_action_cta_turns_the_setting_on(self, feature, column, expected):+ self._click(offer.FEATURE_TIP_CTA_ACTION_ID, feature.value)++ settings = self._settings()+ assert settings is not None+ assert getattr(settings, column) == expected+ assert feature.value in parse_state(settings.feature_tips).used++ def test_opt_out_stops_all_tips(self):+ self._click(offer.FEATURE_TIP_OPT_OUT_ACTION_ID, SlackFeature.SUBSCRIPTION.value)++ assert get_state(WORKSPACE, SLACK_USER).opted_out_at is not None++ def test_a_click_from_another_workspace_changes_nothing(self):+ self._click(offer.FEATURE_TIP_OPT_OUT_ACTION_ID, SlackFeature.SUBSCRIPTION.value, slack_team_id="T_OTHER")++ assert self._settings() is None+ self.respond.assert_called_once_with("https://hooks.slack.com/actions/x", {"delete_original": True})diff --git a/products/slack_app/evals/eval_feature_tip_picker.py b/products/slack_app/evals/eval_feature_tip_picker.pynew file mode 100644index 000000000000..0576368857ed--- /dev/null+++ b/products/slack_app/evals/eval_feature_tip_picker.py@@ -0,0 +1,168 @@+"""Which feature tip fits a message the person sent to PostHog in Slack?++`no_forced_tip` is the number to watch: a tip that claims to fit a message it does not fit reads+as an ad. A missed match only costs the ranked tip, which is still a valid tip.++To run:+ hogli evals eval_feature_tip_picker+ hogli evals eval_feature_tip_picker --eval fix_checkout_error+"""++from __future__ import annotations++import asyncio++from products.posthog_ai.eval_harness.config import BaseEvalCase+from products.posthog_ai.eval_harness.harness.context import EvalContext+from products.posthog_ai.eval_harness.harness.requirements import SuiteKind+from products.posthog_ai.eval_harness.one_shot import OneShotPublicEval+from products.slack_app.backend.logic.feature_tips import picker+from products.slack_app.backend.logic.feature_tips.catalog import CATALOG+from products.slack_app.backend.logic.feature_tips.features import SlackFeature+from products.slack_app.evals.offline_config import offline_suite+from products.slack_app.evals.scorers import FEATURE_TIP_KEY, FeatureTipMatch, NoForcedTip++SUITE_KIND = SuiteKind.ONE_SHOT++ALL_FEATURES = [feature.value for feature in SlackFeature]+++def _case(name: str, prompt: str, expected: str, candidates: list[str] | None = None) -> BaseEvalCase:+ return BaseEvalCase(+ name=name,+ prompt=prompt,+ expected={FEATURE_TIP_KEY: {"feature": expected}},+ metadata={"candidates": candidates or ALL_FEATURES},+ )+++MATCH_CASES = [+ _case("fix_checkout_error", "can you fix the TypeError on the checkout page?", "code_change_pr"),+ _case("add_tracking", "we don't track when people export a file, can you add an event for it?", "code_change_pr"),+ _case("weekly_signups", "what were our signups this week compared to last week?", "subscription"),+ _case("monday_numbers", "give me the weekly active users number, I need it for the Monday update", "subscription"),+ _case("linear_ticket", "look at the bug in our Linear ticket about broken uploads", "mcp_tool"),+ _case("notion_spec", "compare the funnel with what the onboarding spec in Notion says", "mcp_tool"),+ _case("follow_up", "and what about the same numbers for mobile?", "thread_followup"),+ _case(+ "one_customer_revenue", "how much revenue did we get from our biggest customer last quarter?", "direct_message"+ ),+]++# A reader rarely qualifies for every feature, so these cases pass the short lists a real reader gets.+NEW_FEATURE_CASES = [+ _case(+ "screenshot_of_bug",+ "the chart on my screen shows a gap on Tuesday, why?",+ "file_attachments",+ ["file_attachments", "subscription", "model_in_mention"],+ ),+ _case(+ "export_rows",+ "give me a list of all users who churned last month with their plan",+ "file_outputs",+ ["file_outputs", "thread_followup", "answer_rating"],+ ),+ _case(+ "error_spike_watch",+ "did we get any new errors after yesterday's deploy?",+ "inbox_channel",+ ["inbox_channel", "subscription", "app_home_tasks"],+ ),+ _case(+ "named_project",+ "for the mobile app, how many people opened the settings screen?",+ "project_in_mention",+ ["project_in_mention", "file_outputs", "answer_rating"],+ ),+ _case(+ "deep_investigation",+ "do a deep investigation into why retention dropped for the March cohort, take your time",+ "model_in_mention",+ ["model_in_mention", "insight_unfurl", "reply_suggestions"],+ ),+ _case(+ "earlier_task_status",+ "is the pull request you started this morning done yet?",+ "app_home_tasks",+ ["app_home_tasks", "file_attachments", "insight_unfurl"],+ ),+ _case(+ "share_a_chart",+ "I want to share the signup trend chart with the team here",+ "insight_unfurl",+ ["insight_unfurl", "direct_message", "answer_rating"],+ ),+ _case(+ "wrong_answer",+ "that number you gave me before was wrong, it should be much higher",+ "answer_rating",+ ["answer_rating", "file_outputs", "app_home_project"],+ ),+]++NO_MATCH_CASES = [+ _case("plain_count", "how many people visited the pricing page yesterday?", "none", ["code_change_pr", "mcp_tool"]),+ _case("flag_state", "is the new-onboarding flag rolled out to everyone?", "none", ["mcp_tool", "direct_message"]),+ # The obvious feature is not a candidate, so the model must not pick a near one.+ _case(+ "bug_without_pr_candidate", "fix the null error in the signup form", "none", ["subscription", "direct_message"]+ ),+ _case("recurring_without_subscription", "send me signups every Monday", "none", ["code_change_pr", "mcp_tool"]),+ # Near misses: the message mentions an app or an error but names no project and asks for no code change.+ _case(+ "app_without_project_name",+ "how many people opened the app yesterday?",+ "none",+ ["project_in_mention", "file_outputs"],+ ),+ _case(+ "error_count_without_fix",+ "how many users hit the TypeError on checkout this week?",+ "none",+ ["code_change_pr", "direct_message"],+ ),+]+++async def eval_feature_tip_picker(ctx: EvalContext) -> None:+ async def task(case: BaseEvalCase, task_ctx: EvalContext) -> dict:+ model = picker.FEATURE_TIP_DECISION_MODEL+ candidates = [CATALOG[SlackFeature(value)] for value in (case.metadata or {}).get("candidates", ALL_FEATURES)]+ if task_ctx.demo_data is None:+ return {"decision_model": model, "feature": None, "error": "No demo data team to bill the call to"}+ try:+ verdict = await asyncio.to_thread(+ picker.classify_feature_tip,+ case.prompt,+ candidates,+ team_id=task_ctx.demo_data.master_team_id,+ distinct_id=None,+ )+ except Exception as error:+ return {"decision_model": model, "feature": None, "error": f"{type(error).__name__}: {error}"}+ # The same rule production applies: a pick below the threshold counts as no match.+ picked = (+ verdict.choice+ if verdict is not None and verdict.confidence >= picker.FEATURE_TIP_MIN_CONFIDENCE+ else picker.NO_FEATURE+ )+ return {+ "decision_model": model,+ "feature": picked,+ "verdict": {"choice": verdict.choice, "confidence": verdict.confidence} if verdict else None,+ "last_message": f"{model}: feature={picked}",+ }++ await OneShotPublicEval(+ experiment_name="slack-app-feature-tip-picker",+ offline_suite=offline_suite(+ "slack_app/eval_feature_tip_picker::eval_feature_tip_picker",+ metrics=[FEATURE_TIP_KEY, "no_forced_tip"],+ suite_kind=SUITE_KIND,+ ),+ cases=[*MATCH_CASES, *NEW_FEATURE_CASES, *NO_MATCH_CASES],+ scorers=[FeatureTipMatch(), NoForcedTip()],+ task=task,+ ctx=ctx,+ )diff --git a/products/slack_app/evals/offline_config.py b/products/slack_app/evals/offline_config.pyindex ae6c5fa1261b..a37ed60f777a 100644--- a/products/slack_app/evals/offline_config.py+++ b/products/slack_app/evals/offline_config.py@@ -5,6 +5,10 @@ from products.posthog_ai.eval_harness.harness.requirements import SuiteKindfrom products.posthog_ai.eval_harness.offline_results import OfflineEvalSuite, OfflineScorer_SCORERS: dict[str, dict[str, OfflineScorer]] = {+ "feature_tip_picker": {+ "feature_tip": OfflineScorer(kind="boolean", version=UUID("01a1692e-3104-7138-a33c-ab37d915ac6e")),+ "no_forced_tip": OfflineScorer(kind="boolean", version=UUID("01a1692e-3589-7893-a06a-e0f1893d8a19")),+ },"followup_classifier": {"exit_code_zero": OfflineScorer(kind="boolean", version=UUID("01a1557c-9b63-776a-91f3-113ab57c025a")),"followup_routing": OfflineScorer(kind="boolean", version=UUID("01a1557c-d1ca-7c68-96eb-5406fd8dde02")),diff --git a/products/slack_app/evals/scorers.py b/products/slack_app/evals/scorers.pyindex 256013109429..38c18295b958 100644--- a/products/slack_app/evals/scorers.py+++ b/products/slack_app/evals/scorers.py@@ -513,3 +513,50 @@ class NoUnaskedAnswer(Scorer):score=0.0 if (output or {}).get("answerable") else 1.0,metadata={"actual": (output or {}).get("answerable"), "verdict": (output or {}).get("verdict")},)+++FEATURE_TIP_KEY = "feature_tip"+++class FeatureTipMatch(Scorer):+ def _name(self) -> str:+ return FEATURE_TIP_KEY++ def _run_eval_sync(self, output: dict | None, expected=None, **kwargs) -> Score:+ want = (expected or {}).get(FEATURE_TIP_KEY) or {}+ if "feature" not in want:+ return Score(name=self._name(), score=None, metadata={"reason": "No expectation for this case"})+ if output and output.get("error"):+ return Score(name=self._name(), score=0.0, metadata={"reason": output["error"]})++ got = (output or {}).get("feature")+ return Score(+ name=self._name(),+ score=1.0 if got == want["feature"] else 0.0,+ metadata={"expected": want["feature"], "actual": got, "verdict": (output or {}).get("verdict")},+ )+++class NoForcedTip(Scorer):+ """The expensive direction: a pick for a message that no candidate fits, which makes the tip read as an ad.++ Skips on cases with a real match, so the score reads as a rate over the messages that fit nothing.+ """++ def _name(self) -> str:+ return "no_forced_tip"++ def _run_eval_sync(self, output: dict | None, expected=None, **kwargs) -> Score:+ want = (expected or {}).get(FEATURE_TIP_KEY) or {}+ if want.get("feature") != "none":+ return Score(name=self._name(), score=None, metadata={"reason": "Case has a matching feature"})+ if output and output.get("error"):+ # A failed call picks nothing, this scorer's passing answer, so it would hide an outage.+ return Score(name=self._name(), score=None, metadata={"reason": output["error"]})++ got = (output or {}).get("feature")+ return Score(+ name=self._name(),+ score=1.0 if got == "none" else 0.0,+ metadata={"actual": got, "verdict": (output or {}).get("verdict")},+ )diff --git a/products/subscriptions/backend/facade/api.py b/products/subscriptions/backend/facade/api.pyindex 60618f8727b0..3ee47fe2c005 100644--- a/products/subscriptions/backend/facade/api.py+++ b/products/subscriptions/backend/facade/api.py@@ -115,6 +115,7 @@ __all__ = ["subscription_ids_in_team","unsubscribe","update_subscription",+ "user_has_slack_subscription","validate_re_enable","viewable_live_insight_id",]@@ -155,6 +156,11 @@ def subscription_ids_in_team(*, team_id: int, subscription_ids: Collection[int])return queries.subscription_ids_in_team(team_id=team_id, subscription_ids=subscription_ids)+def user_has_slack_subscription(*, team_id: int, user_id: int) -> bool:+ """Whether the user created a subscription that delivers to Slack in this team. A disabled one counts."""+ return queries.user_has_slack_subscription(team_id=team_id, user_id=user_id)++def delete_insight_subscriptions(*, project_id: int, insight_ids: Collection[int]) -> None:# nosemgrep: environment-model-scoped-by-project -- insights are project-level, so deleting one removes its subscriptions in every environmentfor subscription in Subscription.objects.filter(team__project_id=project_id, insight_id__in=insight_ids):diff --git a/products/subscriptions/backend/logic/queries.py b/products/subscriptions/backend/logic/queries.pyindex d229db7d71e1..b44735b9ddf8 100644--- a/products/subscriptions/backend/logic/queries.py+++ b/products/subscriptions/backend/logic/queries.py@@ -35,6 +35,15 @@ def subscription_ids_in_team(*, team_id: int, subscription_ids: Collection[int])return set(Subscription.objects.filter(team_id=team_id, id__in=subscription_ids).values_list("id", flat=True))+def user_has_slack_subscription(*, team_id: int, user_id: int) -> bool:+ return Subscription.objects.filter(+ team_id=team_id,+ created_by_id=user_id,+ target_type=Subscription.SubscriptionTarget.SLACK,+ deleted=False,+ ).exists()++def _active_subscriptions() -> QuerySet[Subscription]:# Callers pass the id of an artifact they already scoped to their team, and ids are unique, so# the lookup needs no team filter.diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex f2a98c5acafa..379bc1a555e5 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -6424,6 +6424,7 @@ def relay_task_run_message(message_id=message_id,trace_id=trace_id,offer_reply_suggestions=True,+ offer_feature_tip=True,)except Exception:logger.exception("task_run_relay_message_enqueue_failed", extra={"run_id": str(run.id)})diff --git a/products/tasks/backend/temporal/client.py b/products/tasks/backend/temporal/client.pyindex f867c3e3b90f..8b5008836277 100644--- a/products/tasks/backend/temporal/client.py+++ b/products/tasks/backend/temporal/client.py@@ -669,6 +669,7 @@ def execute_posthog_code_agent_relay_workflow(message_id: str | None = None,trace_id: str | None = None,offer_reply_suggestions: bool = False,+ offer_feature_tip: bool = False,) -> str:relay_id = relay_id or str(uuid.uuid4())workflow_id = f"posthog-code-agent-relay-{run_id}-{relay_id}"@@ -687,6 +688,7 @@ def execute_posthog_code_agent_relay_workflow(message_id=message_id,trace_id=trace_id,offer_reply_suggestions=offer_reply_suggestions,+ offer_feature_tip=offer_feature_tip,),id=workflow_id,id_reuse_policy=WorkflowIDReusePolicy.ALLOW_DUPLICATE,diff --git a/products/tasks/backend/temporal/process_task/activities/forward_pending_message.py b/products/tasks/backend/temporal/process_task/activities/forward_pending_message.pyindex 81a4f775bb87..d53122f42b29 100644--- a/products/tasks/backend/temporal/process_task/activities/forward_pending_message.py+++ b/products/tasks/backend/temporal/process_task/activities/forward_pending_message.py@@ -272,6 +272,7 @@ def _enqueue_pending_reply_relay(task_run: Any, user_message_ts: str | None, comuser_message_ts=user_message_ts,trace_id=_extract_trace_id_from_command_result(command_result_data),offer_reply_suggestions=is_agent_answer,+ offer_feature_tip=is_agent_answer,)except Exception:logger.exception("forward_pending_message_relay_enqueue_failed", run_id=str(task_run.id))diff --git a/products/tasks/backend/temporal/process_task/activities/slack_agent_design.py b/products/tasks/backend/temporal/process_task/activities/slack_agent_design.pyindex 51cffc7b829c..1496bddfc923 100644--- a/products/tasks/backend/temporal/process_task/activities/slack_agent_design.py+++ b/products/tasks/backend/temporal/process_task/activities/slack_agent_design.py@@ -169,6 +169,7 @@ def append_slack_agent_design_steps(input: AppendSlackAgentDesignStepsInput) ->@close_db_connectionsdef stop_slack_agent_design_stream(input: StopSlackAgentDesignStreamInput) -> None:"""Mark the last step complete, stream the answer and the turn's attachments, close, attach files."""+ from products.slack_app.backend.facade.api import SlackFeature, record_slack_feature_usedfrom products.slack_app.backend.slack_thread import SlackThreadContext, SlackThreadHandlerfrom products.tasks.backend.logic.services.living_artifacts import (SlackFileDeliveryResult,@@ -209,7 +210,7 @@ def stop_slack_agent_design_stream(input: StopSlackAgentDesignStreamInput) -> No))- handler.stop_status_stream(+ answer_delivered = handler.stop_status_stream(ts=input.ts,complete_task_id=input.complete_task_id,complete_task_title=input.complete_task_title,@@ -230,6 +231,11 @@ def stop_slack_agent_design_stream(input: StopSlackAgentDesignStreamInput) -> No)if handler.stream_ended and task_run is not None:# A closed stream takes no cards, so whatever is still pending posts under the answer as its own message.- deliver_pending_slack_file_artifacts(task_run)+ deliveries.append(deliver_pending_slack_file_artifacts(task_run))+ if any(delivery.delivered_count for delivery in deliveries):+ record_slack_feature_used(context.integration_id, handler.actor_slack_user_id, SlackFeature.FILE_OUTPUTS)+ # Last, so a file this answer delivered already counts as used when the tip is picked.+ if answer_delivered and input.answer_markdown is not None:+ handler.offer_feature_tip()except Exception as e:logger.warning("slack_app_stop_agent_design_stream_failed", error=str(e))diff --git a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.pyindex 73cbae6d67ab..fa4438062626 100644--- a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py+++ b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py@@ -368,6 +368,7 @@ class TestForwardPendingUserMessage(TestCase):user_message_ts="1234.5",trace_id="f960aead-b2af-4ee0-b0eb-630109a1b2a0",offer_reply_suggestions=True,+ offer_feature_tip=True,)run.refresh_from_db()assert "pending_user_message" not in run.statediff --git a/products/tasks/backend/temporal/slack_relay/activities.py b/products/tasks/backend/temporal/slack_relay/activities.pyindex a7e90b2d4bbf..50a03fceb956 100644--- a/products/tasks/backend/temporal/slack_relay/activities.py+++ b/products/tasks/backend/temporal/slack_relay/activities.py@@ -191,11 +191,15 @@ class RelaySlackMessageInput:trace_id: str | None = None# Set only for the agent's own answer, so a notice or a placeholder never gets reply buttons.offer_reply_suggestions: bool = False+ # Set only for the agent's own answer, so a notice or a placeholder never gets a feature tip.+ # Separate from the reply buttons, so turning those off for a surface leaves tips alone.+ offer_feature_tip: bool = False@activity.defn@close_db_connectionsdef relay_slack_message(input: RelaySlackMessageInput) -> None:+ from products.slack_app.backend.facade.api import SlackFeature, record_slack_feature_usedfrom products.slack_app.backend.models import SlackThreadTaskMappingfrom products.slack_app.backend.services.slack_messages import (leading_mention_prefix,@@ -325,6 +329,8 @@ def relay_slack_message(input: RelaySlackMessageInput) -> None:if has_pending_slack_files and not compose_with_charts:deliver_pending_slack_file_artifacts(task_run)handler.capture_reply_posted(ReplyKind.ANSWER, delivered=answer_delivered)+ if answer_delivered and has_pending_slack_files:+ record_slack_feature_used(mapping.integration_id, target, SlackFeature.FILE_OUTPUTS)if input.reaction_emoji is not None:handler.update_reaction(input.reaction_emoji)@@ -332,3 +338,5 @@ def relay_slack_message(input: RelaySlackMessageInput) -> None:# Last, because the model call behind it is the slowest step and the answer must not wait for it.if answer_delivered and input.offer_reply_suggestions:handler.offer_reply_suggestions(text)+ if answer_delivered and input.offer_feature_tip:+ handler.offer_feature_tip()diff --git a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py b/products/tasks/backend/temporal/slack_relay/tests/test_activities.pyindex 5d97d1b0e6d2..f9b9b3f74a1d 100644--- a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py+++ b/products/tasks/backend/temporal/slack_relay/tests/test_activities.py@@ -180,6 +180,31 @@ class TestRelaySlackMessage(TestCase):assert mock_post.call_args.args[0].turn_trace_id == trace_id+ @parameterized.expand(+ [+ ("tip without reply buttons", False, True, True),+ ("reply buttons without tip", True, False, False),+ ]+ )+ @patch("products.slack_app.backend.slack_thread.SlackThreadHandler.offer_feature_tip")+ @patch("products.slack_app.backend.slack_thread.SlackThreadHandler.offer_reply_suggestions")+ @patch("products.slack_app.backend.slack_thread.SlackThreadHandler.post_thread_message", return_value=True)+ @patch("products.slack_app.backend.slack_thread.SlackThreadHandler.delete_progress")+ def test_feature_tip_follows_its_own_flag(+ self, _name, offer_suggestions, offer_tip, tip_expected, _delete, _post, _suggestions, mock_tip+ ):+ relay_slack_message(+ RelaySlackMessageInput(+ run_id=str(self.task_run.id),+ relay_id=f"relay-tip-{offer_tip}",+ text="Done.",+ offer_reply_suggestions=offer_suggestions,+ offer_feature_tip=offer_tip,+ )+ )++ assert mock_tip.called is tip_expected+_RICH_ANSWER = "## Heading\n\n| a | b |\n| --- | --- |\n| 1 | 2 |\n\n- [ ] todo"@patch("products.slack_app.backend.slack_thread.SlackThreadHandler.post_thread_message")diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex 565fabd80797..5c80b8bd9451 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -8823,6 +8823,7 @@ class TestTaskRunAPI(BaseTaskAPITest):message_id=None,trace_id=expected_trace_id,offer_reply_suggestions=True,+ offer_feature_tip=True,)@parameterized.expand(@@ -8878,6 +8879,7 @@ class TestTaskRunAPI(BaseTaskAPITest):message_id=None,trace_id=None,offer_reply_suggestions=True,+ offer_feature_tip=True,)@patch("products.tasks.backend.temporal.client.execute_posthog_code_agent_relay_workflow")diff --git a/tach.toml b/tach.tomlindex 0a2df5c1ad2d..8426cd280244 100644--- a/tach.toml+++ b/tach.toml@@ -979,6 +979,9 @@ depends_on = ["products.exports",# Mention workflows check billing quota limits before they start a task."ee",+ # Feature tips skip MCP tools and Slack subscriptions that the reader already uses.+ "products.mcp_store",+ "products.subscriptions",]layer = "modules"