diff --git a/scripts/comfy-host-agent.mjs b/scripts/comfy-host-agent.mjs index 7507d5a..5727dff 100644 --- a/scripts/comfy-host-agent.mjs +++ b/scripts/comfy-host-agent.mjs @@ -67,7 +67,6 @@ const server = http.createServer(async (req, res) => { } if (req.method === 'POST' && url.pathname === '/start') { if (await httpUp()) return json(res, 200, { ok: true, started: false, already: true }) - if (await processUp()) return json(res, 200, { ok: true, started: false, booting: true }) const launched = startComfy() return json(res, 200, { ok: true, ...launched }) } diff --git a/server/utils/comfyLifecycle.ts b/server/utils/comfyLifecycle.ts index 048c856..3c855fd 100644 --- a/server/utils/comfyLifecycle.ts +++ b/server/utils/comfyLifecycle.ts @@ -223,23 +223,27 @@ async function ensureUnlocked(onStatus: StatusFn) { processRunning: true }) const ready = await pollUntilHealthy(cfg.bootPollAttempts, cfg.bootPollDelayMs, onStatus, 'booting', 'Waiting for ComfyUI to finish booting') - if (!ready) { - throw createError({ - statusCode: 503, - statusMessage: 'ComfyUI is running but port 8188 never became ready. Check the desktop instance.' - }) + if (ready) { + await waitWhileBusy(onStatus) + onStatus({ state: 'online', message: 'ComfyUI online', host, processRunning: true }) + return } - await waitWhileBusy(onStatus) - onStatus({ state: 'online', message: 'ComfyUI online', host, processRunning: true }) - return + onStatus({ + state: 'starting', + message: 'ComfyUI is running but the API never came up. Attempting a relaunch...', + host, + processRunning: true + }) } - onStatus({ - state: 'starting', - message: 'ComfyUI is offline. Starting the desktop instance...', - host, - processRunning: false - }) + if (!running) { + onStatus({ + state: 'starting', + message: 'ComfyUI is offline. Starting the desktop instance...', + host, + processRunning: false + }) + } const started = await startComfy() if (!started.started) { throw createError({