Stop idle Comfy after 30 minutes and add a Wake GPU poke.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-08-29 17:59:18 -05:00
co-authored by Cursor
parent cdc69d2bd6
commit ad1f4f905a
8 changed files with 283 additions and 26 deletions
+5
View File
@@ -0,0 +1,5 @@
import { requestComfyWake } from '~/server/utils/comfyLifecycle'
export default defineEventHandler(async () => {
return await requestComfyWake()
})
+7 -3
View File
@@ -1,4 +1,4 @@
import { checkComfyHttp, fetchQueue } from '~/server/utils/comfyLifecycle'
import { checkComfyHttp, fetchQueue, fetchComfyControlStatus } from '~/server/utils/comfyLifecycle'
import { comfyConfigured } from '~/server/utils/comfy'
import { imageComfyConfigured, getBeastImageHost, getSidecarImageHost, sameImageHost } from '~/server/utils/imageComfy'
import { checkImageComfyHttp, fetchQueueAt } from '~/server/utils/imageComfyLifecycle'
@@ -9,7 +9,7 @@ export default defineEventHandler(async () => {
const beastHost = getBeastImageHost()
const promptHost = getSidecarImageHost()
const promptIsBeast = Boolean(promptHost && beastHost && sameImageHost(promptHost, beastHost))
const [comfy, queue, beast, beastQueue, prompt, promptQueue] = await Promise.all([
const [comfy, queue, beast, beastQueue, prompt, promptQueue, control] = await Promise.all([
videoConfigured
? checkComfyHttp().catch(() => ({ ok: false, host: '', stats: null }))
: Promise.resolve({ ok: false, host: '', stats: null }),
@@ -21,7 +21,8 @@ export default defineEventHandler(async () => {
promptHost && !promptIsBeast
? checkImageComfyHttp(5000, promptHost).catch(() => ({ ok: false, host: promptHost, stats: null }))
: Promise.resolve({ ok: false, host: promptHost, stats: null }),
promptHost && !promptIsBeast ? fetchQueueAt(promptHost) : Promise.resolve({ running: 0, pending: 0, ok: false })
promptHost && !promptIsBeast ? fetchQueueAt(promptHost) : Promise.resolve({ running: 0, pending: 0, ok: false }),
fetchComfyControlStatus().catch(() => null)
])
const comfyReachable = Boolean(comfy.ok || queue.ok)
const beastReachable = Boolean(beast.ok || beastQueue.ok || comfyReachable)
@@ -43,6 +44,9 @@ export default defineEventHandler(async () => {
host: comfy.host || '',
queueRunning: queue.running,
queuePending: queue.pending,
asleep: Boolean(control?.asleep) && !comfyReachable,
processUp: Boolean(control?.process ?? control?.processUp),
lastActivityAt: control?.lastActivityAt || null,
stats: comfy.ok ? comfy.stats : undefined
},
imageComfy: {
+42
View File
@@ -98,17 +98,59 @@ async function controlRequest(path: string, method = 'GET') {
ok?: boolean
http?: boolean
process?: boolean
processUp?: boolean
asleep?: boolean
lastActivityAt?: string | null
idleMs?: number
pid?: number
started?: boolean
already?: boolean
port?: number | null
proxyPort?: number | null
stopped?: boolean
error?: string
status?: number
}
} catch {
return null
}
}
export async function fetchComfyControlStatus() {
return await controlRequest('/status')
}
export async function requestComfyWake() {
const { controlUrl } = settings()
if (!controlUrl) {
throw createError({
statusCode: 503,
statusMessage: 'COMFY_CONTROL_URL is not set. The studio cannot poke the Beast host agent.'
})
}
const remote = await controlRequest('/start', 'POST')
if (!remote) {
throw createError({
statusCode: 503,
statusMessage: 'Beast host agent is unreachable. Confirm it is running on the desktop.'
})
}
if (remote.ok === false) {
throw createError({
statusCode: Number(remote.status) || 502,
statusMessage: 'Beast host agent refused to start Comfy.'
})
}
return {
ok: true,
started: Boolean(remote.started),
already: Boolean(remote.already),
asleep: false,
port: remote.port ?? null,
proxyPort: remote.proxyPort ?? null
}
}
async function findLocalComfyProcess() {
const platform = process.platform
try {