Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(comfy): a restart that cannot reach the engine says so

David8d8d3cb546ec
diff --git a/src/api/__tests__/comfy-restart.test.ts b/src/api/__tests__/comfy-restart.test.ts
new file mode 100644
index 00000000..255bab70
--- /dev/null
+++ b/src/api/__tests__/comfy-restart.test.ts
@@ -0,0 +1,66 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+
+const backendCall = vi.fn()
+const checkComfyConnection = vi.fn()
+
+vi.mock('../backend', () => ({ backendCall: (...a: unknown[]) => backendCall(...a) }))
+vi.mock('../comfyui', () => ({ checkComfyConnection: () => checkComfyConnection() }))
+
+import { restartComfyForNewNodes } from '../comfy-restart'
+
+/**
+ * Der Fall stammt vom 15.08.2026 von der Testmaschine. ComfyUI lief dort nicht
+ * als Kind von LU. `stop_comfyui` hat deshalb nichts beendet, der alte Prozess
+ * hat weiter geantwortet, der neu gestartete kam nie an den Port, und die
+ * Oberflaeche schickte den Nutzer in ein Startprotokoll, in dem der gesuchte
+ * Fehler gar nicht stehen konnte.
+ */
+describe('Neustart fuer frisch installierte Knoten', () => {
+ beforeEach(() => {
+ vi.useFakeTimers()
+ backendCall.mockReset().mockResolvedValue(undefined)
+ checkComfyConnection.mockReset()
+ })
+
+ const lauf = async (p: Promise<unknown>) => {
+ const gefangen = p.then((r) => ({ ok: true, r }), (e: Error) => ({ ok: false, e: e.message }))
+ await vi.runAllTimersAsync()
+ return gefangen
+ }
+
+ it('ein fremdes ComfyUI wird benannt statt still uebergangen', async () => {
+ checkComfyConnection.mockResolvedValue(true)
+ const r = await lauf(restartComfyForNewNodes())
+ expect(r).toMatchObject({ ok: false })
+ expect((r as { e: string }).e).toContain('running outside LU')
+ // Und vor allem: es wird kein zweiter Prozess danebengestartet.
+ expect(backendCall.mock.calls.map((c) => c[0])).toEqual(['stop_comfyui'])
+ })
+
+ it('das eigene ComfyUI wird gestoppt und wieder gestartet', async () => {
+ checkComfyConnection.mockResolvedValue(false)
+ const r = await lauf(restartComfyForNewNodes())
+ expect(r).toMatchObject({ ok: true })
+ expect(backendCall.mock.calls.map((c) => c[0])).toEqual(['stop_comfyui', 'start_comfyui'])
+ })
+
+ it('ein langsamer Stopp ist kein fremder Prozess', async () => {
+ // Zwei Runden lang antwortet der Port noch, dann ist er still.
+ checkComfyConnection
+ .mockResolvedValueOnce(true)
+ .mockResolvedValueOnce(true)
+ .mockResolvedValue(false)
+ const r = await lauf(restartComfyForNewNodes())
+ expect(r).toMatchObject({ ok: true })
+ expect(backendCall.mock.calls.map((c) => c[0])).toEqual(['stop_comfyui', 'start_comfyui'])
+ })
+
+ it('ein Stopp, der gar nicht geht, haelt den Neustart nicht auf', async () => {
+ backendCall.mockImplementation((cmd: string) =>
+ cmd === 'stop_comfyui' ? Promise.reject(new Error('not running')) : Promise.resolve(undefined))
+ checkComfyConnection.mockResolvedValue(false)
+ const r = await lauf(restartComfyForNewNodes())
+ expect(r).toMatchObject({ ok: true })
+ expect(backendCall.mock.calls.map((c) => c[0])).toEqual(['stop_comfyui', 'start_comfyui'])
+ })
+})
diff --git a/src/api/comfy-restart.ts b/src/api/comfy-restart.ts
new file mode 100644
index 00000000..869bc8d4
--- /dev/null
+++ b/src/api/comfy-restart.ts
@@ -0,0 +1,39 @@
+import { backendCall } from './backend'
+import { checkComfyConnection } from './comfyui'
+
+/**
+ * Restart ComfyUI so a freshly installed node pack registers, because packs
+ * only load at startup.
+ *
+ * `stop_comfyui` can only kill the ComfyUI that LU itself spawned. Started from
+ * a terminal, a batch file or ComfyUI Desktop, the old process keeps the port
+ * and keeps serving its old node list, while the process LU starts next never
+ * gets the port at all. Everything downstream then looks like a broken install:
+ * the connection check says the engine is up, the node is still missing, and
+ * the user is sent to hunt an IMPORT FAILED line that was never written,
+ * because that process never tried the import.
+ *
+ * Measured on the test box on 2026-08-15: two python.exe alive, VHS_VideoCombine
+ * installed on disk and absent from the answering /object_info, no import error
+ * anywhere in the log. Killing both and starting once listed all 40 VHS nodes.
+ *
+ * So: stop, then confirm the port actually went quiet before starting again.
+ * Whatever still answers after that is an engine LU does not own, and the only
+ * honest thing to do is say so.
+ */
+export async function restartComfyForNewNodes(): Promise<void> {
+ try { await backendCall('stop_comfyui') } catch { /* may already be stopped */ }
+ // stop_comfyui reaps its child before returning, so LU's own engine is down
+ // by now — poll a few extra rounds anyway instead of trusting one sleep.
+ let stillUp = await checkComfyConnection()
+ for (let i = 0; stillUp && i < 5; i++) {
+ await new Promise((r) => setTimeout(r, 2000))
+ stillUp = await checkComfyConnection()
+ }
+ if (stillUp) {
+ throw new Error(
+ 'Your ComfyUI is running outside LU, so LU cannot restart it. New node packs only load on startup: restart your ComfyUI yourself, then come back here.',
+ )
+ }
+ await backendCall('start_comfyui')
+}
diff --git a/src/components/create/experimental/CreateContext.tsx b/src/components/create/experimental/CreateContext.tsx
index 566fc516..2ce2007b 100644
--- a/src/components/create/experimental/CreateContext.tsx
+++ b/src/components/create/experimental/CreateContext.tsx
@@ -12,14 +12,9 @@ import { useDownloadStore } from '../../../stores/downloadStore'
import { downloadBundleFiles, waitOrAbort, waitForModelsVisible } from '../../../lib/bundle-install'
import { ensureLocalFilename } from './loadImage'
import { comfyStartupError } from './comfyError'
+import { restartComfyForNewNodes } from '../../../api/comfy-restart'
import type { CloudQuota } from '../../../lib/render/cloud-jobs'
-/** Restart ComfyUI so a freshly installed node pack registers (packs only load
- * on startup). stop_comfyui can only kill the ComfyUI that LU itself spawned:
- * if the engine was started outside LU (user's own terminal/script), the old
- * process keeps the port and keeps serving the stale node list — the pack
- * would look installed but never show up, and the register-poll would burn
- * 40s to end in a misleading error. Detect that case and state the real fix. */
/** Hold until nothing is rendering, so a heal never lands on a live job.
* Bounded: a render that never reports finished must not park an install
* forever, and the caller falls back to the plain-language error either way. */
@@ -43,24 +38,6 @@ async function waitForComfyBack(onStatus?: (m: string) => void, signal?: AbortSi
return await checkComfyConnection()
}
-async function restartComfyForNewNodes(): Promise<void> {
- try { await backendCall('stop_comfyui') } catch { /* may already be stopped */ }
- // stop_comfyui reaps its child before returning, so LU's own engine is down
- // by now — poll a few extra rounds anyway instead of trusting one sleep.
- // Whatever still answers after that is an engine LU does not own.
- let stillUp = await checkComfyConnection()
- for (let i = 0; stillUp && i < 5; i++) {
- await new Promise((r) => setTimeout(r, 2000))
- stillUp = await checkComfyConnection()
- }
- if (stillUp) {
- throw new Error(
- 'Your ComfyUI is running outside LU, so LU cannot restart it. New node packs only load on startup: restart your ComfyUI yourself, then come back here.',
- )
- }
- await backendCall('start_comfyui')
-}
-
/**
* The seam between the redesigned Create surface and the live backend. Replaces
* the sandbox mockStore's non-persisted actions (generate/cancel) and mockComfy
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index 3f79ce0c..68a406da 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -38,6 +38,7 @@ import {
} from '../api/comfyui-ws'
import { buildDynamicWorkflow, buildLocalOpWorkflow, checkVideoOutputCapability } from '../api/dynamic-workflow'
import { getAllNodeInfo, clearNodeCache } from '../api/comfyui-nodes'
+import { restartComfyForNewNodes } from '../api/comfy-restart'
import { installCustomNodes } from '../api/discover'
import { backendCall } from '../api/backend'
import { checkPromptSafety, SAFETY_BLOCK_MESSAGE } from '../lib/render/safety'
@@ -942,11 +943,13 @@ export function useCreate() {
try {
await installCustomNodes(['videohelpersuite'])
setProgress(9, 'Restarting ComfyUI to register the new node...')
- try {
- await backendCall('stop_comfyui')
- } catch { /* may already be stopped */ }
- await new Promise(r => setTimeout(r, 2000))
- await backendCall('start_comfyui')
+ // Shared with the Create surface on purpose. The version that
+ // used to live here trusted "something answers on the port"
+ // as proof of a restart, which is exactly wrong when the
+ // engine was started outside LU: the old process keeps the
+ // port and its old node list, and the error below then sent
+ // people hunting an IMPORT FAILED line nobody ever wrote.
+ await restartComfyForNewNodes()
// Wait for ComfyUI to come back; poll /object_info up to 30s
let backUp = false
for (let i = 0; i < 15; i++) {
diff --git a/src/lib/__tests__/model-visible-wait.test.ts b/src/lib/__tests__/model-visible-wait.test.ts
index 748d5c20..4f6aa862 100644
--- a/src/lib/__tests__/model-visible-wait.test.ts
+++ b/src/lib/__tests__/model-visible-wait.test.ts
@@ -179,7 +179,11 @@ describe('the install path uses it, and says something honest when it runs out',
})
it('coming back up must not trigger a multi gigabyte install behind the download', () => {
- const helper = src.slice(src.indexOf('async function waitForComfyBack'), src.indexOf('async function restartComfyForNewNodes'))
+ // Endanker ist der Kommentar der naechsten Deklaration. Vorher stand hier
+ // `restartComfyForNewNodes`, die seit dem 15.08. in `api/comfy-restart.ts`
+ // liegt, weil der Generate-Pfad dieselbe Fassung braucht. Ein Anker, der
+ // nicht mehr existiert, liefert -1 und schneidet die ganze Datei mit.
+ const helper = src.slice(src.indexOf('async function waitForComfyBack'), src.indexOf('The seam between the redesigned Create surface'))
expect(helper).not.toContain('install_comfyui')
})
})