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(tasks): keep scout runs out of the activity feed (#89201)

Andrew Maguire12591325f049
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 1e2145f423b7..df0422e4a7c8 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -8298,18 +8298,33 @@ def project_completed_activity(task_run: "TaskRun") -> None:
)
+# A scout runs headless on a schedule, under an acting user resolved from the scout skill's
+# author rather than from whoever asked for the run. Its task therefore carries a real person
+# as `created_by`, so every projected row lands in a feed that person never asked for. Scout
+# output belongs in the Signals inbox instead.
+ACTIVITY_FEED_EXCLUDED_ORIGIN_PRODUCTS = (Task.OriginProduct.SIGNALS_SCOUT,)
+
+
+def _activity_visible_task_qs(team_id: int, user_id: int) -> QuerySet[Task]:
+ return (
+ _visible_task_qs(team_id, user_id)
+ .filter(internal=False, archived=False)
+ .exclude(origin_product__in=ACTIVITY_FEED_EXCLUDED_ORIGIN_PRODUCTS)
+ )
+
+
def _task_activity_qs(team_id: int, user_id: int) -> QuerySet[TaskActivity]:
"""The requester's feed rows, gated to tasks they can still see.
Rows outlive visibility changes (a task moving to a private channel, say), so the
visibility gate belongs on read rather than being enforced when projecting.
"""
- visible_tasks = _visible_task_qs(team_id, user_id).filter(internal=False, archived=False)
+ visible_tasks = _activity_visible_task_qs(team_id, user_id)
return TaskActivity.objects.for_team(team_id).filter(user_id=user_id, task__in=visible_tasks)
def _comment_activity_qs(team_id: int, user_id: int) -> QuerySet[TaskCommentActivity]:
- visible_tasks = _visible_task_qs(team_id, user_id).filter(internal=False, archived=False)
+ visible_tasks = _activity_visible_task_qs(team_id, user_id)
return TaskCommentActivity.objects.for_team(team_id).filter(
user_id=user_id, task__in=visible_tasks, comment__deleted=False
)
diff --git a/products/tasks/backend/tests/test_channels_api.py b/products/tasks/backend/tests/test_channels_api.py
index c247a262c2c3..3ce4aabaf48f 100644
--- a/products/tasks/backend/tests/test_channels_api.py
+++ b/products/tasks/backend/tests/test_channels_api.py
@@ -860,9 +860,10 @@ class TaskActivityAPITestCase(ChannelTaskAPITestCase):
[
("internal", {"internal": True}),
("archived", {"archived": True}),
+ ("scout", {"origin_product": Task.OriginProduct.SIGNALS_SCOUT}),
]
)
- def test_hidden_tasks_are_excluded_from_activity(self, _name, task_updates):
+ def test_tasks_outside_the_feed_are_excluded_from_activity(self, _name, task_updates):
Task.objects.filter(id=self.task.id).update(**task_updates)
self._awaiting_input()
diff --git a/products/tasks/backend/tests/test_comment_activity.py b/products/tasks/backend/tests/test_comment_activity.py
index 157c92c50d86..732def4ac1e7 100644
--- a/products/tasks/backend/tests/test_comment_activity.py
+++ b/products/tasks/backend/tests/test_comment_activity.py
@@ -175,12 +175,22 @@ class TestCommentActivity(CommentActivityTestCase):
assert not TaskCommentActivity.objects.filter(team=self.team, user=self.author).exists()
- def test_deleted_comments_are_hidden_from_activity(self):
+ @parameterized.expand(
+ [
+ ("deleted_comment", {}, {"deleted": True}),
+ ("scout_task", {"origin_product": Task.OriginProduct.SIGNALS_SCOUT}, {}),
+ ]
+ )
+ def test_comments_outside_the_feed_are_hidden_from_activity(
+ self, _name: str, task_updates: dict[str, object], comment_updates: dict[str, object]
+ ) -> None:
unread_before = tasks_facade.count_unread_task_activity(self.team.id, self.author.id)
comment = self._comment()
self._record_activity(comment, [self.author.id])
- comment.deleted = True
- comment.save(update_fields=["deleted"])
+ if task_updates:
+ Task.objects.filter(id=self.task.id).update(**task_updates)
+ if comment_updates:
+ Comment.objects.filter(id=comment.id).update(**comment_updates)
page = tasks_facade.list_task_activity(self.team.id, self.author.id)