From 8ac1c5df0ac7790531311d602f2938236e38033b Mon Sep 17 00:00:00 2001 From: Dante Date: Thu, 22 Oct 2026 10:37:50 +0000 Subject: [PATCH] FE-3434 fix(billing): keep payment recovery and run capability through the SDK rail (#21547) ## Why On the SDK billing rail a past-due owner sees the member Run lock, and after the invoice is paid the button stays Subscribe to Run until a full reload. ## Root cause `CapabilitiesBodySchema` omits `payment_recovery_available`, and Zod drops it before the host view is built. `denied_reasons` still arrive, so the owner is classified as a member for the button while `can_manage_billing` still opens the owner dialog. Separately, the Run button ignores a resolved `can_run_workflows` when the subscription snapshot is still inactive. ## How The optional boolean is decoded onto the capabilities snapshot and copied onto the host read. When it is absent the key stays omitted. The Run button also renders when `can_run_workflows` is true, so a paid capability is not held behind the stale snapshot. ## AS IS / TO BE AS IS: placeholder TO BE: placeholder ## Plan position | Item | Ticket | PR | Status | | --- | --- | --- | --- | | Past-due top-up opens Update payment | FE-3434 | PR 21265 | merged | | Run lock reads payment_recovery_available | FE-3434 | PR 21362 | merged | | Add credits stays visible for payment recovery | FE-3434 | PR 21546 | open | | **Carry payment_recovery_available through the SDK** | FE-3434 | this PR | open | | Out-of-credits banner on a past-due workspace | FE-3434 | PR 21548 | open | ```mermaid flowchart LR merged["PR 21265 merged"] --> credits["PR 21546"] lock["PR 21362 merged"] --> thisPR["this PR"] merged --> banner["PR 21548"] style thisPR fill:#9f9,stroke:#333 ``` --- .../src/core/billing/capabilities.test.ts | 25 +++++++++++++++++++ .../src/core/billing/capabilities.ts | 8 ++++++ .../CloudRunButtonWrapper.test.ts | 16 ++++++++++++ .../ComfyRunButton/CloudRunButtonWrapper.vue | 9 ++++++- .../sdk/billingCapabilitiesView.test.ts | 12 +++++++++ .../billing/sdk/billingCapabilitiesView.ts | 5 +++- .../__mocks__/useBillingCapabilities.ts | 1 + .../composables/useBillingCapabilities.ts | 4 +++ 8 files changed, 78 insertions(+), 2 deletions(-) diff --git a/packages/account-core/src/core/billing/capabilities.test.ts b/packages/account-core/src/core/billing/capabilities.test.ts index 9e7a35455a0..954665383ae 100644 --- a/packages/account-core/src/core/billing/capabilities.test.ts +++ b/packages/account-core/src/core/billing/capabilities.test.ts @@ -98,6 +98,31 @@ describe('createCapabilitiesReader', () => { expect(result.value.rolloutDefaultsApplied.can_top_up).toBe(true) }) + it.for([ + { served: true, expected: true }, + { served: false, expected: false }, + { served: undefined, expected: undefined } + ])( + 'keeps payment_recovery_available $served instead of dropping it', + async ({ served, expected }) => { + const { scopeSource } = fakeSession() + const { transport } = fakeTransport([ + httpOk( + capabilitiesBody( + served === undefined ? {} : { payment_recovery_available: served } + ) + ) + ]) + const reader = createCapabilitiesReader({ transport, scopeSource }) + + const result = await reader.read() + + expect(result.status).toBe('ok') + if (result.status !== 'ok') return + expect(result.value.paymentRecoveryAvailable).toBe(expected) + } + ) + it.for([true, false])( 'preserves can_manage_members=%s from the server', async (allowed) => { diff --git a/packages/account-core/src/core/billing/capabilities.ts b/packages/account-core/src/core/billing/capabilities.ts index 7402efdf481..f3749dce354 100644 --- a/packages/account-core/src/core/billing/capabilities.ts +++ b/packages/account-core/src/core/billing/capabilities.ts @@ -14,6 +14,7 @@ */ import { zBillingCapabilities, + zBillingCapabilitiesResponse, zBillingCapabilityRolloutDefaults, zBillingCapabilityScope } from '@comfyorg/ingest-types/zod' @@ -59,6 +60,8 @@ export type CapabilityRolloutDefaults = z.infer< const CapabilitiesBodySchema = z.object({ capabilities: zBillingCapabilities, expires_at: z.string(), + payment_recovery_available: + zBillingCapabilitiesResponse.shape.payment_recovery_available, resolved_for: zBillingCapabilityScope, revision: z.number(), rollout_defaults_applied: zBillingCapabilityRolloutDefaults @@ -75,6 +78,10 @@ export interface CapabilitiesSnapshot { * key never implies the capability was granted — read `capabilities`. */ readonly denials: CapabilityDenials + /** + * As received. Absent when the server omits it: unknown, not a refusal. + */ + readonly paymentRecoveryAvailable?: boolean /** True values are rollout guidance, not evidence a write will succeed. */ readonly rolloutDefaultsApplied: CapabilityRolloutDefaults readonly revision: number @@ -179,6 +186,7 @@ export function createCapabilitiesReader( value: { capabilities: data.capabilities, denials, + paymentRecoveryAvailable: data.payment_recovery_available, rolloutDefaultsApplied: data.rollout_defaults_applied, revision: data.revision, scope, diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts index 45159373cd5..bfa2586078a 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts @@ -9,6 +9,7 @@ import TopbarSubscribeButton from '@/components/topbar/TopbarSubscribeButton.vue import { useBillingContext } from '@/composables/billing/useBillingContext' import enMessages from '@/locales/en/main.json' with { type: 'json' } import type { BillingStatus } from '@/platform/workspace/api/workspaceApi' +import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { usePaymentRecoveryDialog } from '@/platform/workspace/composables/usePaymentRecoveryDialog' import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue' @@ -32,6 +33,7 @@ vi.mock( ) vi.mock(import('@/platform/workspace/composables/usePaymentRecoveryDialog')) +vi.mock(import('@/platform/workspace/composables/useBillingCapabilities')) vi.mock( import('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue'), @@ -119,6 +121,8 @@ describe('CloudRunButtonWrapper', () => { mockSubscriptionTier.value = null mockIsFreeTier.value = true mockPaymentRecoveryLock.value = null + useBillingCapabilities().canRunWorkflows = computed(() => false) + useBillingCapabilities().hasResolvedCapabilities = computed(() => true) vi.mocked(usePaymentRecoveryDialog).mockReturnValue({ showPaymentRecoveryDialog, updatePayment: vi.fn(), @@ -201,6 +205,18 @@ describe('CloudRunButtonWrapper', () => { ).not.toBeInTheDocument() }) + it('unlocks Run when resolved capabilities say the actor can run', () => { + mockCanRunWorkflows.value = false + mockPaymentRecoveryLock.value = 'owner' + useBillingCapabilities().canRunWorkflows = computed(() => true) + renderWrapper() + + expect(screen.getByTestId('queue-button')).toHaveTextContent('Run') + expect( + screen.queryByTestId('subscribe-to-run-button') + ).not.toBeInTheDocument() + }) + it('locks the run button when the subscription is inactive', () => { mockCanRunWorkflows.value = false renderWrapper() diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue index e175eb78843..62fde8d84be 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue @@ -1,6 +1,11 @@