Skip to content

Commit ef98664

Browse files
fix(github): a 403 GraphQL error that names a limit still pauses the host
A decoded GraphQL errors list reaches the classifier without its raw body, so an untyped secondary-limit or abuse-detection message on a 403 was no longer read as a limit once Retry-After stopped counting on its own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent df677a0 commit ef98664

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎packages/source-control-github/src/server/GitHubRequestPolicy.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function retryAtFrom(
149149

150150
/**
151151
* HTTP 200 GraphQL rate limits use RATE_LIMITED or untyped errors with quota headers. A 403 is a
152-
* limit only when GitHub names one, by an exhausted quota or its body (older hosts say "abuse
153-
* detection"): a proxy in front of GitHub Enterprise can refuse with `Retry-After` and nothing else.
152+
* limit only when GitHub names one, by an exhausted quota or its body or GraphQL errors (older hosts
153+
* say "abuse detection"): a proxy in front of GitHub Enterprise can refuse with `Retry-After` alone.
154154
*/
155155
export function isRateLimited(input: {
156156
readonly status: number;
@@ -171,10 +171,15 @@ export function isRateLimited(input: {
171171
))) ||
172172
(status === 403 &&
173173
(headers["x-ratelimit-remaining"] === "0" ||
174-
/rate limit|abuse detection/i.test(input.body ?? "")))
174+
namesLimit(input.body) ||
175+
(errors ?? []).some((error) => namesLimit(error.message))))
175176
);
176177
}
177178

179+
function namesLimit(text: unknown): boolean {
180+
return typeof text === "string" && /rate limit|abuse detection/i.test(text);
181+
}
182+
178183
export type GitHubAnswer<A> = {
179184
readonly status: number | undefined;
180185
readonly headers: Readonly<Record<string, string | undefined>>;

‎packages/source-control-github/src/server/gitHubGraphQlClient.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ describe("GitHubGraphQlAuth", () => {
223223
const answers = [
224224
json({ message: "You have exceeded a secondary rate limit." }, { status: 403 }),
225225
json({ message: "Bad credentials" }, { status: 401 }),
226+
json(
227+
{ data: null, errors: [{ message: "You have exceeded a secondary rate limit." }] },
228+
{ status: 403, headers: { "retry-after": "60" } },
229+
),
226230
];
227231
const { layer, invalidations } = harness(() => answers.shift()!);
228232
return Effect.gen(function* () {
@@ -231,6 +235,10 @@ describe("GitHubGraphQlAuth", () => {
231235
expect((yield* Effect.flip(readStats("github.example")))._tag).toBe(
232236
"GitHubApiAuthenticationError",
233237
);
238+
expect(yield* Effect.flip(readStats("github.acme.test"))).toMatchObject({
239+
_tag: "GitHubApiRateLimitError",
240+
retryAt: NOW + 60_000,
241+
});
234242
expect(invalidations()).toBe(1);
235243
}).pipe(Effect.provide(layer));
236244
});

0 commit comments

Comments
 (0)