The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(github): a proxy's 403 with Retry-After is no longer reported as a rate limit (#33676)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 12:48 UTC
d290c1f1b6c93416dfda6c9f7cd15d928a9aeb4c
3 files changed
+71
-3
packages/source-control-github/src/server/GitHubRequestPolicy.ts
+11
-3
@@ -147,7 +147,11 @@ function retryAtFrom(
147
return Number.isFinite(reset) && reset > now ? reset : undefined;
148
}
149
150
-/** HTTP 200 GraphQL rate limits use RATE_LIMITED or untyped errors with quota headers. */
150
+/**
151
+ * HTTP 200 GraphQL rate limits use RATE_LIMITED or untyped errors with quota headers. A 403 is a
152
+ * limit only when its quota, body or GraphQL errors name one (older hosts say "abuse detection
153
+ * mechanism"): a proxy in front of GitHub Enterprise can refuse with `Retry-After` alone.
154
+ */
155
export function isRateLimited(input: {
156
readonly status: number;
157
readonly headers: Readonly<Record<string, string | undefined>>;
@@ -167,11 +171,15 @@ export function isRateLimited(input: {
171
))) ||
172
(status === 403 &&
173
(headers["x-ratelimit-remaining"] === "0" ||
170
- headers["retry-after"] !== undefined ||
171
- /rate limit/i.test(input.body ?? "")))
174
+ namesLimit(input.body) ||
175
+ (errors ?? []).some((error) => namesLimit(error.message))))
176
);
177
}
178
179
+function namesLimit(text: unknown): boolean {
180
+ return typeof text === "string" && /rate limit|abuse detection mechanism/i.test(text);
181
+}
182
+
183
export type GitHubAnswer<A> = {
184
readonly status: number | undefined;
185
readonly headers: Readonly<Record<string, string | undefined>>;
packages/source-control-github/src/server/GitHubRest.test.ts
+52
@@ -510,6 +510,58 @@ describe("GitHubRest", () => {
510
}).pipe(Effect.provide(layer));
511
});
512
513
+ it.effect("reads a proxy's 403 with Retry-After as a refusal and keeps the host open", () => {
514
+ const pages = [
515
+ "<html><head><title>403 Forbidden</title></head><body>nginx</body></html>",
516
+ "<html><body>Request blocked by proxy abuse detection; contact your administrator</body></html>",
517
+ ];
518
+ const { layer, requests } = harness(
519
+ () =>
520
+ new Response(pages.shift(), {
521
+ status: 403,
522
+ headers: { "content-type": "text/html", "retry-after": "5" },
523
+ }),
524
+ );
525
+ return Effect.gen(function* () {
526
+ yield* TestClock.setTime(NOW);
527
+ const api = yield* GitHubRest.GitHubRest;
528
+ const read = {
529
+ host: "ghes.example.internal",
530
+ operation: "checks",
531
+ path: "repos/acme/web/pulls/7",
532
+ };
533
+ const first = yield* Effect.flip(api.rest(read));
534
+ expect(first).toMatchObject({ _tag: "GitHubApiResponseError", status: 403 });
535
+ const second = yield* Effect.flip(api.rest(read));
536
+ expect(second).toMatchObject({ _tag: "GitHubApiResponseError", status: 403 });
537
+ expect(requests).toHaveLength(2);
538
+ }).pipe(Effect.provide(layer));
539
+ });
540
+
541
+ it.effect("pauses the host on an abuse-detection 403 that never says rate limit", () => {
542
+ const { layer, requests } = harness(() =>
543
+ json(
544
+ {
545
+ message: "You have triggered an abuse detection mechanism. Please wait before retrying.",
546
+ documentation_url:
547
+ "https://docs.github.com/rest/overview/resources-in-the-rest-api#abuse-rate-limits",
548
+ },
549
+ { status: 403, headers: { "retry-after": "60", "x-ratelimit-remaining": "4878" } },
550
+ ),
551
+ );
552
+ return Effect.gen(function* () {
553
+ yield* TestClock.setTime(NOW);
554
+ const api = yield* GitHubRest.GitHubRest;
555
+ const read = { host: "github.com", operation: "checks", path: "repos/acme/web/pulls/7" };
556
+ expect(yield* Effect.flip(api.rest(read))).toMatchObject({
557
+ _tag: "GitHubApiRateLimitError",
558
+ retryAt: NOW + 60_000,
559
+ });
560
+ expect((yield* Effect.flip(api.rest(read)))._tag).toBe("SourceControlRateLimitPausedError");
561
+ expect(requests).toHaveLength(1);
562
+ }).pipe(Effect.provide(layer));
563
+ });
564
+
565
it.effect("drops a refused token so the next request asks the source again", () => {
566
const { layer, requests, invalidations } = harness((request) =>
567
request.headers.authorization === "Bearer first"
packages/source-control-github/src/server/gitHubGraphQlClient.test.ts
+8
@@ -223,6 +223,10 @@ describe("GitHubGraphQlAuth", () => {
223
const answers = [
224
json({ message: "You have exceeded a secondary rate limit." }, { status: 403 }),
225
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
+ ),
230
];
231
const { layer, invalidations } = harness(() => answers.shift()!);
232
return Effect.gen(function* () {
@@ -231,6 +235,10 @@ describe("GitHubGraphQlAuth", () => {
235
expect((yield* Effect.flip(readStats("github.example")))._tag).toBe(
236
"GitHubApiAuthenticationError",
237
);
238
+ expect(yield* Effect.flip(readStats("github.acme.test"))).toMatchObject({
239
+ _tag: "GitHubApiRateLimitError",
240
+ retryAt: NOW + 60_000,
241
+ });
242
expect(invalidations()).toBe(1);
243
}).pipe(Effect.provide(layer));
244
});