Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(slack-app): stop routing a site mention to its dev project (#116795)

Vojta Bartošbab92a26cc7e
diff --git a/posthog/temporal/ai/slack_app/activities/prompts/project_route.md.j2 b/posthog/temporal/ai/slack_app/activities/prompts/project_route.md.j2
index 47472fbcb0ad..dbaf35473dfe 100644
--- a/posthog/temporal/ai/slack_app/activities/prompts/project_route.md.j2
+++ b/posthog/temporal/ai/slack_app/activities/prompts/project_route.md.j2
@@ -11,6 +11,8 @@ Only these projects can be selected, and the id is the number:
Before you answer with an id, find the words in this message that name that project — its name, or its number. If you cannot point to them, the answer is null. A message that shares a subject with a project, or asks for work a project's team does, has not named it, however sure you are about whose desk it lands on.
+Those words have to name the whole project, not only part of its name. Projects often share a name and differ by a qualifier such as "development", "dev", "staging", "test", "sandbox" or "local", and that kind of project holds test traffic, not real users. A message that says only the shared part and leaves the qualifier off has not named the qualified project, even when no project on the list carries the shorter name. With a project called "Fernwood sandbox", "how many orders did Fernwood take today" names no project: it asks about the real product, and the default is where that data is.
+
A number counts only where it is written as a project: "in project 42", "for 42", or a `/project/42/` link. Messages carry counts, percentages, ids, version numbers and error codes, and any of them may happen to equal a project id. A bare number names no project, however exactly it matches.
Name a project when the message says where to look:
@@ -23,6 +25,7 @@ Answer with null when the project is the thing being worked on rather than the p
- "we should split staging and production" (a proposal about projects).
- "update the reply this agent sends", "fix the skill so it stops truncating" (a request to change the agent's own behaviour or output). The project whose team owns that work is not where the answer comes from, because the request asks for no data at all.
- A word that only happens to match a project name. With a project called "Website", "the website is down" names no project.
+ - A site, domain or app that the data is about. "On" a site says what to measure, not which project to read, unless a project carries exactly that name.
- "I already checked staging, look at the SDK instead" (an account of a place already ruled out — past tense is the tell).
- Two projects at once, as in "compare staging and production". One task answers from one project, and picking one of the two on a guess is worse than staying on the default.
diff --git a/posthog/temporal/tests/ai/slack_app/activities/__snapshots__/test_classify_slack_app_project_route.ambr b/posthog/temporal/tests/ai/slack_app/activities/__snapshots__/test_classify_slack_app_project_route.ambr
index 87cbbab33dfd..ac5536150680 100644
--- a/posthog/temporal/tests/ai/slack_app/activities/__snapshots__/test_classify_slack_app_project_route.ambr
+++ b/posthog/temporal/tests/ai/slack_app/activities/__snapshots__/test_classify_slack_app_project_route.ambr
@@ -15,6 +15,8 @@
Before you answer with an id, find the words in this message that name that project — its name, or its number. If you cannot point to them, the answer is null. A message that shares a subject with a project, or asks for work a project's team does, has not named it, however sure you are about whose desk it lands on.
+ Those words have to name the whole project, not only part of its name. Projects often share a name and differ by a qualifier such as "development", "dev", "staging", "test", "sandbox" or "local", and that kind of project holds test traffic, not real users. A message that says only the shared part and leaves the qualifier off has not named the qualified project, even when no project on the list carries the shorter name. With a project called "Fernwood sandbox", "how many orders did Fernwood take today" names no project: it asks about the real product, and the default is where that data is.
+
A number counts only where it is written as a project: "in project 42", "for 42", or a `/project/42/` link. Messages carry counts, percentages, ids, version numbers and error codes, and any of them may happen to equal a project id. A bare number names no project, however exactly it matches.
Name a project when the message says where to look:
@@ -27,6 +29,7 @@
- "we should split staging and production" (a proposal about projects).
- "update the reply this agent sends", "fix the skill so it stops truncating" (a request to change the agent's own behaviour or output). The project whose team owns that work is not where the answer comes from, because the request asks for no data at all.
- A word that only happens to match a project name. With a project called "Website", "the website is down" names no project.
+ - A site, domain or app that the data is about. "On" a site says what to measure, not which project to read, unless a project carries exactly that name.
- "I already checked staging, look at the SDK instead" (an account of a place already ruled out — past tense is the tell).
- Two projects at once, as in "compare staging and production". One task answers from one project, and picking one of the two on a guess is worse than staying on the default.
diff --git a/products/slack_app/evals/eval_project_classifier.py b/products/slack_app/evals/eval_project_classifier.py
index 5fe57e273f32..e9893db491a3 100644
--- a/products/slack_app/evals/eval_project_classifier.py
+++ b/products/slack_app/evals/eval_project_classifier.py
@@ -17,7 +17,7 @@ is the whole of the quality signal. Nothing downstream second-guesses the answer
model returns is an id the run is moved to.
Most cases run with the project the run is already on offered as the default, which is how
-a mention usually arrives. `NO_DEFAULT_CASES` repeats five of them with none, the shape a
+a mention usually arrives. `NO_DEFAULT_CASES` repeats some of them with none, the shape a
mention takes when the resolved install is one `routable_projects` drops. Same message on
either side, so a difference in the answers is the default's doing and nothing else.
@@ -103,7 +103,19 @@ CROWD = [
_project(team_id=52, integration_id=520, name="Statuspage"),
]
-WORKSPACES: dict[str, tuple[list[Integration], Integration]] = {"simple": (PROJECTS, MAIN), "crowded": (CROWD, MAIN)}
+# A third workspace, where the project the run is on carries the company's name and a
+# second project is named for the live site plus a qualifier. A message about the site
+# matches part of that second name, and the default's name not at all, so the partial
+# match pulls the answer into a project that holds only test traffic.
+NORTHWIND = _project(team_id=53, integration_id=530, name="Northwind")
+SITE_DEV = _project(team_id=54, integration_id=540, name="northwind.io development")
+SITES = [NORTHWIND, SITE_DEV, STAGING, AGENT_PLATFORM, MOBILE]
+
+WORKSPACES: dict[str, tuple[list[Integration], Integration]] = {
+ "simple": (PROJECTS, MAIN),
+ "crowded": (CROWD, MAIN),
+ "sites": (SITES, NORTHWIND),
+}
def _routes_to(project: Integration | None = None) -> dict:
@@ -114,6 +126,10 @@ def _in_the_crowd(**kwargs) -> BaseEvalCase:
return BaseEvalCase(metadata={"workspace": "crowded"}, **kwargs)
+def _beside_the_site(**kwargs) -> BaseEvalCase:
+ return BaseEvalCase(metadata={"workspace": "sites"}, **kwargs)
+
+
ROUTING_CASES = [
BaseEvalCase(
name="explicit_on_project",
@@ -358,11 +374,42 @@ CROWDED_ROUTING_CASES = [
),
]
+# The qualifier is what names the test project. Said in full or cut short, it still routes.
+SITE_ROUTING_CASES = [
+ _beside_the_site(
+ name="qualified_project_named_in_full",
+ prompt="@PostHog anything odd in the northwind.io development project since this morning's deploy?",
+ expected=_routes_to(SITE_DEV),
+ ),
+ _beside_the_site(
+ name="qualifier_written_short",
+ prompt="@PostHog check northwind.io dev for duplicate pageviews from the new tracker",
+ expected=_routes_to(SITE_DEV),
+ ),
+]
+
+# The site without its qualifier is the live product, which the default already holds.
+SITE_NO_ROUTE_CASES = [
+ _beside_the_site(
+ name="site_named_without_its_qualifier",
+ prompt="@PostHog are visitors actually opening the new command palette on northwind.io?",
+ expected=_routes_to(),
+ ),
+ _beside_the_site(
+ name="site_as_the_subject_without_its_qualifier",
+ prompt="@PostHog how many trials on northwind.io turned into paid plans last month?",
+ expected=_routes_to(),
+ ),
+]
+
# A mention normally arrives with the resolved project on offer as the default, but not
# always: `routable_projects` drops an install the bot cannot post into, and the project
# the run is on can be that one. The model then sees the list in the auth filter's own
# order and no sentence naming where it already is.
-_CASES_BY_NAME = {case.name: case for case in [*ROUTING_CASES, *NO_ROUTE_CASES, *CROWDED_ROUTING_CASES]}
+_CASES_BY_NAME = {
+ case.name: case
+ for case in [*ROUTING_CASES, *NO_ROUTE_CASES, *CROWDED_ROUTING_CASES, *SITE_ROUTING_CASES, *SITE_NO_ROUTE_CASES]
+}
def _without_a_default(name: str) -> BaseEvalCase:
@@ -389,6 +436,7 @@ NO_DEFAULT_CASES = [
"crowded_change_the_agents_own_wordiness",
"crowded_change_the_agents_reply",
"crowded_explicit_on_project",
+ "site_named_without_its_qualifier",
)
]
@@ -420,7 +468,14 @@ async def eval_project_classifier(ctx: EvalContext) -> None:
await OneShotPublicEval(
experiment_name="slack-app-project-classifier",
- cases=[*ROUTING_CASES, *CROWDED_ROUTING_CASES, *NO_ROUTE_CASES, *NO_DEFAULT_CASES],
+ cases=[
+ *ROUTING_CASES,
+ *CROWDED_ROUTING_CASES,
+ *SITE_ROUTING_CASES,
+ *NO_ROUTE_CASES,
+ *SITE_NO_ROUTE_CASES,
+ *NO_DEFAULT_CASES,
+ ],
scorers=[ProjectRouteMatch(), NoUnaskedProjectSwitch()],
task=task,
ctx=ctx,