Elffuss BraidHub

kikocis/continue public

fix: exponential backoff refresh token fix

don't set a limit to the max number of retries in token refresh. they are valid for a very long time
Changeset4248554ef60b4c8ca36af54aabb7e19e8a17353b3ae1ff2175f0807a98687bac
AuthorNate <sestinj@gmail.com> · 2025-07-07 23:01 -07:00
CommitterNate <sestinj@gmail.com> · 2025-07-07 23:01 -07:00
Parents3389e73db7c2

Browse the files at this changeset

1 file changed

modified extensions/vscode/src/stubs/WorkOsAuthProvider.ts +7 −12
@@ -229,7 +229,6 @@
229229 private async _refreshSessionWithRetry(
230230 refreshToken: string,
231231 attempt = 1,
232- maxAttempts = 3,
233232 baseDelay = 1000,
234233 ): Promise<{
235234 accessToken: string;
@@ -243,26 +242,22 @@
243242 if (
244243 error.message?.includes("401") ||
245244 error.message?.includes("Invalid refresh token") ||
246- error.message?.includes("Unauthorized") ||
247- attempt >= maxAttempts
245+ error.message?.includes("Unauthorized")
248246 ) {
249247 throw error;
250248 }
251249
252250 // For network errors or transient server issues, retry with backoff
253251 // Calculate exponential backoff delay with jitter
254- const delay =
255- baseDelay * Math.pow(2, attempt - 1) * (0.5 + Math.random() * 0.5);
252+ const delay = Math.min(
253+ baseDelay * Math.pow(2, attempt - 1) * (0.5 + Math.random() * 0.5),
254+ 60 * 60 * 1000, // 1 hour in milliseconds
255+ );
256256
257257 // Schedule retry after delay
258258 return new Promise((resolve, reject) => {
259259 setTimeout(() => {
260- this._refreshSessionWithRetry(
261- refreshToken,
262- attempt + 1,
263- maxAttempts,
264- baseDelay,
265- )
260+ this._refreshSessionWithRetry(refreshToken, attempt + 1, baseDelay)
266261 .then(resolve)
267262 .catch(reject);
268263 }, delay);
@@ -357,7 +352,7 @@
357352
358353 return session;
359354 } catch (e) {
360- window.showErrorMessage(`Sign in failed: ${e}`);
355+ void window.showErrorMessage(`Sign in failed: ${e}`);
361356 throw e;
362357 }
363358 }