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.

feat(signals): record who manually added an inbox report reviewer (#74009)

Andrew Maguire6a498275afd4
diff --git a/products/signals/backend/test/test_signal_report_artefact_api.py b/products/signals/backend/test/test_signal_report_artefact_api.py
index 0b081031c4dc..3c27aaf7c9d4 100644
--- a/products/signals/backend/test/test_signal_report_artefact_api.py
+++ b/products/signals/backend/test/test_signal_report_artefact_api.py
@@ -382,6 +382,47 @@ class TestSignalReportArtefactViewSet(APIBaseTest):
assert stored["dave"]["reason"] == "Owns this area"
assert "bob" not in stored
+ def test_put_stamps_manual_add_reason_without_clobbering_kept_reviewer(self):
+ # A manually-added reviewer carries no routing evidence, so the server stamps a
+ # "who added them, when" reason for the inbox UI. A kept reviewer's existing reason
+ # must survive the same edit — the manual-add default only fills newly-added entries.
+ self.user.first_name = "Zelda"
+ self.user.last_name = "Zebra"
+ self.user.save()
+ dave = self._create_org_member("[email protected]", github_login="dave")
+ report = self._create_report()
+ artefact = self._create_artefact(
+ report,
+ content=[{"github_login": "alice", "reason": "Top recent author on the affected surface"}],
+ )
+
+ response = self.client.put(
+ self._detail_url(str(report.id), str(artefact.id)),
+ data=json.dumps({"content": [{"github_login": "alice"}, {"user_uuid": str(dave.uuid)}]}),
+ content_type="application/json",
+ )
+ assert response.status_code == status.HTTP_200_OK, response.json()
+
+ stored = {r["github_login"]: r for r in self._latest_reviewers(report)}
+ assert stored["alice"]["reason"] == "Top recent author on the affected surface"
+ assert stored["dave"]["reason"].startswith("Added as a reviewer by Zelda Zebra on ")
+
+ def test_put_explicit_null_reason_on_new_reviewer_is_not_stamped(self):
+ # Field-presence semantics: an explicitly-supplied null reason clears the reason, so the
+ # manual-add note must only fill entries where the reason field was omitted entirely.
+ report = self._create_report()
+ artefact = self._create_artefact(report, content=[])
+
+ response = self.client.put(
+ self._detail_url(str(report.id), str(artefact.id)),
+ data=json.dumps({"content": [{"github_login": "alice", "reason": None}]}),
+ content_type="application/json",
+ )
+ assert response.status_code == status.HTTP_200_OK, response.json()
+
+ stored = {r["github_login"]: r for r in self._latest_reviewers(report)}
+ assert stored["alice"]["reason"] is None
+
def test_put_resolves_user_uuid_to_github_login(self):
member = self._create_org_member("[email protected]", github_login="AliceCase")
report = self._create_report()
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 3f9d71dd8b5c..45c413277d49 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -2486,6 +2486,14 @@ def append_suggested_reviewers(
if isinstance(prior_reason, str):
prior_reason_by_login[login] = prior_reason
+ # Newly-added reviewers carry no routing evidence, so record who added them and when
+ # (this path is always attributed to request.user). Dates use the report's project timezone.
+ actor = cast(User, request.user)
+ # Build the date without the platform-specific %-d directive (fails on non-Unix).
+ now_local = timezone.now().astimezone(team.timezone_info)
+ added_on = f"{now_local:%b} {now_local.day}, {now_local.year}"
+ manual_add_reason = f"Added as a reviewer by {actor.get_full_name().strip() or actor.email} on {added_on}"
+
# Dedupe by canonical login, preserve first-seen order.
new_content: list[dict] = []
for login_lc, github_name, explicit_name, reason, explicit_reason in resolved_entries:
@@ -2494,9 +2502,12 @@ def append_suggested_reviewers(
seen.add(login_lc)
# If the client supplied github_name (incl. ""), honour it. Otherwise
# carry over the prior one so kept reviewers don't lose their name.
- # Same rule for reason.
+ # Same rule for reason. Only fall back to the manual-add note when the field was
+ # omitted for a brand-new reviewer — an explicit null clears the reason, as for kept ones.
effective_name = github_name if explicit_name else prior_name_by_login.get(login_lc)
effective_reason = reason if explicit_reason else prior_reason_by_login.get(login_lc)
+ if not explicit_reason and login_lc not in prior_logins:
+ effective_reason = manual_add_reason
new_content.append(
{
"github_login": login_lc,