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): show the project only where it tells the reader something (#103219)

Vojta Bartošdfb088bd72ed
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 b1f8d911c068..709f018af318 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
@@ -6,9 +6,9 @@ Only these projects can be selected, and the id is the number:
Most messages name no project at all, and null is the answer for those. Only name one when the message points at it.
Name a project when the message says where to look:
- - "check the error rate on Endpaper staging", "in the website project, why did signups drop", "for production, which exports failed yesterday".
+ - "check the error rate on Fernwood staging", "in the website project, why did signups drop", "for production, which exports failed yesterday".
- The project can be named anywhere in the sentence, and the rest of the message is still the request.
- - A project named as the place a problem lives is still where to look: "why is Endpaper production throwing 500s" is answered from Endpaper production. A project is usually the subject of the question AND the place the answer comes from.
+ - A project named as the place a problem lives is still where to look: "why is Fernwood production throwing 500s" is answered from Fernwood production. A project is usually the subject of the question AND the place the answer comes from.
Answer with null when the project is the thing being worked on rather than the place to look:
- "rename the Website project", "add staging to the project dropdown" (a project as the object of a change).
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 1d9c6e8b6b8d..9cafa4e0738b 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
@@ -10,9 +10,9 @@
Most messages name no project at all, and null is the answer for those. Only name one when the message points at it.
Name a project when the message says where to look:
- - "check the error rate on Endpaper staging", "in the website project, why did signups drop", "for production, which exports failed yesterday".
+ - "check the error rate on Fernwood staging", "in the website project, why did signups drop", "for production, which exports failed yesterday".
- The project can be named anywhere in the sentence, and the rest of the message is still the request.
- - A project named as the place a problem lives is still where to look: "why is Endpaper production throwing 500s" is answered from Endpaper production. A project is usually the subject of the question AND the place the answer comes from.
+ - A project named as the place a problem lives is still where to look: "why is Fernwood production throwing 500s" is answered from Fernwood production. A project is usually the subject of the question AND the place the answer comes from.
Answer with null when the project is the thing being worked on rather than the place to look:
- "rename the Website project", "add staging to the project dropdown" (a project as the object of a change).
diff --git a/products/slack_app/backend/services/integration_resolver.py b/products/slack_app/backend/services/integration_resolver.py
index 4a101669edee..509349835833 100644
--- a/products/slack_app/backend/services/integration_resolver.py
+++ b/products/slack_app/backend/services/integration_resolver.py
@@ -1,3 +1,4 @@
+from collections.abc import Iterable
from dataclasses import dataclass, field
from typing import Literal
@@ -142,17 +143,11 @@ def resolve_from_candidates(
``slack_user_id=""``; the SlackSettings lookup is skipped and the result
falls through to ``sole_candidate`` / ``needs_picker``.
"""
- # ``user.teams`` keys its access-control filter off a single arbitrary
- # ``Organization.first()`` row's feature flags, so a user whose AC-enabled
- # org isn't the one picked sees private projects from that org. Per-team
- # ``effective_membership_level`` is the right check — it consults each
- # team's own organization's feature flags.
if user is None:
accessible_team_ids: set[int] | None = None
accessible = candidates
else:
- permissions = UserPermissions(user=user)
- accessible = [c for c in candidates if permissions.team(c.team).effective_membership_level is not None]
+ accessible = accessible_candidates(candidates, user=user)
accessible_team_ids = {c.team_id for c in accessible}
candidate_ids = {c.id for c in candidates}
candidates_by_team_id = {c.team_id: c for c in candidates}
@@ -243,6 +238,34 @@ def load_integrations(
)
+def accessible_candidates(candidates: Iterable[Integration], *, user: User) -> list[Integration]:
+ """The candidates whose project this user is a member of.
+
+ Per-team ``effective_membership_level`` rather than ``user.teams``: the latter keys
+ its access-control filter off a single arbitrary ``Organization.first()`` row's
+ feature flags, so a user whose AC-enabled org isn't the one picked sees private
+ projects from that org.
+ """
+ permissions = UserPermissions(user=user)
+ return [c for c in candidates if permissions.team(c.team).effective_membership_level is not None]
+
+
+def multiple_accessible_projects(*, slack_team_id: str, user: User) -> bool:
+ """Whether this user can open more than one of the workspace's projects.
+
+ Membership alone, with no scope or reachability check: a caller asking only whether
+ there is anything to tell apart should not pay an ``auth.test`` per candidate.
+ ``routable_projects`` asks the stricter question of where a run may actually be sent.
+ """
+ installs = Integration.objects.filter(kind="slack", integration_id=slack_team_id)
+ # Accessible is a subset of installed, so one install settles it without the
+ # membership scan — on a count, which reads an index rather than hydrating and
+ # decrypting every row.
+ if installs.count() < 2:
+ return False
+ return len(accessible_candidates(installs.select_related("team"), user=user)) > 1
+
+
def routable_projects(*, slack_team_id: str, slack_user_id: str, user: User) -> list[Integration]:
"""The projects a message from this user may route itself to, in this workspace.
@@ -342,20 +365,12 @@ def resolve_user_for_workspace(
)
return UserAndIntegrationsResolution(failure_reason="user_not_found", slack_email=slack_email)
- # Filter to integrations the user can access. A resolved target the user can't
- # reach is dropped so the caller falls through to the picker / sole-candidate
- # path rather than auto-redirecting to a default the thread didn't imply.
- # Use per-team ``effective_membership_level`` rather than ``user.teams``: the
- # latter gates its access-control filter on an arbitrary ``Organization.first()``
- # row's feature flags, so a Slack user spanning multiple orgs can otherwise
- # be treated as having access to a private project in a different org than
- # the one that drove the AC check.
- permissions = UserPermissions(user=posthog_user)
- accessible_candidates = [
- c for c in workspace_result.candidates if permissions.team(c.team).effective_membership_level is not None
- ]
- accessible_team_ids = {c.team_id for c in accessible_candidates}
- if not accessible_candidates:
+ # A resolved target the user can't reach is dropped so the caller falls through to
+ # the picker / sole-candidate path rather than auto-redirecting to a default the
+ # thread didn't imply.
+ reachable_candidates = accessible_candidates(workspace_result.candidates, user=posthog_user)
+ accessible_team_ids = {c.team_id for c in reachable_candidates}
+ if not reachable_candidates:
# Fetch slack_email lazily for the failure reply (cached after the
# earlier resolve_posthog_user_from_event call, so this is free).
slack_email = get_slack_email_for_user(probe, slack_user_id)
@@ -377,6 +392,6 @@ def resolve_user_for_workspace(
return UserAndIntegrationsResolution(
user=posthog_user,
integration=target,
- candidates=accessible_candidates,
+ candidates=reachable_candidates,
source=workspace_result.source if target is not None else "needs_picker",
)
diff --git a/products/slack_app/backend/services/model_catalogue.py b/products/slack_app/backend/services/model_catalogue.py
index d45cdd5b498a..1d77746d5162 100644
--- a/products/slack_app/backend/services/model_catalogue.py
+++ b/products/slack_app/backend/services/model_catalogue.py
@@ -44,7 +44,7 @@ def describe_run_model(model: str | None, reasoning_effort: str | None) -> str:
label = display_name_for_model(model) if model else "—"
if not reasoning_effort:
return f"*{label}*"
- return f"*{label}* · Reasoning: *{label_for(reasoning_effort, REASONING_EFFORT_DISPLAY_NAMES)}*"
+ return f"*{label}* [{label_for(reasoning_effort, REASONING_EFFORT_DISPLAY_NAMES)}]"
__all__ = [
diff --git a/products/slack_app/backend/services/slack_messages.py b/products/slack_app/backend/services/slack_messages.py
index 2e59b91f6ac3..19c34fa43746 100644
--- a/products/slack_app/backend/services/slack_messages.py
+++ b/products/slack_app/backend/services/slack_messages.py
@@ -691,25 +691,51 @@ class RunFooter:
return any((self.task_url, self.desktop_url, self.model, self.project))
-def _project_name(team_id: int) -> str | None:
- """The project a run answered from, named for the footer.
-
- The run's own team is the project, so this needs no join through the thread mapping:
- a task, its mapping and every run on it belong to one project.
+def _project_name(team_id: int, *, integration_id: int | None, created_by_id: int | None) -> str | None:
+ """The project a run answered from, named only where the name tells the opener
+ something they could not already assume.
+
+ The run's own team is the project, so the name needs no join through the thread
+ mapping: a task, its mapping and every run on it belong to one project. A workspace
+ offering the opener a single project has nothing to disambiguate, and the name would
+ then repeat under every reply while never changing.
"""
from posthog.models.team.team import Team # noqa: PLC0415 — keeps the model off this module's import path
+ from posthog.models.user import User # noqa: PLC0415
+
+ from products.slack_app.backend.services.integration_resolver import multiple_accessible_projects # noqa: PLC0415
+ if integration_id is None or created_by_id is None:
+ return None
try:
+ # The id is the install this reply posts through, read off stored thread state
+ # rather than off the message, and all this reads from the row is the Slack
+ # workspace it belongs to.
+ integration = (
+ Integration.objects.filter(pk=integration_id) # nosemgrep: idor-lookup-without-team
+ .only("integration_id")
+ .first()
+ )
+ user = User.objects.filter(pk=created_by_id).first()
+ if integration is None or user is None:
+ return None
+ if not multiple_accessible_projects(slack_team_id=integration.integration_id, user=user):
+ return None
team = Team.objects.filter(pk=team_id).only("name").first()
except Exception:
# Its own guard, not the caller's: a failed lookup must cost the reader one
# segment, not the links and the model with it.
- logger.warning("slack_app_footer_project_lookup_failed", team_id=team_id)
+ logger.warning(
+ "slack_app_footer_project_lookup_failed",
+ team_id=team_id,
+ integration_id=integration_id,
+ exc_info=True,
+ )
return None
return team.name if team else None
-def load_run_footer(run_id: str | UUID | None) -> RunFooter:
+def load_run_footer(run_id: str | UUID | None, *, integration_id: int | None) -> RunFooter:
"""Describe a run for the footer.
Never raises: the footer is the last thing added to an answer that is already
@@ -718,6 +744,10 @@ def load_run_footer(run_id: str | UUID | None) -> RunFooter:
Describes the run in full, links included. Whether the reader gets the desktop link
is ``viewer_has_code_access``'s question, asked where the reader is known; the web
link is for everyone, since the task page enforces access itself.
+
+ ``integration_id`` is the install the reply is posted through, and the workspace
+ behind it is what the project segment is judged against. Required rather than
+ defaulted, so a new caller cannot drop the segment without saying so.
"""
# Deferred so the tasks product stays off this module's import path, matching
# `model_catalogue`.
@@ -742,13 +772,45 @@ def load_run_footer(run_id: str | UUID | None) -> RunFooter:
desktop_url=_desktop_bridge_url(run.task_id),
model=state.model,
reasoning_effort=state.reasoning_effort,
- project=_project_name(run.team_id),
+ project=_project_name(
+ run.team_id,
+ integration_id=integration_id,
+ created_by_id=run.created_by_id,
+ ),
)
except Exception:
logger.exception("slack_app_run_footer_load_failed", run_id=str(run_id))
return RunFooter()
+def _run_context_segments(footer: RunFooter) -> list[str]:
+ """What the run is, as footer segments: the project it answered from, then the model.
+
+ Shared by the reply footer and the progress message so the two cannot describe one
+ run differently, and so the escaping below has a single home.
+ """
+ segments: list[str] = []
+ if footer.project:
+ # A project name is tenant text in a `mrkdwn` block, so `<!channel>` broadcasts
+ # and `<url|label>` renders a link the reader reads as the bot's. Escaped here
+ # rather than on the way in, so `RunFooter.project` stays the plain name.
+ segments.append(f"Project: *{escape_slack_mrkdwn(footer.project)}*")
+ if footer.model:
+ segments.append(describe_run_model(footer.model, footer.reasoning_effort))
+ return segments
+
+
+def run_context_block(footer: RunFooter) -> dict[str, Any] | None:
+ """The run's project and model as a standalone `context` block, or `None` when
+ neither is known.
+
+ What a message that is still working can say about its run: the links the reply
+ footer carries lead to an answer that does not exist yet.
+ """
+ segments = _run_context_segments(footer)
+ return context_block(" · ".join(segments)) if segments else None
+
+
def reply_footer_block(footer: RunFooter, configure_url: str | None = None) -> dict[str, Any] | None:
"""The footer as a `context` block, or `None` when there is nothing to say.
@@ -761,13 +823,7 @@ def reply_footer_block(footer: RunFooter, configure_url: str | None = None) -> d
segments.append(f"<{footer.task_url}|View on web>")
if footer.desktop_url:
segments.append(f"<{footer.desktop_url}|View on desktop>")
- if footer.project:
- # A project name is tenant text in a `mrkdwn` block, so `<!channel>` broadcasts
- # and `<url|label>` renders a link the reader reads as the bot's. Escaped here
- # rather than on the way in, so `RunFooter.project` stays the plain name.
- segments.append(f"Project: *{escape_slack_mrkdwn(footer.project)}*")
- if footer.model:
- segments.append(describe_run_model(footer.model, footer.reasoning_effort))
+ segments.extend(_run_context_segments(footer))
if configure_url:
segments.append(f"<{configure_url}|Configure>")
if not segments:
diff --git a/products/slack_app/backend/slack_thread.py b/products/slack_app/backend/slack_thread.py
index a9b8d7376b03..d9a1dca729a3 100644
--- a/products/slack_app/backend/slack_thread.py
+++ b/products/slack_app/backend/slack_thread.py
@@ -10,7 +10,6 @@ from posthog.helpers.slack_markdown import SLACK_MARKDOWN_TEXT_MAX_LEN, slack_ma
from posthog.models.integration import Integration, SlackIntegration
from products.slack_app.backend.feature_flags import is_slack_app_forking_enabled
-from products.slack_app.backend.services.model_catalogue import describe_run_model
from products.slack_app.backend.services.slack_messages import (
RunFooter,
app_home_url,
@@ -22,6 +21,7 @@ from products.slack_app.backend.services.slack_messages import (
post_slack_thread_reply,
project_web_url,
reply_footer_block,
+ run_context_block,
slack_message_exists,
turn_feedback_block,
viewer_has_code_access,
@@ -467,18 +467,20 @@ class SlackThreadHandler:
def post_or_update_progress(self, stage: str, task_url: str | None = None) -> None:
"""Post a new progress message or update the existing one.
- The model rides along as a context line rather than its own message: which
- model is running is a property of the task, and the thread already has one
- place that describes the task while it works. Unlike the reply footer this
- is not gated — a running task says what it is running on either way.
+ The project and model ride along as a context line rather than their own
+ message: what a task is running on and against is a property of the task, and
+ the thread already has one place that describes it while it works. Unlike the
+ reply footer's links this is not gated on the reader — a running task says what
+ it is running on either way.
"""
text = f"*{PROGRESS_MESSAGE_MARKER}* :hourglass_flowing_sand:\nStage: {stage}"
blocks: list[dict[str, Any]] = [
{"type": "section", "text": {"type": "mrkdwn", "text": text}},
]
- if self.run_footer.model:
- blocks.append(context_block(describe_run_model(self.run_footer.model, self.run_footer.reasoning_effort)))
+ run_context = run_context_block(self.run_footer)
+ if run_context:
+ blocks.append(run_context)
if task_url:
blocks.append(
diff --git a/products/slack_app/backend/tests/services/slack_messages/test_run_footer.py b/products/slack_app/backend/tests/services/slack_messages/test_run_footer.py
index 3650851698b9..678175b36f68 100644
--- a/products/slack_app/backend/tests/services/slack_messages/test_run_footer.py
+++ b/products/slack_app/backend/tests/services/slack_messages/test_run_footer.py
@@ -2,6 +2,7 @@ from types import SimpleNamespace
from typing import cast
from uuid import uuid4
+import pytest
from unittest.mock import patch
from django.test import SimpleTestCase
@@ -29,7 +30,7 @@ class TestRunFooter(SimpleTestCase):
RunFooter(TASK_URL, DESKTOP_URL, "claude-opus-5", "high"),
"slack://app?team=T1&id=A1&tab=home",
f"<{TASK_URL}|View on web> · <{DESKTOP_URL}|View on desktop>"
- " · *Claude Opus 5* · Reasoning: *High* · <slack://app?team=T1&id=A1&tab=home|Configure>",
+ " · *Claude Opus 5* [High] · <slack://app?team=T1&id=A1&tab=home|Configure>",
),
(
"links_only",
@@ -42,9 +43,9 @@ class TestRunFooter(SimpleTestCase):
# answer looks the same whichever it was, so the footer has to name it.
(
"project_precedes_the_model",
- RunFooter(model="claude-opus-5", project="Endpaper staging"),
+ RunFooter(model="claude-opus-5", project="Fernwood staging"),
None,
- "Project: *Endpaper staging* · *Claude Opus 5*",
+ "Project: *Fernwood staging* · *Claude Opus 5*",
),
# A project name is tenant text with no character validation, and the footer
# rides under every reply. Unescaped, `<!channel>` broadcasts to everyone in
@@ -75,7 +76,7 @@ class TestRunFooter(SimpleTestCase):
def test_a_project_alone_still_renders(self) -> None:
# `has_content` gates whether callers bother building a footer at all, so a run
# known only by its project must not read as nothing to say.
- assert RunFooter(project="Endpaper staging").has_content()
+ assert RunFooter(project="Fernwood staging").has_content()
def test_contributes_no_block_when_there_is_nothing_to_say(self) -> None:
# A context block with an empty `elements` list is rejected by Slack, which would
@@ -89,10 +90,12 @@ class TestLoadRunFooter(SimpleTestCase):
def test_describes_the_run_links_included(self, mock_get_run, mock_parse) -> None:
# Whether the reader may open the links is asked later, where the reader is known.
task_id = uuid4()
- mock_get_run.return_value = SimpleNamespace(id=uuid4(), task_id=task_id, team_id=1, state={})
+ mock_get_run.return_value = SimpleNamespace(
+ id=uuid4(), task_id=task_id, team_id=1, state={}, created_by_id=None
+ )
mock_parse.return_value = SimpleNamespace(model="claude-opus-5", reasoning_effort="high")
- footer = load_run_footer("run-1")
+ footer = load_run_footer("run-1", integration_id=None)
assert f"/code/task/{task_id}" in (footer.desktop_url or "")
assert f"/tasks/{task_id}" in (footer.task_url or "")
@@ -100,7 +103,7 @@ class TestLoadRunFooter(SimpleTestCase):
@patch("products.tasks.backend.facade.api.get_task_run", side_effect=RuntimeError("db down"))
def test_a_failure_to_describe_the_run_costs_the_footer_not_the_answer(self, _mock_get_run) -> None:
- assert load_run_footer("run-1") == RunFooter()
+ assert load_run_footer("run-1", integration_id=None) == RunFooter()
class TestViewerHasCodeAccess(SimpleTestCase):
@@ -148,41 +151,51 @@ class TestViewerHasCodeAccess(SimpleTestCase):
class TestFooterProject:
- """The footer names the project a thread's task belongs to.
+ """The footer names the project a run answered from, and only where naming it tells
+ the opener something.
Covers what the `SimpleTestCase` classes above cannot: those run without a database,
- so the mapping lookup takes its failure path there and the segment is always absent.
+ so the lookup takes its failure path there and the segment is always absent.
"""
- def test_names_the_project_the_thread_is_pinned_to(self, db):
+ @pytest.mark.parametrize(
+ "sibling_owner,expected",
+ [
+ # Nothing to tell apart: the name would be identical under every reply in
+ # the workspace, so it costs a segment and carries no information.
+ (None, None),
+ ("same_org", "Test Team"),
+ # Counting workspace installs rather than the opener's own access would name
+ # the project for someone who never had a second one to confuse it with.
+ ("other_org", None),
+ ],
+ )
+ def test_names_the_project_only_when_another_reachable_one_exists(
+ self, db, org_team_user, workspace_integration, sibling_owner, expected
+ ):
from django.apps import apps
from posthog.models.organization import Organization
from posthog.models.team.team import Team
- from products.slack_app.backend.models import SlackThreadTaskMapping
+ organization, routed_team, user = org_team_user
+ if sibling_owner is not None:
+ owner = (
+ organization if sibling_owner == "same_org" else Organization.objects.create(name="Someone else's org")
+ )
+ Integration.objects.create(
+ team=Team.objects.create(organization=owner, name="Sibling"),
+ kind="slack",
+ integration_id=workspace_integration.integration_id,
+ sensitive_config={"access_token": "xoxb-test"},
+ )
- organization = Organization.objects.create(name="Org")
- routed_team = Team.objects.create(organization=organization, name="Staging")
- integration = Integration.objects.create(
- team=routed_team, kind="slack", integration_id="T_WS", sensitive_config={"access_token": "xoxb"}
- )
Task = apps.get_model("tasks", "Task")
TaskRun = apps.get_model("tasks", "TaskRun")
- task = Task.objects.create(team=routed_team, title="t")
+ task = Task.objects.create(team=routed_team, title="t", created_by=user)
run = TaskRun.objects.create(team=routed_team, task=task)
- SlackThreadTaskMapping.objects.create(
- integration=integration,
- team=routed_team,
- slack_workspace_id="T_WS",
- channel="C1",
- thread_ts="1.1",
- task=task,
- task_run=run,
- mentioning_slack_user_id="U1",
- )
- footer = load_run_footer(run.id)
+ footer = load_run_footer(run.id, integration_id=workspace_integration.id)
- # The routed project, not the one the workspace would otherwise have answered from.
- assert footer.project == "Staging"
+ # The project the run answered from, not the one the workspace defaults to.
+ assert footer.project == expected
diff --git a/products/slack_app/backend/tests/services/test_run_preferences.py b/products/slack_app/backend/tests/services/test_run_preferences.py
index 24c668b1d004..7d70de43ef36 100644
--- a/products/slack_app/backend/tests/services/test_run_preferences.py
+++ b/products/slack_app/backend/tests/services/test_run_preferences.py
@@ -172,9 +172,9 @@ class TestDescribeRunModel:
@pytest.mark.parametrize(
"model,reasoning_effort,expected",
[
- ("claude-fable-5", "high", "*Claude Fable 5* · Reasoning: *High*"),
+ ("claude-fable-5", "high", "*Claude Fable 5* [High]"),
("claude-fable-5", None, "*Claude Fable 5*"),
- ("claude-opus-5", "ultracode", "*Claude Opus 5* · Reasoning: *Ultracode*"),
+ ("claude-opus-5", "ultracode", "*Claude Opus 5* [Ultracode]"),
],
)
def test_renders_the_shared_phrasing(self, model, reasoning_effort, expected):
diff --git a/products/slack_app/backend/tests/test_slack_thread.py b/products/slack_app/backend/tests/test_slack_thread.py
index f3f583eff407..e4dc87dfa159 100644
--- a/products/slack_app/backend/tests/test_slack_thread.py
+++ b/products/slack_app/backend/tests/test_slack_thread.py
@@ -239,6 +239,24 @@ class TestSlackThreadHandlerWithoutTaskUrl(SimpleTestCase):
mock_client.chat_postMessage.assert_called_once()
assert _action_blocks(mock_client.chat_postMessage.call_args.kwargs) == []
+ @patch.object(SlackThreadHandler, "_find_progress_message_ts", return_value=None)
+ @patch.object(SlackThreadHandler, "_get_client")
+ def test_post_or_update_progress_names_the_project_it_runs_against(self, mock_get_client, _mock_find_progress):
+ # A task that routed itself to another project says so while it works, not only
+ # in the footer of the answer minutes later.
+ mock_client = MagicMock()
+ mock_get_client.return_value = mock_client
+ handler = SlackThreadHandler(
+ self._make_context(),
+ RunFooter(model="claude-opus-5", reasoning_effort="high", project="Staging"),
+ )
+
+ handler.post_or_update_progress("Building", task_url=None)
+
+ blocks = mock_client.chat_postMessage.call_args.kwargs["blocks"]
+ context_text = next(b["elements"][0]["text"] for b in blocks if b["type"] == "context")
+ assert context_text == "Project: *Staging* · *Claude Opus 5* [High]"
+
@patch.object(SlackThreadHandler, "delete_progress")
@patch.object(SlackThreadHandler, "_get_client")
def test_post_pr_opened_without_task_url_keeps_pr_button(self, mock_get_client, _mock_delete_progress):
diff --git a/products/tasks/backend/temporal/process_task/activities/post_slack_update.py b/products/tasks/backend/temporal/process_task/activities/post_slack_update.py
index dd3f7ac40580..cb387ad24789 100644
--- a/products/tasks/backend/temporal/process_task/activities/post_slack_update.py
+++ b/products/tasks/backend/temporal/process_task/activities/post_slack_update.py
@@ -103,7 +103,7 @@ def post_slack_update(input: PostSlackUpdateInput) -> None:
try:
context = SlackThreadContext.from_dict(input.slack_thread_context)
- footer = load_run_footer(task_run.id)
+ footer = load_run_footer(task_run.id, integration_id=context.integration_id)
handler = SlackThreadHandler(context, footer)
# The buttons lead where the footer's links do, so they answer to the same reader.
task_url = handler.reader_task_url()
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.py
index 11f699886813..27e945ba8b73 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
@@ -127,7 +127,7 @@ def stop_slack_agent_design_stream(input: StopSlackAgentDesignStreamInput) -> No
try:
context = SlackThreadContext.from_dict(input.slack_thread_context)
handler = SlackThreadHandler(context, turn_trace_id=input.trace_id)
- handler.run_footer = load_run_footer(input.run_id)
+ handler.run_footer = load_run_footer(input.run_id, integration_id=context.integration_id)
handler.stop_status_stream(
ts=input.ts,
complete_task_id=input.complete_task_id,
diff --git a/products/tasks/backend/temporal/slack_relay/activities.py b/products/tasks/backend/temporal/slack_relay/activities.py
index bc58433f9e88..d62caf0b6a71 100644
--- a/products/tasks/backend/temporal/slack_relay/activities.py
+++ b/products/tasks/backend/temporal/slack_relay/activities.py
@@ -243,7 +243,7 @@ def relay_slack_message(input: RelaySlackMessageInput) -> None:
)
handler = SlackThreadHandler(context, actor_slack_user_id=target, turn_trace_id=input.trace_id)
- handler.run_footer = load_run_footer(task_run.id)
+ handler.run_footer = load_run_footer(task_run.id, integration_id=mapping.integration_id)
# The mention opens the answer, in the same line, so the reply reads as one message. An answer
# that opens with a heading, a list, a quote, a table, or a fence is the exception: Markdown