: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): spread the dri pick across the whole owning team (#104261)
Julian Bez849421936fe0
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.mdindex 8424e3ac68da..da426b443ccc 100644--- a/products/signals/ARCHITECTURE.md+++ b/products/signals/ARCHITECTURE.md@@ -1325,10 +1325,10 @@ Under the `signals-pr-dri-assignee` flag, the candidates are, most responsible f1. **The person who chose the work.** A claim a person made, or one their agent made for them, since an agent claim records the person it ran as. A task claim does not count: an auto-started report is claimed by its own implementation task, and that task runs as the report's top suggested reviewer, so it names a commit-history guess rather than a decision.2. **Somebody who asked to be assigned** through `SignalUserAutonomyConfig.github_assign_on_pull_request`. Where several did, the one who owns the changed code wins, else the highest-ranked suggested reviewer among them.-3. **A member of the team that owns the changed files**, when the repository declares ownership in `owners.yaml` (`backend/pr_owning_team.py`). A member the report already suggests comes first, because they touched this code; the rest follow in random order. The engineering analytics facade (`resolve_path_owners`) resolves the team. GitHub teams are the canonical team identity, so the members come from GitHub's team members API, which needs the organization members read permission on the GitHub app.+3. **A member of the team that owns the changed files**, when the repository declares ownership in `owners.yaml` (`backend/pr_owning_team.py`). The members follow in random order. A member the report suggests gets no priority, because commit history would otherwise give one prolific committer every pull request. The engineering analytics facade (`resolve_path_owners`) resolves the team. GitHub teams are the canonical team identity, so the members come from GitHub's team members API, which needs the organization members read permission on the GitHub app.4. **The suggested reviewers in rank order**, when no ownership source names a team.-A candidate must be an organization member with a connected GitHub account. Each is checked with GitHub's read-only assignee check first, because the add-assignees call drops a login without push access instead of failing. A candidate GitHub cannot assign moves the walk to the next one, for up to four checks, and a failed check stops it. A report with no candidate at all gets no DRI.+A candidate from rungs 1, 2 and 4 must be an organization member with a connected GitHub account. A member of the owning team needs only GitHub team membership, because that membership is the ownership, and does not need a PostHog account. Each candidate is checked with GitHub's read-only assignee check first, because the add-assignees call drops a login without push access instead of failing. A candidate GitHub cannot assign moves the walk to the next one, for up to four checks, and a failed check stops it. A report with no candidate at all gets no DRI.A pull request that already has an assignee is left alone, and so is one that somebody ever unassigned by hand, because a later report event must not undo that decision.diff --git a/products/signals/backend/pr_owning_team.py b/products/signals/backend/pr_owning_team.pyindex 0f386c7cb17b..d6f1991d0c59 100644--- a/products/signals/backend/pr_owning_team.py+++ b/products/signals/backend/pr_owning_team.py@@ -19,7 +19,6 @@ from posthog.models.integration import GitHubIntegrationfrom products.engineering_analytics.backend.facade.api import resolve_path_ownersfrom products.engineering_analytics.backend.facade.contracts import UNOWNED_TEAM-from products.signals.backend.report_generation.resolve_reviewers import resolve_org_github_login_to_userslogger = structlog.get_logger(__name__)@@ -31,7 +30,8 @@ _TEAM_SLUG_RE = re.compile(r"^[A-Za-z0-9._-]+$")@frozenclass OwningTeam:slug: str- # Organization members of the team with a connected GitHub account, in random order.+ # Lowercase GitHub logins of every team member, in random order. GitHub team membership is the+ # ownership, so a member needs no PostHog account.logins: tuple[str, ...]@@ -40,7 +40,6 @@ class OwningTeamResolver:def __init__(self, github: GitHubIntegration, *, team_id: int, report_id: str, parsed: PullRequestRef) -> None:self.github = github- self.team_id = team_idself.parsed = parsedself.log = logger.bind(team_id=team_id, report_id=report_id, repository=parsed.repository, pr_number=parsed.number@@ -82,7 +81,8 @@ class OwningTeamResolver:)return None- logins = list(resolve_org_github_login_to_users(self.team_id, members["logins"]))+ # Lowercase, so the logins match the normalized suggested reviewer and opt-in logins.+ logins = list(dict.fromkeys(login.lower() for login in members["logins"]))# TODO: prefer the member with the fewest open self-driving pull requests, to spread the load.random.shuffle(logins)self.log.info("signals.pr_owning_team.resolved", team_slug=slug, candidates=len(logins))diff --git a/products/signals/backend/reviewer_pr_assignment.py b/products/signals/backend/reviewer_pr_assignment.pyindex 5a85e19b3b7e..926a02e8bee7 100644--- a/products/signals/backend/reviewer_pr_assignment.py+++ b/products/signals/backend/reviewer_pr_assignment.py@@ -387,8 +387,8 @@ def dri_candidate_logins(of the team that owns the changed files. The suggested reviewers are the owners only when noownership source names a team.- Within a rung, somebody who has touched this code comes first — an owning-team member among- those who opted in, and a suggested reviewer among the team.+ Among those who opted in, an owning-team member comes first. Among the owning team, commit+ history gives no priority, so one prolific committer does not get every pull request."""team_logins = list(team.logins) if team is not None and team.logins else []owners = team_logins or reviewers@@ -397,7 +397,6 @@ def dri_candidate_logins(candidates = [claimant]candidates += [login for login in opted_in_ranked if login in team_logins]candidates += opted_in_ranked- candidates += [login for login in owners if login in reviewers]candidates += ownersreturn list(dict.fromkeys(login for login in candidates if login))diff --git a/products/signals/backend/test/test_reviewer_pr_assignment.py b/products/signals/backend/test/test_reviewer_pr_assignment.pyindex da0a54543d1d..80fe3a111213 100644--- a/products/signals/backend/test/test_reviewer_pr_assignment.py+++ b/products/signals/backend/test/test_reviewer_pr_assignment.py@@ -451,7 +451,7 @@ class TestDirectlyResponsibleIndividual:return githubdef _team_x(self, github: MagicMock) -> None:- github.list_team_members.return_value = {"success": True, "logins": ["bob", "dave", "stranger"]}+ github.list_team_members.return_value = {"success": True, "logins": ["Bob", "dave", "stranger"]}def _claim(self, team, report, users: dict, *, kind: str, login: str, automation_branch: str | None = "auto"@@ -566,26 +566,26 @@ class TestDirectlyResponsibleIndividual:@pytest.mark.parametrize(("reviewers", "team_by_path", "members", "claimant", "expected_owner"),[- (["alice"], {"a.py": "team-x", "b.py": "team-x", "c.py": "team-y"}, {"success": True}, None, "dave"),- (["bob"], {"a.py": "team-x"}, {"success": True}, None, "bob"),- (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "carol"), "dave"),- (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "bob"), "dave"),+ (["alice"], {"a.py": "team-x", "b.py": "team-x", "c.py": "team-y"}, {"success": True}, None, "stranger"),+ (["bob"], {"a.py": "team-x"}, {"success": True}, None, "stranger"),+ (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "carol"), "stranger"),+ (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "bob"), "stranger"),(["alice"], {"a.py": "team-x"}, {"success": True}, ("user", "carol"), "carol"),(["alice"], None, {"success": True}, None, "alice"),(["alice"], {"a.py": UNOWNED_TEAM}, {"success": True}, None, "alice"),(["alice"], {"a.py": "team-x"}, {"success": False, "status_code": 403}, None, "alice"),- (["alice"], {"a.py": "team-y"}, {"success": True}, None, "alice"),+ (["alice"], {"a.py": "team-z"}, {"success": True}, None, "alice"),],ids=[- "random_member_of_the_majority_team",- "a_suggested_member_comes_before_a_random_one",+ "random_member_of_the_majority_team_without_a_posthog_account",+ "a_suggested_member_gets_no_priority_in_the_team","a_task_claim_outside_the_team_does_not_rank","a_task_claim_inside_the_team_does_not_reorder_it","a_person_who_chose_the_work_outranks_the_team","no_owners_files_uses_reviewers","unowned_files_use_reviewers","unreadable_team_uses_reviewers",- "team_without_org_members_uses_reviewers",+ "team_without_members_uses_reviewers",],)def test_the_owning_team_supplies_the_owner(@@ -606,7 +606,7 @@ class TestDirectlyResponsibleIndividual:ownership.return_value = PathOwnership(team_by_path=team_by_path, registry={}, resolved=True)github = self._github(existing_assignees=[], assignable=None)github.list_pull_request_files.return_value = {"success": True, "paths": list(team_by_path or ["a.py"])}- logins_by_team = {"team-x": ["bob", "dave", "stranger"], "team-y": ["stranger"]}+ logins_by_team = {"team-x": ["Bob", "dave", "Stranger"], "team-y": ["stranger"], "team-z": []}github.list_team_members.side_effect = lambda _org, slug: {**members, "logins": logins_by_team[slug]}with patch(