From 3c124e46676242b22fb051fa6ea22c2eda3bd9b7 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Sat, 17 Oct 2026 22:09:26 +0000 Subject: [PATCH 1/4] fix(agent): hold the out-of-credits card until the thread is activated --- .../agentCreditsExhaustionEmptyThread.spec.ts | 59 ++++++++++++++++++ .../extensions/agent/AgentPanelRoot.test.ts | 60 +++++++++++++++++++ .../extensions/agent/AgentPanelRoot.vue | 18 +++++- 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts diff --git a/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts b/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts new file mode 100644 index 00000000000..f7eb9a9004c --- /dev/null +++ b/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts @@ -0,0 +1,59 @@ +import { expect } from '@playwright/test' + +import enMessages from '@/locales/en/main.json' with { type: 'json' } + +import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture' +import { agentTest as test } from '@e2e/tests/agent/agentPanelMocks' + +// A fresh grant can take a while to be realized by billing, so a workspace that +// is about to be funded can still read as exhausted when the panel opens. The +// standing out-of-credits card therefore waits until the thread is activated by +// the user's first message instead of greeting an empty thread. +test.describe( + 'Agent standing credits-exhaustion on an empty thread', + { tag: ['@cloud', '@ui'] }, + () => { + test('waits for the first user message before showing the out-of-credits card', async ({ + agentBilling, + agentPanel, + page + }) => { + const paywall = agentPanel.creditsExhaustedPaywall + + agentBilling.setFundingState('exhausted') + const exhaustedStatus = page.waitForResponse( + (response) => + response.request().method() === 'GET' && + new URL(response.url()).pathname === '/api/billing/status' + ) + await page.reload() + await waitForCloudApp(page) + await exhaustedStatus + await agentPanel.open() + await agentPanel.selectWorkflow() + + await test.step('stay hidden on the empty thread', async () => { + await expect(agentPanel.composer).toBeVisible() + await expect(paywall).toHaveCount(0) + }) + + await test.step('show once the first message activates the thread', async () => { + await agentPanel.sendMessage('Build a red fox workflow') + await expect( + agentPanel.root.getByTestId('user-message-bubble') + ).toHaveText(['Build a red fox workflow']) + await expect(paywall).toBeVisible() + }) + + await test.step('hide again on a new empty thread', async () => { + await agentPanel.root + .getByRole('button', { name: enMessages.agent.newChat }) + .click() + await expect( + agentPanel.root.getByTestId('user-message-bubble') + ).toHaveCount(0) + await expect(paywall).toHaveCount(0) + }) + }) + } +) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 60b0f54c0d9..924872a9bc3 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -601,6 +601,14 @@ function renderWithSelectedTarget() { return render(AgentPanelRoot, { global: { plugins: [i18n] } }) } +/** + * The standing credits-exhausted card waits for an activated thread, so cases + * about it start from one rather than a fresh empty chat. + */ +function activateThread(): void { + useAgentConversationStore().setThreadId('th-active') +} + async function sendFromComposer(text: string): Promise { const textbox = screen.getByRole('textbox') await userEvent.click(textbox) @@ -1810,6 +1818,7 @@ describe('AgentPanelRoot Agent credit transition notice', () => { observeAgentScopedFunds(true) render(AgentPanelRoot, { global: { plugins: [i18n] } }) await screen.findByRole('textbox') + activateThread() observeAgentScopedFunds(false) paywallAgentHasFunds.value = false @@ -1905,6 +1914,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallBilling.tier = subscription paywallHasFunds.value = effectiveFunds render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -1929,6 +1939,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallBilling.isActive = isActive paywallHasFunds.value = effectiveFunds render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() expect(await screen.findByTestId(STANDING)).toBeInTheDocument() } @@ -1937,6 +1948,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('shows an upgrade path when the workspace is out of credits, with no refusal first', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const card = await screen.findByTestId(STANDING) @@ -1960,6 +1972,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = false workflowStore.activeWorkflow = addTab('workflows/current.json') renderWithSelectedTarget() + activateThread() await screen.findByTestId(STANDING) await sendFromComposer('continue anyway') @@ -1971,6 +1984,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('reports the impression against the credits_exhausted surface', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await waitFor(() => expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledExactlyOnceWith({ @@ -1983,6 +1997,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('attributes its CTA to the credits_exhausted surface and opens the credits flow', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const card = await screen.findByTestId(STANDING) await userEvent.click( @@ -2003,16 +2018,40 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('stays hidden while the workspace has funds', async () => { paywallHasFunds.value = true render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() + await screen.findByRole('textbox') + + expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() + expect(telemetry.trackAgentPaywallShown).not.toHaveBeenCalled() + }) + + // A fresh grant can take a while to be realized by billing, so a funded-soon + // user must not be greeted by an out-of-credits card on a fresh empty chat. + it('stays hidden on an empty thread until the thread is activated', async () => { + paywallHasFunds.value = false + render(AgentPanelRoot, { global: { plugins: [i18n] } }) await screen.findByRole('textbox') + await nextTick() expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() expect(telemetry.trackAgentPaywallShown).not.toHaveBeenCalled() + + activateThread() + + expect(await screen.findByTestId(STANDING)).toBeInTheDocument() + await waitFor(() => + expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledExactlyOnceWith({ + reason: 'no_funds', + surface: 'credits_exhausted' + }) + ) }) it('stays hidden while Agent-scoped gratis can fund the turn', async () => { paywallHasFunds.value = false paywallAgentHasFunds.value = true render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2023,6 +2062,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { Object.assign(useAgentConsentStore(), { accepted: false }) paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2033,6 +2073,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = false paywallBilling.type = 'legacy' render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2044,6 +2085,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = false paywallBilling.status = status render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2055,6 +2097,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('stays hidden while the billing read has not answered', async () => { paywallHasFunds.value = null render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2068,6 +2111,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = false paywallCapabilities.isReady = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') await nextTick() @@ -2082,6 +2126,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallCapabilities.canTopUp = false paywallCapabilities.hasResolvedCapabilities = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') await nextTick() @@ -2093,6 +2138,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallWorkspace.role = 'member' paywallCapabilities.canTopUp = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() @@ -2103,6 +2149,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('yields to an inline paywall card rather than duplicating it', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) useAgentConversationStore().recordPaywall( @@ -2119,6 +2166,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('shows the standing card when a normal reply follows an older unresolved inline card', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const conversation = useAgentConversationStore() conversation.recordPaywall(toTurnId('msg-paywall'), 'continue') await waitFor(() => @@ -2139,6 +2187,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('returns after the inline paywall is resolved and credits run out again', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) useAgentConversationStore().recordPaywall( @@ -2161,6 +2210,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('reports only after returning from chat history', async () => { paywallHasFunds.value = true render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByRole('textbox') await userEvent.click( @@ -2197,6 +2247,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { const firstPanel = render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) await waitFor(() => expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(1) @@ -2224,6 +2275,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { firstPanel.unmount() render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(2) @@ -2232,6 +2284,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('disappears once funds arrive', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) paywallHasFunds.value = true @@ -2246,6 +2299,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('reports one impression per exhaustion episode, not per re-evaluation', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) await waitFor(() => expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(1) @@ -2261,6 +2315,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('does not re-arm the impression when capabilities refresh while still exhausted', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) await waitFor(() => expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(1) @@ -2277,6 +2332,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('does not report the same exhaustion episode after a panel remount', async () => { paywallHasFunds.value = false const firstPanel = render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) await waitFor(() => expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(1) @@ -2284,6 +2340,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { firstPanel.unmount() render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() await screen.findByTestId(STANDING) expect(telemetry.trackAgentPaywallShown).toHaveBeenCalledTimes(1) @@ -2291,6 +2348,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { it('refreshes workspace billing after an active turn becomes idle', async () => { paywallHasFunds.value = true render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const conversation = useAgentConversationStore() const turnId = toTurnId('billing-refresh') @@ -2313,6 +2371,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = true paywallBilling.type = 'legacy' render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const conversation = useAgentConversationStore() const turnId = toTurnId('legacy-billing-refresh') @@ -2334,6 +2393,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { paywallHasFunds.value = true paywallBilling.fetchStatus.mockRejectedValueOnce(refreshError) render(AgentPanelRoot, { global: { plugins: [i18n] } }) + activateThread() const conversation = useAgentConversationStore() const turnId = toTurnId('failed-billing-refresh') diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index bd1fd5a1f31..87ccebd59f8 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -272,8 +272,11 @@ function onPaywallAction( openAccountPrecondition('subscription', { source: 'agent_paywall' }) } -const { messages: conversationMessages, entries: conversationEntries } = - storeToRefs(conversationStore) +const { + messages: conversationMessages, + entries: conversationEntries, + threadId: conversationThreadId +} = storeToRefs(conversationStore) watch( () => // Gated on the read having *settled*, which includes settling as @@ -369,8 +372,17 @@ const latestEntryHasPaywall = computed(() => { latestEntry.parts.some((part) => part.type === 'paywall') ) }) +/** + * Held back until the thread is activated (its first user turn was accepted, + * or an existing thread is open). A freshly granted credit can take a while to + * be realized by billing, so an empty thread would otherwise greet a user who + * is about to be funded with an out-of-credits card. A refused first send still + * surfaces the inline card. Revisit if the agent ever opens threads with a + * proactive first turn: an empty thread would no longer mean "user not engaged". + */ const showStandingPaywall = computed(() => { - if (!creditsExhausted.value) return false + if (!creditsExhausted.value || conversationThreadId.value === null) + return false return !latestEntryHasPaywall.value }) From 26593ae6bde3a436faa2825239e7550ba1e94576 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Sat, 17 Oct 2026 22:21:35 +0000 Subject: [PATCH 2/4] chore(agent): drop rationale comments per AGENTS.md --- .../tests/agent/agentCreditsExhaustionEmptyThread.spec.ts | 4 ---- src/workbench/extensions/agent/AgentPanelRoot.test.ts | 6 ------ src/workbench/extensions/agent/AgentPanelRoot.vue | 8 -------- 3 files changed, 18 deletions(-) diff --git a/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts b/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts index f7eb9a9004c..813e7eae3bf 100644 --- a/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts +++ b/browser_tests/tests/agent/agentCreditsExhaustionEmptyThread.spec.ts @@ -5,10 +5,6 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' } import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture' import { agentTest as test } from '@e2e/tests/agent/agentPanelMocks' -// A fresh grant can take a while to be realized by billing, so a workspace that -// is about to be funded can still read as exhausted when the panel opens. The -// standing out-of-credits card therefore waits until the thread is activated by -// the user's first message instead of greeting an empty thread. test.describe( 'Agent standing credits-exhaustion on an empty thread', { tag: ['@cloud', '@ui'] }, diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 924872a9bc3..665045132a3 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -601,10 +601,6 @@ function renderWithSelectedTarget() { return render(AgentPanelRoot, { global: { plugins: [i18n] } }) } -/** - * The standing credits-exhausted card waits for an activated thread, so cases - * about it start from one rather than a fresh empty chat. - */ function activateThread(): void { useAgentConversationStore().setThreadId('th-active') } @@ -2025,8 +2021,6 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { expect(telemetry.trackAgentPaywallShown).not.toHaveBeenCalled() }) - // A fresh grant can take a while to be realized by billing, so a funded-soon - // user must not be greeted by an out-of-credits card on a fresh empty chat. it('stays hidden on an empty thread until the thread is activated', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 87ccebd59f8..b799695fe15 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -372,14 +372,6 @@ const latestEntryHasPaywall = computed(() => { latestEntry.parts.some((part) => part.type === 'paywall') ) }) -/** - * Held back until the thread is activated (its first user turn was accepted, - * or an existing thread is open). A freshly granted credit can take a while to - * be realized by billing, so an empty thread would otherwise greet a user who - * is about to be funded with an out-of-credits card. A refused first send still - * surfaces the inline card. Revisit if the agent ever opens threads with a - * proactive first turn: an empty thread would no longer mean "user not engaged". - */ const showStandingPaywall = computed(() => { if (!creditsExhausted.value || conversationThreadId.value === null) return false From 4fe474b4cd8e9da4205be797af7da9023d55aeb6 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 06:59:02 +0000 Subject: [PATCH 3/4] fix(agent): gate the out-of-credits card on a user message, not thread id A first send that fails before the server acknowledges it (network, 5xx, or a 402 whose inline card is later resolved) leaves a user message in the transcript with no thread id, which hid the standing card on a non-empty conversation. Restoring a thread set the id before its history loaded, which showed the card over an empty transcript. Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/21241#discussion_r4305998498 and https://github.com/Comfy-Org/ComfyUI_frontend/pull/21241#discussion_r4305998502 --- .../extensions/agent/AgentPanelRoot.test.ts | 54 ++++++++++++++++++- .../extensions/agent/AgentPanelRoot.vue | 13 +++-- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 665045132a3..d825c3bff59 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -602,7 +602,17 @@ function renderWithSelectedTarget() { } function activateThread(): void { - useAgentConversationStore().setThreadId('th-active') + const conversation = useAgentConversationStore() + conversation.setThreadId('th-active') + const turnId = toTurnId('msg-first') + conversation.recordUser(turnId, 'first message') + conversation.messages.push({ + id: turnId, + role: 'assistant', + parts: [{ type: 'text', text: 'First reply', state: 'done' }], + streaming: false, + thinking: false + }) } async function sendFromComposer(text: string): Promise { @@ -2021,7 +2031,7 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { expect(telemetry.trackAgentPaywallShown).not.toHaveBeenCalled() }) - it('stays hidden on an empty thread until the thread is activated', async () => { + it('stays hidden on an empty thread until the first user message', async () => { paywallHasFunds.value = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) await screen.findByRole('textbox') @@ -2041,6 +2051,46 @@ describe('AgentPanelRoot standing credits-exhausted paywall', () => { ) }) + it('stays hidden while a restored thread has not loaded any messages', async () => { + paywallHasFunds.value = false + render(AgentPanelRoot, { global: { plugins: [i18n] } }) + await screen.findByRole('textbox') + useAgentConversationStore().setThreadId('th-restoring') + await nextTick() + + expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() + expect(telemetry.trackAgentPaywallShown).not.toHaveBeenCalled() + }) + + it('shows after a first send that failed before the thread was created', async () => { + paywallHasFunds.value = false + render(AgentPanelRoot, { global: { plugins: [i18n] } }) + await screen.findByRole('textbox') + + useAgentConversationStore().recordFailedSend( + toTurnId('msg-failed-first'), + 'Build a red fox workflow', + 'Something went wrong' + ) + + expect(await screen.findByTestId(STANDING)).toBeInTheDocument() + }) + + it('shows once a refused first send has its inline card resolved', async () => { + paywallHasFunds.value = false + render(AgentPanelRoot, { global: { plugins: [i18n] } }) + await screen.findByRole('textbox') + const conversation = useAgentConversationStore() + + conversation.recordPaywall(toTurnId('msg-refused-first'), 'continue') + expect(await findInlinePaywallButton('Add credits')).toBeInTheDocument() + expect(screen.queryByTestId(STANDING)).not.toBeInTheDocument() + + conversation.resolvePaywalls() + + expect(await screen.findByTestId(STANDING)).toBeInTheDocument() + }) + it('stays hidden while Agent-scoped gratis can fund the turn', async () => { paywallHasFunds.value = false paywallAgentHasFunds.value = true diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index b799695fe15..275480b43fa 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -272,11 +272,8 @@ function onPaywallAction( openAccountPrecondition('subscription', { source: 'agent_paywall' }) } -const { - messages: conversationMessages, - entries: conversationEntries, - threadId: conversationThreadId -} = storeToRefs(conversationStore) +const { messages: conversationMessages, entries: conversationEntries } = + storeToRefs(conversationStore) watch( () => // Gated on the read having *settled*, which includes settling as @@ -372,9 +369,11 @@ const latestEntryHasPaywall = computed(() => { latestEntry.parts.some((part) => part.type === 'paywall') ) }) +const threadHasUserMessage = computed(() => + conversationEntries.value.some((entry) => entry.role === 'user') +) const showStandingPaywall = computed(() => { - if (!creditsExhausted.value || conversationThreadId.value === null) - return false + if (!creditsExhausted.value || !threadHasUserMessage.value) return false return !latestEntryHasPaywall.value }) From f7fe95eb4d9a83041165c31a7dad5f02280763a0 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 07:29:33 +0000 Subject: [PATCH 4/4] test(agent): serve completed turns as thread history in the credits lifecycle e2e The lifecycle fixture answered every thread history read with an empty list, so reopening the panel restored the thread with no messages. A real thread keeps its turns, and the standing out-of-credits card now waits for a user message in the transcript. --- .../agentCreditsExhaustionLifecycle.spec.ts | 15 ++++-- .../agentCreditsExhaustionLifecycleMocks.ts | 54 ++++++++++++++++--- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/browser_tests/tests/agent/agentCreditsExhaustionLifecycle.spec.ts b/browser_tests/tests/agent/agentCreditsExhaustionLifecycle.spec.ts index b3ca04cbd47..8651c82868c 100644 --- a/browser_tests/tests/agent/agentCreditsExhaustionLifecycle.spec.ts +++ b/browser_tests/tests/agent/agentCreditsExhaustionLifecycle.spec.ts @@ -60,7 +60,7 @@ test.describe( agentBilling.failSubsequentRefreshes() await expect( agentPanel.root.getByTestId('user-message-bubble') - ).toHaveText(['Make the lighting warmer']) + ).toHaveText(['Build a red fox workflow', 'Make the lighting warmer']) await agentPanel.close() heldRefresh.release() await heldRefresh.completed @@ -78,7 +78,11 @@ test.describe( await expect(paywall).toBeVisible() await expect( agentPanel.root.getByTestId('user-message-bubble') - ).toHaveText(['Add shallow depth of field']) + ).toHaveText([ + 'Build a red fox workflow', + 'Make the lighting warmer', + 'Add shallow depth of field' + ]) }) await test.step('recover again and preserve the conversation', async () => { @@ -89,7 +93,12 @@ test.describe( await expect(paywall).toHaveCount(0) await expect( agentPanel.root.getByTestId('user-message-bubble') - ).toHaveText(['Add shallow depth of field', 'Finish the workflow']) + ).toHaveText([ + 'Build a red fox workflow', + 'Make the lighting warmer', + 'Add shallow depth of field', + 'Finish the workflow' + ]) }) await test.step('warn once the Agent grant alone runs out', async () => { diff --git a/browser_tests/tests/agent/agentCreditsExhaustionLifecycleMocks.ts b/browser_tests/tests/agent/agentCreditsExhaustionLifecycleMocks.ts index 7ea547e7bfd..62a553b021c 100644 --- a/browser_tests/tests/agent/agentCreditsExhaustionLifecycleMocks.ts +++ b/browser_tests/tests/agent/agentCreditsExhaustionLifecycleMocks.ts @@ -1,6 +1,8 @@ import type { Page, WebSocketRoute } from '@playwright/test' import { expect, mergeTests } from '@playwright/test' +import type { AgentMessage } from '@comfyorg/ingest-types' + import type { AgentTurnAccepted, AgentWsEvent @@ -10,8 +12,39 @@ import { webSocketFixture } from '@e2e/fixtures/ws' import { hostTelemetryFixture } from '@e2e/fixtures/hostTelemetryFixture' import type { AgentFundingState } from '@e2e/tests/agent/agentPanelMocks' import { agentTest } from '@e2e/tests/agent/agentPanelMocks' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' + +interface CompletedTurn { + prompt: string + accepted: AgentTurnAccepted +} + +function toThreadHistory(turns: CompletedTurn[]): AgentMessage[] { + return turns.flatMap(({ prompt, accepted }, index) => [ + { + id: `${accepted.message_id}-user`, + thread_id: accepted.thread_id, + turn_id: accepted.message_id, + seq: index * 2 + 1, + role: 'user', + status: 'complete', + content: { text: prompt } + }, + { + id: accepted.message_id, + thread_id: accepted.thread_id, + turn_id: accepted.message_id, + seq: index * 2 + 2, + role: 'assistant', + status: 'complete', + content: { text: '' } + } + ]) +} class AgentCreditsLifecycleFixture { + readonly completedTurns: CompletedTurn[] = [] + constructor( private readonly page: Page, private readonly agentPanel: AgentPanel, @@ -57,6 +90,7 @@ class AgentCreditsLifecycleFixture { } const ws = await this.getAgentSocket() ws.send(JSON.stringify(doneEvent)) + this.completedTurns.push({ prompt, accepted }) await billingRefresh } } @@ -70,14 +104,18 @@ export const test = base.extend<{ { acceptedTurns, agentBilling, agentPanel, getAgentSocket, page }, use ) => { - await use( - new AgentCreditsLifecycleFixture( - page, - agentPanel, - acceptedTurns, - getAgentSocket, - (state) => agentBilling.setFundingState(state) - ) + const lifecycle = new AgentCreditsLifecycleFixture( + page, + agentPanel, + acceptedTurns, + getAgentSocket, + (state) => agentBilling.setFundingState(state) + ) + await page.route('**/api/agent/threads/*/messages', (route) => + route.request().method() === 'GET' + ? route.fulfill(jsonRoute(toThreadHistory(lifecycle.completedTurns))) + : route.fallback() ) + await use(lifecycle) } })