: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
fix(signals): name the editor in a reviewer correction note (#106124)
posthog[bot]4391cdda0025
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.mdindex 6fce543c2f1f..76b78d29420f 100644--- a/products/signals/ARCHITECTURE.md+++ b/products/signals/ARCHITECTURE.md@@ -1020,6 +1020,7 @@ It is the only derived origin addressed to more than one scout. Every live scoutA report no live scout touched falls back to the fleet-wide target only when no holder resolved, because a run reads the fleet-wide notes alongside its own and would otherwise hear the same edit twice.An impersonated edit forwards nothing: the reviewer-corrections project profile already excludes impersonated activity rows, since a support-staff edit is not the team's ownership evidence.Logins are shape-checked against GitHub's login rule before rendering, and an edit contributes at most `MAX_CORRECTION_LOGINS` of them: both write paths into the reviewers artefact accept any string of any length, and the value lands inside a backtick span in a prompt every scout reads.+The note names the editor, because who corrected the routing is what tells a scout whether a domain owner spoke or somebody trimmed a list in passing; the name is normalized to one line, capped, and kept out of the backtick spans the suppression parser reads back, and an account with no name falls back to a neutral word.Repeated edits are coalesced rather than queued: a login already named in a note to a target, in the same direction, inside `SUPPRESSION_WINDOW` is left out of the next one, so one person trimming the same login off ten reports in a morning tells each scout once.Suppression is per direction, so an edit that reverses an earlier one inside the window — a login added and then removed — still forwards, since that is exactly the stale-routing correction the channel exists to carry.Authorization, the 30-day TTL, the child-environment rule, and the read-side withholding are the dismissal ones (`dismissal_notes.principal_may_steer_scouts`); the key scopes aren't demanded on top, because the logins already reach scouts through the report's reviewers artefact and the profile.diff --git a/products/signals/backend/reviewer_correction_notes.py b/products/signals/backend/reviewer_correction_notes.pyindex 86a77324ac70..8caab6656430 100644--- a/products/signals/backend/reviewer_correction_notes.py+++ b/products/signals/backend/reviewer_correction_notes.py@@ -32,7 +32,9 @@ event are already committed, so nothing here may fail a reviewer edit.A login itself is untrusted input, whichever path stored it, so it is shape-checked before it reachesa note and dropped when it is not a GitHub login: these values land inside a backtick span in a-prompt every scout reads while holding privileged tools.+prompt every scout reads while holding privileged tools. The editor's own name goes in for the same+reason the logins do — a scout weighs a correction by who made it — and it is sanitized on the same+terms, minus the backtick span."""from __future__ import annotations@@ -86,6 +88,14 @@ SUPPRESSION_WINDOW = timedelta(hours=24)# Report titles are unbounded TextFields; a note references them for recognition only._MAX_TITLE_CHARS = 200+# The editor's name tells a scout whether a domain owner corrected the routing or somebody trimmed a+# list in passing, so it is named rather than elided. It is user-controlled text, so it is normalized+# to one line and capped the way a report title is. It never enters a backtick span:+# `_logins_already_told` reads those spans back as suppression state, so a quoted name could stand in+# for a login and silently swallow a later real correction.+_MAX_ACTOR_NAME_CHARS = 60+_UNNAMED_ACTOR = "someone"+# GitHub logins are alphanumerics with single interior hyphens, 39 characters at most. Both write# paths into the reviewers artefact accept any non-empty string, so a login can carry a backtick or a# newline that closes the span it is rendered in and fakes a section of a note every scout reads.@@ -198,6 +208,7 @@ def _forward(*, team: Team, correction: ReviewerCorrection) -> ForwardedCorrecticontinuecontent = _build_note_content(report=report,+ editor=_actor_name(actor),added_logins=added,# Split per note rather than per edit: the caveat belongs to the logins this scout is# actually being told about, and the suppression filter above can leave a batch holding@@ -303,6 +314,12 @@ def _live_skills(team_id: int, names: Sequence[str]) -> list[str]:return [name for name in names if name in live]+def _actor_name(actor: User) -> str:+ """How the editor is named in the note, or a neutral word when the account carries no name."""+ name = " ".join(f"{actor.first_name or ''} {actor.last_name or ''}".split()).replace("`", "")+ return name[:_MAX_ACTOR_NAME_CHARS] if name else _UNNAMED_ACTOR++def _actor_login(team_id: int, actor: User) -> str | None:"""The editor's own GitHub login, so a self-removal is not reported as a teammate's verdict."""return get_org_member_github_logins_by_user_uuid(team_id, [str(actor.uuid)]).get(str(actor.uuid))@@ -346,11 +363,12 @@ def _quoted_logins(content: str) -> set[str]:def _build_note_content(*,report: SignalReport,+ editor: str,added_logins: Sequence[str],self_removed: Sequence[str],teammate_removed: Sequence[str],) -> str:- sections = [f"Inbox routing correction: someone changed the suggested reviewers on {_subject(report)}"]+ sections = [f"Inbox routing correction: {editor} changed the suggested reviewers on {_subject(report)}"]if added_logins:sections.append(f"{_ADDED_SECTION_PREFIX}{_listed(added_logins)}. An added login is a positive ownership fact for this "diff --git a/products/signals/backend/test/test_reviewer_correction_scout_notes.py b/products/signals/backend/test/test_reviewer_correction_scout_notes.pyindex 576799e47fd5..6473041f423a 100644--- a/products/signals/backend/test/test_reviewer_correction_scout_notes.py+++ b/products/signals/backend/test/test_reviewer_correction_scout_notes.py@@ -8,6 +8,8 @@ from django.test import SimpleTestCasefrom parameterized import parameterized+from posthog.models import User+from products.signals.backend.models import (SignalReport,SignalScoutConfig,@@ -18,6 +20,7 @@ from products.signals.backend.models import (from products.signals.backend.reviewer_correction_notes import (MAX_CORRECTION_LOGINS,ReviewerCorrection,+ _actor_name,_build_note_content,_logins_already_told,_renderable,@@ -61,6 +64,7 @@ class TestReviewerCorrectionNoteContent(SimpleTestCase):) -> None:content = _build_note_content(report=SignalReport(id="0198e7f0-0000-7000-8000-000000000001", title="Checkout errors"),+ editor="Ada Lovelace",added_logins=(),self_removed=self_removed,teammate_removed=teammate_removed,@@ -72,6 +76,34 @@ class TestReviewerCorrectionNoteContent(SimpleTestCase):if not teammate_removed:assert "a teammate removed the login" not in content+ @parameterized.expand(+ [+ ("both_names", "Ada", "Lovelace", "Ada Lovelace"),+ ("first_name_only", "Ada", "", "Ada"),+ ("no_name_falls_back", "", "", "someone"),+ ("whitespace_is_normalized", " Ada\n\nRemoved: ", "x ", "Ada Removed: x"),+ ("backticks_are_stripped", "`Ada`", "", "Ada"),+ ("capped", "A" * 80, "", "A" * 60),+ ]+ )+ def test_the_editors_name_is_sanitized(self, _name: str, first: str, last: str, expected: str) -> None:+ # The name reaches a prompt every scout reads, so it stays one line and bounded. Backticks go+ # because `_logins_already_told` reads backtick spans back as suppression state.+ assert _actor_name(User(first_name=first, last_name=last)) == expected++ def test_the_note_names_the_editor(self) -> None:+ content = _build_note_content(+ report=SignalReport(id="0198e7f0-0000-7000-8000-000000000001", title="Checkout errors"),+ editor="Ada Lovelace",+ added_logins=("octocat",),+ self_removed=(),+ teammate_removed=(),+ )++ # Who corrected the routing is the evidence a scout weighs, so it must reach the note body,+ # which is the only part of a note the run prompt renders.+ assert content.startswith("Inbox routing correction: Ada Lovelace changed the suggested reviewers")+class TestReviewerCorrectionScoutNotes(APIBaseTest):def _create_report(self, title: str = "Checkout errors spiked") -> SignalReport:@@ -291,6 +323,16 @@ class TestReviewerCorrectionScoutNotes(APIBaseTest):assert "Removed: `someone-else`." in contentassert "Removed: `octocat`. That is the editor's own login" in content+ def test_the_forwarded_note_names_the_editor(self) -> None:+ report = self._create_report()+ self.user.first_name = "Ada"+ self.user.last_name = "Lovelace"+ self.user.save()++ self._forward(report, added=("octocat",))++ assert self._correction_notes()[0].content.startswith("Inbox routing correction: Ada Lovelace changed")+def test_a_child_environment_correction_stays_off_the_notes_channel(self) -> None:self._create_skill()report = self._create_report()