Repository navigation
fix(agent-crdt): rebind follower when session binding is absent (FE-1969) #16708
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
Closed
christian-byrne
wants to merge
61
commits into
main
from
christian-byrne/fe-1969-agent-panel-crdt-follower-restore
Closed
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 6376cbb
fix(agent): select idle agent-opened workflow targets
christian-byrne f43dd70
test(agent): wake reload follower on mock socket
christian-byrne 31cf1a8
test(agent): address reload review feedback
christian-byrne 510ef4d
fix(agent): derive follower connection from acknowledgment
christian-byrne 8855dfc
Merge origin/main and restore the finite-expiry guard
christian-byrne 51b2326
test(agent-crdt): assert the reload resubscribe across sockets, not o…
christian-byrne 36f81ba
test(agent-crdt): stage the reload assertions so a red says where it …
christian-byrne addd675
Merge origin/main: translate the gave-up/reconnect disconnect onto th…
christian-byrne ae89468
docs(agent-crdt): state the doc_reset invariant instead of main's old…
christian-byrne 143beca
docs(agent-crdt): drop the rebase history from the finite-expiry comment
christian-byrne 856062e
test(agent-crdt): open the reload spec's panel through the AgentPanel…
christian-byrne f129225
fix(agent-crdt): collapse the persisted doc id onto one owner
christian-byrne 3cb46cf
chore: merge main into FE-1969 restore branch
christian-byrne 91cd294
fix(agent): preserve reload-time workflow restore
christian-byrne c8d8905
refactor(agent): use CRDT status for mint wiring
christian-byrne 19d8576
test(agent): state CRDT reset invariant directly
christian-byrne 42290c1
fix(agent): validate persisted CRDT records
christian-byrne aebf865
fix(agent): narrow reload navigation entries
christian-byrne 6c0719f
test(agent): read reload state through typed owners
christian-byrne 5013dfe
test(agent): load storage transitions at module scope
christian-byrne 75383fa
test(agent): execute blank workflow through helper
christian-byrne d99538c
docs(agent): distinguish remount and reload restore
christian-byrne aa9e305
fix(agent): parse browser binding through store owner
christian-byrne 3f5b666
[automated] Apply ESLint and Oxfmt fixes
actions-user d74cbbc
test(agent): isolate reload storage parser
christian-byrne 8c01607
[automated] Apply ESLint and Oxfmt fixes
actions-user 6901638
fix(agent): preserve follower identity while inactive
christian-byrne f2ebb22
test(agent): rely on live edit after reload
christian-byrne e56f41c
Merge remote-tracking branch 'origin/main' into christian-byrne/fe-19…
christian-byrne 1772298
Merge branch 'main' into christian-byrne/fe-1969-agent-panel-crdt-fol…
DrJKL f6d9809
fix(agent): close reload follower review gaps
christian-byrne 8e82e68
fix(agent): address reload follower review findings
ampagent 5838f36
Merge branch 'main' of github.com:Comfy-Org/ComfyUI_frontend into chr…
christian-byrne ee6c2d6
refactor(agent): reduce workflow restore complexity
christian-byrne 3d9bc69
chore(agent): keep client frame type internal
christian-byrne 21286fa
test(agent): apply reload review cleanup
christian-byrne babac60
Merge branch 'main' into christian-byrne/fe-1969-agent-panel-crdt-fol…
christian-byrne 3a6b0a8
test(agent): cover persisted tab binding reader
christian-byrne 7e20fa4
test(agent): type reload model folder mock
christian-byrne 7b5099f
test(agent): keep reload workflow id local
christian-byrne 865a8d8
chore(agent): remove redundant follower comments
christian-byrne d8ac257
docs(agent): clarify reload nonce adoption
christian-byrne 2525087
test(agent): assert minted tab selection and binding
christian-byrne 3f99ca3
fix(agent): synchronize target reattachment state
christian-byrne 042affd
test(agent): assert reload reattachment subscribes
christian-byrne a6486cb
test(e2e): make websocket capture opt in
christian-byrne b797adb
test(agent): reuse shared client frame parser
christian-byrne 13d7902
test(agent): acknowledge the subscribing reload socket
christian-byrne f6247e1
test(agent): narrow tab-return subscription claim
christian-byrne 3d04ff0
fix(agent): detach persisted follower before history load
christian-byrne 4f2d30f
fix(agent): restore hydrated workflow session binding
christian-byrne f64267b
docs(agent): state persisted doc identity contract
christian-byrne 33dc07e
test(agent): move socket capture queries into fixture
christian-byrne b8cbb42
[automated] Apply ESLint and Oxfmt fixes
actions-user 357f350
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent 1d4356f
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent 7e523db
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent 955cd7b
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent 0279d75
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent 3b7a900
Merge main into christian-byrne/fe-1969-agent-panel-crdt-follower-res…
ampagent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
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) | ||
|
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) | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.