Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Worker: a face self-check that didn't finish is tried again before a restart, and a failed one waits 5 minutes

Adarsh995793db0eb9
diff --git a/bin/lib/worker/run.mjs b/bin/lib/worker/run.mjs
index d7fb5615..e8373952 100644
--- a/bin/lib/worker/run.mjs
+++ b/bin/lib/worker/run.mjs
@@ -64,6 +64,10 @@ export function loadRequirements(file = path.join(ROOT, "workflows/comfyui/requi
}
const HOUR = 3_600_000;
+/** After a failed face self-check, the wait before the next try of a check that did not run to the end. */
+export const SELF_CHECK_RETRY_MS = 5_000;
+/** A face self-check that failed twice (once more after a restart of its ComfyUI): face jobs wait this long, then it checks again. */
+export const SELF_CHECK_PAUSE_MS = 5 * 60_000;
/** How long the last counters read that worked stands in for one that failed. */
export const COUNTERS_REUSE_MS = 90_000;
/** Busy readings in a row (5 s apart) that only the GPU's total decided, before they pause the worker. */
@@ -497,15 +501,27 @@ async function work(saved, deps, owner) {
}
/**
* Its face detector's self-check (self-check.mjs) on its GPU ComfyUI, while that ComfyUI has the face nodes. A failure
- * starts its ComfyUI again and checks once more; a second failure pauses the worker ("self-check") for an hour. True
- * when it passed, or when there is nothing to check.
+ * starts its ComfyUI again and checks once more; a second failure pauses face work ("self-check") for
+ * SELF_CHECK_PAUSE_MS (5 minutes). True when it passed, or when there is nothing to check.
*/
async function checkFaces(when) {
if (!faceNodes || !comfy.ready) return true;
const once = () => runSelfCheck((url, init) => comfy.fetch(url, init), comfy.base, { n: ++faceChecks, now, sleep });
- const first = await once();
+ const read = (r) => `${r.height === null ? "no face" : `${Math.round(r.height)} px`} (${r.why}${r.detail ? `: ${r.detail}` : ""})`;
+ let first = await once();
if (first.ok) return true;
- log(`Its face check ${when} read ${first.height === null ? "no face" : `${Math.round(first.height)} px`} (${first.why}): starting its ComfyUI again.`);
+ // A check that didn't run to the end (its graph failed, its photo didn't upload, it timed out) is often a ComfyUI
+ // that has only just started: one more try after a few seconds, before it is started again.
+ if (first.why !== "height" && first.why !== "no-report") {
+ log(`Its face check ${when} didn't finish: ${read(first)}. Trying once more in ${Math.round(SELF_CHECK_RETRY_MS / 1000)} s.`);
+ await sleep(SELF_CHECK_RETRY_MS);
+ first = await once();
+ if (first.ok) {
+ log(`Its face check passed on the second try (${Math.round(first.height)} px).`);
+ return true;
+ }
+ }
+ log(`Its face check ${when} read ${read(first)}: starting its ComfyUI again.`);
// While it starts again, the loop starts no ComfyUI of its own (a start under way already holds `starting`).
const mine = !starting;
const again = (async () => {
@@ -530,7 +546,7 @@ async function work(saved, deps, owner) {
}
comfyTrouble = "self-check";
troubleAt = now();
- log(`Its face check failed again after the restart (${second.why}): face jobs go back in line, and it pauses for an hour.`);
+ log(`Its face check failed again after the restart (${second.why}${second.detail ? `: ${second.detail}` : ""}): face jobs go back in line, and it checks again in ${Math.round(SELF_CHECK_PAUSE_MS / 60_000)} minutes.`);
return false;
}
// One look at a time; the next beat carries a changed hash, and the studio then asks for the list.
@@ -1283,8 +1299,8 @@ async function work(saved, deps, owner) {
awake.set(!!answer?.worker && (busyJob || busyCpu || hold.ids().length > 0 || !!mayWork()));
// A taken port is tried again (a bind test, never a connection) once a minute.
if (comfyTrouble === "port-busy" && t - troubleAt >= 60_000) comfyTrouble = null;
- // A failed face self-check: an hour later its ComfyUI starts again, and checks again first.
- if (comfyTrouble === "self-check" && t - troubleAt >= HOUR) comfyTrouble = null;
+ // A failed face self-check: five minutes later its ComfyUI starts again, and checks again first.
+ if (comfyTrouble === "self-check" && t - troubleAt >= SELF_CHECK_PAUSE_MS) comfyTrouble = null;
const s = state();
if (s !== lastState) {
lastState = s;
diff --git a/bin/lib/worker/self-check.mjs b/bin/lib/worker/self-check.mjs
index c9733dbb..70594253 100644
--- a/bin/lib/worker/self-check.mjs
+++ b/bin/lib/worker/self-check.mjs
@@ -3,7 +3,7 @@
// change nothing. So the worker runs the detector on one fixed photo (its face is about 168 px tall): after each start
// of its ComfyUI, and before each job that detects faces. It takes about a second. A reading outside FACE_RANGE starts
// its ComfyUI again, then checks once more; a second failure gives the job back to the line, and the worker pauses
-// itself ("self-check") for an hour.
+// itself ("self-check") for 5 minutes.
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
@@ -69,6 +69,16 @@ export function faceHeight(report) {
return m ? { min: Number(m[1]), mean: Number(m[2]), max: Number(m[3]) } : null;
}
+/** ComfyUI's reason a check failed, as one short line for the worker's log (no folders: a path keeps only its file name). */
+export function shortDetail(s) {
+ return String(s ?? "")
+ .replace(/[A-Za-z]:[\\/][^\s'"]*[\\/]([^\\/\s'"]+)/g, "$1")
+ .replace(/\/(?:[^/\s'"]+\/)+([^/\s'"]+)/g, "$1")
+ .replace(/\s+/g, " ")
+ .trim()
+ .slice(0, 200);
+}
+
/** Does this reading pass? Every frame's height (one frame here) has to be inside FACE_RANGE. */
export const facePasses = (h) => !!h && h.min >= FACE_RANGE.min && h.max <= FACE_RANGE.max;
@@ -86,8 +96,8 @@ export async function runSelfCheck(fetchFn, base, o = {}) {
form.append("image", new Blob([photo], { type: "image/jpeg" }), SELF_CHECK_INPUT);
form.append("overwrite", "true");
form.append("type", "input");
- const up = await fetchFn(`${base}/upload/image`, { method: "POST", body: form }).catch(() => null);
- if (!up?.ok) return { ok: false, height: null, why: "upload" };
+ const up = await fetchFn(`${base}/upload/image`, { method: "POST", body: form }).catch((e) => ({ ok: false, status: 0, text: async () => String(e?.message ?? e) }));
+ if (!up?.ok) return { ok: false, height: null, why: "upload", detail: shortDetail(`HTTP ${up?.status ?? 0} ${await up?.text?.().catch(() => "")}`) };
const sent = await fetchFn(`${base}/prompt`, json({ prompt: selfCheckGraph(o.n ?? 0), client_id: o.clientId ?? "fuobe-self-check" })).catch(() => null);
const id = sent?.ok ? (await sent.json().catch(() => ({})))?.prompt_id : null;
if (typeof id !== "string" || !id) return { ok: false, height: null, why: "refused" };
@@ -108,7 +118,10 @@ export async function runSelfCheck(fetchFn, base, o = {}) {
await fetchFn(`${base}/interrupt`, json({ prompt_id: id })).catch(() => null);
return { ok: false, height: null, why: "timeout" };
}
- if (entry.status?.status_str === "error") return { ok: false, height: null, why: "failed" };
+ if (entry.status?.status_str === "error") {
+ const err = (entry.status.messages ?? []).find((m) => Array.isArray(m) && m[0] === "execution_error")?.[1];
+ return { ok: false, height: null, why: "failed", detail: err ? shortDetail(`${err.node_type ?? ""}: ${err.exception_type ?? ""} ${err.exception_message ?? ""}`) : null };
+ }
const text = entry.outputs?.["3"]?.text;
const h = faceHeight(Array.isArray(text) ? text.join("\n") : text);
if (!h) return { ok: false, height: null, why: "no-report" };
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index 0ce90340..7b35227d 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -216,7 +216,7 @@ export function workerState(w: WorkerRow, now = Date.now()): { state: WorkerStat
if (why.startsWith("gpu-busy")) return { state: "gpu-busy", words: `Your GPU is busy${why.includes(":") ? ` (${why.split(":").slice(1).join(":")})` : ""}` };
if (why === "comfy-crashes") return { state: "comfy-down", words: "ComfyUI keeps stopping" };
if (why === "port-busy") return { state: "comfy-down", words: "Its ComfyUI port is taken by another program" };
- if (why === "self-check") return { state: "comfy-down", words: "Its face check didn't pass after a restart: it starts its ComfyUI again within the hour" };
+ if (why === "self-check") return { state: "comfy-down", words: "Its face check didn't pass after a restart: it checks again within 5 minutes" };
// A model folder isn't there yet (a drive still locked after a restart): it waits for it, with its lanes as they were.
if (why === MODELS_NOT_READY) return { state: "models-not-ready", words: "Waiting for its model folders" };
return { state: "paused", words: w.local_until ? `Paused here until ${clock(w.local_until, tz)}` : "Paused here" };
diff --git a/tests/worker-self-check.test.ts b/tests/worker-self-check.test.ts
index 34d5f329..ebb0469c 100644
--- a/tests/worker-self-check.test.ts
+++ b/tests/worker-self-check.test.ts
@@ -6,7 +6,7 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
-import { detectsFaces, FACE_DETECTOR, FACE_RANGE, faceHeight, facePasses, runSelfCheck, SELF_CHECK_INPUT, SELF_CHECK_PHOTO, selfCheckGraph } from "../bin/lib/worker/self-check.mjs";
+import { detectsFaces, FACE_DETECTOR, FACE_RANGE, faceHeight, facePasses, runSelfCheck, SELF_CHECK_INPUT, SELF_CHECK_PHOTO, selfCheckGraph, shortDetail } from "../bin/lib/worker/self-check.mjs";
const ROOT = path.resolve(__dirname, "..");
const report = (min: number, mean: number, max: number) =>
@@ -112,4 +112,21 @@ describe("one check against its ComfyUI", () => {
expect(r).toMatchObject({ ok: false, why: "timeout" });
expect(silent.calls.some((x) => new URL(x.url).pathname === "/interrupt")).toBe(true);
});
+
+ it("says why it failed: ComfyUI's error, or the upload's answer, with no folders in it", async () => {
+ const failing = standIn({ status: "error" });
+ const fetchFn = async (url: string, init?: RequestInit) => {
+ if (new URL(url).pathname === "/history/check-1") {
+ const messages = [["execution_start", {}], ["execution_error", { node_type: "LoadImage", exception_type: "PermissionError", exception_message: "[Errno 13] Permission denied: 'X:\\fuobe-worker\\work\\input\\fuobe-self-check.jpg'" }]];
+ return new Response(JSON.stringify({ "check-1": { status: { status_str: "error", completed: false, messages }, outputs: {} } }), { status: 200 });
+ }
+ return failing.fetchFn(url, init);
+ };
+ const r = await runSelfCheck(fetchFn, base, fast);
+ expect(r).toMatchObject({ ok: false, why: "failed" });
+ expect(r.detail).toBe("LoadImage: PermissionError [Errno 13] Permission denied: 'fuobe-self-check.jpg'");
+ expect(await runSelfCheck(standIn({ uploadOk: false }).fetchFn, base, fast)).toMatchObject({ why: "upload", detail: "HTTP 500 no" });
+ expect(shortDetail("OSError: /home/x/models/face/model.onnx not found " + "z".repeat(400)).startsWith("OSError: model.onnx not found")).toBe(true);
+ expect(shortDetail("z".repeat(400))).toHaveLength(200);
+ });
});