Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6262b7b
feat(agent): surface the credits paywall on exhaustion, not only on a…
christian-byrne Sep 26, 2026
0e0d450
Fix standing paywall after inline resolution
christian-byrne Sep 28, 2026
42a6f16
Track standing paywall only when visible
christian-byrne Sep 28, 2026
ae05e18
Use Agent-effective funds for exhaustion UI
christian-byrne Sep 28, 2026
e5eceeb
Persist exhaustion impression across panel remounts
christian-byrne Sep 28, 2026
932f1f9
Harden standing exhaustion paywall lifecycle
christian-byrne Sep 28, 2026
63bd045
fix(agent): repair exhaustion paywall checks
christian-byrne Sep 28, 2026
f891b39
fix(billing): consume scoped Agent funds verdict
christian-byrne Sep 28, 2026
fa57dd6
fix(agent): cover billing refresh and impression recovery
christian-byrne Sep 28, 2026
bb32cc7
test(agent): provide billing context in load failure fixture
christian-byrne Sep 28, 2026
7ee33d7
fix(agent): rearm exhaustion outside panel lifetime
christian-byrne Sep 28, 2026
833459f
test(agent): mock billing in panel store regression
christian-byrne Sep 28, 2026
96fcc0d
test(agent): use complete billing fixtures
christian-byrne Sep 28, 2026
68d1d3c
test(agent): cover workspace funds composition
christian-byrne Sep 28, 2026
963b82a
test: cover standing agent paywall lifecycle
christian-byrne Sep 28, 2026
0859d10
test(agent): synchronize paywall lifecycle fixture
christian-byrne Sep 28, 2026
e4be2b9
test(agent): simplify accepted-turn fixture
christian-byrne Sep 28, 2026
566c3b9
feat(agent): consume live funds status updates
christian-byrne Sep 28, 2026
a8f52f0
test(agent): assert paywall stays hidden during active turn
christian-byrne Sep 28, 2026
0a5e539
test(agent): narrow accepted turn with assertion
christian-byrne Sep 28, 2026
6841eb5
fix(agent): remove premature funds event handling
ampagent Sep 28, 2026
029d6a0
fix(agent): report standing paywall only when visible
ampagent Sep 28, 2026
a9e8c28
test(agent): name exhaustion recovery outcome
christian-byrne Sep 29, 2026
1979e37
fix(agent): adapt exhaustion paywall to cloud 1.55
christian-byrne Sep 30, 2026
058d106
chore: reconcile cloud/1.55 release head
christian-byrne Sep 30, 2026
9628f0e
chore: reconcile cloud/1.55 release head
christian-byrne Sep 30, 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
96 changes: 95 additions & 1 deletion browser_tests/tests/agent/agentPanel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import assert from 'node:assert/strict'

import type { WebSocketRoute } from '@playwright/test'
import { expect, mergeTests } from '@playwright/test'

import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog'
import { webSocketFixture } from '@e2e/fixtures/ws'

import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { AgentWsEvent } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import {
zAgentAdmissionError,
zAgentWsEvent
} from '@/workbench/extensions/agent/schemas/agentApiSchema'

import {
INTERMEDIATE_MESSAGE_EVENT,
Expand Down Expand Up @@ -214,6 +220,94 @@ test.describe('In-App Agent panel', { tag: '@cloud' }, () => {
})
})

test('keeps the standing paywall in sync across turn completion and panel close', async ({
acceptedTurns,
agentBilling,
agentPanel,
comfyPage,
getWebSocket,
postedMessages
}) => {
test.setTimeout(30_000)
const page = comfyPage.page
const paywall = page.getByTestId('agent-credits-exhausted-paywall')
const ws = await getWebSocket()

await test.step('show the standing paywall after an accepted turn exhausts credits', async () => {
await agentPanel.open()
await agentPanel.selectWorkflow()
agentBilling.setAgentFunds(false)
await agentPanel.sendMessage('Complete this workflow without a refusal')
await expect.poll(() => postedMessages.length).toBe(1)
pushEvent(ws, THINKING_EVENT)
await expect(
agentPanel.root.getByRole('button', { name: 'Stop' })
).toBeVisible()
await expect(paywall).toHaveCount(0)
pushEvent(ws, MESSAGE_DONE_EVENT)
await expect(paywall).toBeVisible()
})

await test.step('finish the funded recovery while the panel is closed', async () => {
agentBilling.setAgentFunds(true)
const recovery = agentBilling.holdNextFundedRefresh()
await paywall.getByRole('button', { name: 'Add Credits' }).click()
const topUpDialog = new TopUpCreditsDialog(page)
await topUpDialog.waitForVisible()
await recovery.entered
await topUpDialog.close()
await agentPanel.root
.getByRole('button', { name: enMessages.g.close })
.click()
await expect(agentPanel.root).toHaveCount(0)
recovery.release()
await recovery.completed
})

await test.step('reopen without the stale paywall', async () => {
await agentPanel.open()
await expect(paywall).toHaveCount(0)
})

await test.step('show the standing paywall after a second exhaustion', async () => {
agentBilling.setAgentFunds(false)
await agentPanel.sendMessage(
'Complete another workflow without a refusal'
)
await expect.poll(() => postedMessages.length).toBe(2)
expect(acceptedTurns).toHaveLength(2)
const secondTurn = acceptedTurns.at(-1)
assert(secondTurn)
pushEvent(
ws,
zAgentWsEvent.parse({
...THINKING_EVENT,
data: { ...THINKING_EVENT.data, message_id: secondTurn.message_id }
})
)
await expect(
agentPanel.root.getByRole('button', { name: 'Stop' })
).toBeVisible()
pushEvent(
ws,
zAgentWsEvent.parse({
...MESSAGE_DONE_EVENT,
data: {
...MESSAGE_DONE_EVENT.data,
message_id: secondTurn.message_id
}
})
)
await expect(paywall).toBeVisible()
})

await test.step('remove the standing paywall after the final funded refresh', async () => {
agentBilling.setAgentFunds(true)
await paywall.getByRole('button', { name: 'Add Credits' }).click()
await expect(paywall).toHaveCount(0)
})
})

test('keeps a failed prompt available to retry', async ({
agentPanel,
comfyPage
Expand Down
102 changes: 102 additions & 0 deletions browser_tests/tests/agent/agentPanelMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Page, Route } from '@playwright/test'

import type {
AgentThreadListResponse,
BillingStatusResponse,
GlobalSetting,
WorkflowListResponse
} from '@comfyorg/ingest-types'
Expand Down Expand Up @@ -37,6 +38,89 @@ const TURN_ACCEPTED: AgentTurnAccepted = {

const CANCEL_ACCEPTED: AgentCancelAccepted = { status: 'cancelling' }

const FUNDED_BILLING_STATUS = {
billing_rail: 'stripe',
billing_status: 'paid',
has_funds: true,
is_active: true,
max_seats: 1,
occupied_seats: 1,
scoped_effective_has_funds: { agent: true },
scheduled_change: null,
subscription_duration: 'MONTHLY',
subscription_status: 'active',
subscription_tier: 'STANDARD',
team_credit_stop: null
} satisfies BillingStatusResponse

type HeldBillingRefresh = {
entered: Promise<void>
completed: Promise<void>
release: () => void
}

class AgentBillingFixture {
private status: BillingStatusResponse = FUNDED_BILLING_STATUS
private heldRefresh:
| {
resolveEntered: () => void
resolveCompleted: () => void
releaseRequest?: () => void
}
| undefined

setAgentFunds(hasFunds: boolean): void {
this.status = {
...FUNDED_BILLING_STATUS,
has_funds: hasFunds,
scoped_effective_has_funds: { agent: hasFunds }
}
}

holdNextFundedRefresh(): HeldBillingRefresh {
let resolveEntered!: () => void
let resolveCompleted!: () => void
const entered = new Promise<void>((resolve) => {
resolveEntered = resolve
})
const completed = new Promise<void>((resolve) => {
resolveCompleted = resolve
})
const heldRefresh: NonNullable<AgentBillingFixture['heldRefresh']> = {
resolveEntered,
resolveCompleted
}
this.heldRefresh = heldRefresh

return {
entered,
completed,
release: () => {
if (heldRefresh.releaseRequest === undefined) {
throw new Error('Funded billing refresh has not entered the fixture')
}
heldRefresh.releaseRequest()
}
}
}

async fulfillStatus(route: Route): Promise<void> {
const response = this.status
const heldRefresh = this.heldRefresh
let completedHeldRefresh: typeof heldRefresh
if (heldRefresh && response.scoped_effective_has_funds?.agent) {
this.heldRefresh = undefined
completedHeldRefresh = heldRefresh
heldRefresh.resolveEntered()
await new Promise<void>((resolve) => {
heldRefresh.releaseRequest = resolve
})
}
await route.fulfill(jsonRoute(response))
completedHeldRefresh?.resolveCompleted()
}
}

export const FUNDS_UNAVAILABLE_MESSAGE =
'Billing status is temporarily unavailable; please retry.'
const FUNDS_UNAVAILABLE = zAgentAdmissionError.parse({
Expand Down Expand Up @@ -160,6 +244,8 @@ async function mockAgentBoot(
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
agentBilling,
acceptedTurns,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand Down Expand Up @@ -215,6 +301,9 @@ async function mockAgentBoot(
)

await mockBilling(page)
await page.route('**/api/billing/status', (route) =>
agentBilling.fulfillStatus(route)
)
await page.route(
'https://media.comfy.org/website/comfy-agent/**',
(route) => {
Expand Down Expand Up @@ -391,6 +480,7 @@ async function mockAgentBoot(
? TURN_ID
: `${TURN_ID}-${postedMessages.length}`
}
acceptedTurns.push(accepted)
return route.fulfill({
status: 202,
contentType: 'application/json',
Expand All @@ -407,6 +497,8 @@ async function mockAgentBoot(

type AgentFixtures = {
agentAutoShownReadProbe: boolean
acceptedTurns: AgentTurnAccepted[]
agentBilling: AgentBillingFixture
agentConsentAccepted: boolean
agentConsentReads: boolean[]
agentConsentSave: { status: number; pending?: Promise<void> }
Expand All @@ -424,6 +516,12 @@ type AgentFixtures = {

export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentAutoShownReadProbe: [false, { option: true }],
acceptedTurns: async ({ agentFlagEnabled: _agentFlagEnabled }, use) => {
await use([])
},
agentBilling: async ({ agentFlagEnabled: _agentFlagEnabled }, use) => {
await use(new AgentBillingFixture())
},
agentConsentAccepted: [true, { option: true }],
agentConsentReads: async ({ agentFlagEnabled: _agentFlagEnabled }, use) => {
await use([])
Expand Down Expand Up @@ -454,6 +552,8 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
agentBilling,
acceptedTurns,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand All @@ -474,6 +574,8 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
agentBilling,
acceptedTurns,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand Down
1 change: 1 addition & 0 deletions src/components/topbar/CurrentUserPopoverLegacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function makeSubscription(
endDate: null,
isCancelled: false,
hasFunds: true,
agentHasFunds: true,
...overrides
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/composables/billing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface SubscriptionInfo {
endDate: string | null
isCancelled: boolean
hasFunds: boolean
/** Agent funds across shared credits and the Agent-scoped balance. */
agentHasFunds: boolean
}

export interface BalanceInfo {
Expand Down
33 changes: 32 additions & 1 deletion src/composables/billing/useBillingContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { prepareChurnkey } from '@/platform/cloud/churnkey/churnkeyClient'
import { launchCancellationFlow } from '@/platform/cloud/subscription/launchCancellationFlow'
import { reportError } from '@/platform/telemetry/reportError'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useAgentDockMount'
import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore'

import { workspaceApi } from '@/platform/workspace/api/workspaceApi'
import type {
Expand Down Expand Up @@ -224,10 +226,39 @@ describe('useBillingContext', () => {
renewalDate: '2025-01-01T00:00:00Z',
endDate: null,
isCancelled: false,
hasFunds: true
hasFunds: true,
agentHasFunds: true
})
})

it('re-arms the exhaustion impression after workspace-scoped Agent funds recover while the dock is closed', async () => {
vi.stubGlobal('__DISTRIBUTION__', 'cloud')
mockBillingRail.value = 'stripe'
mockBillingStatus.value = {
...DEFAULT_BILLING_STATUS,
has_funds: false,
scoped_effective_has_funds: { agent: false }
}
const scope = effectScope()
onTestFinished(() => scope.stop())
const billing = scope.run(useSharedBillingContext)
assert.exists(billing)
const dock = scope.run(useAgentDockMount)
assert.exists(dock)
const agentPanelStore = useAgentPanelStore()
agentPanelStore.isOpen = false
agentPanelStore.reportedExhaustionIdentity = 'account-a:workspace-a'

await billing.fetchStatus()
expect(dock.docked.value).toBe(false)

mockBillingStatus.value.scoped_effective_has_funds = { agent: true }
await billing.fetchStatus()
await nextTick()

expect(agentPanelStore.reportedExhaustionIdentity).toBeNull()
})

describe('canRunWorkflows', () => {
it('is true when not on free tier', async () => {
remoteConfigState.value = 'authenticated'
Expand Down
4 changes: 3 additions & 1 deletion src/composables/billing/useLegacyBilling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function useLegacyBilling(): BillingState & BillingActions {
const maxSeats = computed(() => null)
const occupiedSeats = computed(() => null)

const hasFunds = computed(() => (authStore.balance?.amount_micros ?? 0) > 0)
const subscription = computed<SubscriptionInfo | null>(() => {
if (!legacyCanAccessSubscriptionFeatures.value && !subscriptionTier.value) {
return null
Expand All @@ -76,7 +77,8 @@ export function useLegacyBilling(): BillingState & BillingActions {
renewalDate: legacySubscriptionStatus.value?.renewal_date ?? null,
endDate: legacySubscriptionStatus.value?.cancel_at ?? null,
isCancelled: isCancelled.value,
hasFunds: (authStore.balance?.amount_micros ?? 0) > 0
hasFunds: hasFunds.value,
agentHasFunds: hasFunds.value
}
})

Expand Down
1 change: 1 addition & 0 deletions src/composables/billing/useNextInvoice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function makeSubscription(
endDate: null,
isCancelled: false,
hasFunds: true,
agentHasFunds: true,
...overrides
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('CreditsTile', () => {
endDate: null,
isCancelled: false,
hasFunds: true,
agentHasFunds: true,
...state.subscription
}
: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ beforeEach(() => {
renewalDate: null,
endDate: null,
isCancelled: false,
hasFunds: true
hasFunds: true,
agentHasFunds: true
}
: null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ beforeEach(() => {
endDate: null,
isCancelled: false,
hasFunds: true,
agentHasFunds: true,
...mockSubscription.value
}
: null
Expand Down
Loading
Loading