Refuse to start Comfy while AITraining has the GPU.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -109,6 +109,8 @@ async function controlRequest(path: string, method = 'GET', timeoutMs = 5000) {
|
||||
stopped?: boolean
|
||||
killed?: unknown
|
||||
error?: string
|
||||
message?: string
|
||||
training?: { busy?: boolean; jobId?: string | null; status?: string | null; name?: string | null; message?: string }
|
||||
running?: number
|
||||
pending?: number
|
||||
status?: number
|
||||
@@ -118,6 +120,8 @@ async function controlRequest(path: string, method = 'GET', timeoutMs = 5000) {
|
||||
ok: false as const,
|
||||
status: res.status,
|
||||
error: body?.error,
|
||||
message: body?.message,
|
||||
training: body?.training,
|
||||
running: body?.running,
|
||||
pending: body?.pending,
|
||||
killed: body?.killed
|
||||
@@ -133,6 +137,15 @@ export async function fetchComfyControlStatus() {
|
||||
return await controlRequest('/status')
|
||||
}
|
||||
|
||||
function throwIfTrainingBusy(remote: { training?: { busy?: boolean; message?: string }; error?: string; message?: string } | null) {
|
||||
const busy = Boolean(remote?.training?.busy || remote?.error === 'train-busy')
|
||||
if (!busy) return
|
||||
throw createError({
|
||||
statusCode: 409,
|
||||
statusMessage: remote?.training?.message || remote?.message || 'AITraining is using the GPU. Stop that job before poking Comfy.'
|
||||
})
|
||||
}
|
||||
|
||||
export async function requestComfyWake() {
|
||||
const { controlUrl } = settings()
|
||||
if (!controlUrl) {
|
||||
@@ -148,10 +161,11 @@ export async function requestComfyWake() {
|
||||
statusMessage: 'Beast host agent is unreachable. Confirm it is running on the desktop.'
|
||||
})
|
||||
}
|
||||
throwIfTrainingBusy(remote)
|
||||
if (remote.ok === false) {
|
||||
throw createError({
|
||||
statusCode: Number(remote.status) || 502,
|
||||
statusMessage: 'Beast host agent refused to start Comfy.'
|
||||
statusMessage: String(remote.message || remote.error || 'Beast host agent refused to start Comfy.')
|
||||
})
|
||||
}
|
||||
return {
|
||||
@@ -250,6 +264,7 @@ async function startComfy() {
|
||||
lastStartAt = now
|
||||
|
||||
const remote = await controlRequest('/start', 'POST')
|
||||
throwIfTrainingBusy(remote)
|
||||
if (remote?.ok || remote?.started) {
|
||||
log('start-remote', { pid: remote.pid || null })
|
||||
return { started: true, reason: 'remote' as const }
|
||||
@@ -322,6 +337,8 @@ function hostWithPort(host: string, port: number) {
|
||||
async function ensureUnlocked(onStatus: StatusFn, skipBusyWait = false) {
|
||||
const cfg = settings()
|
||||
const host = cfg.host
|
||||
const lock = await controlRequest('/status')
|
||||
throwIfTrainingBusy(lock)
|
||||
onStatus({ state: 'offline', message: 'Checking ComfyUI...', host })
|
||||
|
||||
const health = await checkComfyHttp(cfg.healthTimeoutMs)
|
||||
|
||||
Reference in New Issue
Block a user