diff --git a/docs/adr/DEFAULT-WORKFLOW-0050-core-serves-the-default-workflow.md b/docs/adr/DEFAULT-WORKFLOW-0050-core-serves-the-default-workflow.md new file mode 100644 index 00000000000..39beb9e95ed --- /dev/null +++ b/docs/adr/DEFAULT-WORKFLOW-0050-core-serves-the-default-workflow.md @@ -0,0 +1,141 @@ +# ADR-DEFAULT-WORKFLOW-0050: Core Serves the Default Workflow + +Date: 2026-10-28 + +## Status + +Proposed + +## Context + +The workflow a new user lands on has lived in frontend TypeScript +(`src/scripts/defaultGraph.ts`) since it existed. Changing it therefore costs a +frontend release plus a core version bump, which is why it sat on Stable +Diffusion 1.5 for years before ComfyUI_frontend#12804 moved it to Z-Image Turbo. + +Two things want that coupling gone: + +- Core wants to refresh the default on a cadence measured in weeks (the + community-submitted showcase workflow), which a release train cannot serve. +- Each distribution wants a different default. Cloud does not want a workflow + that assumes a local GPU; desktop would rather open one whose model it + already bundles; Apple Silicon wants something that runs there. + +ComfyUI#16956 (CORE-340) landed the backend half: `default_workflow.json` plus +`GET /default_workflow` (and `/api/default_workflow`), documented in +`openapi.yaml` and served with `Cache-Control: no-cache` so an updated file is +not heuristically reused from cache. The file is a byte-for-byte copy of the +frontend's current `prodDefaultGraph`. Cloud implements the same endpoint. + +This ADR covers the frontend half (FE-1178), the last of the four steps planned +for this change. Decoupling the e2e suites from the default workflow was the +other, and it already shipped as the `VITE_USE_LEGACY_DEFAULT_GRAPH` build +variable. + +The frontend constraint that shapes the design: all three places that need a +default are synchronous. `loadGraphData` falls back to it when handed invalid +data, `createNewWorkflow` seeds a new tab with it, and `loadDefaultWorkflow` +loads it on the last tab closing. Making the default async would push +`await` into a store getter and a tab-creation path that are not async today. + +## Decision + +The frontend fetches the default workflow from the backend once per page load +and keeps the bundled graph as the fallback. + +- `defaultWorkflowService` owns resolution. `initDefaultWorkflow()` performs + the request at most once; `getDefaultWorkflow()` returns the fetched workflow + if there is one and the bundled `defaultGraph` otherwise. +- `ComfyApp.setup` starts the request before `syncWorkflows` and awaits it as + its last step, so the request overlaps the rest of boot rather than adding to + it. The startup workflow load runs after `setup` returns, so a resolved + default is already in place by the time anything reads it. +- The three call sites stay synchronous: they call `getDefaultWorkflow()` where + they used to read the `defaultGraph` import. Each already cloned before + mutating, which a shared module-level object also required. +- `initDefaultWorkflow()` never rejects. A 404 (any backend older than + ComfyUI#16956), a server error, a body that is not JSON, a body that fails + `validateComfyWorkflow`, and a failed request all resolve to the bundled + graph. Only a 404 is silent, because that is simply what an older backend + says. The rest go through `reportError` with a distinct `errorType`, so a + core that starts serving a workflow this schema rejects is visible. +- The default is a template, not a document, so `getDefaultWorkflow()` never + returns a workflow `id`. The schema and the route's contract both permit one, + and core serves the selected file as-is, so a replacement default could ship + with an exported UUID. `ensureWorkflowId` preserves a valid id on purpose, so + without this every `createTemporary()` would copy that one id into a + different new workflow, leaving new tabs sharing a root graph id and + `openWorkflowPathForGraph` unable to attribute a polled run to a single tab. + The strip lives at that one read, covering the bundled fallback as well as a + served workflow; a second guard at the creation site would be unreachable and + only testable through a state the service cannot produce. Explicitly supplied + or opened workflows keep their ids as before. +- The whole prefetch is bounded, body read included, not just the request. + `fetchApi` clears its timeout once the response arrives, so a backend that + sends headers and then stalls mid-body would otherwise leave `res.json()` + pending and hold the editor closed for as long as the socket lives. On expiry + the bundled graph is used and `setup` continues. +- Builds with `VITE_USE_LEGACY_DEFAULT_GRAPH=true` skip the request entirely. + Those builds run against a real core, so fetching would serve the current + default and undo the test pinning that hundreds of specs depend on. The flag + is read at call time rather than at module load; Vite inlines + `import.meta.env` the same either way, and a call-time read is testable + without resetting the module registry. + +A prefetch was chosen over a fetch per use because the call sites are +synchronous and because core sends `Cache-Control: no-cache` — a reload is the +intended way to pick up a changed default, not a mid-session swap. + +Alternatives considered and rejected: + +- Making the default async end to end. Correct in the abstract, but it turns a + store getter and a tab-creation path async for a value that is known before + the editor opens. +- Mocking the route in the e2e suites instead of skipping the fetch. The + pinning already exists and works; adding a route mock to every spec file + would be a larger change than the feature. +- Serving the default from the workflow templates index, which the frontend + already fetches. It is a different contract with a different owner, and core + wants `server.py` to be the one-line edit. + +## Consequences + +### Positive + +- Core changes the default workflow in a one-line `server.py` edit, with no + frontend release and no core version bump. A CMS can replace the file later + without the frontend noticing. +- Cloud, desktop and platform-specific builds can each serve their own default + from their own backend. +- No user-visible change on this commit: core serves a byte-for-byte copy of + the workflow the frontend already bundles, so the decoupling ships before any + content change does. +- Every backend older than the route keeps working, silently. + +### Negative + +- Boot awaits one more request. It is started early and awaited last, so it + adds nothing unless it outlasts the rest of `setup`. A slow backend can still + delay the editor opening by up to the prefetch bound. +- The default is now a network-dependent value, so two users on the same + frontend build can land on different workflows. That is the point, but it + makes "what did the user see" unanswerable from the frontend version alone. +- A core that serves a workflow this frontend's schema rejects falls back + without telling the user. The fallback is reported, so it is visible in + telemetry rather than only in a console, but nothing tells core at publish + time that its workflow would be refused. A server-side contract test against + this schema is the follow-up. +- E2E builds do not exercise the fetch path at all, by construction. The unit + tests cover it; no browser test does. +- `defaultGraph` remains exported and bundled, so the workflow is still shipped + in the frontend bundle even once core always serves one. It cannot be dropped + while it is the fallback. + +## Notes + +The service and its fallback matrix are covered in +`src/platform/workflow/core/services/defaultWorkflowService.test.ts`. + +Backend half: ComfyUI#16956. Tracked as FE-1178 (frontend) and CORE-340 +(core, done). The community-submission program that motivates the cadence is +still in design and is not part of this decision. diff --git a/src/platform/workflow/core/services/defaultWorkflowService.test.ts b/src/platform/workflow/core/services/defaultWorkflowService.test.ts new file mode 100644 index 00000000000..b958459cec2 --- /dev/null +++ b/src/platform/workflow/core/services/defaultWorkflowService.test.ts @@ -0,0 +1,264 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { reportError } from '@comfyorg/telemetry/reportError' +import type { ComfyWorkflowJSON } from '@comfyorg/graph-model/workflowSchema' +import { api } from '@/scripts/api' +import { blankGraph, defaultGraph } from '@/scripts/defaultGraph' + +import { + getDefaultWorkflow, + initDefaultWorkflow, + resetDefaultWorkflowForTesting +} from './defaultWorkflowService' + +vi.mock(import('@/scripts/api')) +vi.mock(import('@comfyorg/telemetry/reportError')) + +const fetchApi = vi.mocked(api.fetchApi) + +const PREFETCH_TIMEOUT_MS = 10_000 + +const servedWorkflow: ComfyWorkflowJSON = { + ...blankGraph, + last_node_id: 42 +} + +function jsonResponse(body: unknown): Response { + return new Response(JSON.stringify(body), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }) +} + +function errorResponse(status: number): Response { + return new Response('', { status }) +} + +function notJsonResponse(): Response { + return new Response('nope', { + status: 200, + headers: { 'Content-Type': 'text/html' } + }) +} + +function stalledBodyResponse(): Response { + return new Response(new ReadableStream({ start() {} }), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }) +} + +function abortingBodyResponse(signal: AbortSignal): Response { + return new Response( + new ReadableStream({ + start(controller) { + signal.addEventListener('abort', () => { + controller.error( + new DOMException('The operation was aborted.', 'AbortError') + ) + }) + } + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ) +} + +function reportedErrorTypes(): unknown[] { + return vi + .mocked(reportError) + .mock.calls.map(([, context]) => context.errorType) +} + +describe('defaultWorkflowService', () => { + beforeEach(() => { + resetDefaultWorkflowForTesting() + }) + + it('serves the backend workflow once the route has answered', async () => { + fetchApi.mockResolvedValue(jsonResponse(servedWorkflow)) + + await initDefaultWorkflow() + + expect(fetchApi).toHaveBeenCalledWith( + '/default_workflow', + expect.objectContaining({ signal: expect.any(AbortSignal) }) + ) + expect(getDefaultWorkflow()).toEqual(servedWorkflow) + }) + + it('serves the bundled default until the route has answered', async () => { + fetchApi.mockResolvedValue(jsonResponse(servedWorkflow)) + + const ready = initDefaultWorkflow() + expect(getDefaultWorkflow()).toEqual(defaultGraph) + + await ready + }) + + it('falls back to the bundled default on a backend without the route', async () => { + fetchApi.mockResolvedValue(errorResponse(404)) + + await initDefaultWorkflow() + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + }) + + it('does not report a 404, which is how older backends answer', async () => { + fetchApi.mockResolvedValue(errorResponse(404)) + + await initDefaultWorkflow() + + expect(reportError).not.toHaveBeenCalled() + }) + + it('reports a server error and falls back to the bundled default', async () => { + fetchApi.mockResolvedValue(errorResponse(500)) + + await initDefaultWorkflow() + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ + errorType: 'default_workflow_route_unavailable' + }) + ) + }) + + it('reports an invalid workflow and falls back to the bundled default', async () => { + fetchApi.mockResolvedValue(jsonResponse({ not: 'a workflow' })) + + await initDefaultWorkflow() + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'default_workflow_invalid' }) + ) + }) + + it('falls back to the bundled default when the body is not JSON', async () => { + fetchApi.mockResolvedValue(notJsonResponse()) + + await initDefaultWorkflow() + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'default_workflow_fetch_failed' }) + ) + }) + + it('falls back to the bundled default when the request fails outright', async () => { + fetchApi.mockRejectedValue(new TypeError('Failed to fetch')) + + await expect(initDefaultWorkflow()).resolves.toBeUndefined() + expect(getDefaultWorkflow()).toEqual(defaultGraph) + }) + + it('requests the workflow at most once per page load', async () => { + fetchApi.mockResolvedValue(jsonResponse(servedWorkflow)) + + await Promise.all([ + initDefaultWorkflow(), + initDefaultWorkflow(), + initDefaultWorkflow() + ]) + await initDefaultWorkflow() + + expect(fetchApi).toHaveBeenCalledTimes(1) + }) + + it('opens with the bundled default when the request never answers', async () => { + vi.useFakeTimers() + fetchApi.mockReturnValue(new Promise(() => {})) + + const ready = initDefaultWorkflow() + await vi.advanceTimersByTimeAsync(PREFETCH_TIMEOUT_MS) + await ready + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'default_workflow_timed_out' }) + ) + vi.useRealTimers() + }) + + it('opens with the bundled default when headers arrive but the body stalls', async () => { + vi.useFakeTimers() + fetchApi.mockResolvedValue(stalledBodyResponse()) + + const ready = initDefaultWorkflow() + await vi.advanceTimersByTimeAsync(PREFETCH_TIMEOUT_MS) + await ready + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'default_workflow_timed_out' }) + ) + vi.useRealTimers() + }) + + it('aborts a stalled request instead of leaving its body pending', async () => { + vi.useFakeTimers() + fetchApi.mockResolvedValue(stalledBodyResponse()) + + const ready = initDefaultWorkflow() + await vi.advanceTimersByTimeAsync(PREFETCH_TIMEOUT_MS) + await ready + + const [, options] = fetchApi.mock.calls[0] ?? [] + expect(options?.signal?.aborted).toBe(true) + vi.useRealTimers() + }) + + it('reports the timeout once when the abort makes the body reject', async () => { + vi.useFakeTimers() + fetchApi.mockImplementation((_route, options) => + Promise.resolve(abortingBodyResponse(options!.signal!)) + ) + + const ready = initDefaultWorkflow() + await vi.advanceTimersByTimeAsync(PREFETCH_TIMEOUT_MS) + await ready + await vi.advanceTimersByTimeAsync(0) + + expect(getDefaultWorkflow()).toEqual(defaultGraph) + expect(reportedErrorTypes()).toEqual(['default_workflow_timed_out']) + vi.useRealTimers() + }) + + it('serves a workflow that arrived with a document id, without that id', async () => { + fetchApi.mockResolvedValue( + jsonResponse({ + ...servedWorkflow, + id: '11111111-1111-4111-8111-111111111111' + }) + ) + + await initDefaultWorkflow() + + expect(getDefaultWorkflow()).toEqual(servedWorkflow) + }) + + it('never exposes a document id, so each caller mints its own', () => { + expect(getDefaultWorkflow()).not.toHaveProperty('id') + }) +}) + +describe('defaultWorkflowService in e2e builds', () => { + beforeEach(() => { + resetDefaultWorkflowForTesting() + vi.stubEnv('VITE_USE_LEGACY_DEFAULT_GRAPH', 'true') + fetchApi.mockResolvedValue(jsonResponse(servedWorkflow)) + }) + + it('never requests the route, so the pinned test graph stays pinned', async () => { + await initDefaultWorkflow() + + expect(fetchApi).not.toHaveBeenCalled() + expect(getDefaultWorkflow()).toEqual(defaultGraph) + }) +}) diff --git a/src/platform/workflow/core/services/defaultWorkflowService.ts b/src/platform/workflow/core/services/defaultWorkflowService.ts new file mode 100644 index 00000000000..d6427deda7c --- /dev/null +++ b/src/platform/workflow/core/services/defaultWorkflowService.ts @@ -0,0 +1,103 @@ +import type { ComfyWorkflowJSON } from '@comfyorg/graph-model/workflowSchema' +import { validateComfyWorkflow } from '@comfyorg/graph-model/workflowSchema' +import { reportError } from '@comfyorg/telemetry/reportError' + +import { api } from '@/scripts/api' +import { defaultGraph } from '@/scripts/defaultGraph' + +const DEFAULT_WORKFLOW_ROUTE = '/default_workflow' +const PREFETCH_TIMEOUT_MS = 10_000 + +function usesLegacyDefaultGraph(): boolean { + return import.meta.env.VITE_USE_LEGACY_DEFAULT_GRAPH === 'true' +} + +let remoteDefaultWorkflow: ComfyWorkflowJSON | null = null +let prefetch: Promise | null = null + +function reportFallback(cause: unknown, errorType: string): void { + reportError(cause, { errorType, surface: 'graph', level: 'warning' }) +} + +function asTemplate({ + id: _documentId, + ...workflow +}: ComfyWorkflowJSON): ComfyWorkflowJSON { + return workflow +} + +async function readDefaultWorkflow( + signal: AbortSignal +): Promise { + try { + const res = await api.fetchApi(DEFAULT_WORKFLOW_ROUTE, { signal }) + if (!res.ok) { + if (res.status !== 404) { + reportFallback( + new Error(`${DEFAULT_WORKFLOW_ROUTE} responded ${res.status}`), + 'default_workflow_route_unavailable' + ) + } + return null + } + const json: unknown = await res.json() + return await validateComfyWorkflow(json, (error) => { + reportFallback(new Error(error), 'default_workflow_invalid') + }) + } catch (cause) { + if (!signal.aborted) { + reportFallback(cause, 'default_workflow_fetch_failed') + } + return null + } +} + +async function fetchDefaultWorkflow(): Promise { + const controller = new AbortController() + let timer: ReturnType | undefined + const bound = new Promise((resolve) => { + timer = setTimeout(() => { + reportFallback( + new Error( + `${DEFAULT_WORKFLOW_ROUTE} did not settle within ${PREFETCH_TIMEOUT_MS}ms` + ), + 'default_workflow_timed_out' + ) + controller.abort() + resolve(null) + }, PREFETCH_TIMEOUT_MS) + }) + + try { + return await Promise.race([readDefaultWorkflow(controller.signal), bound]) + } finally { + clearTimeout(timer) + } +} + +/** + * Loads the backend's default workflow, if it serves one. Requests it at most + * once per page load and never rejects: every failure resolves to the bundled + * default. + */ +export function initDefaultWorkflow(): Promise { + if (usesLegacyDefaultGraph()) return Promise.resolve() + prefetch ??= fetchDefaultWorkflow().then((workflow) => { + remoteDefaultWorkflow = workflow + }) + return prefetch +} + +/** + * The backend's default workflow when one loaded, otherwise the bundled graph. + * Always free of a document identity, so each caller mints its own. + */ +export function getDefaultWorkflow(): ComfyWorkflowJSON { + return asTemplate(remoteDefaultWorkflow ?? defaultGraph) +} + +/** Drops the prefetched workflow so the request runs again. */ +export function resetDefaultWorkflowForTesting(): void { + remoteDefaultWorkflow = null + prefetch = null +} diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index 0a16d45b1e9..9040407e0e0 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -20,6 +20,7 @@ import { } from '@/platform/workflow/management/stores/comfyWorkflow' import { useSettingStore } from '@/platform/settings/settingStore' import { defaultGraph } from '@/scripts/defaultGraph' +import { getDefaultWorkflow } from '@/platform/workflow/core/services/defaultWorkflowService' import { useToast } from '@/components/ui/toast/toastStore' import type { ComfyWorkflow } from '@/platform/workflow/management/stores/workflowStore' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' @@ -52,6 +53,10 @@ beforeEach(() => { stubFirebaseAuthHarness() }) +function isDefaultWorkflow(data: unknown): boolean { + return JSON.stringify(data) === JSON.stringify(getDefaultWorkflow()) +} + function createModeTestWorkflow( options: { path?: string @@ -2246,7 +2251,7 @@ describe('useWorkflowService', () => { path: 'Unsaved Workflow.json' }) vi.mocked(app.loadGraphData).mockImplementation(async (data) => { - if (data === defaultGraph) + if (isDefaultWorkflow(data)) useWorkflowStore().activeWorkflow = fallback as LoadedComfyWorkflow return true }) diff --git a/src/platform/workflow/core/services/workflowService.ts b/src/platform/workflow/core/services/workflowService.ts index dd84f84303d..79a49ec56ed 100644 --- a/src/platform/workflow/core/services/workflowService.ts +++ b/src/platform/workflow/core/services/workflowService.ts @@ -27,8 +27,9 @@ import type { ComfyWorkflowJSON } from '@comfyorg/graph-model/workflowSchema' // oxlint-disable-next-line comfy/no-restricted-paths import { useWorkflowThumbnail } from '@/renderer/core/thumbnail/useWorkflowThumbnail' import { useApp } from '@/scripts/appInstance' +import { getDefaultWorkflow } from '@/platform/workflow/core/services/defaultWorkflowService' import { ChangeTracker } from '@/scripts/changeTracker' -import { blankGraph, defaultGraph } from '@/scripts/defaultGraph' +import { blankGraph } from '@/scripts/defaultGraph' import { useDialogService } from '@/services/dialogService' import { nodeTypesMayStillArrive } from '@/platform/customNodes/lateLoading/lateNodeTypes' import { showPlaceholdersAsWaiting } from '@/platform/customNodes/lateLoading/waitingNodes' @@ -421,7 +422,7 @@ export const useWorkflowService = () => { * Load the default workflow */ const loadDefaultWorkflow = () => - queueWorkflowLoad(() => useApp().loadGraphData(defaultGraph)) + queueWorkflowLoad(() => useApp().loadGraphData(getDefaultWorkflow())) /** * Load a blank workflow diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index 84aa0c74707..11e33c44ef8 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -1,4 +1,12 @@ -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + assert, + beforeEach, + describe, + expect, + it, + onTestFinished, + vi +} from 'vitest' import { fromAny, fromPartial } from '@total-typescript/shoehorn' import { nextTick, reactive } from 'vue' @@ -17,6 +25,10 @@ import { zComfyWorkflow } from '@comfyorg/graph-model/workflowSchema' import { useWorkflowDraftStoreV2 } from '@/platform/workflow/persistence/stores/workflowDraftStoreV2' import { api } from '@/scripts/api' import { app as comfyApp } from '@/scripts/app' +import { + initDefaultWorkflow, + resetDefaultWorkflowForTesting +} from '@/platform/workflow/core/services/defaultWorkflowService' import { defaultGraph, defaultGraphJSON } from '@/scripts/defaultGraph' import '@/scripts/changeTracker' import { useWidgetHistoryStore } from '@/stores/widgetHistoryStore' @@ -267,6 +279,31 @@ describe('useWorkflowStore', () => { expect(workflow2.path).toBe('workflows/Unsaved Workflow (2).json') }) + it('gives each default-created workflow its own root graph id', async () => { + const servedId = '11111111-1111-4111-8111-111111111111' + onTestFinished(resetDefaultWorkflowForTesting) + resetDefaultWorkflowForTesting() + vi.mocked(api.fetchApi).mockResolvedValue( + new Response( + JSON.stringify({ + ...defaultGraph, + id: servedId, + last_node_id: 4242 + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ) + ) + await initDefaultWorkflow() + + const first = JSON.parse(store.createTemporary().content!) + const second = JSON.parse(store.createTemporary().content!) + + expect(first.last_node_id).toBe(4242) + expect(first.id).toBeTruthy() + expect(first.id).not.toBe(servedId) + expect(second.id).not.toBe(first.id) + }) + it('assigns each workflow a stable unique session identity', async () => { const workflow = store.createTemporary() const otherWorkflow = store.createTemporary() diff --git a/src/platform/workflow/management/stores/workflowStore.ts b/src/platform/workflow/management/stores/workflowStore.ts index d3c7f30a88a..13b2c62b345 100644 --- a/src/platform/workflow/management/stores/workflowStore.ts +++ b/src/platform/workflow/management/stores/workflowStore.ts @@ -23,7 +23,7 @@ import { useWorkflowThumbnail } from '@/renderer/core/thumbnail/useWorkflowThumb import { api } from '@/scripts/api' import { useApp } from '@/scripts/appInstance' import { ChangeTrackerAccess } from '@/scripts/changeTrackerAccess' -import { defaultGraph } from '@/scripts/defaultGraph' +import { getDefaultWorkflow } from '@/platform/workflow/core/services/defaultWorkflowService' import { useDialogService } from '@/services/dialogService' import { useWidgetHistoryStore } from '@/stores/widgetHistoryStore' import { reportError } from '@comfyorg/telemetry/reportError' @@ -275,7 +275,9 @@ export const useWorkflowStore = defineStore('workflow', () => { }) workflow.legacyId = getLegacyWorkflowId(workflowData?.id) - const initialWorkflowData = ensureWorkflowId(workflowData ?? defaultGraph) + const initialWorkflowData = ensureWorkflowId( + workflowData ?? getDefaultWorkflow() + ) workflow.originalContent = workflow.content = JSON.stringify(initialWorkflowData) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 2ff4f7cc1a7..d2fc5909c91 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -61,6 +61,10 @@ import { MIME_ASSET_INFO } from '@/platform/assets/schemas/mediaAssetSchema' import { restoreDynamicGroupInputs } from '@/platform/workflow/core/utils/restoreDynamicGroupInputs' import { updatePendingWarnings } from '@/platform/workflow/core/utils/pendingWarnings' import { useWorkflowService } from '@/platform/workflow/core/services/workflowService' +import { + getDefaultWorkflow, + initDefaultWorkflow +} from '@/platform/workflow/core/services/defaultWorkflowService' import { ComfyWorkflow, useWorkflowStore @@ -183,7 +187,6 @@ import { deserialiseAndCreate } from '@/utils/vintageClipboard' import { PromptExecutionError, api } from './api' import type { ComfyApi } from './api' -import { defaultGraph } from './defaultGraph' import { importA1111 } from './pnginfo' import { applyPromotedWidgetControl } from '@/core/graph/subgraph/promotedWidgetControl' import { syncPromotedComboHostOptions } from '@/core/graph/widgets/syncPromotedComboHostOptions' @@ -863,6 +866,8 @@ export class ComfyApp implements IComfyApp { this.canvasElRef.value = canvasEl + const defaultWorkflowReady = initDefaultWorkflow() + await bootstrapTracer.settle('bootstrap/sync-workflows', () => useWorkspaceStore().workflow.syncWorkflows() ) @@ -971,6 +976,8 @@ export class ComfyApp implements IComfyApp { useExtensionService().invokeExtensionsAsync('setup') ) + await defaultWorkflowReady + this.positionConversion = useCanvasPositionConversion( this.canvasContainer, this.canvas @@ -1225,7 +1232,7 @@ export class ComfyApp implements IComfyApp { typeof graphData !== 'object' || Array.isArray(graphData) ) { - graphData = defaultGraph + graphData = getDefaultWorkflow() reset_invalid_values = true } diff --git a/src/utils/fetchRouteTemplate.ts b/src/utils/fetchRouteTemplate.ts index fe1ee49e206..0386a2152af 100644 --- a/src/utils/fetchRouteTemplate.ts +++ b/src/utils/fetchRouteTemplate.ts @@ -2,6 +2,7 @@ const TELEMETRY_SAFE_ROUTE_GROUPS = new Set([ 'assets', 'billing', 'customers', + 'default_workflow', 'embeddings', 'experiment', 'extensions',