diff --git a/.github/scripts/pull-request-dashboard/RATIONALE.md b/.github/scripts/pull-request-dashboard/RATIONALE.md index b37bf7c5efb4..b9a8311508ff 100644 --- a/.github/scripts/pull-request-dashboard/RATIONALE.md +++ b/.github/scripts/pull-request-dashboard/RATIONALE.md @@ -381,10 +381,23 @@ the implementation understandable and operationally cheap. gate would arrive older still. Either way the age blames reviewers for a wait they could not have answered, and sorts the PR above ones they really have been sitting on. -- Only the handoff from the author restarts the wait. A held PR that was already - with reviewers and is released to maintainers keeps its wait, because it never - left the people who owe it a response, and restarting there would present an - approval a week old as a merge request that just arrived. +- Without an explicit command, only the handoff from the author restarts the + wait. A held PR already with reviewers and released to maintainers keeps its + wait, because it never left the people who owe it a response, and restarting + there would present an approval a week old as a merge request that just arrived. +- An explicit `/dashboard route:reviewers` command starts the reviewer wait at + the command's effective timestamp, including when an approver issues it or the + PR is already with reviewers. The handoff overrides older activity and pending + threads, so reviewers are not charged for time before the explicit handoff. + That timestamp remains a lower bound while the handoff is active, including + across refreshes and pushes, without replacing a later review re-request. +- Handoffs and pending human re-requests are ordered by their GitHub event + timestamps, not by when a refresh discovers them or which clock rule runs + first. Pending review requests have no timestamp themselves, so the timestamp + comes from the paginated review-request timeline. An active handoff uses the + later of its command and the pending re-requests, including without cached + routing state. An undated request cannot supersede a dated handoff. Completing + a re-request preserves its cached wait as the PR progresses to maintainers. - PRs from unattended automation never route to their author because the automation cannot respond to a dashboard action. Copilot-delegated PRs are different. The dashboard recovers a human assignee or the first commit's diff --git a/.github/scripts/pull-request-dashboard/dashboard.py b/.github/scripts/pull-request-dashboard/dashboard.py index 9ab34bf1fcd1..cb540e114825 100644 --- a/.github/scripts/pull-request-dashboard/dashboard.py +++ b/.github/scripts/pull-request-dashboard/dashboard.py @@ -218,6 +218,10 @@ handoff reaches reviewers, restarted when a re-review returns the PR to approvers, + or dated by the later of an + explicit reviewer handoff + and pending human re-requests + using their event timestamps, and otherwise never moves forward on a reviewer route. waiting_age_basis str Which heuristic chose diff --git a/.github/scripts/pull-request-dashboard/github_cli.py b/.github/scripts/pull-request-dashboard/github_cli.py index e5208e770b18..9209f72889cb 100644 --- a/.github/scripts/pull-request-dashboard/github_cli.py +++ b/.github/scripts/pull-request-dashboard/github_cli.py @@ -1012,6 +1012,53 @@ def fetch_review_threads(owner: str, repo_name: str, number: int) -> list[dict[s """ +REVIEW_REQUEST_EVENTS_QUERY = """ +query($owner: String!, $name: String!, $number: Int!, $after: String) { + repository(owner: $owner, name: $name) { + pullRequest(number: $number) { + timelineItems(first: 100, after: $after, itemTypes: [REVIEW_REQUESTED_EVENT]) { + pageInfo { + hasNextPage + endCursor + } + nodes { + ... on ReviewRequestedEvent { + createdAt + requestedReviewer { + ... on User { + login + } + } + } + } + } + } + } +} +""" + + +def _review_request_times(owner: str, repo_name: str, number: int) -> dict[str, str]: + requested_at: dict[str, str] = {} + after: str | None = None + while True: + data = gh_graphql( + REVIEW_REQUEST_EVENTS_QUERY, + {"owner": owner, "name": repo_name, "number": number, "after": after}, + ) + page = (((data.get("data") or {}).get("repository") or {}).get("pullRequest") or {}).get("timelineItems") or {} + for event in page.get("nodes") or []: + login = (event.get("requestedReviewer") or {}).get("login") + timestamp = event.get("createdAt") + if login and timestamp: + key = login.casefold() + requested_at[key] = max(timestamp, requested_at.get(key, "")) + page_info = page.get("pageInfo") or {} + if not page_info.get("hasNextPage"): + return requested_at + after = page_info.get("endCursor") or "" + + def fetch_review_requests(owner: str, repo_name: str, number: int) -> list[dict[str, Any]]: # `gh pr view --json reviewRequests` silently drops Bot reviewers, so a # pending Copilot request looks absent. Ask GraphQL for the Bot node @@ -1030,5 +1077,16 @@ def fetch_review_requests(owner: str, repo_name: str, number: int) -> list[dict[ reviewers.append(reviewer) page_info = page.get("pageInfo") or {} if not page_info.get("hasNextPage"): - return reviewers + break after = page_info.get("endCursor") or "" + human_reviewers = [ + reviewer for reviewer in reviewers + if reviewer.get("__typename") == "User" and reviewer.get("login") + ] + if human_reviewers: + requested_at = _review_request_times(owner, repo_name, number) + for reviewer in human_reviewers: + timestamp = requested_at.get(reviewer["login"].casefold()) + if timestamp: + reviewer["requested_at"] = timestamp + return reviewers diff --git a/.github/scripts/pull-request-dashboard/pull_request_evaluation.py b/.github/scripts/pull-request-dashboard/pull_request_evaluation.py index fc8a292fd900..ba7fdec4d210 100644 --- a/.github/scripts/pull-request-dashboard/pull_request_evaluation.py +++ b/.github/scripts/pull-request-dashboard/pull_request_evaluation.py @@ -576,6 +576,11 @@ async def evaluate_pull_request( pending_human_reviewer_logins=( prepared_reviewers.pending_human_reviewer_logins ), + pending_review_requested_at={ + request.login: request.requested_at + for request in pr_source.review_requests + if request.login in prepared_reviewers.pending_human_reviewer_logins + }, ) ) route = routing_outcome.route diff --git a/.github/scripts/pull-request-dashboard/pull_request_source.py b/.github/scripts/pull-request-dashboard/pull_request_source.py index 9b1adddf691e..3182552fd17b 100644 --- a/.github/scripts/pull-request-dashboard/pull_request_source.py +++ b/.github/scripts/pull-request-dashboard/pull_request_source.py @@ -271,6 +271,7 @@ def effective_content_timestamp(self) -> str: class ReviewRequest: kind: str = "" login: str = "" + requested_at: str = "" @property def is_copilot_reviewer(self) -> bool: @@ -639,6 +640,7 @@ def normalize_review_requests(values: Any) -> tuple[ReviewRequest, ...]: or ("Team" if reviewer.get("slug") else "") ), login=_text(reviewer.get("login") or reviewer.get("slug")), + requested_at=_text(item.get("requested_at")), )) return tuple(requests) diff --git a/.github/scripts/pull-request-dashboard/routing_decision.py b/.github/scripts/pull-request-dashboard/routing_decision.py index 502a621d9c7c..70ac537b6449 100644 --- a/.github/scripts/pull-request-dashboard/routing_decision.py +++ b/.github/scripts/pull-request-dashboard/routing_decision.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Mapping -from dataclasses import dataclass +from dataclasses import dataclass, field from datetime import datetime, timedelta from typing import Any @@ -33,6 +33,7 @@ class RoutingInput: require_clean_copilot_review: bool manual_reviewer_handoff: bool pending_human_reviewer_logins: frozenset[str] + pending_review_requested_at: Mapping[str, str] = field(default_factory=dict) now: datetime | None = None @@ -242,12 +243,51 @@ def _add_wait_age_facts( previous_facts: DashboardFacts, now: datetime, pending_human_reviewer_logins: frozenset[str], + pending_review_requested_at: Mapping[str, str], ) -> DashboardFacts: + handoff_ts = ( + parse_ts(facts.dashboard_override_since) + if route.value in _REVIEWER_ROUTES and reviewer_handoff_active(facts) + else None + ) + previous_wait_ts = parse_ts(previous_facts.waiting_since) + request_times = [ + timestamp + for login in pending_human_reviewer_logins + if (timestamp := parse_ts(pending_review_requested_at.get(login))) is not None + ] + latest_request_ts = max(request_times, default=None) + if handoff_ts is not None: + wait_ts, basis = handoff_ts, "reviewer_handoff" + if latest_request_ts is not None and latest_request_ts > wait_ts: + wait_ts, basis = latest_request_ts, "review_rerequest" + if ( + previous_route is not None + and previous_route.value in _REVIEWER_ROUTES + and previous_facts.waiting_age_basis == "review_rerequest" + and parse_ts(previous_facts.dashboard_override_since) == handoff_ts + and previous_wait_ts is not None + and previous_wait_ts > wait_ts + ): + wait_ts, basis = previous_wait_ts, "review_rerequest" + return facts.with_changes( + waiting_since=format_ts(wait_ts), + waiting_age_basis=basis, + ) previous_pending_reviewers = { reviewer.login for reviewer in previous_facts.reviewers if reviewer.pending_review } + if ( + route is DashboardRoute.APPROVER + and previous_route is DashboardRoute.MAINTAINER + and pending_human_reviewer_logins - previous_pending_reviewers + ): + return facts.with_changes( + waiting_since=format_ts(latest_request_ts or now), + waiting_age_basis="review_rerequest", + ) if facts.route_held_for_gates and previous_facts.waiting_since: return facts.with_changes( waiting_since=previous_facts.waiting_since, @@ -262,15 +302,6 @@ def _add_wait_age_facts( waiting_since=format_ts(now), waiting_age_basis="gate_release", ) - if ( - route is DashboardRoute.APPROVER - and previous_route is DashboardRoute.MAINTAINER - and pending_human_reviewer_logins - previous_pending_reviewers - ): - return facts.with_changes( - waiting_since=format_ts(now), - waiting_age_basis="review_rerequest", - ) if ( route.value in _REVIEWER_ROUTES and previous_route is not None @@ -311,7 +342,6 @@ def _add_wait_age_facts( if wait_ts is None: wait_ts = parse_ts(facts.created_at) basis = "created" - previous_wait_ts = parse_ts(previous_facts.waiting_since) if ( route.value in _REVIEWER_ROUTES and previous_route is not None @@ -367,5 +397,6 @@ def resolve_routing(routing_input: RoutingInput) -> RoutingOutcome: routing_input.previous_facts, now, routing_input.pending_human_reviewer_logins, + routing_input.pending_review_requested_at, ) return RoutingOutcome(route=route, facts=facts) diff --git a/.github/scripts/pull-request-dashboard/state.py b/.github/scripts/pull-request-dashboard/state.py index 32829b5dba61..845eaf9ca3ac 100644 --- a/.github/scripts/pull-request-dashboard/state.py +++ b/.github/scripts/pull-request-dashboard/state.py @@ -44,7 +44,7 @@ # caches. Every constant ending in _STATE_VERSION or _REVISION is included. # dashboard-state.json: accepted PR routing results and backfill readiness. # Routing facts include current-head Copilot error counts for bounded retries. -DASHBOARD_STATE_VERSION = 19 +DASHBOARD_STATE_VERSION = 20 DASHBOARD_STATE_COMPATIBLE_VERSIONS: tuple[int, ...] = () # backfill-state.json: round-robin cursor used by full dashboard refreshes. BACKFILL_STATE_VERSION = 3 diff --git a/.github/scripts/pull-request-dashboard/test_dashboard.py b/.github/scripts/pull-request-dashboard/test_dashboard.py index 84c1181fd99d..1efb67a5629f 100644 --- a/.github/scripts/pull-request-dashboard/test_dashboard.py +++ b/.github/scripts/pull-request-dashboard/test_dashboard.py @@ -913,7 +913,7 @@ async def test_evaluation_routes_pending_reviewers_and_projects_reviewer_rows( submitted_at="2026-08-16T08:00:00Z", body="", ),), - review_requests=(review_request(),), + review_requests=(review_request(requested_at="2026-08-16T09:00:00Z"),), ) result = await evaluate_pr( @@ -927,6 +927,10 @@ async def test_evaluation_routes_pending_reviewers_and_projects_reviewer_rows( frozenset({"reviewer"}), routing_input.pending_human_reviewer_logins, ) + self.assertEqual( + {"reviewer": "2026-08-16T09:00:00Z"}, + routing_input.pending_review_requested_at, + ) self.assertEqual( (ReviewerSummary(login="reviewer", pending_review=True),), result.facts.reviewers, diff --git a/.github/scripts/pull-request-dashboard/test_github_cli.py b/.github/scripts/pull-request-dashboard/test_github_cli.py index 95e62b97c28c..3d647d044274 100644 --- a/.github/scripts/pull-request-dashboard/test_github_cli.py +++ b/.github/scripts/pull-request-dashboard/test_github_cli.py @@ -36,12 +36,12 @@ from pull_request_source import fetch_pull_request_source -def _review_requests_page(nodes, has_next=False, cursor=""): +def _review_requests_page(nodes, has_next=False, cursor="", connection="reviewRequests"): return { "data": { "repository": { "pullRequest": { - "reviewRequests": { + connection: { "pageInfo": { "hasNextPage": has_next, "endCursor": cursor, @@ -240,7 +240,7 @@ def test_returns_bot_reviewers_that_gh_pr_view_omits(self) -> None: reviewers, ) # A Bot login is only returned when the query asks for it explicitly. - self.assertIn("... on Bot", gh_graphql.call_args.args[0]) + self.assertIn("... on Bot", gh_graphql.call_args_list[0].args[0]) def test_skips_reviewers_the_caller_cannot_see(self) -> None: page = _review_requests_page([ @@ -266,6 +266,7 @@ def test_follows_pagination(self) -> None: _review_requests_page( [{"requestedReviewer": {"__typename": "User", "login": "second"}}], ), + _review_requests_page([], connection="timelineItems"), ] with patch("github_cli.gh_graphql", side_effect=pages) as gh_graphql: @@ -277,6 +278,64 @@ def test_follows_pagination(self) -> None: gh_graphql.call_args_list[1].args[1]["after"], ) + def test_attaches_latest_request_time_across_timeline_pages(self) -> None: + pages = [ + _review_requests_page([ + {"requestedReviewer": {"__typename": "User", "login": "reviewer"}}, + {"requestedReviewer": {"__typename": "Team", "slug": "approvers"}}, + ]), + _review_requests_page( + [ + {"createdAt": "2026-08-16T08:00:00Z", + "requestedReviewer": {"login": "reviewer"}}, + {"createdAt": "2026-08-16T09:00:00Z", + "requestedReviewer": None}, + ], + has_next=True, + cursor="timeline-next", + connection="timelineItems", + ), + _review_requests_page( + [ + {"createdAt": "2026-08-16T11:00:00Z", + "requestedReviewer": {"login": "Reviewer"}}, + {"createdAt": "2026-08-16T10:00:00Z", + "requestedReviewer": {"login": "reviewer"}}, + ], + connection="timelineItems", + ), + ] + with patch("github_cli.gh_graphql", side_effect=pages) as query: + reviewers = fetch_review_requests("owner", "repo", 7) + + self.assertEqual([ + {"__typename": "User", "login": "reviewer", + "requested_at": "2026-08-16T11:00:00Z"}, + {"__typename": "Team", "slug": "approvers"}, + ], reviewers) + self.assertEqual("timeline-next", query.call_args_list[2].args[1]["after"]) + + def test_does_not_fetch_timeline_for_bot_and_team_requests(self) -> None: + page = _review_requests_page([ + {"requestedReviewer": {"__typename": "Bot", "login": "Copilot"}}, + {"requestedReviewer": {"__typename": "Team", "slug": "approvers"}}, + ]) + with patch("github_cli.gh_graphql", return_value=page) as query: + fetch_review_requests("owner", "repo", 7) + + query.assert_called_once() + + def test_timeline_failure_is_not_treated_as_missing_timestamps(self) -> None: + page = _review_requests_page([ + {"requestedReviewer": {"__typename": "User", "login": "reviewer"}}, + ]) + with patch( + "github_cli.gh_graphql", + side_effect=[page, TransientGhError("timeline unavailable")], + ): + with self.assertRaisesRegex(TransientGhError, "timeline unavailable"): + fetch_review_requests("owner", "repo", 7) + class GithubCliTest(unittest.TestCase): def test_generic_action_required_keeps_unknown_ownership(self) -> None: diff --git a/.github/scripts/pull-request-dashboard/test_pull_request_source.py b/.github/scripts/pull-request-dashboard/test_pull_request_source.py index e5cc257f54b4..b96c787c05c0 100644 --- a/.github/scripts/pull-request-dashboard/test_pull_request_source.py +++ b/.github/scripts/pull-request-dashboard/test_pull_request_source.py @@ -111,7 +111,8 @@ def test_normalizes_mixed_gh_rest_and_graphql_shapes(self) -> None: "requestedReviewer": { "__typename": "Team", "slug": "maintainers", - } + }, + "requested_at": "2026-08-20T08:00:00Z", } ], "review_threads": [ @@ -194,6 +195,7 @@ def test_normalizes_mixed_gh_rest_and_graphql_shapes(self) -> None: ) self.assertEqual(13, source.reviews[0].database_id) self.assertEqual("maintainers", source.review_requests[0].login) + self.assertEqual("2026-08-20T08:00:00Z", source.review_requests[0].requested_at) self.assertEqual( "2026-08-20T08:30:00Z", source.review_threads[0].comments[0].updated_at, diff --git a/.github/scripts/pull-request-dashboard/test_routing_decision.py b/.github/scripts/pull-request-dashboard/test_routing_decision.py index 56f408c7f49e..d7f123368b69 100644 --- a/.github/scripts/pull-request-dashboard/test_routing_decision.py +++ b/.github/scripts/pull-request-dashboard/test_routing_decision.py @@ -28,6 +28,7 @@ def resolve( require_clean_copilot_review: bool = False, manual_reviewer_handoff: bool = False, pending_human_reviewer_logins: frozenset[str] = frozenset(), + pending_review_requested_at: dict[str, str] | None = None, now: datetime = NOW, ) -> RoutingOutcome: typed_facts = ( @@ -54,6 +55,7 @@ def resolve( require_clean_copilot_review=require_clean_copilot_review, manual_reviewer_handoff=manual_reviewer_handoff, pending_human_reviewer_logins=pending_human_reviewer_logins, + pending_review_requested_at=pending_review_requested_at or {}, now=now, ) ) @@ -218,6 +220,7 @@ def test_manual_handoff_has_the_complete_expected_outcome(self) -> None: "ci_pending_count": 1, "head_sha": "abc", "dashboard_override_head_sha": "abc", + "dashboard_override_since": "2026-08-16T11:55:00Z", "last_author_activity_at": "2026-08-16T08:00:00+00:00", "copilot_review_exists": False, "copilot_review_requested": False, @@ -240,8 +243,8 @@ def test_manual_handoff_has_the_complete_expected_outcome(self) -> None: "required_checks_settled": False, "route_hold_expired": False, "route_held_for_gates": False, - "waiting_since": "2026-08-16T08:00:00+00:00", - "waiting_age_basis": "last_author_activity", + "waiting_since": "2026-08-16T11:55:00+00:00", + "waiting_age_basis": "reviewer_handoff", }), ), outcome, @@ -830,6 +833,266 @@ def test_stale_copilot_review_can_expire_without_looking_settled(self) -> None: class RoutingWaitAgeTest(RoutingTestMixin, unittest.TestCase): + def test_manual_handoff_restarts_the_wait_from_the_command_timestamp(self) -> None: + for previous_route in (None, "author", "approver", "maintainer"): + for approval_count in (0, 1): + for held in (False, True): + with self.subTest( + previous_route=previous_route, + approval_count=approval_count, + held=held, + ): + outcome = self.resolve( + { + "approval_count": approval_count, + "head_sha": "abc", + "dashboard_override_head_sha": "abc", + "dashboard_override_since": "2026-08-16T11:55:00Z", + "last_author_activity_at": "2026-07-29T08:00:00Z", + }, + {"thread": { + "action": "reviewer", + "since": "2026-07-30T08:00:00Z", + }}, + previous_route=previous_route, + previous_facts={ + "head_sha": "abc", + "route_held_for_gates": held, + "waiting_since": "2026-07-29T08:00:00Z", + "waiting_age_basis": "last_author_activity", + }, + manual_reviewer_handoff=True, + ) + + self.assertEqual( + DashboardRoute.APPROVER + if approval_count == 0 else DashboardRoute.MAINTAINER, + outcome.route, + ) + self.assertEqual( + "2026-08-16T11:55:00+00:00", outcome.facts.waiting_since + ) + self.assertEqual( + "reviewer_handoff", outcome.facts.waiting_age_basis + ) + + def test_manual_handoff_wait_survives_refresh_push_and_route_progression(self) -> None: + facts = dashboard_facts( + head_sha="abc", + dashboard_override_head_sha="abc", + dashboard_override_since="2026-08-16T11:55:00Z", + dashboard_override_persistent=True, + last_author_activity_at="2026-07-29T08:00:00Z", + ) + started = self.resolve(facts, manual_reviewer_handoff=True) + for head_sha, approval_count, last_author_activity_at in ( + ("abc", 0, "2026-07-29T08:00:00Z"), + ("new-head", 0, "2026-08-16T12:30:00Z"), + ("new-head", 1, "2026-08-16T12:30:00Z"), + ): + with self.subTest(head_sha=head_sha, approval_count=approval_count): + outcome = self.resolve( + facts.with_changes( + head_sha=head_sha, + approval_count=approval_count, + last_author_activity_at=last_author_activity_at, + ), + {"thread": { + "action": "reviewer", + "since": "2026-07-30T08:00:00Z", + }}, + previous_route=started.route, + previous_facts=started.facts, + manual_reviewer_handoff=True, + now=NOW + timedelta(hours=1), + ) + + self.assertEqual( + "2026-08-16T11:55:00+00:00", outcome.facts.waiting_since + ) + self.assertEqual( + "reviewer_handoff", outcome.facts.waiting_age_basis + ) + + def test_manual_handoff_without_cached_state_survives_a_push(self) -> None: + outcome = self.resolve( + { + "head_sha": "new-head", + "dashboard_override_head_sha": "abc", + "dashboard_override_since": "2026-08-16T11:55:00Z", + "dashboard_override_persistent": True, + "last_author_activity_at": "2026-08-16T12:30:00Z", + }, + manual_reviewer_handoff=True, + now=NOW + timedelta(hours=1), + ) + + self.assertEqual("2026-08-16T11:55:00+00:00", outcome.facts.waiting_since) + self.assertEqual("reviewer_handoff", outcome.facts.waiting_age_basis) + + def test_inactive_or_undated_handoff_keeps_normal_wait_age(self) -> None: + for changes in ( + {"dashboard_override_since": ""}, + {"dashboard_override_since": "invalid"}, + {"dashboard_override_head_sha": ""}, + {"dashboard_override_head_sha": "old-head"}, + {"dashboard_override_cleared_by_feedback": True}, + ): + with self.subTest(changes=changes): + facts = dashboard_facts( + head_sha="abc", + ci_pending_count=0, + dashboard_override_head_sha="abc", + dashboard_override_since="2026-08-16T11:55:00Z", + last_author_activity_at="2026-07-29T08:00:00Z", + ).with_changes(**changes) + outcome = self.resolve( + facts, + manual_reviewer_handoff=reviewer_handoff_active(facts), + ) + + self.assertEqual( + "2026-07-29T08:00:00+00:00", outcome.facts.waiting_since + ) + self.assertEqual( + "last_author_activity", outcome.facts.waiting_age_basis + ) + + def test_manual_handoff_does_not_replace_a_later_review_rerequest(self) -> None: + facts = dashboard_facts( + head_sha="abc", + dashboard_override_head_sha="abc", + dashboard_override_since="2026-08-16T10:00:00Z", + last_author_activity_at="2026-07-29T08:00:00Z", + reviewers=[{"login": "reviewer", "pending_review": True}], + ) + for previous_since, previous_basis in ( + ("2026-08-16T10:00:00Z", "reviewer_handoff"), + ("2026-07-29T08:00:00Z", "last_author_activity"), + ): + with self.subTest(previous_since=previous_since): + started = self.resolve( + facts, + previous_route="maintainer", + previous_facts={ + "waiting_since": previous_since, + "waiting_age_basis": previous_basis, + }, + pending_human_reviewer_logins=frozenset({"reviewer"}), + pending_review_requested_at={"reviewer": "2026-08-16T11:00:00Z"}, + manual_reviewer_handoff=True, + ) + carried = self.resolve( + facts, + previous_route=started.route, + previous_facts=started.facts, + pending_human_reviewer_logins=frozenset({"reviewer"}), + pending_review_requested_at={"reviewer": "2026-08-16T11:00:00Z"}, + manual_reviewer_handoff=True, + now=NOW + timedelta(hours=1), + ) + + for outcome in (started, carried): + self.assertEqual( + "2026-08-16T11:00:00+00:00", outcome.facts.waiting_since + ) + self.assertEqual( + "review_rerequest", outcome.facts.waiting_age_basis + ) + + def test_handoff_and_rerequest_clocks_follow_event_order_not_refresh_time(self) -> None: + for requested_at, expected_since, expected_basis in ( + ("2026-08-16T08:00:00Z", "2026-08-16T09:00:00+00:00", "reviewer_handoff"), + ("2026-08-16T09:00:00Z", "2026-08-16T09:00:00+00:00", "reviewer_handoff"), + ("2026-08-16T10:00:00Z", "2026-08-16T10:00:00+00:00", "review_rerequest"), + ("2026-08-16T04:00:00-07:00", "2026-08-16T04:00:00-07:00", "review_rerequest"), + ("", "2026-08-16T09:00:00+00:00", "reviewer_handoff"), + ): + for previous_route in (None, "author", "approver", "maintainer"): + with self.subTest(requested_at=requested_at, previous_route=previous_route): + facts = dashboard_facts( + head_sha="abc", + dashboard_override_head_sha="abc", + dashboard_override_since="2026-08-16T09:00:00Z", + last_author_activity_at="2026-07-29T08:00:00Z", + reviewers=[{"login": "reviewer", "pending_review": True}], + ) + started = self.resolve( + facts, + previous_route=previous_route, + previous_facts={ + "waiting_since": "2026-07-29T08:00:00Z", + "waiting_age_basis": "last_author_activity", + }, + pending_human_reviewer_logins=frozenset({"reviewer"}), + pending_review_requested_at={"reviewer": requested_at}, + manual_reviewer_handoff=True, + ) + carried = self.resolve( + facts, + previous_route=started.route, + previous_facts=started.facts, + pending_human_reviewer_logins=frozenset({"reviewer"}), + pending_review_requested_at={"reviewer": requested_at}, + manual_reviewer_handoff=True, + now=NOW + timedelta(hours=1), + ) + for outcome in (started, carried): + self.assertEqual(expected_since, outcome.facts.waiting_since) + self.assertEqual(expected_basis, outcome.facts.waiting_age_basis) + + def test_completed_rerequest_does_not_roll_back_the_handoff_wait(self) -> None: + outcome = self.resolve( + { + "approval_count": 1, + "head_sha": "abc", + "dashboard_override_head_sha": "abc", + "dashboard_override_since": "2026-08-16T09:00:00Z", + }, + previous_route="approver", + previous_facts={ + "dashboard_override_since": "2026-08-16T09:00:00Z", + "waiting_since": "2026-08-16T10:00:00Z", + "waiting_age_basis": "review_rerequest", + }, + manual_reviewer_handoff=True, + ) + + self.assertEqual("maintainer", outcome.route) + self.assertEqual("2026-08-16T10:00:00+00:00", outcome.facts.waiting_since) + self.assertEqual("review_rerequest", outcome.facts.waiting_age_basis) + + def test_multiple_pending_rerequests_use_the_latest_event(self) -> None: + outcome = self.resolve( + { + "head_sha": "abc", + "dashboard_override_head_sha": "abc", + "dashboard_override_since": "2026-08-16T09:00:00Z", + }, + pending_human_reviewer_logins=frozenset({"first", "second"}), + pending_review_requested_at={ + "first": "2026-08-16T08:00:00Z", + "second": "2026-08-16T10:00:00Z", + "not-pending": "2026-08-16T11:00:00Z", + }, + manual_reviewer_handoff=True, + ) + + self.assertEqual("2026-08-16T10:00:00+00:00", outcome.facts.waiting_since) + self.assertEqual("review_rerequest", outcome.facts.waiting_age_basis) + + def test_rerequest_without_a_handoff_uses_the_event_time(self) -> None: + outcome = self.resolve( + {"ci_pending_count": 0}, + previous_route="maintainer", + previous_facts={"waiting_since": "2026-08-16T08:00:00Z"}, + pending_human_reviewer_logins=frozenset({"reviewer"}), + pending_review_requested_at={"reviewer": "2026-08-16T10:00:00Z"}, + ) + + self.assertEqual("2026-08-16T10:00:00+00:00", outcome.facts.waiting_since) + self.assertEqual("review_rerequest", outcome.facts.waiting_age_basis) + def test_held_route_carries_the_previous_wait_forward(self) -> None: outcome = self.resolve( { diff --git a/.github/scripts/pull-request-dashboard/test_state.py b/.github/scripts/pull-request-dashboard/test_state.py index 65d9c3432687..a32cd9441c07 100644 --- a/.github/scripts/pull-request-dashboard/test_state.py +++ b/.github/scripts/pull-request-dashboard/test_state.py @@ -906,7 +906,7 @@ def test_legacy_dashboard_state_payload_reencodes_to_current_shape(self) -> None def test_notification_state_version_is_independent(self) -> None: self.assertEqual(BACKFILL_STATE_VERSION, 3) self.assertEqual(NOTIFICATION_STATE_VERSION, 3) - self.assertEqual(DASHBOARD_STATE_VERSION, 19) + self.assertEqual(DASHBOARD_STATE_VERSION, 20) self.assertEqual(DASHBOARD_STATE_COMPATIBLE_VERSIONS, ()) self.assertEqual(STATUS_COMMENT_ROLLOUT_STATE_VERSION, 3) self.assertEqual(STATUS_COMMENT_REVISION, 22) diff --git a/pull-request-dashboard/README.md b/pull-request-dashboard/README.md index aee49030f91a..a4de2fc39410 100644 --- a/pull-request-dashboard/README.md +++ b/pull-request-dashboard/README.md @@ -243,8 +243,13 @@ The dashboard groups open non-draft pull requests by who is expected to act next reviewer comment yesterday shows `1d` when it is waiting on the author. When possible, this is based on the oldest pending thread for the routed party; otherwise it falls back to the latest activity from the opposite party, then - to recent PR activity or PR creation time. Format: `<1m`, `Xm`, `Xh`, or - `Xd`. + to recent PR activity or PR creation time. An explicit + `/dashboard route:reviewers` handoff starts the reviewer wait at the command's + timestamp, even when older author activity or pending threads remain. Refreshes + and pushes do not restart that wait while the handoff stays active. + A later human review re-request starts a new wait at its GitHub event + timestamp; a re-request before the command does not override the handoff. + Format: `<1m`, `Xm`, `Xh`, or `Xd`. Merge conflicts remain visible without overriding normal CI, discussion, and approval routing. A conflicted PR can therefore stay with reviewers or