From 64dccf998d427e9b339ef43c704f4f98c0d99893 Mon Sep 17 00:00:00 2001 From: AustinMroz Date: Tue, 10 Nov 2026 21:43:39 +0000 Subject: [PATCH] Ensure a workflow is always loaded during setup (#23085) Under several circumstances a workflow would fail to load during startup. Not having a loaded workflow creates a bugged state where no workflow displays in the tab bar and common operations like undo/redo don't function. This is solved by loading the default workflow as a fallback. This was most recently triggered by #21945. In moving drafts to `uid:workspace` keys, pre-existing drafts are unable to be found. This bug is not uniquely isolated to that change. It has sporadically popped up several times over the last ~9 months. The fix and test aim to prevent the general case of the bug rather than this specific intermittent cause. --- .../tests/workflowPersistence.spec.ts | 28 +++++++++++++++++++ src/components/graph/GraphCanvas.test.ts | 3 +- src/components/graph/GraphCanvas.vue | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/browser_tests/tests/workflowPersistence.spec.ts b/browser_tests/tests/workflowPersistence.spec.ts index 97e1fb3cfe3..8c7600628e0 100644 --- a/browser_tests/tests/workflowPersistence.spec.ts +++ b/browser_tests/tests/workflowPersistence.spec.ts @@ -1316,3 +1316,31 @@ test.describe('Workflow Persistence', () => { .toBeLessThanOrEqual(101) }) }) + +const workflowListing404Test = test.extend({ + initialLocalStorage: { + 'Comfy.Workflow.LastOpenPaths:personal': JSON.stringify({ + workspaceId: 'personal', + paths: ['workflows/missing.json'], + activeIndex: 0 + }) + }, + page: async ({ page }, use) => { + await page.route('**/api/userdata?dir=workflows&*', (route) => + route.fulfill({ status: 404 }) + ) + await use(page) + } +}) + +workflowListing404Test( + 'Loads the default workflow when the workflow listing returns 404', + async ({ comfyPage }) => { + await expect + .poll(() => comfyPage.menu.topbar.getTabNames()) + .toEqual(['Unsaved Workflow']) + await expect + .poll(() => comfyPage.nodeOps.getGraphNodesCount()) + .toBeGreaterThan(0) + } +) diff --git a/src/components/graph/GraphCanvas.test.ts b/src/components/graph/GraphCanvas.test.ts index 409bbfb8120..a995e9288c9 100644 --- a/src/components/graph/GraphCanvas.test.ts +++ b/src/components/graph/GraphCanvas.test.ts @@ -149,7 +149,8 @@ vi.mock(import('@/scripts/app'), () => { rootGraphInternal = graph }, ui: { settings: { dispatchChange: vi.fn() } }, - setup: vi.fn() + setup: vi.fn(), + loadGraphData: vi.fn() } } }) diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index bb62b158fc2..266af032970 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -634,6 +634,8 @@ onMounted(async () => { startupOutcome = await workflowPersistence.initializeWorkflow() await workflowPersistence.restoreWorkflowTabsState() urlTemplateId = await workflowPersistence.loadTemplateFromUrlIfPresent() + if (!workflowStore.activeWorkflow) + await useWorkflowService().loadDefaultWorkflow() await useFirstRunEntry().handleStartupOutcome(startupOutcome) }) bootstrapOutcome = 'completed'