From e0551e013a5e20b0d1c0e5401ade8fed8158a17c Mon Sep 17 00:00:00 2001 From: Dante Date: Thu, 22 Oct 2026 10:37:56 +0000 Subject: [PATCH] FE-1908 fix(billing): retry a hosted checkout refused with 503 unavailable (#21540) ## Why After [cloud PR 14736](https://github.com/Comfy-Org/cloud/pull/14736), the hosted top-up checkout endpoint returns `503 TOPUP_CHECKOUT_UNAVAILABLE` when billing-api is out of lock slots or database connections. That response means retry. The client currently retries only `409` `TOPUP_CHECKOUT_BUSY` and `TOPUP_CHECKOUT_NOT_PAYABLE`, so this refusal fails the reopen immediately. ## Root cause `isRetryableCheckoutRefusal` required HTTP 409. A 503 never matched, on either the legacy or the SDK rail. ## How Retry the status-and-code pair `503` + `TOPUP_CHECKOUT_UNAVAILABLE` with the same two backoff delays. A 503 with any other code still fails immediately. Both rails already surface the server code on `WorkspaceApiError`, so the predicate covers both. ## AS IS / TO BE No live capture. testcloud does not return this code until cloud PR 14736 is deployed. The unit test is the proof: an unavailable checkout is minted again, and a 503 with a different code is not. ## Plan position | Item | Ticket | PR | Status | | --- | --- | --- | --- | | Retry a 409 checkout refusal | FE-1908 | PR 21463 | merged, on testcloud | | **Retry 503 TOPUP_CHECKOUT_UNAVAILABLE** | **FE-1908** | **this PR** | **open** | ```mermaid graph LR A["PR 21463 retry 409"] --> B["this PR retry 503 unavailable"] style B fill:#9f9,stroke:#333 ``` --- .../composables/useTopupOperation.test.ts | 31 ++++++++++++++----- .../composables/useTopupOperation.ts | 14 +++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/platform/workspace/composables/useTopupOperation.test.ts b/src/platform/workspace/composables/useTopupOperation.test.ts index d5e4b3816a5..086cf4febba 100644 --- a/src/platform/workspace/composables/useTopupOperation.test.ts +++ b/src/platform/workspace/composables/useTopupOperation.test.ts @@ -198,6 +198,10 @@ describe('useTopupOperation', () => { status: 409, code: 'TOPUP_CHECKOUT_NOT_PAYABLE' } + const unavailable: Refusal = { + status: 503, + code: 'TOPUP_CHECKOUT_UNAVAILABLE' + } const returnUrl = 'https://cloud.comfy.org/topup-return' const rails = [ @@ -253,18 +257,31 @@ describe('useTopupOperation', () => { return outcome } - it.for(rails)( - 'mints a fresh checkout after a retryable refusal on the $rail rail', - async ({ flagOn, mint }) => { + it.for( + rails.flatMap((rail) => [ + { + ...rail, + name: 'a busy then not-payable checkout', + outcomes: [busy, notPayable, 'https://stripe/new'] + }, + { + ...rail, + name: 'an unavailable checkout', + outcomes: [unavailable, 'https://stripe/new'] + } + ]) + )( + 'mints a fresh checkout after $name on the $rail rail', + async ({ flagOn, mint, outcomes }) => { flagState.billingSdkTopupEnabled = flagOn - const mintCheckout = mint([busy, notPayable, 'https://stripe/new']) + const mintCheckout = mint(outcomes) const outcome = await settle( useTopupOperation().createHostedCheckout(1000, returnUrl) ) expect(outcome).toEqual({ url: 'https://stripe/new' }) - expect(mintCheckout).toHaveBeenCalledTimes(3) + expect(mintCheckout).toHaveBeenCalledTimes(outcomes.length) } ) @@ -272,8 +289,8 @@ describe('useTopupOperation', () => { rails.flatMap((rail) => [ { ...rail, - name: 'a refusal outside the retryable set', - outcomes: [{ status: 503, code: 'TOPUP_CHECKOUT_UNAVAILABLE' }], + name: 'a 503 without the unavailable code', + outcomes: [{ status: 503, code: 'UPSTREAM_UNAVAILABLE' }], attempts: 1 }, { diff --git a/src/platform/workspace/composables/useTopupOperation.ts b/src/platform/workspace/composables/useTopupOperation.ts index 7d9cf0ab9d0..73d45fa2060 100644 --- a/src/platform/workspace/composables/useTopupOperation.ts +++ b/src/platform/workspace/composables/useTopupOperation.ts @@ -14,18 +14,20 @@ import { import { useBillingSdkStore } from '@/platform/workspace/billing/sdk/billingSdkStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' -const RETRYABLE_CHECKOUT_CODES: ReadonlySet = new Set([ - 'TOPUP_CHECKOUT_BUSY', - 'TOPUP_CHECKOUT_NOT_PAYABLE' -]) +const RETRYABLE_CHECKOUT_REFUSALS: ReadonlyArray = [ + [409, 'TOPUP_CHECKOUT_BUSY'], + [409, 'TOPUP_CHECKOUT_NOT_PAYABLE'], + [503, 'TOPUP_CHECKOUT_UNAVAILABLE'] +] const CHECKOUT_RETRY_DELAYS_MS = [1000, 2000] function isRetryableCheckoutRefusal(error: unknown): boolean { return ( error instanceof WorkspaceApiError && - error.status === 409 && - RETRYABLE_CHECKOUT_CODES.has(error.code) + RETRYABLE_CHECKOUT_REFUSALS.some( + ([status, code]) => error.status === status && error.code === code + ) ) }