Skip to content

Commit 1ae0ddc

Browse files
fix(server): an exhausted GraphQL quota pauses the host even without a RATE_LIMITED type
Found against live GitHub: with the GraphQL quota at zero, GitHub answers HTTP 200 with an untyped "API rate limit already exceeded" error and x-ratelimit-remaining: 0. That read as an ordinary failure, so background sweeps kept asking instead of waiting for the reset. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent ac627ca commit 1ae0ddc

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/server/src/sourceControl/GitHubApi.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ describe("GitHubApi", () => {
249249
}).pipe(Effect.provide(layer));
250250
});
251251

252+
it.effect("reads an untyped GraphQL quota error as a rate limit", () => {
253+
const reset = Math.floor(NOW / 1000) + 900;
254+
const { layer } = harness(() =>
255+
json(
256+
{ errors: [{ message: "API rate limit already exceeded for user ID 1." }] },
257+
{ headers: { "x-ratelimit-remaining": "0", "x-ratelimit-reset": String(reset) } },
258+
),
259+
);
260+
return Effect.gen(function* () {
261+
yield* TestClock.setTime(NOW);
262+
const api = yield* GitHubApi.GitHubApi;
263+
const error = yield* Effect.flip(
264+
api.graphql({ host: "github.com", operation: "lookup", query: "query { viewer { id } }" }),
265+
);
266+
expect(error).toMatchObject({ _tag: "GitHubApiRateLimitError", retryAt: reset * 1000 });
267+
}).pipe(Effect.provide(layer));
268+
});
269+
252270
it.effect("maps REST 403 with an exhausted quota to a rate limit, and 304 to an answer", () => {
253271
let call = 0;
254272
const { layer } = harness(() =>

‎apps/server/src/sourceControl/GitHubApi.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ function classify(input: {
276276
if (
277277
status === 429 ||
278278
types.includes("RATE_LIMITED") ||
279+
// An exhausted GraphQL quota can answer HTTP 200 with an untyped "API rate limit already
280+
// exceeded" error; the headers say the same thing.
281+
(input.graphql && errors !== undefined && headers["x-ratelimit-remaining"] === "0") ||
282+
(input.graphql &&
283+
messages !== undefined &&
284+
messages.some((message) => /rate limit (already )?exceeded/i.test(message))) ||
279285
(status === 403 &&
280286
(headers["x-ratelimit-remaining"] === "0" ||
281287
headers["retry-after"] !== undefined ||

0 commit comments

Comments
 (0)