Fix FetcherService retrying with multiple fetchers on 429 and other application errors (#282100)

* Initial plan

* Fix FetcherService to not retry with other fetchers on 429 status code

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

* Improve test robustness based on code review feedback

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
This commit is contained in:
Copilot
2025-12-10 01:57:09 +00:00
committed by GitHub
parent 89d1458dcb
commit b2590e0b22
2 changed files with 57 additions and 0 deletions

View File

@@ -76,6 +76,16 @@ export function createFetch(): Fetch {
};
}
function shouldNotRetry(status: number): boolean {
// Don't retry with other fetchers for these HTTP status codes:
// - 429 Too Many Requests (rate limiting)
// - 401 Unauthorized (authentication issue)
// - 403 Forbidden (authorization issue)
// - 404 Not Found (resource doesn't exist)
// These are application-level errors where retrying with a different fetcher won't help
return status === 429 || status === 401 || status === 403 || status === 404;
}
async function fetchWithFallbacks(availableFetchers: readonly Fetcher[], url: string, options: FetchOptions, logService: Log): Promise<{ response: FetchResponse; updatedFetchers?: Fetcher[] }> {
if (options.retryFallbacks && availableFetchers.length > 1) {
let firstResult: { ok: boolean; response: FetchResponse } | { ok: false; err: any } | undefined;
@@ -85,6 +95,11 @@ async function fetchWithFallbacks(availableFetchers: readonly Fetcher[], url: st
firstResult = result;
}
if (!result.ok) {
// For certain HTTP status codes, don't retry with other fetchers
// These are application-level errors, not network-level errors
if ('response' in result && shouldNotRetry(result.response.status)) {
return { response: result.response };
}
continue;
}
if (fetcher !== availableFetchers[0]) {