From 29184961c41102304cffef542c523a0f39c032f0 Mon Sep 17 00:00:00 2001 From: Towsty Date: Tue, 1 Sep 2026 07:26:21 -0500 Subject: [PATCH] Make GPU wake return before Coolify times out, and skip hung Comfy ports. The site poke hit /start while the agent waited on a dead 8188 probe, so wake looked down even with the host agent running. Co-authored-by: Cursor --- scripts/comfy-host-agent.mjs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/comfy-host-agent.mjs b/scripts/comfy-host-agent.mjs index 6602683..27cc001 100644 --- a/scripts/comfy-host-agent.mjs +++ b/scripts/comfy-host-agent.mjs @@ -68,9 +68,9 @@ function candidatePorts() { return ordered } -async function probeStats(portNum) { +async function probeStats(portNum, timeoutMs = 800) { try { - const res = await fetch(`http://127.0.0.1:${portNum}/system_stats`, { signal: AbortSignal.timeout(2500) }) + const res = await fetch(`http://127.0.0.1:${portNum}/system_stats`, { signal: AbortSignal.timeout(timeoutMs) }) if (!res.ok) return null const stats = await res.json() if (!stats?.system) return null @@ -91,12 +91,11 @@ function advertisedPort(stats) { } async function findHealthyPort() { - const found = [] - for (const next of candidatePorts()) { + const probed = await Promise.all(candidatePorts().map(async (next) => { const stats = await probeStats(next) - if (!stats) continue - found.push({ port: next, advertised: advertisedPort(stats) }) - } + return stats ? { port: next, advertised: advertisedPort(stats) } : null + })) + const found = probed.filter(Boolean) const native = found.find(item => item.advertised && item.advertised === item.port) if (native) return native.port for (const item of found) { @@ -242,11 +241,13 @@ function desktopShellCommand() { async function pythonMainUp() { try { - const { stdout } = await execFileAsync('powershell.exe', [ + const { stdout } = await execFileAsync('tasklist', ['/FO', 'CSV', '/NH'], { windowsHide: true, timeout: 2000 }) + if (!/python(?:w)?\.exe/i.test(stdout)) return false + const { stdout: verbose } = await execFileAsync('powershell.exe', [ '-NoProfile', '-Command', "Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -match 'ComfyUI\\\\main.py|ComfyUI/main.py' } | Select-Object -First 1 -ExpandProperty ProcessId" - ], { windowsHide: true, timeout: 6000 }) - return Boolean(String(stdout).trim()) + ], { windowsHide: true, timeout: 2500 }) + return Boolean(String(verbose).trim()) } catch { return false } @@ -270,7 +271,7 @@ async function pickListenPort() { for (const next of ordered) { if (!next || seen.has(next)) continue seen.add(next) - if (await probeStats(next)) return next + if (await probeStats(next, 400)) return next if (!(await portInUse(next))) return next } return preferred @@ -614,6 +615,10 @@ const server = http.createServer(async (req, res) => { } await taskkillImage('Comfy Desktop.exe') const launched = await startComfy() + if (launched.port) { + lastProcessUp = true + ensureProxy(launched.port) + } return json(res, 200, { ok: true, asleep: false, ...launched }) } if (req.method === 'POST' && url.pathname === '/stop') {