From bb49f240bdf71d7c310d8ecf0f5fd6afba700a4f Mon Sep 17 00:00:00 2001 From: pauldambra Date: Thu, 25 Jun 2026 20:10:14 +0100 Subject: [PATCH] fix: address qa-swarm backoff comment accuracy and sleep delegation Correct retry-budget comment from ~77s to ~100s (2+3+5+7+11+13+17+19+23=100) in two locations in auth.ts. Make sleepWithBackoff delegate to sleep so the Promise/setTimeout body is expressed OnceAndOnlyOnce. Generated-By: PostHog Code Task-Id: 47d056fa-5014-40c5-b330-d5c34d9d49bc --- packages/core/src/auth/auth.ts | 12 ++++++------ packages/shared/src/backoff.ts | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/core/src/auth/auth.ts b/packages/core/src/auth/auth.ts index 1fa48b659..e76bdd690 100644 --- a/packages/core/src/auth/auth.ts +++ b/packages/core/src/auth/auth.ts @@ -944,9 +944,7 @@ export class AuthService extends TypedEventEmitter { fetch, `${apiHost}/api/code/invites/check-access/`, { - signal: AbortSignal.timeout( - AuthService.CODE_ACCESS_FETCH_TIMEOUT_MS, - ), + signal: AbortSignal.timeout(AuthService.CODE_ACCESS_FETCH_TIMEOUT_MS), }, session.accessToken, ); @@ -981,7 +979,7 @@ export class AuthService extends TypedEventEmitter { // Background retry loop with prime-number backoff. Stepping through primes // (rather than a doubling schedule) keeps many clients' retries from lining // up into bursts after a shared outage. The prime sequence is the whole - // budget — it sums to ~77s of waiting — after which we fail closed so a + // budget — it sums to ~100s of waiting — after which we fail closed so a // sustained inability to call home revokes access rather than granting it // forever. `seq` guards against a newer authoritative check (or logout) // having superseded this loop while it slept. @@ -995,7 +993,9 @@ export class AuthService extends TypedEventEmitter { if (this.codeAccessCheckSeq !== seq || !this.session) return; // Could not confirm access within the retry window: fail closed so the // invite gate can't be bypassed by keeping the client offline. - this.logger.warn("Code access check failed within retry window, failing closed"); + this.logger.warn( + "Code access check failed within retry window, failing closed", + ); this.updateState({ hasCodeAccess: false }); } private static readonly REFRESH_MAX_ATTEMPTS = 3; @@ -1003,7 +1003,7 @@ export class AuthService extends TypedEventEmitter { private static readonly ORG_RECOVERY_MAX_ATTEMPTS = 5; private static readonly CODE_ACCESS_FETCH_TIMEOUT_MS = 10_000; // Prime-number backoff (ms) for the code-access retry loop; the sequence - // sums to ~77s, which is the full retry window before failing closed. + // sums to ~100s, which is the full retry window before failing closed. private static readonly CODE_ACCESS_BACKOFF_PRIMES_MS = [ 2_000, 3_000, 5_000, 7_000, 11_000, 13_000, 17_000, 19_000, 23_000, ]; diff --git a/packages/shared/src/backoff.ts b/packages/shared/src/backoff.ts index 4ac881ad3..26ffa114d 100644 --- a/packages/shared/src/backoff.ts +++ b/packages/shared/src/backoff.ts @@ -26,8 +26,7 @@ export function sleepWithBackoff( attempt: number, options: BackoffOptions, ): Promise { - const delay = getBackoffDelay(attempt, options); - return new Promise((resolve) => setTimeout(resolve, delay)); + return sleep(getBackoffDelay(attempt, options)); } /**