Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions browser_tests/tests/agent/agentEntryServerLifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, mergeTests } from '@playwright/test'
import { webSocketFixture } from '@e2e/fixtures/ws'
import { agentTest } from '@e2e/tests/agent/agentPanelMocks'
import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { AgentServerFeature } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import type { ComfyAgentFeature } from '@/platform/remoteConfig/comfyAgentFeature'

const test = mergeTests(agentTest, webSocketFixture)

Expand Down Expand Up @@ -34,7 +34,7 @@ test.describe(
ws.send(JSON.stringify({ type, data }))

await test.step('a starting agent shows on the button, inert', async () => {
const agent: AgentServerFeature = { state: 'starting', reason: null }
const agent: ComfyAgentFeature = { state: 'starting', reason: null }
publish('feature_flags', { agent })
const starting = page.getByRole('button', {
name: enMessages.agent.entryStarting,
Expand All @@ -47,7 +47,7 @@ test.describe(
})

await test.step('a failed agent names its reason, inert', async () => {
const status: AgentServerFeature = {
const status: ComfyAgentFeature = {
state: 'failed',
reason: 'not_found'
}
Expand All @@ -66,7 +66,7 @@ test.describe(
})

await test.step('a ready agent offers itself to a signed-out user', async () => {
const status: AgentServerFeature = { state: 'ready', reason: null }
const status: ComfyAgentFeature = { state: 'ready', reason: null }
publish('agent_status', status)
await expect(agentPanel.openButton).not.toHaveAttribute(
'aria-disabled',
Expand Down
118 changes: 118 additions & 0 deletions browser_tests/tests/agent/agentHostedGateIsShared.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { expect, mergeTests } from '@playwright/test'

import type { AgentSkillListResponse } from '@comfyorg/ingest-types'

import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { ComfyAgentFeature } from '@/platform/remoteConfig/comfyAgentFeature'

import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { webSocketFixture } from '@e2e/fixtures/ws'
import { agentTest } from '@e2e/tests/agent/agentPanelMocks'

const test = mergeTests(agentTest, webSocketFixture)

const SKILL_NAME = 'shared-gate'
const SKILLS: AgentSkillListResponse = {
skills: [
{
id: 'shared-gate-skill',
name: SKILL_NAME,
description: 'A fixture skill for the shared hosted-agent gate.',
body: 'Reply briefly; do not run workflows.',
body_hash: 'b'.repeat(64),
created_at: '2026-11-05T00:00:00Z',
updated_at: '2026-11-05T00:00:00Z'
}
]
}

test.describe(
'The skill picker and the agent panel share one hosted-agent gate',
{
tag: ['@cloud', '@agent', '@ui'],
annotation: {
type: 'issue',
description:
'https://github.com/Comfy-Org/ComfyUI_frontend/pull/22985: the picker and the panel each decided whether ComfyUI hosts an agent, so they could disagree and offer a skill the panel cannot run'
}
},
() => {
test.use({ connectWebSocketToServer: false })

test('offers a skill only while the panel can run it', async ({
page,
agentPanel,
getWebSocket
}) => {
await page.route('**/api/agent/skills', (route) =>
route.fulfill(jsonRoute(SKILLS))
)
const ws = await getWebSocket()
const publishAgent = (agent: ComfyAgentFeature) =>
ws.send(JSON.stringify({ type: 'agent_status', data: agent }))
const skillOption = page.getByRole('menuitem', {
name: SKILL_NAME,
exact: true
})

// The boot mocks seed `agent: { state: 'ready' }`, and the browser
// fixtures disable PostHog flags, so ComfyUI's agent feature is the only
// thing that can enable either surface here.
await test.step('a ready agent opens the panel and offers the skill', async () => {
await agentPanel.open()
await agentPanel.selectWorkflow()
await agentPanel.composer.fill('/')
await expect(skillOption).toBeVisible()
})

await test.step('the same agent failing withdraws both surfaces together', async () => {
publishAgent({ state: 'failed', reason: 'crashed' })
await expect(agentPanel.root).toHaveCount(0)
await expect(skillOption).toHaveCount(0)
const failed = page.getByRole('button', {
name: enMessages.agent.entryFailed,
exact: true
})
await expect(failed).toHaveAttribute('aria-disabled', 'true')
})

await test.step('the agent returning restores both surfaces together', async () => {
publishAgent({ state: 'ready', reason: null })
await expect(agentPanel.openButton).not.toHaveAttribute(
'aria-disabled',
'true'
)
await agentPanel.open()
await agentPanel.composer.fill('/')
await expect(skillOption).toBeVisible()
})
})

test('names an unreadable failure reason rather than rendering it', async ({
page,
agentPanel,
getWebSocket
}) => {
const ws = await getWebSocket()
await expect(agentPanel.openButton).toBeVisible()

// One reader validates the payload for both surfaces, so a reason the
// server did not send as a string is dropped instead of stringified.
ws.send(
JSON.stringify({
type: 'agent_status',
data: { state: 'failed', reason: { code: 'not_found' } }
})
)

const failed = page.getByRole('button', {
name: enMessages.agent.entryFailed,
exact: true
})
await expect(failed).toHaveAttribute(
'title',
enMessages.agent.entryFailedReason.replace('{reason}', 'unknown')
)
})
}
)
4 changes: 2 additions & 2 deletions src/components/topbar/AgentEntryButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import { cn } from '@comfyorg/tailwind-utils'

import Button from '@comfyorg/design-system/button/Button'
import type { AgentServerFeature } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import type { ComfyAgentFeature } from '@/platform/remoteConfig/comfyAgentFeature'

const {
active = false,
Expand All @@ -55,6 +55,6 @@ const {
/** Draw attention to the button for a user who has never opened the panel. */
inviting?: boolean
/** ComfyUI's agent while it is not ready: shown, but inert. */
comfyAgent?: AgentServerFeature
comfyAgent?: ComfyAgentFeature
}>()
</script>
1 change: 0 additions & 1 deletion src/composables/__mocks__/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const defaultFlags: FeatureFlags = {
supportsPreviewMetadata: false,
maxUploadSize: 0,
supportsManagerV4: false,
agent: undefined,
modelUploadButtonEnabled: false,
assetDeletionEnabled: false,
privateModelsEnabled: false,
Expand Down
6 changes: 0 additions & 6 deletions src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ export function useFeatureFlags() {
get supportsManagerV4() {
return api.getServerFeature(ServerFeatureFlag.MANAGER_SUPPORTS_V4)
},
/** ComfyUI's `agent` server feature; callers validate `state`. */
get agent() {
return api.getServerFeature<{ state?: unknown } | null | undefined>(
ServerFeatureFlag.AGENT
)
},
get modelUploadButtonEnabled() {
return resolveFlag(
ServerFeatureFlag.MODEL_UPLOAD_BUTTON_ENABLED,
Expand Down
49 changes: 49 additions & 0 deletions src/platform/remoteConfig/comfyAgentFeature.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, expect, it, vi } from 'vitest'

import { api } from '@/scripts/api'

import { isComfyAgentReady, readComfyAgentFeature } from './comfyAgentFeature'

vi.mock(import('@/scripts/api'))

function serve(agent: unknown): void {
vi.mocked(api.getServerFeature).mockImplementation(
<T>(name: string, fallback?: T): T | undefined =>
name === 'agent' ? (agent as T) : fallback
)
}

describe('readComfyAgentFeature', () => {
it.for([undefined, null, {}, { state: 'stopped' }, { state: 1 }])(
'ignores a feature without a known state: %j',
(agent) => {
serve(agent)

expect(readComfyAgentFeature()).toBeUndefined()
expect(isComfyAgentReady()).toBe(false)
}
)

it('returns a known feature as served', () => {
const agent = { state: 'failed', reason: 'port in use' }
serve(agent)

expect(readComfyAgentFeature()).toBe(agent)
expect(isComfyAgentReady()).toBe(false)
})

it('drops a reason that is not a string', () => {
serve({ state: 'ready', reason: { code: 7 } })

expect(readComfyAgentFeature()).toEqual({ state: 'ready' })
expect(isComfyAgentReady()).toBe(true)
})

it("ignores ComfyUI's agent in the standalone harness", () => {
vi.stubEnv('VITE_AGENT_STANDALONE', 'true')
serve({ state: 'ready' })

expect(readComfyAgentFeature()).toBeUndefined()
expect(isComfyAgentReady()).toBe(false)
})
})
47 changes: 47 additions & 0 deletions src/platform/remoteConfig/comfyAgentFeature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ServerFeatureFlag } from '@/platform/remoteConfig/serverFeatureFlag'
import { api } from '@/scripts/api'

/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: CONFIRMED repository-rule violation: this new multi-paragraph block records rationale and deferred work in source. AGENTS.md permits only one- or two-line JSDoc contracts on exported APIs. Could you move this explanation to the PR description/contract tracking issue and remove the new narrative comments in agentHostedGateIsShared.spec.ts as well?

* The one declaration of ComfyUI's `agent` server feature, pushed again on
* every change. Both the agent panel and the skill picker read it through this
* module; a second copy anywhere else is what lets the two surfaces drift.
*
* Not sourced from a generated contract, and neither generated package can
* supply it today:
* - ingest's `GetFeaturesResponse['agent']` is `{ state: 'ready' }` — Cloud's
* rollout gate for a different server. Widening it by hand would make one
* type claim two unrelated payloads.
* - `@comfyorg/comfyui-api-types` is generated from `openapi.yaml`, vendored
* byte-identical from `Comfy-Org/ComfyUI` behind a sha256 pin that
* `check:generated` enforces, and that spec declares no `agent` feature. A
* generated source therefore needs the schema added in core first.
*/
export interface ComfyAgentFeature {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: ComfyAgentFeature is a new handwritten copy of the server's agent payload (state and reason), and agentPanelStore still annotates the same result with the separately handwritten AgentServerFeature. Sharing the reader therefore leaves two independent wire declarations that can drift when the server changes. Could we source the payload from the owning server's generated contract instead? If that export is missing, please add the backend schema and generated type first. The existing ingest GetFeaturesResponse['agent'] documents Cloud's rollout-only { state: 'ready' }, so it should not be widened by hand to represent ComfyUI's separate startup/failure lifecycle. (CONFIRMED, Gate 3.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the drift, deferred the generated-contract part — and the deferral is measured, not a punt.

Fixed (4fb07230ad): there is now exactly one declaration of ComfyUI's agent payload. AgentServerFeature is gone from agentApiSchema.ts; ComfyAgentFeature in comfyAgentFeature.ts is the only one, and it sits next to the reader that validates it. AgentEntryButton.vue and agentPanelStore both point at it, so there is no second wire declaration left to drift.

Not done — neither generated package can express this payload today:

  • ingest's GetFeaturesResponse['agent'] is { state: 'ready' }, Cloud's rollout gate. Agreed it must not be widened by hand, so it is not the source.
  • @comfyorg/comfyui-api-types is the right owner — it is generated from ComfyUI core's own spec — but that openapi.yaml is vendored byte-identical from Comfy-Org/ComfyUI behind a sha256 pin that check:generated enforces, and it declares no agent feature. Adding the schema here would fail the pin, so a generated type needs the schema added in core first.

That is recorded as a comment on the interface so the next reader does not re-add a copy or widen ingest's type. Happy to open the core schema PR as a follow-up if you want it tracked.

Also added (6697ffa725): a black-box case, browser_tests/tests/agent/agentHostedGateIsShared.spec.ts. It drives ComfyUI's published agent lifecycle over the socket and asserts the skill picker offers a skill only while the panel can run it, plus that an unreadable failure reason is named rather than stringified. That second assertion is red on the parent — it renders the raw JSON into the entry button's tooltip there — and green here.

state: 'starting' | 'ready' | 'failed'
reason?: string | null
}

function isKnownState(state: unknown): state is ComfyAgentFeature['state'] {
return state === 'starting' || state === 'ready' || state === 'failed'
}

/**
* ComfyUI's `agent` server feature, or undefined while its state is unknown.
* The standalone harness runs its own agent, so it ignores ComfyUI's.
*/
export function readComfyAgentFeature(): ComfyAgentFeature | undefined {
if (import.meta.env.VITE_AGENT_STANDALONE === 'true') return undefined
const agent = api.getServerFeature<
{ state?: unknown; reason?: unknown } | null | undefined
>(ServerFeatureFlag.AGENT)
if (!agent || !isKnownState(agent.state)) return undefined
const { state, reason } = agent
if (reason === undefined || reason === null || typeof reason === 'string')
return agent as ComfyAgentFeature
return { state }
}

/** Whether ComfyUI hosts an agent that is ready to serve requests. */
export function isComfyAgentReady(): boolean {
return readComfyAgentFeature()?.state === 'ready'
}
37 changes: 37 additions & 0 deletions src/platform/skills/stores/skillPacksStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,43 @@ describe('skillPacksStore', () => {
expect(listSkillPacks).toHaveBeenCalledOnce()
})

it('lists once when the cohort flags turn on while the hosted agent is ready', async () => {
mocks.isFeatureEnabled.mockReturnValue(undefined)
hostAgent('ready')
const store = useSkillPacksStore()

await store.startFlagGate()
await vi.waitFor(() => expect(store.hasLoaded).toBe(true))

mocks.isFeatureEnabled.mockReturnValue(true)
const [onFlags] = mocks.onFeatureFlags.mock.calls[0]
onFlags([], {}, {})
await nextTick()

expect(store.flagsEnabled).toBe(true)
expect(listSkillPacks).toHaveBeenCalledOnce()
})

it("ignores ComfyUI's agent in the standalone harness but still follows the cohort flags", async () => {
vi.stubEnv('VITE_AGENT_STANDALONE', 'true')
mocks.isFeatureEnabled.mockReturnValue(undefined)
hostAgent('ready')
const store = useSkillPacksStore()

await store.startFlagGate()

expect(store.enabled).toBe(false)
expect(listSkillPacks).not.toHaveBeenCalled()

mocks.isFeatureEnabled.mockReturnValue(true)
const [onFlags] = mocks.onFeatureFlags.mock.calls[0]
onFlags([], {}, {})
await nextTick()

expect(store.enabled).toBe(true)
expect(listSkillPacks).toHaveBeenCalledOnce()
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it('hides the hosted-agent surface when its routes answer 404', async () => {
mocks.isFeatureEnabled.mockReturnValue(undefined)
vi.mocked(listSkillPacks).mockRejectedValue(
Expand Down
7 changes: 2 additions & 5 deletions src/platform/skills/stores/skillPacksStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import { computed, ref, watch } from 'vue'

import { useCurrentUser } from '@/composables/auth/useCurrentUser'
import { isComfyAgentReady } from '@/platform/remoteConfig/comfyAgentFeature'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
import { api } from '@/scripts/api'

Expand Down Expand Up @@ -32,11 +33,7 @@ export const useSkillPacksStore = defineStore('skillPacks', () => {
// Disabled backend gates answer 404, independently of PostHog flags.
const routesAvailable = ref(true)

const agentHosted = computed(
() =>
api.getServerFeature<{ state?: unknown } | null>('agent')?.state ===
'ready'
)
const agentHosted = computed(isComfyAgentReady)
const surfaceEnabled = computed(() => flagsEnabled.value || agentHosted.value)
const enabled = computed(() => surfaceEnabled.value && routesAvailable.value)

Expand Down
6 changes: 0 additions & 6 deletions src/workbench/extensions/agent/schemas/agentApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,3 @@ export function parseAgentWsEvent(
export const zAgentIdentity = zGeneratedAgentIdentity.extend({
user_id: z.string().min(1)
})

/** The server's `agent` feature, pushed again on every change. */
export interface AgentServerFeature {
state: 'starting' | 'ready' | 'failed'
reason?: string | null
}
Loading
Loading