Skip to content

[backport core/1.50] FE-1585 fix(billing): refresh stale Run entitlement on app return - #15340

Closed
comfy-pr-bot wants to merge 1 commit into
core/1.50from
backport-15207-to-core-1.50
Closed

comfy-pr-bot wants to merge 1 commit into
core/1.50from
backport-15207-to-core-1.50

Conversation

@comfy-pr-bot

Copy link
Copy Markdown
Member

Backport of #15207 to core/1.50

Automatically created by backport workflow.

…5207)

## Why

FE-1540 is only partially fixed by #14965. The Run surface no longer
shows a paywall before billing initializes, but a successful `inactive`
response remains cached when the authoritative subscription changes
outside the open app—for example after returning from Stripe Portal,
another tab, a delayed webhook, or a support action.

`CloudRunButtonWrapper` previously refreshed on focus only when its own
paused-payment recovery flow set `refreshBillingOnFocus`. A plain
`Subscribe to Run` state had no focus/visibility recovery, so the user
needed a manual page reload even after the server became `active`.

## AS IS

```mermaid
sequenceDiagram
  participant FE as Open editor
  participant API as Billing API
  participant Provider as Stripe / webhook

  FE->>API: Fetch billing status
  API-->>FE: inactive
  Note over FE: Show Subscribe to Run
  Provider->>API: Subscription becomes active
  Note over FE,API: No pending BillingOp and no general refetch
  Note over FE: Cached inactive state remains until reload
```

## TO BE

```mermaid
sequenceDiagram
  participant User
  participant FE as CloudRunButtonWrapper
  participant Context as useBillingContext
  participant API as Authoritative billing API

  User->>FE: Return to app (focus / visible)
  FE->>FE: Confirm Subscribe to Run is displayed
  FE->>Context: fetchStatus + fetchBalance
  alt legacy billing rail
    Context->>API: Legacy billing reads
  else workspace billing rail
    Context->>API: Workspace billing reads
  end
  API-->>Context: active + current balance
  Context-->>FE: Reactive billing state updates
  Note over FE: Subscribe to Run becomes Run
```

## Change

- Revalidate status and balance when an app showing `Subscribe to Run`
regains focus or becomes visible.
- Route through `useBillingContext`, so the active legacy or workspace
billing adapter remains authoritative.
- Deduplicate overlapping `focus` and `visibilitychange` refreshes.
- Preserve the existing paused-payment portal recovery behavior.
- Do not add continuous polling: known new-billing checkouts retain
BillingOp polling, while this is a bounded recovery trigger for changes
outside that flow.

## Scope

This PR does **not** infer subscription state in the frontend and does
not attempt to prevent or resolve duplicate Stripe subscriptions.
Provider subscription integrity remains a backend responsibility; the
frontend only re-reads the server-authored state.

## Testing

- `pnpm test:unit
src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts` —
15 passed
- `pnpm typecheck` — passed
- changed-file ESLint, type-aware oxlint, and formatting checks — passed
- `pnpm knip` — blocked by two existing unused devDependencies on `main`
(`@storybook/addon-mcp`, `lint-staged`); this PR does not change package
or knip configuration

The component regression covers the observable AS IS → TO BE transition:
stale `inactive`/Subscribe state, app focus, authoritative refresh, and
restored Run button. No visual styling changes.

Linear: FE-1540

---------

Co-authored-by: Amp <amp@ampcode.com>
@comfy-pr-bot comfy-pr-bot added the backport Backporting a PR onto a release candidate label Aug 16, 2026
@comfy-pr-bot
comfy-pr-bot enabled auto-merge (squash) August 16, 2026 12:17
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 16, 2026
@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 08/16/2026, 12:19:15 PM UTC

Links

🎭 Playwright: 🕵🏻 0 passed, 0 failed

📊 Browser Reports
  • chromium: ❌ Deployment failed
  • chromium-2x: ❌ Deployment failed
  • chromium-0.5x: ❌ Deployment failed
  • mobile-chrome: ❌ Deployment failed

📦 Bundle Size

⏳ Size data collection in progress…

⚡ Performance

⚠️ Performance tests failed. Check the CI workflow logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Backporting a PR onto a release candidate size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants