Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions scripts/pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@
re-request or a further wait does not clear, unlike 41's other causes (a file count
over the limit, cleared by splitting the pull request), so it is its own code rather
than folded into 41: proceed on the other reviewers' coverage instead of retrying.
47 = this pull request's head carries no Copilot activity of its own, and the
reviewer's own most recent activity anywhere else in the repository, another pull
request's review or comment, is that same account-quota refusal with nothing having
answered it since. The poll that would
47 = this pull request's current head carries no Copilot activity of its own, and
the reviewer's own most recent activity found in the repository, a review or comment
on any pull request including an earlier round on this one, is that same
account-quota refusal with nothing having answered it since. The poll that would
otherwise have run is skipped for this reason, printed as a `note:` line before the
digest, rather than spent finding the same account state out a call late. Pass
--ignore-quota-signal to poll --timeout anyway once the quota is believed to have
reset. 46 is read directly from this pull request and 47 is inferred from another
one, so a genuine 0/40/41/42/43/45 on this pull request outranks 47 whenever both
reset. 46 is read directly from the current head and always takes priority over 47,
so a genuine 0/40/41/42/43/45 on this pull request outranks 47 whenever both
would otherwise apply.
A pending request remains pending until a review, an answer, or the timeout. GitHub's
effort-labeled review lifecycle does not always emit `copilot_work_started`, so that
Expand Down Expand Up @@ -514,12 +514,12 @@ def copilot_history(owner: str, repo: str) -> list[tuple[int, dict]]:
where it looked rather than just assert one. Sorted by timestamp rather than trusted to
arrive in that order, since the two connections are read separately and merged.

Unfiltered, including the caller's own pull request if it appears in the window, since
`copilot_bot_id` is happy to read a valid id from anywhere, including an earlier round on
the very pull request `wait` is running against. A caller needing the repo-wide quota
reading instead, where the caller's own pull request adds nothing and only crowds its own
"most recently updated" window, filters this result by pull request number before handing
it to `quota_signal` rather than losing that id lookup to the same exclusion.
Unfiltered, including the caller's own pull request if it appears in the window. No pull
request is special-cased out: `copilot_bot_id` is happy to read a valid id from anywhere,
including an earlier round on the very pull request `wait` is running against, and
`quota_signal` treats an earlier round on that same pull request as real evidence about the
account rather than a self-reference to discard. A refusal on the caller's own current head
is caught directly, at higher priority, before either reading here is ever consulted.

A plain comment is read alongside a formal review, tagged `_kind` so `copilot_bot_id` can
still tell them apart, because `answered_outside_review` already treats a comment as
Expand Down Expand Up @@ -2168,10 +2168,9 @@ def main(argv: list[str] | None = None) -> int:
history = [] if done or answer or drift else copilot_history(owner, repo)
# `--ignore-quota-signal` only changes whether the signal below is acted on.
# It does not change whether the history is read, since the auto-request line still needs it for the bot id regardless.
# Filtered to elsewhere only for the signal, since this pull request's own head is already read directly and an earlier round on it is still a valid bot id for the auto-request below.
signal = (
None if a.ignore_quota_signal else quota_signal([e for e in history if e[0] != a.number])
)
# Read from the same, unfiltered history rather than one that drops this pull request's own entries: a genuine review on an earlier head of this same pull request, superseded since by a push, is real evidence about the account and not a self-reference to discard.
# A refusal on this pull request's own current head still never reaches this signal, since it is caught directly and at higher priority first.
signal = None if a.ignore_quota_signal else quota_signal(history)
# Request before the first poll, not just at the call site: a caller expects `wait` to make a review happen, not merely to watch for one.
# Two prior gaps this closed, a push superseding an already-answered request and an auto-seed that never fired, both left nothing outstanding for the loop below to ever see land.
# Skipped once a review already covers the head, once Copilot has already answered outside a formal review, or once something is already in the request set, so a second `wait` on the same PR never double-requests.
Expand Down
57 changes: 42 additions & 15 deletions scripts/tests/test_pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -2507,26 +2507,56 @@ def test_a_silent_head_short_circuits_on_the_repo_wide_quota_signal(self) -> Non
self.assertEqual(1, len([c for c in calls if "requestReviews" in c[0]]))

def test_the_current_pull_requests_own_bot_id_still_seeds_the_auto_request(self) -> None:
"""The bot-id lookup reads the caller's own history unfiltered even though the signal
excludes it: an earlier round on this very pull request is still a valid id to request
with, and it must not also be misread as repo-wide evidence about this same head.
"""An earlier round on this very pull request is still a valid id to request with."""
self.answer(payload([review(oid=OLD)]))
calls = self.wire_history([hist_review(7, OVERVIEW + "\n" + COVERED, at=EARLY)])
with mock.patch.object(pr_review.time, "sleep") as slept:
self.assertEqual(30, self.cli(["wait", "7", "--timeout", "0"]))
slept.assert_not_called()
mutations = [(q, v) for q, v in calls if "requestReviews" in q]
self.assertEqual(1, len(mutations))
self.assertEqual("BOT_1", mutations[0][1].get("bot"))
out = self.out.getvalue()
self.assertNotIn("COPILOT_QUOTA_EXHAUSTED_REPO_WIDE", out)
self.assertIn("status=PENDING", out)

def test_a_genuine_review_on_this_pull_requests_own_earlier_head_clears_the_signal(
self,
) -> None:
"""A pull request number is not what makes an entry irrelevant to the repo-wide signal.

The history entry carries a quota refusal specifically, since ordinary content would
pass this same assertion whether or not the exclusion existed at all: it is the refusal
that a caller-scoped exclusion has to catch and a missing one would leak through as 47.
An earlier round posted before this pull request's current head is real evidence about
the account, not a self-reference to discard, and it correctly outranks a strictly
older refusal elsewhere: excluding this pull request's own history entirely, as an
earlier fix here did, would have hidden that evidence and let the older refusal read
as the newest activity instead.
"""
self.answer(payload([review(oid=OLD)]))
calls = self.wire_history([hist_review(7, QUOTA_REFUSED, at=EARLY)])
calls = self.wire_history(
[
hist_review(900, QUOTA_REFUSED, at=EARLY),
hist_review(7, OVERVIEW + "\n" + COVERED, at=LATE),
]
)
with mock.patch.object(pr_review.time, "sleep") as slept:
self.assertEqual(30, self.cli(["wait", "7", "--timeout", "0"]))
slept.assert_not_called()
mutations = [(q, v) for q, v in calls if "requestReviews" in q]
self.assertEqual(1, len(mutations))
self.assertEqual("BOT_1", mutations[0][1].get("bot"))
out = self.out.getvalue()
self.assertNotIn("COPILOT_QUOTA_EXHAUSTED_REPO_WIDE", out)
self.assertIn("status=PENDING", out)

def test_a_stale_refusal_on_this_pull_requests_own_earlier_head_still_signals(self) -> None:
"""This pull request's own older refusal is exactly as much evidence as any other pull
request's, once nothing on the current head answers it directly first."""
self.answer(payload([]))
self.wire_history([hist_review(7, QUOTA_REFUSED, at=EARLY)])
with mock.patch.object(pr_review.time, "sleep") as slept:
self.assertEqual(47, self.cli(["wait", "7"]))
slept.assert_not_called()
self.assertIn("status=COPILOT_QUOTA_EXHAUSTED_REPO_WIDE", self.out.getvalue())

def test_a_genuine_review_since_the_refusal_clears_the_signal(self) -> None:
"""The most recent record settles it: a working round after the refusal spends it."""
self.answer(payload([]))
Expand Down Expand Up @@ -2641,11 +2671,10 @@ def test_a_later_comment_outranks_an_earlier_review_in_the_merged_history(self)
self.assertEqual("comment", history[0][1]["_kind"])
self.assertIsNone(pr_review.quota_signal(history))

def test_copilot_history_is_unfiltered_so_a_caller_can_choose_what_to_exclude(self) -> None:
"""`copilot_bot_id` reads a valid id from anywhere, including the caller's own pull
request, so the fetch itself carries every pull request in the window; a caller
computing the repo-wide quota signal instead filters this result by number itself,
rather than losing that id lookup to the same exclusion."""
def test_copilot_history_carries_the_callers_own_pull_request_too(self) -> None:
"""No pull request is special-cased out of the fetch, the caller's own included: an
earlier round on it is a valid id for `copilot_bot_id` and real evidence for
`quota_signal` alike, neither of which this function decides on its own."""
self.answer(payload([]))
self.enterContext(
mock.patch.object(
Expand All @@ -2665,8 +2694,6 @@ def test_copilot_history_is_unfiltered_so_a_caller_can_choose_what_to_exclude(se
)
history = pr_review.copilot_history("o", "r")
self.assertEqual([969, 962], [number for number, _ in history])
elsewhere = [e for e in history if e[0] != 969]
self.assertEqual([962], [number for number, _ in elsewhere])

def test_an_empty_history_carries_no_signal_and_no_bot_id(self) -> None:
self.assertIsNone(pr_review.quota_signal([]))
Expand Down