Skip to content

Commit 5edb00a

Browse files
Copilottrask
andauthored
Recognize Copilot "insufficient remaining quota" notice for review fallback (#501)
* Initial plan * Recognize insufficient-quota Copilot notice for review fallback Co-authored-by: trask <218610+trask@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trask <218610+trask@users.noreply.github.com>
1 parent 2b4a315 commit 5edb00a

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎.github/scripts/pull-request-dashboard/copilot_review.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
)
2323

2424

25-
COPILOT_QUOTA_FAILURE_BODY = (
25+
COPILOT_QUOTA_FAILURE_BODIES = frozenset({
2626
"Copilot was unable to review this pull request because the user who "
27-
"requested the review has reached their quota limit."
28-
)
27+
"requested the review has reached their quota limit.",
28+
"Copilot was unable to review this pull request because the user who "
29+
"requested the review has insufficient remaining quota.",
30+
})
2931
COPILOT_ERROR_BODY = (
3032
"Copilot encountered an error and was unable to review this pull request. "
3133
"You can try again by re-requesting a review."
@@ -51,7 +53,7 @@ def is_copilot_reviewer(
5153
def is_copilot_quota_failure(review: Review) -> bool:
5254
return (
5355
is_copilot_reviewer(review)
54-
and review.body.strip() == COPILOT_QUOTA_FAILURE_BODY
56+
and review.body.strip() in COPILOT_QUOTA_FAILURE_BODIES
5557
)
5658

5759

‎.github/scripts/pull-request-dashboard/test_copilot_review.py‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
"Copilot was unable to review this pull request because the user who "
5353
"requested the review has reached their quota limit."
5454
)
55+
INSUFFICIENT_QUOTA_FAILURE_BODY = (
56+
"Copilot was unable to review this pull request because the user who "
57+
"requested the review has insufficient remaining quota."
58+
)
5559
ERROR_BODY = (
5660
"Copilot encountered an error and was unable to review this pull request. "
5761
"You can try again by re-requesting a review."
@@ -203,6 +207,17 @@ def test_quota_failure_requires_the_copilot_actor_and_exact_notice(self) -> None
203207
self.assertFalse(is_copilot_quota_failure(
204208
replace(failure, actor=actor("reviewer"))
205209
))
210+
insufficient = replace(failure, body=INSUFFICIENT_QUOTA_FAILURE_BODY)
211+
self.assertTrue(is_copilot_quota_failure(insufficient))
212+
self.assertTrue(is_copilot_quota_failure(
213+
replace(insufficient, body=f"\n{INSUFFICIENT_QUOTA_FAILURE_BODY}\n")
214+
))
215+
self.assertFalse(is_copilot_quota_failure(
216+
replace(insufficient, actor=actor("reviewer"))
217+
))
218+
self.assertFalse(is_copilot_quota_failure(
219+
replace(insufficient, body=f"> {INSUFFICIENT_QUOTA_FAILURE_BODY}")
220+
))
206221
self.assertFalse(is_copilot_quota_failure(
207222
replace(failure, body=f"Handle this failure:\n> {QUOTA_FAILURE_BODY}")
208223
))
@@ -226,6 +241,11 @@ def test_quota_failures_do_not_count_as_completed_reviews(self) -> None:
226241
(replace(quota_failure, body=f"\n{QUOTA_FAILURE_BODY}\n"),),
227242
(False, False),
228243
),
244+
(
245+
"insufficient_quota",
246+
(replace(quota_failure, body=INSUFFICIENT_QUOTA_FAILURE_BODY),),
247+
(False, False),
248+
),
229249
(
230250
"current_review_then_failure",
231251
(completed_review, quota_failure),
@@ -418,12 +438,12 @@ def enqueue(self, *, quota_exhausted: bool = False) -> None:
418438
NOW,
419439
)
420440

421-
def quota_notice(self, review_id: int) -> dict:
441+
def quota_notice(self, review_id: int, body: str = QUOTA_FAILURE_BODY) -> dict:
422442
return {
423443
"id": review_id,
424444
"user": {"login": "copilot"},
425445
"commit_id": "current-head",
426-
"body": QUOTA_FAILURE_BODY,
446+
"body": body,
427447
}
428448

429449
def error_notice(self, review_id: int) -> dict:
@@ -438,6 +458,19 @@ def error_notice(self, review_id: int) -> dict:
438458
def deliver(self) -> list[str]:
439459
return deliver_copilot_review_requests("open-telemetry/example", NOW)
440460

461+
def test_insufficient_quota_notice_triggers_the_fallback_token(self) -> None:
462+
self.enqueue()
463+
self.reviews = [
464+
self.quota_notice(10, INSUFFICIENT_QUOTA_FAILURE_BODY),
465+
self.quota_notice(11),
466+
]
467+
self.assertEqual([], self.deliver())
468+
self.assertEqual(
469+
CopilotReviewFallback((10, 11), format_ts(NOW)),
470+
load_copilot_review_fallbacks()["7"],
471+
)
472+
self.request.assert_called_with("PR_node", token="request-token")
473+
441474
def test_uses_app_until_a_live_quota_notice_arrives(self) -> None:
442475
self.assertEqual([], self.deliver())
443476
self.request.assert_called_once_with("PR_node")

0 commit comments

Comments
 (0)