Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b5ede20
feat: retry idempotent requests on 429/502/503/504 in the shared fetc…
claude Oct 18, 2026
9b4364d
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 22, 2026
3d5ddd1
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 22, 2026
d767c7a
test: cover an unparseable balance failure body in fetchBalance
claude Oct 22, 2026
81ff8d1
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 26, 2026
72dd15c
fix: retry per-request axios adapters and keep retries inside the req…
claude Oct 26, 2026
cb10990
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 26, 2026
bbad486
refactor: split the axios retrying adapter into smaller functions
claude Oct 26, 2026
5a36721
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 26, 2026
b2c44aa
fix: retry web-session sends, replay request bodies, and cover the bi…
claude Oct 26, 2026
7be2339
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 27, 2026
d7fb989
fix: keep retry deadlines, cancellation and config intact across retries
claude Oct 27, 2026
7b7f927
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 27, 2026
f74bb14
refactor: split the axios retrying adapter attempt and budget checks
claude Oct 27, 2026
5f876db
test: consume the Request the retry hands to fetch
claude Oct 27, 2026
78adba8
Merge origin/main into feat/shared-retry-retryable-responses
claude Oct 27, 2026
7e7cd76
test: mock the ingest URL builder in the web-session retry test
claude Oct 27, 2026
d142bd2
fix: reject on abort mid-backoff and skip the shared retry where call…
dante01yoon Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/platform/auth/apiAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AuthHeader } from '@/types/authTypes'
import type { RetryPolicy } from '@/utils/retryPolicy'

export interface RetrySignalLifecycle {
clearInitialTimeout: () => void
Expand All @@ -19,7 +20,8 @@ export interface ApiAuthProvider {
input: RequestInfo | URL,
init: RequestInit,
retryOn401: boolean,
retrySignalLifecycle?: RetrySignalLifecycle
retrySignalLifecycle?: RetrySignalLifecycle,
retryPolicy?: RetryPolicy
): Promise<Response>
}

Expand Down
104 changes: 101 additions & 3 deletions src/platform/auth/unified/remintRetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
attachUnifiedRemintInterceptor,
fetchWithUnifiedRemint
} from '@/platform/auth/unified/remintRetry'
import { attachRetryableStatusRetry } from '@/utils/axiosRetryableStatus'
import { NO_RETRY_POLICY } from '@/utils/retryPolicy'

vi.mock(import('@/platform/telemetry'))

Expand Down Expand Up @@ -119,6 +121,84 @@ describe('fetchWithUnifiedRemint', () => {
expect(useTelemetry()?.trackUnifiedAuthRetry).not.toHaveBeenCalled()
})

describe('with retryable server failures', () => {
beforeEach(() => {
vi.useFakeTimers()
})

const unavailable = () =>
new Response(null, { status: 503, headers: { 'Retry-After': '1' } })

it('retries a 503 without re-minting', async () => {
vi.mocked(fetch)
.mockResolvedValueOnce(unavailable())
.mockResolvedValueOnce(ok)

const pending = fetchWithUnifiedRemint(
'https://cloud/x',
{ headers: { Authorization: 'Bearer tokenA' as const } },
true
)
await vi.advanceTimersByTimeAsync(1_000)

expect(await pending).toBe(ok)
expect(fetch).toHaveBeenCalledTimes(2)
expect(useWorkspaceAuthStore().remintUnifiedOnce).not.toHaveBeenCalled()
})

it('gives the re-minted request its own retry budget', async () => {
vi.mocked(fetch)
.mockResolvedValueOnce(unavailable())
.mockResolvedValueOnce(unavailable())
.mockResolvedValueOnce(unauthorized)
.mockResolvedValueOnce(unavailable())
.mockResolvedValueOnce(unavailable())
.mockResolvedValueOnce(ok)
vi.mocked(useWorkspaceAuthStore().remintUnifiedOnce).mockResolvedValue(
'tokenB'
)

const pending = fetchWithUnifiedRemint(
'https://cloud/x',
{ headers: { Authorization: 'Bearer tokenA' as const } },
true
)
await vi.advanceTimersByTimeAsync(10_000)

expect(await pending).toBe(ok)
expect(fetch).toHaveBeenCalledTimes(6)
expect(useWorkspaceAuthStore().remintUnifiedOnce).toHaveBeenCalledTimes(1)
})

it('sends once on a 503 under the no-retry policy', async () => {
vi.mocked(fetch).mockResolvedValueOnce(unavailable())

const result = await fetchWithUnifiedRemint(
'https://cloud/x',
{ headers: { Authorization: 'Bearer tokenA' as const } },
true,
undefined,
NO_RETRY_POLICY
)

expect(result.status).toBe(503)
expect(fetch).toHaveBeenCalledTimes(1)
})

it('does not retry a POST that got a 503', async () => {
vi.mocked(fetch).mockResolvedValueOnce(unavailable())

const result = await fetchWithUnifiedRemint(
'https://cloud/x',
{ method: 'POST', body: '{}' },
true
)

expect(result.status).toBe(503)
expect(fetch).toHaveBeenCalledTimes(1)
})
})

it('does not retry a non-401 response', async () => {
const serverError = { status: 500 } as Response
vi.mocked(fetch).mockResolvedValueOnce(serverError)
Expand Down Expand Up @@ -428,7 +508,7 @@ describe('attachUnifiedRemintInterceptor', () => {
// A custom axios adapter is responsible for its own status handling (axios
// only applies validateStatus inside its built-in adapters), so reject
// non-2xx with a real AxiosError to mirror a live response.
function makeAdapter(statuses: number[]): ReturnType<typeof vi.fn> {
function makeAdapter(statuses: number[]) {
let call = 0
return vi.fn<AxiosAdapter>(async (config) => {
const status = statuses[Math.min(call, statuses.length - 1)]
Expand All @@ -455,7 +535,7 @@ describe('attachUnifiedRemintInterceptor', () => {

function makeClient(statuses: number[]) {
const adapter = makeAdapter(statuses)
const client = axios.create({ adapter: adapter as unknown as AxiosAdapter })
const client = axios.create({ adapter })
attachUnifiedRemintInterceptor(client)
return { client, adapter }
}
Expand Down Expand Up @@ -512,6 +592,24 @@ describe('attachUnifiedRemintInterceptor', () => {
})
})

it('keeps the 503 retries and the 401 re-mint on separate budgets', async () => {
const adapter = makeAdapter([503, 503, 401, 503, 200])
const client = axios.create({ adapter })
attachRetryableStatusRetry(client, { sleep: async () => {} })
attachUnifiedRemintInterceptor(client)
vi.mocked(useWorkspaceAuthStore().remintUnifiedOnce).mockResolvedValue(
'tokenB'
)

const res = await client.get('https://cloud/x', {
headers: { Authorization: 'Bearer tokenA' as const }
})

expect(res.status).toBe(200)
expect(adapter).toHaveBeenCalledTimes(5)
expect(useWorkspaceAuthStore().remintUnifiedOnce).toHaveBeenCalledTimes(1)
})

it('does not re-mint when the flag is OFF (AC3)', async () => {
vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false
const { client, adapter } = makeClient([401])
Expand Down Expand Up @@ -613,7 +711,7 @@ describe('attachUnifiedRemintInterceptor', () => {
response
)
})
const client = axios.create({ adapter: adapter as unknown as AxiosAdapter })
const client = axios.create({ adapter })
attachUnifiedRemintInterceptor(client)
vi.mocked(useWorkspaceAuthStore().remintUnifiedOnce).mockResolvedValue(
'tokenB'
Expand Down
11 changes: 8 additions & 3 deletions src/platform/auth/unified/remintRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type {
UnifiedAuthRetryFailureReason,
UnifiedAuthRetryMetadata
} from '@/platform/telemetry/types'
import { fetchWithRetry } from '@/utils/fetchWithRetry'
import type { RetryPolicy } from '@/utils/retryPolicy'

let cachedUnifiedFlags:
| { readonly unifiedCloudAuthEnabled: boolean }
Expand Down Expand Up @@ -146,13 +148,14 @@ export async function fetchWithUnifiedRemint(
input: RequestInfo | URL,
init: RequestInit,
shouldRetryOn401: boolean,
retrySignalLifecycle?: RetrySignalLifecycle
retrySignalLifecycle?: RetrySignalLifecycle,
retryPolicy?: RetryPolicy
): Promise<Response> {
const retryInput =
shouldRetryOn401 && input instanceof Request && input.body !== null
? input.clone()
: input
const response = await fetch(input, init)
const response = await fetchWithRetry(input, init, { policy: retryPolicy })
if (response.status === 403 && isCloud) {
await presentSsoRequired(() => presentForResponse(response))
}
Expand Down Expand Up @@ -188,7 +191,9 @@ export async function fetchWithUnifiedRemint(
? { ...init, headers, signal: retrySignalLifecycle.createSignal() }
: { ...init, headers }
try {
const retryResponse = await fetch(retryInput, retryInit)
const retryResponse = await fetchWithRetry(retryInput, retryInit, {
policy: retryPolicy
})
trackRetryResponse('fetch', retryResponse.status)
return retryResponse
} catch (error) {
Expand Down
71 changes: 71 additions & 0 deletions src/platform/billing/sdk/billingSdkStore.retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { CREDITS_ROUTE } from '@comfyorg/account-core/billing'
import type {
AccountCredential,
SessionSnapshot
} from '@comfyorg/account-core/session'
import { fromPartial } from '@total-typescript/shoehorn'
import type { User } from 'firebase/auth'
import { beforeEach, expect, it, vi } from 'vitest'

import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore'

Check warning on line 10 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'authentication/application' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/platform/workspace/stores/workspaceAuthStore.ts Route the import through an allowed zone or restructure the dependency.
import {
stubAccountIdentityPort,

Check warning on line 12 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'authentication/integration' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/utils/__tests__/stubAccountIdentityPort.ts Route the import through an allowed zone or restructure the dependency.
stubFirebaseAuthHarness
} from '@/utils/__tests__/stubAccountIdentityPort'

import { useBillingSdkStore } from './billingSdkStore'

vi.mock(import('@/platform/telemetry'))

Check warning on line 18 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'telemetry/application' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/platform/telemetry/index.ts Route the import through an allowed zone or restructure the dependency.
vi.mock(import('@/composables/useFeatureFlags'))

Check warning on line 19 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'remote-config/application' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/composables/useFeatureFlags.ts Route the import through an allowed zone or restructure the dependency.

Check warning on line 19 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'remote-config/application' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/composables/__mocks__/useFeatureFlags.ts Route the import through an allowed zone or restructure the dependency.
vi.mock(import('@/platform/billing/composables/useBillingCapabilities'))
vi.mock(import('@/platform/settings/composables/useSettingsDialog'))

Check warning on line 21 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'settings/application/outer-1' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/platform/settings/composables/useSettingsDialog.ts Route the import through an allowed zone or restructure the dependency.

Check warning on line 21 in src/platform/billing/sdk/billingSdkStore.retry.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'billing/infrastructure/outer-1' to zone 'settings/application/outer-1' is not allowed. src/platform/billing/sdk/billingSdkStore.retry.test.ts -> src/platform/settings/composables/__mocks__/useSettingsDialog.ts Route the import through an allowed zone or restructure the dependency.
vi.mock(import('firebase/auth'))

const CREDENTIAL: AccountCredential = {
token: 'workspace-jwt',
expiresAt: Date.now() + 60 * 60 * 1000,
uid: 'uid-1',
workspace: { id: 'ws-1', name: 'Personal', type: 'personal' },
role: 'owner',
permissions: ['workspace:read']
}

const SNAPSHOT: SessionSnapshot<User> = {
phase: 'authenticated',
user: fromPartial<User>({ uid: 'uid-1' }),
session: CREDENTIAL
}

beforeEach(() => {
stubAccountIdentityPort()
stubFirebaseAuthHarness()
const session = useWorkspaceAuthStore().getUnifiedSessionClient()
vi.spyOn(session, 'getSnapshot').mockReturnValue(SNAPSHOT)
vi.spyOn(session, 'ensureFresh').mockResolvedValue({
status: 'ok',
session: CREDENTIAL
})
})

it('reads the balance again after a 503 through the store wiring', async () => {
vi.useFakeTimers()
const answers = [
new Response(null, { status: 503 }),
Response.json({ amount_micros: 1_000_000, currency: 'USD' })
]
vi.mocked(fetch).mockImplementation(async (input) => {
expect(String(input)).toContain(CREDITS_ROUTE)
const answer = answers.shift()
if (!answer) throw new Error('fetch called more times than scripted')
return answer
})

const pending = useBillingSdkStore().readBalance()
await vi.advanceTimersByTimeAsync(10_000)

expect(await pending).toMatchObject({
status: 'ok',
value: { amount_micros: 1_000_000 }
})
expect(fetch).toHaveBeenCalledTimes(2)
})
2 changes: 2 additions & 0 deletions src/platform/billing/sdk/billingSdkStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { useWorkspaceIdentity } from '@/platform/workspace/ports/workspaceIdenti
import { useWorkspaceSession } from '@/platform/workspace/ports/workspaceSession'
import { getCheckoutJourneyPaymentIntentSource } from '@/platform/billing/utils/checkoutJourney'
import { useDialogStore } from '@/stores/dialogStore'
import { fetchWithRetry } from '@/utils/fetchWithRetry'

import { projectBillingCapabilities } from './billingCapabilitiesView'
import { projectBillingPlans } from './billingPlansView'
Expand Down Expand Up @@ -144,6 +145,7 @@ export const useBillingSdkStore = defineStore('billingSdk', () => {
const sdk = createBillingSdk({
...sessionPorts(),
resolveUrl: ingestApiUrl,
fetchImpl: fetchWithRetry,
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
pointerStorage: sessionStorage,
hostedDestination: () => flags.hostedBillingDestination,
onTelemetry: reportTelemetry
Expand Down
25 changes: 25 additions & 0 deletions src/platform/settings/globalSettingsApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ vi.mock(import('@/services/dialogService'))
import type { GlobalSetting } from '@comfyorg/ingest-types'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import type { WebSessionSend } from '@/platform/auth/session/webSessionFetch'
import { api } from '@/scripts/api'
import { useAuthStore } from '@/stores/authStore'

Expand Down Expand Up @@ -159,4 +160,28 @@ describe('Global Settings transport', () => {
})
}
)
describe('on the web session', () => {
const unavailable = () => new Response(null, { status: 503 })

it('reads again after a 503 with exactly two sends', async () => {
vi.useFakeTimers()
const answers = [unavailable(), Response.json(stored)]
const send = vi.fn<WebSessionSend>(async () => answers.shift()!)

const pending = getGlobalSetting(key, send)
await vi.advanceTimersByTimeAsync(10_000)

await expect(pending).resolves.toEqual(stored)
expect(send).toHaveBeenCalledTimes(2)
})

it('does not send a write twice after a 503', async () => {
const send = vi.fn<WebSessionSend>(async () => unavailable())

await expect(
setGlobalSetting({ key, value: true }, send)
).rejects.toMatchObject({ status: 503 })
expect(send).toHaveBeenCalledOnce()
})
})
})
5 changes: 4 additions & 1 deletion src/platform/settings/globalSettingsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { api } from '@/scripts/api'
import type { WebSessionSend } from '@/platform/auth/session/webSessionFetch'
import { useAuthStore } from '@/stores/authStore'
import type { AuthHeader } from '@/types/authTypes'
import { retryingSend } from '@/utils/fetchWithRetry'

export class GlobalSettingsApiError extends Error {
constructor(
Expand Down Expand Up @@ -57,7 +58,9 @@ function sendGlobalSetting(
auth: GlobalSettingsAuth,
headers: Record<string, string> = {}
): Promise<Response> {
if (typeof auth === 'function') return auth(url, { ...init, headers })
if (typeof auth === 'function') {
return retryingSend(auth)(url, { ...init, headers })
}
return shouldRemintCloudRequest().then((remint) =>
fetchWithUnifiedRemint(
url,
Expand Down
8 changes: 8 additions & 0 deletions src/platform/settings/settingStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ describe('useSettingStore', () => {
expect(api.getSettings).toHaveBeenCalled()
})

it('loads settings without the shared status retry stacking on its own backoff', async () => {
vi.mocked(api.getSettings).mockResolvedValue({} as Settings)

await store.load()

expect(api.getSettings).toHaveBeenCalledWith({ skipStatusRetry: true })
})

describe('Canvas Navigation override migration', () => {
const NAV = 'Comfy.Canvas.NavigationMode'
const LEFT = 'Comfy.Canvas.LeftMouseClickBehavior'
Expand Down
11 changes: 7 additions & 4 deletions src/platform/settings/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ export const useSettingStore = defineStore('setting', () => {
'Setting values must be loaded before any setting is registered.'
)
}
settingValues.value = await retry(() => api.getSettings(), {
retries: 3,
delay: (attempt) => Math.min(1000 * Math.pow(2, attempt), 8000)
})
settingValues.value = await retry(
() => api.getSettings({ skipStatusRetry: true }),
{
retries: 3,
delay: (attempt) => Math.min(1000 * Math.pow(2, attempt), 8000)
}
)
await migrateZoomThresholdToFontSize()
await migrateCanvasNavigationOverrides()
},
Expand Down
Loading
Loading