Skip to content

Commit 6dacd67

Browse files
committed
fix(auth): address PR review threads
1 parent e979e7c commit 6dacd67

10 files changed

Lines changed: 318 additions & 178 deletions

File tree

‎src/agents/auth-profiles/constants.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export const AUTH_STORE_LOCK_OPTIONS = {
3333
// so a legitimate refresh's critical section always finishes well before
3434
// peers would treat the lock as reclaimable. Violating this invariant re-
3535
// introduces the `refresh_token_reused` race the lock is meant to prevent.
36+
//
37+
// Retry budget note: keep the MINIMUM cumulative retry window comfortably
38+
// above OAUTH_REFRESH_CALL_TIMEOUT_MS so waiters do not give up while a
39+
// legitimate slow refresh is still within its allowed runtime budget.
3640
export const OAUTH_REFRESH_LOCK_OPTIONS = {
3741
retries: {
38-
retries: 10,
42+
retries: 20,
3943
factor: 2,
4044
minTimeout: 100,
4145
maxTimeout: 10_000,

‎src/agents/auth-profiles/oauth-refresh-timeout.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import { describe, expect, it } from "vitest";
22
import { OAUTH_REFRESH_CALL_TIMEOUT_MS, OAUTH_REFRESH_LOCK_OPTIONS } from "./constants.js";
33

4+
function computeMinimumRetryBudgetMs(): number {
5+
let total = 0;
6+
for (let attempt = 0; attempt < OAUTH_REFRESH_LOCK_OPTIONS.retries.retries; attempt += 1) {
7+
total += Math.min(
8+
OAUTH_REFRESH_LOCK_OPTIONS.retries.maxTimeout,
9+
Math.max(
10+
OAUTH_REFRESH_LOCK_OPTIONS.retries.minTimeout,
11+
OAUTH_REFRESH_LOCK_OPTIONS.retries.minTimeout *
12+
OAUTH_REFRESH_LOCK_OPTIONS.retries.factor ** attempt,
13+
),
14+
);
15+
}
16+
return total;
17+
}
18+
419
// Invariant tests for the two constants that together bound the OAuth
520
// refresh critical section. Behavioural tests for the inner `setTimeout`
621
// mechanics are deliberately omitted: the implementation is a thin
@@ -41,4 +56,10 @@ describe("OAuth refresh call timeout (invariants)", () => {
4156
// lock during a legitimate slow-but-successful refresh.
4257
expect(OAUTH_REFRESH_LOCK_OPTIONS.stale).toBeGreaterThan(60_000);
4358
});
59+
60+
it("OAUTH_REFRESH_LOCK_OPTIONS retry budget outlasts the refresh call timeout", () => {
61+
// Waiters should not exhaust their retry budget while a legitimate slow
62+
// refresh is still within its allowed runtime budget.
63+
expect(computeMinimumRetryBudgetMs()).toBeGreaterThan(OAUTH_REFRESH_CALL_TIMEOUT_MS);
64+
});
4465
});

0 commit comments

Comments
 (0)