Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
81d243e
[FE-1969] Rebind agent CRDT follower on identity change (#16708 rebase)
christian-byrne Sep 12, 2026
6376cbb
fix(agent): select idle agent-opened workflow targets
christian-byrne Sep 12, 2026
f43dd70
test(agent): wake reload follower on mock socket
christian-byrne Sep 12, 2026
31cf1a8
test(agent): address reload review feedback
christian-byrne Sep 12, 2026
510ef4d
fix(agent): derive follower connection from acknowledgment
christian-byrne Sep 15, 2026
8855dfc
Merge origin/main and restore the finite-expiry guard
christian-byrne Sep 20, 2026
51b2326
test(agent-crdt): assert the reload resubscribe across sockets, not o…
christian-byrne Sep 20, 2026
36f81ba
test(agent-crdt): stage the reload assertions so a red says where it …
christian-byrne Sep 20, 2026
addd675
Merge origin/main: translate the gave-up/reconnect disconnect onto th…
christian-byrne Sep 20, 2026
ae89468
docs(agent-crdt): state the doc_reset invariant instead of main's old…
christian-byrne Sep 20, 2026
143beca
docs(agent-crdt): drop the rebase history from the finite-expiry comment
christian-byrne Sep 20, 2026
856062e
test(agent-crdt): open the reload spec's panel through the AgentPanel…
christian-byrne Sep 20, 2026
f129225
fix(agent-crdt): collapse the persisted doc id onto one owner
christian-byrne Sep 20, 2026
3cb46cf
chore: merge main into FE-1969 restore branch
christian-byrne Sep 21, 2026
91cd294
fix(agent): preserve reload-time workflow restore
christian-byrne Sep 21, 2026
c8d8905
refactor(agent): use CRDT status for mint wiring
christian-byrne Sep 21, 2026
19d8576
test(agent): state CRDT reset invariant directly
christian-byrne Sep 21, 2026
42290c1
fix(agent): validate persisted CRDT records
christian-byrne Sep 21, 2026
aebf865
fix(agent): narrow reload navigation entries
christian-byrne Sep 21, 2026
6c0719f
test(agent): read reload state through typed owners
christian-byrne Sep 21, 2026
5013dfe
test(agent): load storage transitions at module scope
christian-byrne Sep 21, 2026
75383fa
test(agent): execute blank workflow through helper
christian-byrne Sep 21, 2026
d99538c
docs(agent): distinguish remount and reload restore
christian-byrne Sep 21, 2026
aa9e305
fix(agent): parse browser binding through store owner
christian-byrne Sep 21, 2026
3f5b666
[automated] Apply ESLint and Oxfmt fixes
actions-user Sep 21, 2026
d74cbbc
test(agent): isolate reload storage parser
christian-byrne Sep 21, 2026
8c01607
[automated] Apply ESLint and Oxfmt fixes
actions-user Sep 21, 2026
6901638
fix(agent): preserve follower identity while inactive
christian-byrne Sep 21, 2026
f2ebb22
test(agent): rely on live edit after reload
christian-byrne Sep 21, 2026
e56f41c
Merge remote-tracking branch 'origin/main' into christian-byrne/fe-19…
christian-byrne Sep 21, 2026
1772298
Merge branch 'main' into christian-byrne/fe-1969-agent-panel-crdt-fol…
DrJKL Sep 21, 2026
f6d9809
fix(agent): close reload follower review gaps
christian-byrne Sep 22, 2026
8e82e68
fix(agent): address reload follower review findings
ampagent Sep 22, 2026
5838f36
Merge branch 'main' of github.com:Comfy-Org/ComfyUI_frontend into chr…
christian-byrne Sep 22, 2026
ee6c2d6
refactor(agent): reduce workflow restore complexity
christian-byrne Sep 22, 2026
3d9bc69
chore(agent): keep client frame type internal
christian-byrne Sep 22, 2026
21286fa
test(agent): apply reload review cleanup
christian-byrne Sep 22, 2026
babac60
Merge branch 'main' into christian-byrne/fe-1969-agent-panel-crdt-fol…
christian-byrne Sep 22, 2026
3a6b0a8
test(agent): cover persisted tab binding reader
christian-byrne Sep 22, 2026
7e20fa4
test(agent): type reload model folder mock
christian-byrne Sep 22, 2026
7b5099f
test(agent): keep reload workflow id local
christian-byrne Sep 22, 2026
865a8d8
chore(agent): remove redundant follower comments
christian-byrne Sep 22, 2026
d8ac257
docs(agent): clarify reload nonce adoption
christian-byrne Sep 22, 2026
2525087
test(agent): assert minted tab selection and binding
christian-byrne Sep 22, 2026
3f99ca3
fix(agent): synchronize target reattachment state
christian-byrne Sep 22, 2026
042affd
test(agent): assert reload reattachment subscribes
christian-byrne Sep 22, 2026
a6486cb
test(e2e): make websocket capture opt in
christian-byrne Sep 22, 2026
b797adb
test(agent): reuse shared client frame parser
christian-byrne Sep 22, 2026
13d7902
test(agent): acknowledge the subscribing reload socket
christian-byrne Sep 22, 2026
f6247e1
test(agent): narrow tab-return subscription claim
christian-byrne Sep 22, 2026
3d04ff0
fix(agent): detach persisted follower before history load
christian-byrne Sep 22, 2026
4f2d30f
fix(agent): restore hydrated workflow session binding
christian-byrne Sep 22, 2026
f64267b
docs(agent): state persisted doc identity contract
christian-byrne Sep 22, 2026
33dc07e
test(agent): move socket capture queries into fixture
christian-byrne Sep 22, 2026
b8cbb42
[automated] Apply ESLint and Oxfmt fixes
actions-user Sep 22, 2026
357f350
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 23, 2026
1d4356f
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 24, 2026
7e523db
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 25, 2026
955cd7b
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 27, 2026
0279d75
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 29, 2026
3b7a900
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent Sep 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser_tests/fixtures/agentFollowerHostSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function opLabel(op: WireOpEnvelope): string {
return `${op.op}:${'node_id' in op ? String(op.node_id) : ''}`
}

function parseClientDocFrame(
export function parseClientDocFrame(
raw: string | Buffer
): ParsedClientDocFrame | null {
const envelope = docFrameEnvelope(raw)
Expand Down
62 changes: 60 additions & 2 deletions browser_tests/fixtures/agentPanelFixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Page, Route } from '@playwright/test'
import { expect } from '@playwright/test'
import type { Page, Route, WebSocketRoute } from '@playwright/test'

import type {
AgentRunMode,
Expand All @@ -11,13 +12,18 @@ import type {
import type { RemoteConfig } from '@/platform/remoteConfig/types'
import type { UserDataFullInfo } from '@/platform/remote/comfyui/types'
import { AGENT_CONSENT_SETTING_ID } from '@/platform/settings/constants/agent'
import { AGENT_CRDT_DOC_ID_SESSION_KEY } from '@/platform/workflow/persistence/base/storageKeyConstants'
import { StorageKeys } from '@/platform/workflow/persistence/base/storageKeys'
import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema'
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
import type { AgentTurnAccepted } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import type {
AgentTurnAccepted,
AgentWsEvent
} from '@/workbench/extensions/agent/schemas/agentApiSchema'

import { cloudAppFixture, waitForCloudApp } from '@e2e/fixtures/cloudAppFixture'
import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import { Topbar } from '@e2e/fixtures/components/Topbar'
import {
AGENT_COMPOSER_THREAD_ID,
agentComposerRunMode,
Expand Down Expand Up @@ -194,6 +200,58 @@ export const agentTest = cloudAppFixture.extend<AgentFixtures>({
agentFlagEnabled: [true, { option: true }]
})

export function pushAgentEvent(ws: WebSocketRoute, event: AgentWsEvent): void {
ws.send(JSON.stringify(event))
}

export async function getAgentActiveWorkflowPath(
page: Page
): Promise<string | undefined> {
return await page.evaluate(
() =>
(window.app!.extensionManager as WorkspaceStore).workflow.activeWorkflow
?.path
)
}

export async function switchToAgentWorkflowTab(
page: Page,
tabPath: string
): Promise<void> {
const tabIndex = await page.evaluate(
(path) =>
(
window.app!.extensionManager as WorkspaceStore
).workflow.openWorkflows.findIndex((workflow) => workflow.path === path),
tabPath
)
if (tabIndex < 0) throw new Error(`Workflow tab is not open: ${tabPath}`)
const tab = new Topbar(page).getTab(tabIndex)
await tab.click()
await expect(tab).toHaveClass(/p-togglebutton-checked/)
await expect.poll(() => getAgentActiveWorkflowPath(page)).toBe(tabPath)
}

export async function readPersistedAgentDocIdentity(page: Page) {
const raw = await page.evaluate(
(key) => sessionStorage.getItem(key),
AGENT_CRDT_DOC_ID_SESSION_KEY
)
if (raw === null) throw new Error('Persisted CRDT document record is missing')
const parsed: unknown = JSON.parse(raw)
if (
typeof parsed !== 'object' ||
parsed === null ||
!('docId' in parsed) ||
typeof parsed.docId !== 'string' ||
!('nonce' in parsed) ||
typeof parsed.nonce !== 'string'
) {
throw new Error('Persisted CRDT document record is malformed')
}
return { docId: parsed.docId, nonce: parsed.nonce }
}

type AgentComposerPerformanceFixtures = {
agentComposerTurnCount: number
agentComposerPanel: AgentPanel
Expand Down
76 changes: 67 additions & 9 deletions browser_tests/fixtures/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,95 @@ interface WebSocketTracker {
waitForNext: () => Promise<WebSocketRoute>
}

export class CapturedWebSocketMessages extends Map<WebSocketRoute, string[]> {
countFor(
socket: WebSocketRoute,
matches: (message: string) => boolean
): number {
return (this.get(socket) ?? []).filter(matches).length
}

count(
matches: (message: string) => boolean,
except?: WebSocketRoute
): number {
let total = 0
for (const [socket, messages] of this) {
if (socket !== except) total += messages.filter(matches).length
}
return total
}

firstSocket(
matches: (message: string) => boolean,
except?: WebSocketRoute
): WebSocketRoute | null {
for (const [socket, messages] of this) {
if (socket !== except && messages.some(matches)) return socket
}
return null
}
}

function createWebSocketRouteHandler(
connectWebSocketToServer: boolean,
onRouted: (ws: WebSocketRoute) => void
onRouted: (ws: WebSocketRoute, server: WebSocketRoute | null) => void
) {
return (ws: WebSocketRoute) => {
if (connectWebSocketToServer) {
const server = ws.connectToServer()
server.onMessage((message) => {
ws.send(message)
})
if (!connectWebSocketToServer) {
onRouted(ws, null)
return
}

onRouted(ws)
const server = ws.connectToServer()
server.onMessage((message) => {
ws.send(message)
})
onRouted(ws, server)
}
}

export const webSocketFixture = base.extend<{
connectWebSocketToServer: boolean
captureWebSocketMessages: boolean
getWebSocket: () => Promise<WebSocketRoute>
nextWebSocket: () => Promise<WebSocketRoute>
webSocketTracker: WebSocketTracker
webSocketMessages: CapturedWebSocketMessages
}>({
connectWebSocketToServer: [true, { option: true }],
captureWebSocketMessages: [false, { option: true }],
// oxlint-disable-next-line no-empty-pattern -- Playwright requires an object pattern.
webSocketMessages: async ({}, use) => {
await use(new CapturedWebSocketMessages())
},
webSocketTracker: [
async ({ context, connectWebSocketToServer }, use) => {
async (
{
context,
connectWebSocketToServer,
captureWebSocketMessages,
webSocketMessages
},
use
) => {
let current: WebSocketRoute | undefined
const waiters = new Set<(ws: WebSocketRoute) => void>()

await context.routeWebSocket(
/\/ws/,
createWebSocketRouteHandler(connectWebSocketToServer, (ws) => {
createWebSocketRouteHandler(connectWebSocketToServer, (ws, server) => {
if (captureWebSocketMessages) {
const messages: string[] = []
webSocketMessages.set(ws, messages)
// Registering a page-side handler switches off Playwright's
// automatic page-to-server forwarding, so recording has to
// re-send the frame itself.
ws.onMessage((message) => {
if (typeof message === 'string') messages.push(message)
server?.send(message)
})
}
current = ws
const pending = [...waiters]
waiters.clear()
Expand Down
190 changes: 190 additions & 0 deletions browser_tests/tests/agent/agentCrdtReload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { expect, mergeTests } from '@playwright/test'
import type {
AgentThreadListResponse,
WorkflowListResponse
} from '@comfyorg/ingest-types'

import type { ModelFolderInfo } from '@/platform/assets/schemas/assetSchema'
import { AGENT_CRDT_DOC_ID_SESSION_KEY } from '@/platform/workflow/persistence/base/storageKeyConstants'
import { StorageKeys } from '@/platform/workflow/persistence/base/storageKeys'
import { readPersistedAgentWorkflowTabPath } from '@/workbench/extensions/agent/stores/agent/agentWorkflowTabBindingStorage'
import {
agentTest,
bootAgentApp,
getAgentActiveWorkflowPath,
pushAgentEvent,
readPersistedAgentDocIdentity,
switchToAgentWorkflowTab
} from '@e2e/fixtures/agentPanelFixture'
import { parseClientDocFrame } from '@e2e/fixtures/agentFollowerHostSocket'
import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture'
import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import { CommandHelper } from '@e2e/fixtures/helpers/CommandHelper'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { webSocketFixture } from '@e2e/fixtures/ws'

const test = mergeTests(agentTest, webSocketFixture)

test.describe('Agent CRDT reload', { tag: '@cloud' }, () => {
test.use({
connectWebSocketToServer: false,
captureWebSocketMessages: true
})

test.beforeEach(async ({ page }) => {
const workflows: WorkflowListResponse = {
data: [],
pagination: { has_more: false, limit: 100, offset: 0, total: 0 }
}
const threads: AgentThreadListResponse = {
threads: [],
pagination: { has_more: false, limit: 100, offset: 0, total: 0 }
}

await page.route('**/api/internal/cloud_analytics', (route) =>
route.fulfill(jsonRoute({}))
)
const folders: ModelFolderInfo[] = []
await page.route('**/api/experiment/models', (route) =>
route.fulfill(jsonRoute(folders))
)
await page.route(/\/api\/workflows\?limit=100$/, (route) =>
route.fulfill(jsonRoute(workflows))
)
await page.route('**/api/agent/threads', (route) =>
route.fulfill(jsonRoute(threads))
)
})

test('FE-1969 restores the subscription after reload and suspends it in the background', async ({
page,
agentFlagEnabled,
getWebSocket,
nextWebSocket,
webSocketMessages
}) => {
test.setTimeout(90_000)
const workflowId = 'a81718a4-02ae-41e6-ae85-c33b7bb880f6'
const agentPanel = new AgentPanel(page)
const command = new CommandHelper(page)
const matchesDocFrame =
(type: 'doc_subscribe' | 'doc_unsubscribe') =>
(message: string): boolean => {
const frame = parseClientDocFrame(message)
return frame?.type === type && frame.workflowId === workflowId
}

await bootAgentApp(page, agentFlagEnabled)

const ws =
await test.step('Bind the active workflow and request its subscription', async () => {
const ws = await getWebSocket()
await agentPanel.open()
pushAgentEvent(ws, {
type: 'agent_active_tab',
data: { workflow_id: workflowId, name: 'Reload receipt' }
})

await expect
.poll(() =>
webSocketMessages.countFor(ws, matchesDocFrame('doc_subscribe'))
)
.toBe(1)
return ws
})

ws.send(
JSON.stringify({
type: 'doc_subscribed',
data: { v: 1, workflow_id: workflowId, ok: true, seq: 0 }
})
)

await expect
.poll(() =>
page.evaluate(
(key) => sessionStorage.getItem(key),
AGENT_CRDT_DOC_ID_SESSION_KEY
)
)
.not.toBeNull()
const recordBeforeReload = await readPersistedAgentDocIdentity(page)
expect(recordBeforeReload).toMatchObject({ docId: workflowId })

const rawBindings = await page.evaluate(
(key) => localStorage.getItem(key),
StorageKeys.agentWorkflowTabBindings('personal')
)
const boundPath = readPersistedAgentWorkflowTabPath(rawBindings, workflowId)
if (!boundPath) throw new Error('Persisted workflow tab binding is missing')
await expect.poll(() => getAgentActiveWorkflowPath(page)).toBe(boundPath)
expect(
await page.evaluate(() => localStorage.getItem('Comfy.Agent.ThreadId'))
).toBeNull()

// Count across every socket EXCEPT the pre-reload one. The claim under test
// is "the reloaded app resubscribed", not "one particular WebSocketRoute
// saw it", and a reload can route more than one replacement socket. Binding
// the assertion to a single captured route turns a product failure and a
// test-plumbing failure into the same red, which is what made the earlier
// run ambiguous.
const countAfterReload = (
type: 'doc_subscribe' | 'doc_unsubscribe'
): number => webSocketMessages.count(matchesDocFrame(type), ws)
const firstSocketWithFrameAfterReload = (
type: 'doc_subscribe' | 'doc_unsubscribe'
) => webSocketMessages.firstSocket(matchesDocFrame(type), ws)

await test.step('Reload and restore the workflow subscription', async () => {
// Arm the waiter BEFORE the reload. The replacement socket is routed
// and starts recording as soon as the reloaded page connects, so a
// waiter registered afterwards can miss it and leave the assertion
// below polling a socket that never receives the resubscribe.
const pendingWs = nextWebSocket()
await page.reload()
await waitForCloudApp(page)
// Not `agentPanel.open()`: the panel restores itself on reload, so this
// is a readiness wait on the same page object's root, not a second open.
await expect(agentPanel.root).toBeVisible()
const reloadedWs = await pendingWs
reloadedWs.send(
JSON.stringify({
type: 'status',
data: { status: { exec_info: { queue_remaining: 0 } } }
})
)
// Assert the restore in stages so a red says WHERE it broke. The doc-id
// record and the rebound tab are the two preconditions for resubscribing;
// if either is wrong the subscribe assertion below is a downstream
// symptom, and if both hold then the gap is in the follower bind itself.
const record = await readPersistedAgentDocIdentity(page)
expect(record).toMatchObject({ docId: workflowId })
expect(record.nonce).not.toBe(recordBeforeReload.nonce)
await expect.poll(() => getAgentActiveWorkflowPath(page)).toBe(boundPath)

await expect.poll(() => countAfterReload('doc_subscribe')).toBe(1)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
Comment thread
christian-byrne marked this conversation as resolved.
Resolved

const subscribedSocket = firstSocketWithFrameAfterReload('doc_subscribe')
if (!subscribedSocket)
throw new Error('Reloaded workflow subscription socket is missing')
subscribedSocket.send(
JSON.stringify({
type: 'doc_subscribed',
data: { v: 1, workflow_id: workflowId, ok: true, seq: 0 }
})
)
})

await test.step('Switching away unsubscribes and returning requests a subscription', async () => {
expect(countAfterReload('doc_unsubscribe')).toBe(0)
await command.executeCommand('Comfy.NewBlankWorkflow')
await expect.poll(() => countAfterReload('doc_unsubscribe')).toBe(1)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const subscribeCountBeforeReturn = countAfterReload('doc_subscribe')

await switchToAgentWorkflowTab(page, boundPath)
await expect
.poll(() => countAfterReload('doc_subscribe'))
.toBe(subscribeCountBeforeReturn + 1)
})
})
})
Loading
Loading