From 8c14eef5dab31d25b1247b2472e5589b32de5171 Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 19 Oct 2026 02:29:10 +0000 Subject: [PATCH 1/4] fix(agent): report why a history chat's workflow could not be restored Selecting a history chat whose recorded workflow cannot be restored left the row at "Could not open. Select this chat to retry." with nothing in the console or telemetry: the restore-failure toast is suppressed while a history row is loading (ADR-AGENT-HISTORY-0038), and the thrown case was an empty catch. Report every restoration failure as agent_workflow_restore_failed with the workflow id and cause. --- ...tHistoryUnresolvedWorkflowReported.spec.ts | 164 ++++++++++++++++++ ...38-wait-for-chat-and-workflow-readiness.md | 3 +- .../agent/useAgentWorkflowSelection.test.ts | 12 ++ .../agent/useAgentWorkflowSelection.ts | 24 ++- 4 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts diff --git a/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts new file mode 100644 index 00000000000..355bf522a52 --- /dev/null +++ b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts @@ -0,0 +1,164 @@ +import { expect } from '@playwright/test' + +import type { + AgentMessage, + AgentThreadListResponse, + WorkflowListResponse +} from '@comfyorg/ingest-types' +import { REPORTED_ERROR_PREFIX } from '@comfyorg/shared-frontend-utils/telemetry' + +import enMessages from '@/locales/en/main.json' with { type: 'json' } +import type { UserDataFullInfo } from '@/platform/remote/comfyui/types' + +import { + agentTest as test, + bootAgentApp +} from '@e2e/fixtures/agentPanelFixture' +import { AgentPanel } from '@e2e/fixtures/components/AgentPanel' +import { collectConsoleErrors } from '@e2e/fixtures/utils/consoleErrorCollector' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' + +const THREAD_ID = '3b7e2d1c-9a4f-4e6b-8c5d-1f2a3b4c5d6e' +const TURN_ID = '6c5d4e3f-2a1b-4c9d-8e7f-0a1b2c3d4e5f' +const WORKFLOW_ID = '0d9c8b7a-6f5e-4d3c-b2a1-f0e9d8c7b6a5' +const TWIN_WORKFLOW_ID = '1e0d9c8b-7a6f-4e5d-c3b2-a1f0e9d8c7b6' +const WORKFLOW_NAME = 'Image and video' +const THREAD_TITLE = 'Lighthouse clip' +const USER_REQUEST = 'Make a lighthouse image, then a short video of it' +const IMAGE_URL = + 'https://cloud.comfy.org/api/view?filename=lighthouse_00001_.png&subfolder=agent%2Foutputs&type=output' +const VIDEO_URL = + 'https://cloud.comfy.org/api/view?filename=lighthouse_00001_.mp4&subfolder=agent%2Foutputs&type=output' +const ASSISTANT_REPLY = `Here is the image: [lighthouse_00001_.png](${IMAGE_URL}) and the video: [lighthouse_00001_.mp4](${VIDEO_URL})` +const SAVED_AT = '2026-10-15T10:00:00Z' + +test.describe( + 'Agent history reports an unresolvable chat workflow', + { tag: ['@cloud', '@agent'] }, + () => { + test('logs why a chat whose workflow cannot be resolved does not open', async ({ + page, + agentFlagEnabled + }) => { + const threads: AgentThreadListResponse = { + threads: [ + { + id: THREAD_ID, + title: THREAD_TITLE, + preview: USER_REQUEST, + workflow_id: WORKFLOW_ID, + status: 'active', + message_count: 2, + created_at: SAVED_AT, + updated_at: SAVED_AT, + last_message_at: SAVED_AT + } + ], + pagination: { offset: 0, limit: 100, total: 1, has_more: false } + } + const transcript: AgentMessage[] = [ + { + id: 'lighthouse-user', + thread_id: THREAD_ID, + turn_id: TURN_ID, + seq: 1, + role: 'user', + status: 'complete', + workflow_id: WORKFLOW_ID, + content: { text: USER_REQUEST } + }, + { + id: TURN_ID, + thread_id: THREAD_ID, + turn_id: TURN_ID, + seq: 2, + role: 'assistant', + status: 'complete', + workflow_id: WORKFLOW_ID, + content: { + text: ASSISTANT_REPLY, + tool_calls: [ + { + id: 'call-image', + tool_call_id: 'toolu_image', + tool_name: 'run_workflow', + status: 'success', + duration_ms: 4200 + }, + { + id: 'call-video', + tool_call_id: 'toolu_video', + tool_name: 'run_workflow', + status: 'success', + duration_ms: 18400 + } + ] + } + } + ] + const cloudWorkflows: WorkflowListResponse = { + data: [WORKFLOW_ID, TWIN_WORKFLOW_ID].map((id) => ({ + id, + name: WORKFLOW_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[] = [ + `${WORKFLOW_NAME}.json`, + `drafts/${WORKFLOW_NAME}.json` + ].map((path) => ({ path, modified: Date.parse(SAVED_AT), size: 64 })) + + await bootAgentApp(page, agentFlagEnabled, { + beforeNavigate: async (page) => { + await page.route('**/api/agent/threads', (route) => + route.fulfill(jsonRoute(threads)) + ) + await page.route('**/api/agent/threads/*/messages', (route) => + route.request().method() === 'GET' + ? route.fulfill(jsonRoute(transcript)) + : route.fallback() + ) + await page.route('**/api/workflows?*', (route) => + route.fulfill(jsonRoute(cloudWorkflows)) + ) + await page.route('**/api/userdata?*', (route) => { + const dir = new URL(route.request().url()).searchParams.get('dir') + if (dir !== 'workflows') return route.fallback() + return route.fulfill(jsonRoute(savedFiles)) + }) + } + }) + + const agentPanel = new AgentPanel(page) + const panel = agentPanel.root + const historyRow = panel.getByRole('button', { + name: THREAD_TITLE, + exact: true + }) + using consoleErrors = collectConsoleErrors(page) + + await agentPanel.open() + await panel + .getByRole('button', { name: enMessages.agent.showChatHistory }) + .click() + await historyRow.click() + + await expect(panel.getByRole('alert')).toHaveText( + enMessages.agent.historyOpenFailed + ) + await expect + .poll(() => + consoleErrors.errors.filter((error) => + error.startsWith( + `${REPORTED_ERROR_PREFIX}agent_workflow_restore_failed` + ) + ) + ) + .toHaveLength(1) + }) + } +) diff --git a/docs/adr/AGENT-HISTORY-0038-wait-for-chat-and-workflow-readiness.md b/docs/adr/AGENT-HISTORY-0038-wait-for-chat-and-workflow-readiness.md index 0bdff941d99..e38d17e2a24 100644 --- a/docs/adr/AGENT-HISTORY-0038-wait-for-chat-and-workflow-readiness.md +++ b/docs/adr/AGENT-HISTORY-0038-wait-for-chat-and-workflow-readiness.md @@ -24,7 +24,8 @@ are ready; a remount whose target is already decided has nothing to restore, so it preserves its current identity. A failed startup restoration leaves the session unmarked until a successful retry. Failures remain in history with a retry affordance and existing error details; -the selected row is their only feedback. A chat whose recorded workflow a +the selected row is their only on-screen feedback, and every workflow +restoration failure is still reported with its reason. A chat whose recorded workflow a successful Cloud listing no longer includes opens without a target, even if a stale local binding still names a tab, and the composer tip says the target workflow is no longer available until a workflow is diff --git a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts index 82ec58edaff..2a06e8eec3f 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts @@ -4,6 +4,7 @@ import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { defineComponent } from 'vue' import { i18n } from '@/i18n' +import { reportError } from '@/platform/telemetry/reportError' import { useWorkflowService } from '@/platform/workflow/core/services/workflowService' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { createMockLoadedWorkflow } from '@/utils/__tests__/litegraphTestUtils' @@ -17,6 +18,7 @@ import { useAgentWorkflowResolver } from './useAgentWorkflowResolver' import { useAgentWorkflowSelection } from './useAgentWorkflowSelection' vi.mock(import('@/platform/workflow/core/services/workflowService')) +vi.mock(import('@/platform/telemetry/reportError')) function setup() { const workflows = useWorkflowStore() @@ -364,6 +366,11 @@ describe('historical workflow restoration', () => { expect(panel.selectedWorkflow).toBeNull() expect(panel.targetUnavailable).toBe(false) expect(warnRestoreFailed).toHaveBeenCalledOnce() + expect(reportError).toHaveBeenCalledWith(expect.any(Error), { + surface: 'agent', + errorType: 'agent_workflow_restore_failed', + context: { workflowId: 'wf-saved' } + }) }) it.for([ @@ -439,6 +446,11 @@ describe('historical workflow restoration', () => { expect(workflows.activeWorkflow?.path).toBe(current.path) expect(panel.targetUnavailable).toBe(false) expect(warnRestoreFailed).toHaveBeenCalledOnce() + expect(reportError).toHaveBeenCalledWith(expect.any(Error), { + surface: 'agent', + errorType: 'agent_workflow_restore_failed', + context: { workflowId: 'wf-saved' } + }) } ) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.ts b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.ts index a3f952225e7..53612439a2f 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.ts @@ -3,6 +3,7 @@ import { computed, onScopeDispose, ref } from 'vue' import { useI18n } from 'vue-i18n' import { useToast } from '@/components/ui/toast/toastStore' +import { reportError } from '@/platform/telemetry/reportError' import type { AgentWorkflowBindSource } from '@/platform/telemetry/types' import { useWorkflowService } from '@/platform/workflow/core/services/workflowService' import type { ComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow' @@ -307,25 +308,40 @@ export function useAgentWorkflowSelection({ } if (target === null) { panelStore.setWorkflowTarget(null) - warnRestoreFailed() + failRestore( + workflowId, + new Error('No saved workflow resolves to the chat target') + ) return RESTORE_ABANDONED } const opened = await workflowService.openWorkflow(target, { isCurrent }) if (!isCurrent()) return RESTORE_ABANDONED if (!opened) { panelStore.setWorkflowTarget(null) - warnRestoreFailed() + failRestore( + workflowId, + new Error('The chat target workflow did not open') + ) return RESTORE_ABANDONED } commitWorkflowTarget(target, workflowId, 'restored') return { ready: true, committedWorkflowId: workflowId } - } catch { + } catch (error) { if (!isCurrent()) return RESTORE_ABANDONED - warnRestoreFailed() + failRestore(workflowId, error) return RESTORE_ABANDONED } } + function failRestore(workflowId: string, cause: unknown): void { + reportError(cause, { + surface: 'agent', + errorType: 'agent_workflow_restore_failed', + context: { workflowId } + }) + warnRestoreFailed() + } + function adoptTarget(workflow: ComfyWorkflow, workflowId: string): void { commitWorkflowTarget(workflow, workflowId, 'restored') } From 1dd5eb6080503c60056028ffae15407cb9b9e5cc Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 26 Oct 2026 19:56:44 +0000 Subject: [PATCH 2/4] test(agent): assert the thrown restore error reaches reportError --- .../agent/useAgentWorkflowSelection.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts index 2a06e8eec3f..63ec834acca 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts @@ -414,20 +414,23 @@ describe('historical workflow restoration', () => { } ) + const openFailure = new Error('Cannot open') it.for([ { opening: 'returns false', - open: async () => false + open: async () => false, + cause: expect.any(Error) }, { opening: 'throws', open: async (): Promise => { - throw new Error('Cannot open') - } + throw openFailure + }, + cause: openFailure } ])( 'reports a failed restore when opening the saved workflow $opening', - async ({ open }) => { + async ({ open, cause }) => { const { selection, workflows, panel, current, warnRestoreFailed } = setup() workflows.attachWorkflow( @@ -446,7 +449,7 @@ describe('historical workflow restoration', () => { expect(workflows.activeWorkflow?.path).toBe(current.path) expect(panel.targetUnavailable).toBe(false) expect(warnRestoreFailed).toHaveBeenCalledOnce() - expect(reportError).toHaveBeenCalledWith(expect.any(Error), { + expect(reportError).toHaveBeenCalledWith(cause, { surface: 'agent', errorType: 'agent_workflow_restore_failed', context: { workflowId: 'wf-saved' } From 96dc18b30f4f21308f14c4441ad7c0fd37fff7ec Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 26 Oct 2026 20:04:26 +0000 Subject: [PATCH 3/4] test(agent): match the thread list request with its query string --- .../tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts index 355bf522a52..84ff4223c67 100644 --- a/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts +++ b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts @@ -114,7 +114,7 @@ test.describe( await bootAgentApp(page, agentFlagEnabled, { beforeNavigate: async (page) => { - await page.route('**/api/agent/threads', (route) => + await page.route('**/api/agent/threads?*', (route) => route.fulfill(jsonRoute(threads)) ) await page.route('**/api/agent/threads/*/messages', (route) => From d1166fad282b18817d504c7d1fb390da3feb255a Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 29 Oct 2026 20:10:04 +0000 Subject: [PATCH 4/4] test(agent): assert restore failure reasons and move spec setup to beforeEach --- ...tHistoryUnresolvedWorkflowReported.spec.ts | 157 +++++++++--------- .../agent/useAgentWorkflowSelection.test.ts | 15 +- 2 files changed, 88 insertions(+), 84 deletions(-) diff --git a/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts index 84ff4223c67..121faa51895 100644 --- a/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts +++ b/browser_tests/tests/agent/agentHistoryUnresolvedWorkflowReported.spec.ts @@ -32,107 +32,108 @@ const VIDEO_URL = const ASSISTANT_REPLY = `Here is the image: [lighthouse_00001_.png](${IMAGE_URL}) and the video: [lighthouse_00001_.mp4](${VIDEO_URL})` const SAVED_AT = '2026-10-15T10:00:00Z' -test.describe( - 'Agent history reports an unresolvable chat workflow', - { tag: ['@cloud', '@agent'] }, - () => { - test('logs why a chat whose workflow cannot be resolved does not open', async ({ - page, - agentFlagEnabled - }) => { - const threads: AgentThreadListResponse = { - threads: [ - { - id: THREAD_ID, - title: THREAD_TITLE, - preview: USER_REQUEST, - workflow_id: WORKFLOW_ID, - status: 'active', - message_count: 2, - created_at: SAVED_AT, - updated_at: SAVED_AT, - last_message_at: SAVED_AT - } - ], - pagination: { offset: 0, limit: 100, total: 1, has_more: false } - } - const transcript: AgentMessage[] = [ +const THREADS: AgentThreadListResponse = { + threads: [ + { + id: THREAD_ID, + title: THREAD_TITLE, + preview: USER_REQUEST, + workflow_id: WORKFLOW_ID, + status: 'active', + message_count: 2, + created_at: SAVED_AT, + updated_at: SAVED_AT, + last_message_at: SAVED_AT + } + ], + pagination: { offset: 0, limit: 100, total: 1, has_more: false } +} +const TRANSCRIPT: AgentMessage[] = [ + { + id: 'lighthouse-user', + thread_id: THREAD_ID, + turn_id: TURN_ID, + seq: 1, + role: 'user', + status: 'complete', + workflow_id: WORKFLOW_ID, + content: { text: USER_REQUEST } + }, + { + id: TURN_ID, + thread_id: THREAD_ID, + turn_id: TURN_ID, + seq: 2, + role: 'assistant', + status: 'complete', + workflow_id: WORKFLOW_ID, + content: { + text: ASSISTANT_REPLY, + tool_calls: [ { - id: 'lighthouse-user', - thread_id: THREAD_ID, - turn_id: TURN_ID, - seq: 1, - role: 'user', - status: 'complete', - workflow_id: WORKFLOW_ID, - content: { text: USER_REQUEST } + id: 'call-image', + tool_call_id: 'toolu_image', + tool_name: 'run_workflow', + status: 'success', + duration_ms: 4200 }, { - id: TURN_ID, - thread_id: THREAD_ID, - turn_id: TURN_ID, - seq: 2, - role: 'assistant', - status: 'complete', - workflow_id: WORKFLOW_ID, - content: { - text: ASSISTANT_REPLY, - tool_calls: [ - { - id: 'call-image', - tool_call_id: 'toolu_image', - tool_name: 'run_workflow', - status: 'success', - duration_ms: 4200 - }, - { - id: 'call-video', - tool_call_id: 'toolu_video', - tool_name: 'run_workflow', - status: 'success', - duration_ms: 18400 - } - ] - } + id: 'call-video', + tool_call_id: 'toolu_video', + tool_name: 'run_workflow', + status: 'success', + duration_ms: 18400 } ] - const cloudWorkflows: WorkflowListResponse = { - data: [WORKFLOW_ID, TWIN_WORKFLOW_ID].map((id) => ({ - id, - name: WORKFLOW_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[] = [ - `${WORKFLOW_NAME}.json`, - `drafts/${WORKFLOW_NAME}.json` - ].map((path) => ({ path, modified: Date.parse(SAVED_AT), size: 64 })) + } + } +] +const CLOUD_WORKFLOWS: WorkflowListResponse = { + data: [WORKFLOW_ID, TWIN_WORKFLOW_ID].map((id) => ({ + id, + name: WORKFLOW_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 SAVED_FILES: UserDataFullInfo[] = [ + `${WORKFLOW_NAME}.json`, + `drafts/${WORKFLOW_NAME}.json` +].map((path) => ({ path, modified: Date.parse(SAVED_AT), size: 64 })) +test.describe( + 'Agent history reports an unresolvable chat workflow', + { tag: ['@cloud', '@agent'] }, + () => { + test.beforeEach(async ({ page, agentFlagEnabled }) => { await bootAgentApp(page, agentFlagEnabled, { beforeNavigate: async (page) => { await page.route('**/api/agent/threads?*', (route) => - route.fulfill(jsonRoute(threads)) + route.fulfill(jsonRoute(THREADS)) ) await page.route('**/api/agent/threads/*/messages', (route) => route.request().method() === 'GET' - ? route.fulfill(jsonRoute(transcript)) + ? route.fulfill(jsonRoute(TRANSCRIPT)) : route.fallback() ) await page.route('**/api/workflows?*', (route) => - route.fulfill(jsonRoute(cloudWorkflows)) + route.fulfill(jsonRoute(CLOUD_WORKFLOWS)) ) await page.route('**/api/userdata?*', (route) => { const dir = new URL(route.request().url()).searchParams.get('dir') if (dir !== 'workflows') return route.fallback() - return route.fulfill(jsonRoute(savedFiles)) + return route.fulfill(jsonRoute(SAVED_FILES)) }) } }) + }) + test('logs why a chat whose workflow cannot be resolved does not open', async ({ + page + }) => { const agentPanel = new AgentPanel(page) const panel = agentPanel.root const historyRow = panel.getByRole('button', { diff --git a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts index e9b2b819a24..ca630124c2f 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentWorkflowSelection.test.ts @@ -369,11 +369,14 @@ describe('historical workflow restoration', () => { expect(panel.selectedWorkflow).toBeNull() expect(panel.targetUnavailable).toBe(false) expect(warnRestoreFailed).toHaveBeenCalledOnce() - expect(reportError).toHaveBeenCalledWith(expect.any(Error), { - surface: 'agent', - errorType: 'agent_workflow_restore_failed', - context: { workflowId: 'wf-saved' } - }) + expect(reportError).toHaveBeenCalledWith( + new Error('No saved workflow resolves to the chat target'), + { + surface: 'agent', + errorType: 'agent_workflow_restore_failed', + context: { workflowId: 'wf-saved' } + } + ) }) it.for([ @@ -422,7 +425,7 @@ describe('historical workflow restoration', () => { { opening: 'returns false', open: async () => false, - cause: expect.any(Error) + cause: new Error('The chat target workflow did not open') }, { opening: 'throws',