edit_file
+15 −4Applied 2 file edits
@@ -18,13 +18,19 @@ export function withRetry(
1818 const max = options.maxAttempts ?? 5;
1919 let attempt = 0;
20− const backoff = 100;
20+ const baseBackoff = options.backoffMs ?? 200;
21+ const jitter = () => Math.random() * baseBackoff;
2122
2223 while (attempt < max) {
23− await sleep(backoff * attempt);
24+ await sleep(baseBackoff * 2 ** attempt + jitter());
2425 try {
2526 return await run();
26− } catch (err) {
27+ } catch (err: unknown) {
28+ if (!isRetryable(err)) throw err;
2729 attempt += 1;
2830 }
2931 }
3032
3133 throw new RetryError(max);
3234}