From c9b47b999f8d259dc0aea42cf04e0a59470b0fb5 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 01:38:44 -0800 Subject: [PATCH 1/9] fix(agent): bind the workflow a followed chat opens (FRONT-3804) Clicking a saved workflow tab brings up that tab's latest chat (#21512). Loading that chat clears the session binding, which is what the CRDT follower subscribes to, and the follow path adopted the tab without binding it again. The follower stayed detached, so agent edits made to a workflow while its tab was in the background never reached the canvas when the user came back, until a reload. The followed chat now binds its workflow the same way a chat restored from history does, including the unsynced-human-ops guard. --- .../fixtures/agentConversationFixture.ts | 18 +- .../agent/agentBackgroundTabEditsLand.spec.ts | 216 ++++++++++++++++++ .../extensions/agent/AgentPanelRoot.vue | 25 +- 3 files changed, 254 insertions(+), 5 deletions(-) create mode 100644 browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts diff --git a/browser_tests/fixtures/agentConversationFixture.ts b/browser_tests/fixtures/agentConversationFixture.ts index f83a571ac36..9a04d5c0f53 100644 --- a/browser_tests/fixtures/agentConversationFixture.ts +++ b/browser_tests/fixtures/agentConversationFixture.ts @@ -73,7 +73,7 @@ import { mockSavedWorkflowPersistence } from '@e2e/fixtures/utils/savedWorkflowP import { loadSeedIntoActiveTab } from '@e2e/fixtures/utils/seedActiveTab' import { nextFrame } from '@e2e/fixtures/utils/timing' -const THREAD_ID = 'e9a2f3d1-7c44-4b2e-9a01-5f6d8c7b3a10' +export const THREAD_ID = 'e9a2f3d1-7c44-4b2e-9a01-5f6d8c7b3a10' // One synthetic message id per turn; the recorded ids never reach the page. const turnId = (turn: number): string => `0c5b1e77-2d4a-4f9e-8b63-1a2c3d4e5${turn.toString(16).padStart(3, '0')}` @@ -936,6 +936,22 @@ export class AgentConversationHarness { ]) } + // Host edits made while this client follows another workflow: the host + // fans them out only to subscribers, so they reach this client only in the + // catch-up that answers its next subscribe. + applyOpsOnHostUnsent(operations: RecordedGraphOperation[]): void { + this.host.apply(operations) + for (const id of Object.keys(this.host.graph().nodes)) this.seenIds.add(id) + } + + /** Serves a second workflow's document beside the recorded one. */ + serveWorkflow(workflowId: string, seed: WorkflowJSON): void { + this.hostSocket.addWorkflow( + workflowId, + new HostDoc(workflowId, seed, this.conversation.workflow.catalog) + ) + } + // Rises once per follower subscribe; a tab return re-subscribes and the // host answers with the catch-up frame this counter has just sent. subscribeCount(workflowId?: string): number { diff --git a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts new file mode 100644 index 00000000000..7096fa71954 --- /dev/null +++ b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts @@ -0,0 +1,216 @@ +import { expect } from '@playwright/test' + +import type { UserDataFullInfo } from '@comfyorg/api-client/types' +import type { WorkflowListResponse } from '@comfyorg/ingest-types' + +import { + agentConversationTest as test, + THREAD_ID +} from '@e2e/fixtures/agentConversationFixture' +import { AgentPanel } from '@e2e/fixtures/components/AgentPanel' +import type { RecordedGraphOperation } from '@e2e/fixtures/data/agent/agentConversation' +import { + agentThreadPage, + agentThreadSummary, + agentUserTranscript +} from '@e2e/fixtures/data/agent/agentThreadList' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' + +// The agent edits saved workflow A while the user is on saved workflow B, whose +// own chat the panel follows. Returning to A must show every edit the agent +// made there, without a reload. Following a tab's chat loads that chat, which +// clears the session binding the CRDT follower subscribes to; unless the +// followed chat binds its workflow again, the follower stays detached. +// Source: frontend 1.60 QA check CNV06 step 5, +// https://linear.app/comfyorg/issue/FRONT-3804 +const CASE = 'agent-rec-set-widget-existing' +const A_NAME = 'Unsaved Workflow' +const B = { + id: '3c1e5b7a-9d2f-4e8b-a6c4-0f1e2d3c4b5a', + name: 'Other Study', + threadId: '7a2b4c6d-8e0f-4a1b-9c3d-5e7f9a1b3c5d', + request: 'Tidy up the other study' +} +const SAVED_AT = '2026-11-02T10:00:00Z' +const BACKGROUND_NODES = [ + { id: 801, title: 'b1', x: 1400 }, + { id: 802, title: 'b2', x: 1700 }, + { id: 803, title: 'b3', x: 2000 } +] +const EMPTY_GRAPH = { + last_node_id: 0, + last_link_id: 0, + nodes: [], + links: [], + groups: [], + config: {}, + extra: {}, + version: 0.4 +} + +function backgroundEdits(): RecordedGraphOperation[] { + const type = 'EmptyLatentImage' + return BACKGROUND_NODES.flatMap(({ id, title, x }) => [ + { + op: 'add_node', + node_id: id, + class_type: type, + pos: [x, 600], + node: { + id, + type, + pos: [x, 600], + size: [240, 134], + flags: {}, + order: 0, + mode: 0, + inputs: [], + outputs: [{ name: 'LATENT', type: 'LATENT', links: [] }], + properties: {}, + widgets_values: [512, 512, 1] + } + }, + { op: 'set_node_field', node_id: id, field: 'title', value: title } + ]) +} + +test.describe( + 'Agent edits to a background workflow tab', + { tag: ['@cloud', '@agent', '@vue-nodes'] }, + () => { + test.use({ conversationCase: CASE }) + + test('are on the canvas when the user returns to that tab', async ({ + agentConversation, + page + }) => { + test.setTimeout(120_000) + const panel = new AgentPanel(page) + const topbar = agentConversation.topbar + const aId = agentConversation.conversation.workflow.id + const aRequest = agentConversation.conversation.turns[0].request.content + + await test.step('agent edits workflow A', () => + agentConversation.runTurns()) + + await test.step('workflow B has a saved chat of its own', async () => { + agentConversation.serveWorkflow(B.id, { + ...agentConversation.conversation.workflow.seed, + nodes: [], + links: [] + }) + const threads = [ + agentThreadSummary(THREAD_ID, 'Workflow A chat', { + preview: aRequest, + workflow_id: aId, + last_message_at: '2026-11-02T09:00:00Z' + }), + agentThreadSummary(B.threadId, 'Workflow B chat', { + preview: B.request, + workflow_id: B.id, + last_message_at: SAVED_AT + }) + ] + const transcripts = { + [THREAD_ID]: agentUserTranscript(THREAD_ID, aId, aRequest), + [B.threadId]: agentUserTranscript(B.threadId, B.id, B.request) + } + const cloudWorkflows: WorkflowListResponse = { + data: [ + { id: aId, name: A_NAME }, + { id: B.id, name: B.name } + ].map(({ id, name }) => ({ + id, + name, + created_at: SAVED_AT, + updated_at: SAVED_AT, + created_by: 'test-user-e2e', + latest_version: 1 + })), + pagination: { offset: 0, limit: 100, total: 2, has_more: false } + } + const savedFiles: UserDataFullInfo[] = [A_NAME, B.name].map((name) => ({ + path: `${name}.json`, + modified: Date.parse(SAVED_AT), + size: 1 + })) + await page.route('**/api/agent/threads?*', (route) => { + const workflowId = new URL(route.request().url()).searchParams.get( + 'workflow_id' + ) + return route.fulfill( + jsonRoute( + agentThreadPage( + workflowId === null + ? threads + : threads.filter((t) => t.workflow_id === workflowId) + ) + ) + ) + }) + await page.route('**/api/agent/threads/*/messages', (route) => { + if (route.request().method() !== 'GET') return route.fallback() + const threadId = new URL(route.request().url()).pathname.split('/')[4] + return route.fulfill(jsonRoute(transcripts[threadId] ?? [])) + }) + await page.route('**/api/workflows**', (route) => + route.fulfill(jsonRoute(cloudWorkflows)) + ) + await page.route( + (url) => + url.pathname.endsWith('/api/userdata') && + url.searchParams.get('dir') === 'workflows', + (route) => route.fulfill(jsonRoute(savedFiles)) + ) + await page.route( + (url) => + decodeURIComponent(url.pathname).endsWith( + `/api/userdata/workflows/${B.name}.json` + ), + (route) => + route.request().method() === 'GET' + ? route.fulfill(jsonRoute(EMPTY_GRAPH)) + : route.fallback() + ) + }) + + await test.step('user opens workflow B and its chat', async () => { + await panel.historyButton.click() + await panel.root + .getByRole('button', { name: 'Workflow B chat', exact: true }) + .click() + await expect(panel.userMessageBubbles).toHaveText([B.request]) + await expect( + topbar.getWorkflowTab(B.name).and(topbar.getActiveTab()) + ).toBeVisible() + }) + + await test.step('user returns to A, then switches to B by its tab', async () => { + await topbar.getWorkflowTab(A_NAME).click() + await expect(panel.userMessageBubbles).toHaveText([aRequest]) + await topbar.getWorkflowTab(B.name).click() + await expect(panel.userMessageBubbles).toHaveText([B.request]) + await expect( + topbar.getWorkflowTab(B.name).and(topbar.getActiveTab()) + ).toBeVisible() + }) + + await test.step('agent adds three titled nodes to A while B is shown', () => + agentConversation.applyOpsOnHostUnsent(backgroundEdits())) + + await test.step('returning to A shows every background edit', async () => { + await topbar.getWorkflowTab(A_NAME).click() + await expect( + topbar.getWorkflowTab(A_NAME).and(topbar.getActiveTab()) + ).toBeVisible() + await expect(panel.userMessageBubbles).toHaveText([aRequest]) + for (const { id, title } of BACKGROUND_NODES) + await expect( + agentConversation.vueNodes + .getNodeLocator(String(id)) + .getByTestId('node-title') + ).toHaveText(title) + }) + }) + } +) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 04a0c1128c6..d4722e21671 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1026,12 +1026,29 @@ async function onWorkflowRestoredAndBound( isCurrent ) if (committedWorkflowId === null || !isCurrent()) return ready - if (hasUnsyncedHumanOps(committedWorkflowId)) return ready - if (boundWorkflowId.value !== committedWorkflowId) - bindWorkflow(committedWorkflowId) + bindRestoredWorkflow(committedWorkflowId) return ready } +// Loading a chat clears the session binding, which is the CRDT follower's +// subscribe target. A chat restored onto its workflow's tab binds it again; +// without that the follower stays detached and the agent's edits to that +// workflow never reach its canvas. +function bindRestoredWorkflow(workflowId: string): void { + if (hasUnsyncedHumanOps(workflowId)) return + if (boundWorkflowId.value !== workflowId) bindWorkflow(workflowId) +} + +// A followed chat adopts the tab it followed instead of restoring one, so it +// binds here rather than in `onWorkflowRestoredAndBound`. +function adoptFollowedWorkflow( + workflow: ComfyWorkflow, + workflowId: string +): void { + adoptWorkflowTarget(workflow, workflowId) + bindRestoredWorkflow(workflowId) +} + function warnWorkflowUnavailable(): void { toast.warning(t('agent.targetNavigationUnavailable'), { duration: 5000 }) } @@ -1901,7 +1918,7 @@ const workflowChatFollow = useAgentWorkflowChatFollow({ trackThreadStarted: () => useTelemetry()?.trackAgentThreadStarted({ source: 'history_select' }), restoreThreadWorkflow, - adoptWorkflowTarget, + adoptWorkflowTarget: adoptFollowedWorkflow, adoptRestoredWorkflowTab }) From aab621e653e12ca5b14beabcfdbbbbcc78de865a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:18:58 -0800 Subject: [PATCH 2/9] test(agent): drop the comment on applyOpsOnHostUnsent Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453080783 --- browser_tests/fixtures/agentConversationFixture.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/browser_tests/fixtures/agentConversationFixture.ts b/browser_tests/fixtures/agentConversationFixture.ts index 9a04d5c0f53..3e70867a964 100644 --- a/browser_tests/fixtures/agentConversationFixture.ts +++ b/browser_tests/fixtures/agentConversationFixture.ts @@ -936,9 +936,6 @@ export class AgentConversationHarness { ]) } - // Host edits made while this client follows another workflow: the host - // fans them out only to subscribers, so they reach this client only in the - // catch-up that answers its next subscribe. applyOpsOnHostUnsent(operations: RecordedGraphOperation[]): void { this.host.apply(operations) for (const id of Object.keys(this.host.graph().nodes)) this.seenIds.add(id) From ce05465062dd5516d8896130e41baa53f9c5b536 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:19:08 -0800 Subject: [PATCH 3/9] test(agent): move the background-tab spec rationale to the PR Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453080794 --- .../tests/agent/agentBackgroundTabEditsLand.spec.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts index 7096fa71954..b55e923c8c9 100644 --- a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts +++ b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts @@ -16,13 +16,6 @@ import { } from '@e2e/fixtures/data/agent/agentThreadList' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' -// The agent edits saved workflow A while the user is on saved workflow B, whose -// own chat the panel follows. Returning to A must show every edit the agent -// made there, without a reload. Following a tab's chat loads that chat, which -// clears the session binding the CRDT follower subscribes to; unless the -// followed chat binds its workflow again, the follower stays detached. -// Source: frontend 1.60 QA check CNV06 step 5, -// https://linear.app/comfyorg/issue/FRONT-3804 const CASE = 'agent-rec-set-widget-existing' const A_NAME = 'Unsaved Workflow' const B = { From 29e0d26d2b720d2aabd8177da50a9405845acbca Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:19:13 -0800 Subject: [PATCH 4/9] refactor(agent): drop the comments on the followed-workflow bind Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453080820 --- src/workbench/extensions/agent/AgentPanelRoot.vue | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index d4722e21671..ccf9d3dbc5d 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1030,17 +1030,11 @@ async function onWorkflowRestoredAndBound( return ready } -// Loading a chat clears the session binding, which is the CRDT follower's -// subscribe target. A chat restored onto its workflow's tab binds it again; -// without that the follower stays detached and the agent's edits to that -// workflow never reach its canvas. function bindRestoredWorkflow(workflowId: string): void { if (hasUnsyncedHumanOps(workflowId)) return if (boundWorkflowId.value !== workflowId) bindWorkflow(workflowId) } -// A followed chat adopts the tab it followed instead of restoring one, so it -// binds here rather than in `onWorkflowRestoredAndBound`. function adoptFollowedWorkflow( workflow: ComfyWorkflow, workflowId: string From 7d3bd31e5226fa0761f4c80db527691ff73f1246 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:21:27 -0800 Subject: [PATCH 5/9] test(agent): move the background-tab chats into a data file and the chats mock The spec now holds only Playwright steps. Its workflows, threads and transcripts come from backgroundTabChats and are served by the existing AgentWorkflowChatsMock, still registered after runTurns. Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453080804 --- .../fixtures/data/agent/backgroundTabEdits.ts | 97 ++++++++++ .../agent/agentBackgroundTabEditsLand.spec.ts | 168 +++--------------- 2 files changed, 122 insertions(+), 143 deletions(-) create mode 100644 browser_tests/fixtures/data/agent/backgroundTabEdits.ts diff --git a/browser_tests/fixtures/data/agent/backgroundTabEdits.ts b/browser_tests/fixtures/data/agent/backgroundTabEdits.ts new file mode 100644 index 00000000000..ef1e9c191ee --- /dev/null +++ b/browser_tests/fixtures/data/agent/backgroundTabEdits.ts @@ -0,0 +1,97 @@ +import type { ComfyWorkflowJSON } from '@comfyorg/graph-model/workflowSchema' + +import type { RecordedGraphOperation } from '@e2e/fixtures/data/agent/agentConversation' +import { + agentThreadSummary, + agentUserTranscript +} from '@e2e/fixtures/data/agent/agentThreadList' +import type { AgentWorkflowChatsMock } from '@e2e/fixtures/helpers/agentWorkflowChats' + +type WorkflowChats = ConstructorParameters[0] + +interface ChatWorkflow { + id: string + name: string + threadId: string + request: string +} + +export const BACKGROUND_TAB_CASE = 'agent-rec-set-widget-existing' +export const FOREGROUND_NAME = 'Unsaved Workflow' +export const BACKGROUND: ChatWorkflow = { + id: '3c1e5b7a-9d2f-4e8b-a6c4-0f1e2d3c4b5a', + name: 'Other Study', + threadId: '7a2b4c6d-8e0f-4a1b-9c3d-5e7f9a1b3c5d', + request: 'Tidy up the other study' +} +export const BACKGROUND_NODES = [ + { id: 801, title: 'b1', x: 1400 }, + { id: 802, title: 'b2', x: 1700 }, + { id: 803, title: 'b3', x: 2000 } +] + +const EMPTY_GRAPH: ComfyWorkflowJSON = { + last_node_id: 0, + last_link_id: 0, + nodes: [], + links: [], + groups: [], + config: {}, + extra: {}, + version: 0.4 +} + +export function backgroundEdits(): RecordedGraphOperation[] { + const type = 'EmptyLatentImage' + return BACKGROUND_NODES.flatMap(({ id, title, x }) => [ + { + op: 'add_node', + node_id: id, + class_type: type, + pos: [x, 600], + node: { + id, + type, + pos: [x, 600], + size: [240, 134], + flags: {}, + order: 0, + mode: 0, + inputs: [], + outputs: [{ name: 'LATENT', type: 'LATENT', links: [] }], + properties: {}, + widgets_values: [512, 512, 1] + } + }, + { op: 'set_node_field', node_id: id, field: 'title', value: title } + ]) +} + +export function backgroundTabChats( + foreground: Omit +): WorkflowChats { + const chats = [ + { ...foreground, name: FOREGROUND_NAME, at: '2026-11-02T09:00:00Z' }, + { ...BACKGROUND, at: '2026-11-02T10:00:00Z' } + ] + return { + workflows: chats.map(({ id, name }) => ({ + id, + name, + content: EMPTY_GRAPH + })), + threads: chats.map(({ id, name, threadId, request, at }) => + agentThreadSummary(threadId, `${name} chat`, { + preview: request, + workflow_id: id, + last_message_at: at + }) + ), + transcripts: Object.fromEntries( + chats.map(({ id, threadId, request }) => [ + threadId, + agentUserTranscript(threadId, id, request) + ]) + ) + } +} diff --git a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts index b55e923c8c9..c5ff482e1de 100644 --- a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts +++ b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts @@ -1,77 +1,25 @@ import { expect } from '@playwright/test' -import type { UserDataFullInfo } from '@comfyorg/api-client/types' -import type { WorkflowListResponse } from '@comfyorg/ingest-types' - import { agentConversationTest as test, THREAD_ID } from '@e2e/fixtures/agentConversationFixture' import { AgentPanel } from '@e2e/fixtures/components/AgentPanel' -import type { RecordedGraphOperation } from '@e2e/fixtures/data/agent/agentConversation' import { - agentThreadPage, - agentThreadSummary, - agentUserTranscript -} from '@e2e/fixtures/data/agent/agentThreadList' -import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' - -const CASE = 'agent-rec-set-widget-existing' -const A_NAME = 'Unsaved Workflow' -const B = { - id: '3c1e5b7a-9d2f-4e8b-a6c4-0f1e2d3c4b5a', - name: 'Other Study', - threadId: '7a2b4c6d-8e0f-4a1b-9c3d-5e7f9a1b3c5d', - request: 'Tidy up the other study' -} -const SAVED_AT = '2026-11-02T10:00:00Z' -const BACKGROUND_NODES = [ - { id: 801, title: 'b1', x: 1400 }, - { id: 802, title: 'b2', x: 1700 }, - { id: 803, title: 'b3', x: 2000 } -] -const EMPTY_GRAPH = { - last_node_id: 0, - last_link_id: 0, - nodes: [], - links: [], - groups: [], - config: {}, - extra: {}, - version: 0.4 -} - -function backgroundEdits(): RecordedGraphOperation[] { - const type = 'EmptyLatentImage' - return BACKGROUND_NODES.flatMap(({ id, title, x }) => [ - { - op: 'add_node', - node_id: id, - class_type: type, - pos: [x, 600], - node: { - id, - type, - pos: [x, 600], - size: [240, 134], - flags: {}, - order: 0, - mode: 0, - inputs: [], - outputs: [{ name: 'LATENT', type: 'LATENT', links: [] }], - properties: {}, - widgets_values: [512, 512, 1] - } - }, - { op: 'set_node_field', node_id: id, field: 'title', value: title } - ]) -} + BACKGROUND, + BACKGROUND_NODES, + BACKGROUND_TAB_CASE, + backgroundEdits, + backgroundTabChats, + FOREGROUND_NAME +} from '@e2e/fixtures/data/agent/backgroundTabEdits' +import { AgentWorkflowChatsMock } from '@e2e/fixtures/helpers/agentWorkflowChats' test.describe( 'Agent edits to a background workflow tab', { tag: ['@cloud', '@agent', '@vue-nodes'] }, () => { - test.use({ conversationCase: CASE }) + test.use({ conversationCase: BACKGROUND_TAB_CASE }) test('are on the canvas when the user returns to that tab', async ({ agentConversation, @@ -87,104 +35,38 @@ test.describe( agentConversation.runTurns()) await test.step('workflow B has a saved chat of its own', async () => { - agentConversation.serveWorkflow(B.id, { + agentConversation.serveWorkflow(BACKGROUND.id, { ...agentConversation.conversation.workflow.seed, nodes: [], links: [] }) - const threads = [ - agentThreadSummary(THREAD_ID, 'Workflow A chat', { - preview: aRequest, - workflow_id: aId, - last_message_at: '2026-11-02T09:00:00Z' - }), - agentThreadSummary(B.threadId, 'Workflow B chat', { - preview: B.request, - workflow_id: B.id, - last_message_at: SAVED_AT + await new AgentWorkflowChatsMock( + backgroundTabChats({ + id: aId, + threadId: THREAD_ID, + request: aRequest }) - ] - const transcripts = { - [THREAD_ID]: agentUserTranscript(THREAD_ID, aId, aRequest), - [B.threadId]: agentUserTranscript(B.threadId, B.id, B.request) - } - const cloudWorkflows: WorkflowListResponse = { - data: [ - { id: aId, name: A_NAME }, - { id: B.id, name: B.name } - ].map(({ id, name }) => ({ - id, - name, - created_at: SAVED_AT, - updated_at: SAVED_AT, - created_by: 'test-user-e2e', - latest_version: 1 - })), - pagination: { offset: 0, limit: 100, total: 2, has_more: false } - } - const savedFiles: UserDataFullInfo[] = [A_NAME, B.name].map((name) => ({ - path: `${name}.json`, - modified: Date.parse(SAVED_AT), - size: 1 - })) - await page.route('**/api/agent/threads?*', (route) => { - const workflowId = new URL(route.request().url()).searchParams.get( - 'workflow_id' - ) - return route.fulfill( - jsonRoute( - agentThreadPage( - workflowId === null - ? threads - : threads.filter((t) => t.workflow_id === workflowId) - ) - ) - ) - }) - await page.route('**/api/agent/threads/*/messages', (route) => { - if (route.request().method() !== 'GET') return route.fallback() - const threadId = new URL(route.request().url()).pathname.split('/')[4] - return route.fulfill(jsonRoute(transcripts[threadId] ?? [])) - }) - await page.route('**/api/workflows**', (route) => - route.fulfill(jsonRoute(cloudWorkflows)) - ) - await page.route( - (url) => - url.pathname.endsWith('/api/userdata') && - url.searchParams.get('dir') === 'workflows', - (route) => route.fulfill(jsonRoute(savedFiles)) - ) - await page.route( - (url) => - decodeURIComponent(url.pathname).endsWith( - `/api/userdata/workflows/${B.name}.json` - ), - (route) => - route.request().method() === 'GET' - ? route.fulfill(jsonRoute(EMPTY_GRAPH)) - : route.fallback() - ) + ).route(page) }) await test.step('user opens workflow B and its chat', async () => { await panel.historyButton.click() await panel.root - .getByRole('button', { name: 'Workflow B chat', exact: true }) + .getByRole('button', { name: `${BACKGROUND.name} chat`, exact: true }) .click() - await expect(panel.userMessageBubbles).toHaveText([B.request]) + await expect(panel.userMessageBubbles).toHaveText([BACKGROUND.request]) await expect( - topbar.getWorkflowTab(B.name).and(topbar.getActiveTab()) + topbar.getWorkflowTab(BACKGROUND.name).and(topbar.getActiveTab()) ).toBeVisible() }) await test.step('user returns to A, then switches to B by its tab', async () => { - await topbar.getWorkflowTab(A_NAME).click() + await topbar.getWorkflowTab(FOREGROUND_NAME).click() await expect(panel.userMessageBubbles).toHaveText([aRequest]) - await topbar.getWorkflowTab(B.name).click() - await expect(panel.userMessageBubbles).toHaveText([B.request]) + await topbar.getWorkflowTab(BACKGROUND.name).click() + await expect(panel.userMessageBubbles).toHaveText([BACKGROUND.request]) await expect( - topbar.getWorkflowTab(B.name).and(topbar.getActiveTab()) + topbar.getWorkflowTab(BACKGROUND.name).and(topbar.getActiveTab()) ).toBeVisible() }) @@ -192,9 +74,9 @@ test.describe( agentConversation.applyOpsOnHostUnsent(backgroundEdits())) await test.step('returning to A shows every background edit', async () => { - await topbar.getWorkflowTab(A_NAME).click() + await topbar.getWorkflowTab(FOREGROUND_NAME).click() await expect( - topbar.getWorkflowTab(A_NAME).and(topbar.getActiveTab()) + topbar.getWorkflowTab(FOREGROUND_NAME).and(topbar.getActiveTab()) ).toBeVisible() await expect(panel.userMessageBubbles).toHaveText([aRequest]) for (const { id, title } of BACKGROUND_NODES) From 2e1e1c4f9b5c0612ed0efebe140e0a9cb8c6cb73 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:29:22 -0800 Subject: [PATCH 6/9] fix(agent): record unbound edits to the visible workflow before a follow binds it Unbound local edits were recorded as unsynced only for the bound workflow. An edit to a visible tab while another workflow, or none, was bound went unrecorded, so a followed chat could bind that tab and run catch-up over a canvas the document never saw. The minter now reports those edits separately, and the panel records them for the visible tab's bound workflow id, so bindRestoredWorkflow's unsynced guard refuses the bind. The new black-box case holds B's transcript, adds a note to B while its followed chat loads, and asserts B is not re-subscribed and keeps the note. It fails with the wiring removed (subscribe count 2, expected 1). Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453115381 https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453080825 --- .../fixtures/agentConversationFixture.ts | 19 ++++++ .../fixtures/data/agent/backgroundTabEdits.ts | 2 + .../agent/agentBackgroundTabEditsLand.spec.ts | 65 ++++++++++++++++--- .../extensions/agent/AgentPanelRoot.vue | 8 +++ .../extensions/agent/crdt/docOpMinter.test.ts | 17 +++++ .../extensions/agent/crdt/docOpMinter.ts | 4 ++ .../agent/crdt/useAgentCrdtFollower.ts | 6 +- 7 files changed, 110 insertions(+), 11 deletions(-) diff --git a/browser_tests/fixtures/agentConversationFixture.ts b/browser_tests/fixtures/agentConversationFixture.ts index 3e70867a964..04e8f59fe57 100644 --- a/browser_tests/fixtures/agentConversationFixture.ts +++ b/browser_tests/fixtures/agentConversationFixture.ts @@ -941,6 +941,25 @@ export class AgentConversationHarness { for (const id of Object.keys(this.host.graph().nodes)) this.seenIds.add(id) } + /** Holds `threadId`'s transcript reads until `release` is called. */ + async holdTranscript( + threadId: string + ): Promise<{ requested: Promise; release: () => void }> { + let release!: () => void + let reached!: () => void + const held = new Promise((resolve) => (release = resolve)) + const requested = new Promise((resolve) => (reached = resolve)) + await this.page.route( + `**/api/agent/threads/${threadId}/messages`, + async (route) => { + reached() + await held + return route.fallback() + } + ) + return { requested, release } + } + /** Serves a second workflow's document beside the recorded one. */ serveWorkflow(workflowId: string, seed: WorkflowJSON): void { this.hostSocket.addWorkflow( diff --git a/browser_tests/fixtures/data/agent/backgroundTabEdits.ts b/browser_tests/fixtures/data/agent/backgroundTabEdits.ts index ef1e9c191ee..c8c9c3e0fb2 100644 --- a/browser_tests/fixtures/data/agent/backgroundTabEdits.ts +++ b/browser_tests/fixtures/data/agent/backgroundTabEdits.ts @@ -95,3 +95,5 @@ export function backgroundTabChats( ) } } + +export const USER_NOTE_POSITION: [number, number] = [400, 400] diff --git a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts index c5ff482e1de..254f79cf2a1 100644 --- a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts +++ b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts @@ -11,9 +11,11 @@ import { BACKGROUND_TAB_CASE, backgroundEdits, backgroundTabChats, - FOREGROUND_NAME + FOREGROUND_NAME, + USER_NOTE_POSITION } from '@e2e/fixtures/data/agent/backgroundTabEdits' import { AgentWorkflowChatsMock } from '@e2e/fixtures/helpers/agentWorkflowChats' +import { nextFrame } from '@e2e/fixtures/utils/timing' test.describe( 'Agent edits to a background workflow tab', @@ -21,14 +23,10 @@ test.describe( () => { test.use({ conversationCase: BACKGROUND_TAB_CASE }) - test('are on the canvas when the user returns to that tab', async ({ - agentConversation, - page - }) => { + test.beforeEach(async ({ agentConversation, page }) => { test.setTimeout(120_000) const panel = new AgentPanel(page) const topbar = agentConversation.topbar - const aId = agentConversation.conversation.workflow.id const aRequest = agentConversation.conversation.turns[0].request.content await test.step('agent edits workflow A', () => @@ -42,7 +40,7 @@ test.describe( }) await new AgentWorkflowChatsMock( backgroundTabChats({ - id: aId, + id: agentConversation.conversation.workflow.id, threadId: THREAD_ID, request: aRequest }) @@ -60,9 +58,21 @@ test.describe( ).toBeVisible() }) - await test.step('user returns to A, then switches to B by its tab', async () => { + await test.step('user returns to A by its tab', async () => { await topbar.getWorkflowTab(FOREGROUND_NAME).click() await expect(panel.userMessageBubbles).toHaveText([aRequest]) + }) + }) + + test('are on the canvas when the user returns to that tab', async ({ + agentConversation, + page + }) => { + const panel = new AgentPanel(page) + const topbar = agentConversation.topbar + const aRequest = agentConversation.conversation.turns[0].request.content + + await test.step('user switches to B by its tab', async () => { await topbar.getWorkflowTab(BACKGROUND.name).click() await expect(panel.userMessageBubbles).toHaveText([BACKGROUND.request]) await expect( @@ -87,5 +97,44 @@ test.describe( ).toHaveText(title) }) }) + + test('do not rebind a tab the user edited while its chat was loading', async ({ + agentConversation, + page + }) => { + const panel = new AgentPanel(page) + const topbar = agentConversation.topbar + const subscribesBefore = agentConversation.subscribeCount(BACKGROUND.id) + const transcript = await agentConversation.holdTranscript( + BACKGROUND.threadId + ) + + const noteId = + await test.step('user edits B before its chat loads', async () => { + await topbar.getWorkflowTab(BACKGROUND.name).click() + await transcript.requested + const id = await agentConversation.addNoteThroughSearchBox({ + x: USER_NOTE_POSITION[0], + y: USER_NOTE_POSITION[1] + }) + await expect( + agentConversation.vueNodes.getNodeLocator(id) + ).toBeVisible() + return id + }) + + await test.step('B stays unbound and keeps the edit', async () => { + transcript.release() + await expect(panel.userMessageBubbles).toHaveText([BACKGROUND.request]) + await nextFrame(page) + await nextFrame(page) + expect(agentConversation.subscribeCount(BACKGROUND.id)).toBe( + subscribesBefore + ) + await expect( + agentConversation.vueNodes.getNodeLocator(noteId) + ).toBeVisible() + }) + }) } ) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index ccf9d3dbc5d..9ca9ad86f48 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1267,10 +1267,18 @@ function boundRootGraphId(): RootGraphId | null { function followerCanDeliver(): boolean { return isFollowerActive.value && subscriptionSent() } +function noteUnboundVisibleIntent(): void { + const visible = workflowStore.activeWorkflow + const workflowId = visible + ? bindingStore.workflowIdFor(visible.path) + : undefined + if (workflowId !== undefined) noteUnboundLocalIntent(workflowId) +} const docOpMinter = attachDocOpMinter({ isEnabled: () => agentPanelStore.enabled, isDocBound: followerCanDeliver, onUnboundLocalIntent: noteUnboundLocalIntent, + onUnboundVisibleIntent: noteUnboundVisibleIntent, enqueue: enqueueHumanOperations, getGraph: () => (app.isGraphReady ? app.rootGraph : null), boundRootGraphId, diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index f325ea4404d..dd7aa3fb042 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -302,6 +302,7 @@ describe('attachDocOpMinter', () => { let seededPromotedDocs: Set> let dynamicComboDocs: Set> let unboundLocalIntents: number + let unboundVisibleIntents: number function registeredDynamicComboScenario() { const scenario = dynamicComboScenario(graph) @@ -326,10 +327,12 @@ describe('attachDocOpMinter', () => { seededPromotedDocs = new Set() dynamicComboDocs = new Set() unboundLocalIntents = 0 + unboundVisibleIntents = 0 minter = attachDocOpMinter({ isEnabled: () => enabled, isDocBound: () => bound, onUnboundLocalIntent: () => unboundLocalIntents++, + onUnboundVisibleIntent: () => unboundVisibleIntents++, enqueue: (operations) => minted.push(...operations), getGraph: () => (graphAvailable ? graph : null), boundRootGraphId: () => (unbound ? null : rootGraphId), @@ -587,6 +590,20 @@ describe('attachDocOpMinter', () => { expect(minted).toEqual([]) }) + it('marks an unbound edit to the visible workflow while another one is bound', async () => { + const { source } = seedGraph(graph) + bound = false + rootGraphId = toRootGraphId('other-root-graph') + source.widgets![0].value = 5 + unbound = true + source.widgets![0].value = 6 + await afterFlush() + + expect(unboundLocalIntents).toBe(0) + expect(unboundVisibleIntents).toBe(2) + expect(minted).toEqual([]) + }) + it('snapshots a pasted node after its same-tick configure, folding the widget and field writes into add_node', async () => { const node = new TestSource() graph.add(node) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index a22c3260b3e..8e19711ff77 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -65,6 +65,8 @@ export interface DocOpMinterDeps { isDocBound(): boolean /** Records a local edit that cannot yet enter the semantic document. */ onUnboundLocalIntent?(): void + /** Records a local edit to the visible workflow while another one, or none, is bound. */ + onUnboundVisibleIntent?(): void /** Receives minted semantic operations (the sender's inbox). */ enqueue(operations: GraphOperation[]): void /** The live root graph, or null when no workflow is open. */ @@ -1204,6 +1206,8 @@ export function attachDocOpMinter(deps: DocOpMinterDeps): DocOpMinter { : null if (boundRootGraphId !== null && eventRootGraphId === boundRootGraphId) deps.onUnboundLocalIntent?.() + else if (graph !== null && eventRootGraphId === graph.id) + deps.onUnboundVisibleIntent?.() } function onIntent(event: GraphIntentEvent): void { diff --git a/src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts b/src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts index e0bdadf5d67..e9defb40c07 100644 --- a/src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts +++ b/src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts @@ -376,7 +376,8 @@ export function useAgentCrdtFollower( }), enqueueHumanOperations: (operations: GraphOperation[]) => follower.value?.enqueueHumanOperations(operations), - noteUnboundLocalIntent: () => follower.value?.noteUnboundLocalIntent(), + noteUnboundLocalIntent: (target?: string) => + follower.value?.noteUnboundLocalIntent(target), retrySubscription: () => follower.value?.retrySubscription(), docInputNames: (nodeId: NodeId) => follower.value?.docInputNames(nodeId) ?? null, @@ -1292,8 +1293,7 @@ function startAgentCrdtFollower( projection.noteLocalWrites(operations) coalescer.enqueue(operations) }, - noteUnboundLocalIntent: () => { - const target = workflowId.value + noteUnboundLocalIntent: (target = workflowId.value) => { if (target === null) return workflowsWithUnsyncedOps.add(target) recordUnsynced() From 282bf44122c53377f8fdb950707aac34dec76297 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:37:50 -0800 Subject: [PATCH 7/9] refactor(agent): extract intentRootGraphId from noteUnboundLocalIntent The visible-workflow branch pushed noteUnboundLocalIntent to cyclomatic 10, which the fallow new-findings gate rejects. Resolving the intent's root graph id moves into its own function; behaviour is unchanged. --- .../extensions/agent/crdt/docOpMinter.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index 8e19711ff77..303ffa51b54 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -1195,19 +1195,23 @@ export function attachDocOpMinter(deps: DocOpMinterDeps): DocOpMinter { heldPromotedWrites.delete(heldWriteKey(event)) } + function intentRootGraphId( + event: GraphIntentEvent, + graph: LGraph | null + ): string | null { + if ('graph' in event) return event.graph.rootGraph.id + return graph !== null && reachableIntentGraph(graph, event.graphId) !== null + ? graph.id + : null + } + function noteUnboundLocalIntent(event: GraphIntentEvent): void { const graph = deps.getGraph() - const boundRootGraphId = deps.boundRootGraphId() - const eventRootGraphId = - 'graph' in event - ? event.graph.rootGraph.id - : graph !== null && reachableIntentGraph(graph, event.graphId) !== null - ? graph.id - : null - if (boundRootGraphId !== null && eventRootGraphId === boundRootGraphId) + const eventRootGraphId = intentRootGraphId(event, graph) + if (eventRootGraphId === null) return + if (eventRootGraphId === deps.boundRootGraphId()) deps.onUnboundLocalIntent?.() - else if (graph !== null && eventRootGraphId === graph.id) - deps.onUnboundVisibleIntent?.() + else if (eventRootGraphId === graph?.id) deps.onUnboundVisibleIntent?.() } function onIntent(event: GraphIntentEvent): void { From b8319d6aa6534b0af84d1820c37c39bdd81f8384 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:48:52 -0800 Subject: [PATCH 8/9] test(agent): hold only transcript reads in holdTranscript Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453639006 --- browser_tests/fixtures/agentConversationFixture.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/browser_tests/fixtures/agentConversationFixture.ts b/browser_tests/fixtures/agentConversationFixture.ts index 04e8f59fe57..a1beb1fdc99 100644 --- a/browser_tests/fixtures/agentConversationFixture.ts +++ b/browser_tests/fixtures/agentConversationFixture.ts @@ -952,6 +952,7 @@ export class AgentConversationHarness { await this.page.route( `**/api/agent/threads/${threadId}/messages`, async (route) => { + if (route.request().method() !== 'GET') return route.fallback() reached() await held return route.fallback() From 77289cf0e99220527ad8740951438ebc77ea0bab Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Nov 2026 02:48:57 -0800 Subject: [PATCH 9/9] test(agent): prove B was not re-subscribed with a later subscribe to A Frames on the follower socket arrive in order, so once the host sees the subscribe for A, any earlier rebind of B would already be counted. The case fails with either the hasUnsyncedHumanOps guard or the visible-intent wiring removed (subscribe count 2, expected 1). Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/22792#discussion_r4453639064 --- .../agent/agentBackgroundTabEditsLand.spec.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts index 254f79cf2a1..2084a0d9028 100644 --- a/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts +++ b/browser_tests/tests/agent/agentBackgroundTabEditsLand.spec.ts @@ -15,7 +15,6 @@ import { USER_NOTE_POSITION } from '@e2e/fixtures/data/agent/backgroundTabEdits' import { AgentWorkflowChatsMock } from '@e2e/fixtures/helpers/agentWorkflowChats' -import { nextFrame } from '@e2e/fixtures/utils/timing' test.describe( 'Agent edits to a background workflow tab', @@ -123,18 +122,25 @@ test.describe( return id }) - await test.step('B stays unbound and keeps the edit', async () => { + await test.step('B keeps the edit once its chat loads', async () => { transcript.release() await expect(panel.userMessageBubbles).toHaveText([BACKGROUND.request]) - await nextFrame(page) - await nextFrame(page) - expect(agentConversation.subscribeCount(BACKGROUND.id)).toBe( - subscribesBefore - ) await expect( agentConversation.vueNodes.getNodeLocator(noteId) ).toBeVisible() }) + + await test.step('the next subscribe, to A, finds B never re-subscribed', async () => { + const aId = agentConversation.conversation.workflow.id + const aSubscribes = agentConversation.subscribeCount(aId) + await topbar.getWorkflowTab(FOREGROUND_NAME).click() + await expect + .poll(() => agentConversation.subscribeCount(aId)) + .toBeGreaterThan(aSubscribes) + expect(agentConversation.subscribeCount(BACKGROUND.id)).toBe( + subscribesBefore + ) + }) }) } )