Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

fix(github-copilot): surface quota exhaustion 429 instead of retrying (#13584)

Octopus496b10f5c05a
diff --git a/packages/model-runtime/src/providers/githubCopilot/index.ts b/packages/model-runtime/src/providers/githubCopilot/index.ts
index d215eb55e03..a7ff8f6bc7b 100644
--- a/packages/model-runtime/src/providers/githubCopilot/index.ts
+++ b/packages/model-runtime/src/providers/githubCopilot/index.ts
@@ -25,6 +25,7 @@ const TOKEN_EXCHANGE_URL = 'https://api.github.com/copilot_internal/v2/token';
const MAX_TOTAL_ATTEMPTS = 5;
const MAX_RATE_LIMIT_RETRIES = 3;
+const QUOTA_EXHAUSTION_THRESHOLD_MS = 5 * 60 * 1000; // 5 minutes
const debugParams = {
chatCompletion: () => process.env.DEBUG_GITHUBCOPILOT_CHAT_COMPLETION === '1',
@@ -457,6 +458,11 @@ export class LobeGithubCopilotAI implements LobeRuntimeAI {
rateLimitAttempts++;
const retryAfter = this.getRetryAfterMs(error) ?? 1000 * Math.pow(2, rateLimitAttempts);
+ // If retry-after exceeds the quota exhaustion threshold, surface immediately
+ if (retryAfter > QUOTA_EXHAUSTION_THRESHOLD_MS) {
+ throw this.mapError(error);
+ }
+
await new Promise<void>((resolve) => {
setTimeout(resolve, Math.min(retryAfter, 10_000));
});