Repository navigation
fix(agent): share one hosted-agent gate between the skill picker and the agent panel #22985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
231e41e
e2837ca
c6c6b8f
4fb0723
6697ffa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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') | ||
| ) | ||
| }) | ||
| } | ||
| ) |
| 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) | ||
| }) | ||
| }) |
| 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' | ||
|
|
||
| /** | ||
| * 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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( Not done — neither generated package can express this payload today:
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 ( |
||
| 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' | ||
| } | ||
There was a problem hiding this comment.
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?