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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Workers: the automatic resume can be switched on from the Workers page
Adarshce9f3eab5fce
diff --git a/bin/lib/worker/config.mjs b/bin/lib/worker/config.mjsindex 22a68498..f8f12021 100644--- a/bin/lib/worker/config.mjs+++ b/bin/lib/worker/config.mjs@@ -17,7 +17,7 @@ export const DEFAULTS = {port: 8190,/** Another program's VRAM above this pauses the worker. */busyVramMb: 1024,- /** The automatic resume: off unless switched on for this PC. */+ /** The automatic resume: off unless switched on for this PC (here, or on the studio's Workers page). */autoResume: false,/** The GPU must stay free this long before an automatic resume, and be cooler than this. */resumeAfterMin: 10,diff --git a/bin/lib/worker/run.mjs b/bin/lib/worker/run.mjsindex 262127e8..0858314e 100644--- a/bin/lib/worker/run.mjs+++ b/bin/lib/worker/run.mjs@@ -99,7 +99,12 @@ export async function runWorker(cfg, deps) {inventoryHash: invHash,warmLane: null,}),- onBeat: (a) => (answer = a),+ onBeat: (a) => {+ answer = a;+ // The owner's switch on the Workers page wins over worker.json; null leaves worker.json's.+ const site = a?.worker?.autoResume;+ gpu.o.autoResume = typeof site === "boolean" ? site : !!cfg.autoResume;+ },},{ device: "worker", port: cfg.port, clientId: crypto.randomBytes(8).toString("hex") },);diff --git a/src/app/api/admin/workers/[id]/route.ts b/src/app/api/admin/workers/[id]/route.tsindex a5097829..c8803c1a 100644--- a/src/app/api/admin/workers/[id]/route.ts+++ b/src/app/api/admin/workers/[id]/route.ts@@ -4,7 +4,7 @@ import { patchWorker, type WorkerPatch } from "@/server/computer/pool";const NO_STORE = { "Cache-Control": "no-store" };/**- * Change a worker (owner only): `{ paused, pauseNow, drain, hours, allow, claimAfterMs, switchAfterMs, rotate, revoke }`.+ * Change a worker (owner only): `{ paused, pauseNow, drain, autoResume, hours, allow, claimAfterMs, switchAfterMs, rotate, revoke }`.* Each reaches the worker at its next beat. Rotate answers with the new token, once; revoke stops the old token at once* and puts its job back in line.*/diff --git a/src/components/workers-admin.tsx b/src/components/workers-admin.tsxindex 57491267..c7e246c5 100644--- a/src/components/workers-admin.tsx+++ b/src/components/workers-admin.tsx@@ -32,6 +32,7 @@ interface WorkerView {pausedServer: boolean;pausedLocal: boolean;drain: boolean;+ autoResume: boolean | null;hours: Hours | null;allow: Record<string, { delayMs: number }>;lanes: string[];@@ -207,6 +208,22 @@ function WorkerCard({ w, lanes, onToken }: { w: WorkerView; lanes: Lane[]; onTok</div></div><p className="text-[12px] text-muted-foreground">{hoursWords(w.hours)}</p>+ <label className="flex items-start gap-2 text-[13px]">+ <input+ type="checkbox"+ className="mt-0.5 size-4 accent-[var(--primary)]"+ checked={!!w.autoResume}+ disabled={patch.isPending}+ onChange={(e) => patch.mutate({ autoResume: e.target.checked })}+ />+ <span>+ Resume by itself after another program used the GPU+ <span className="block text-[12px] text-muted-foreground">+ Once the GPU has been free for its cool-down. A pause by hand always waits for a resume by hand.+ {w.autoResume === null && " Now: as the PC's own setting says."}+ </span>+ </span>+ </label><HoursEditor w={w} onSave={(hours) => patch.mutate({ hours })} /><LanesEditor key={JSON.stringify(w.allow)} w={w} lanes={lanes} onSave={(allow) => patch.mutate({ allow })} /><div className="flex flex-wrap gap-1.5 border-t pt-2">diff --git a/src/lib/relay.ts b/src/lib/relay.tsindex 8ceebe13..4a6fce4f 100644--- a/src/lib/relay.ts+++ b/src/lib/relay.ts@@ -159,6 +159,8 @@ export interface WorkerAnswer {pauseNow: boolean;/** Finish the current job, then take nothing new. */drain: boolean;+ /** The automatic resume after a busy GPU, as the owner set it; null: the worker's own setting. */+ autoResume: boolean | null;insideHours: boolean;/** When its hours start or end next. */nextChangeAt: number | null;diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex d83de66f..60c121a1 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -167,6 +167,7 @@ export function workerBeat(w: WorkerRow, b: WorkerBeat, now = Date.now()): BeatApaused: !!fresh.paused_server,pauseNow: stopNow,drain: !!fresh.drain,+ autoResume: fresh.auto_resume === null || fresh.auto_resume === undefined ? null : !!fresh.auto_resume,insideHours: h.inside,nextChangeAt: h.nextChangeAt,lanes: Object.keys(allowOf(fresh)),@@ -424,6 +425,7 @@ export interface WorkerView {pausedLocal: boolean;localWhy: string | null;drain: boolean;+ autoResume: boolean | null;hours: Hours | null;allow: Record<string, Allow>;claimAfterMs: number;@@ -454,6 +456,7 @@ export function workerView(w: WorkerRow, now = Date.now()): WorkerView {pausedLocal: !!w.paused_local,localWhy: w.local_why,drain: !!w.drain,+ autoResume: w.auto_resume === null || w.auto_resume === undefined ? null : !!w.auto_resume,hours: hoursOf(w),allow: allowOf(w),claimAfterMs: w.claim_after_ms,@@ -487,6 +490,8 @@ export interface WorkerPatch {paused?: boolean;pauseNow?: boolean;drain?: boolean;+ /** true or false sets the automatic resume for this worker; null leaves it to the worker's worker.json. */+ autoResume?: boolean | null;hours?: unknown;allow?: unknown;claimAfterMs?: number;@@ -513,6 +518,10 @@ export function patchWorker(id: string, p: WorkerPatch, now = Date.now()): { vie}if (p.pauseNow) Object.assign(set, { paused_server: 1, stop_now: 1 });if (p.drain !== undefined) set.drain = p.drain ? 1 : 0;+ if (p.autoResume !== undefined) {+ if (p.autoResume !== null && typeof p.autoResume !== "boolean") throw new Error("The automatic resume is on, off or the PC's own setting");+ set.auto_resume = p.autoResume === null ? null : p.autoResume ? 1 : 0;+ }if (p.hours !== undefined) {if (p.hours !== null && !parseHours(p.hours)) throw new Error("Hours need a time zone and windows like 01:00–09:00");set.hours_json = p.hours === null ? null : JSON.stringify(parseHours(p.hours));diff --git a/src/server/computer/workers.ts b/src/server/computer/workers.tsindex fc610053..3cfe6f5b 100644--- a/src/server/computer/workers.ts+++ b/src/server/computer/workers.ts@@ -52,6 +52,8 @@ export interface WorkerRow {local_until: number | null;drain: number;stop_now: number;+ /** The automatic resume after a busy GPU: 1 on, 0 off, NULL as the worker's own worker.json says. */+ auto_resume: number | null;hours_json: string | null;allow_json: string | null;claim_after_ms: number;diff --git a/src/server/db.ts b/src/server/db.tsindex 000446ad..41614237 100644--- a/src/server/db.ts+++ b/src/server/db.ts@@ -695,6 +695,7 @@ export const RELAY_TABLES = `CREATE TABLE IF NOT EXISTS relay_runners (local_until INTEGER,drain INTEGER NOT NULL DEFAULT 0,stop_now INTEGER NOT NULL DEFAULT 0,+ auto_resume INTEGER,hours_json TEXT,allow_json TEXT,claim_after_ms INTEGER NOT NULL DEFAULT 0,diff --git a/tests/e2e/worker.mjs b/tests/e2e/worker.mjsindex 9d417f00..b34087df 100644--- a/tests/e2e/worker.mjs+++ b/tests/e2e/worker.mjs@@ -7,8 +7,9 @@//// Checks: the owner adds a worker, and it starts paused; resumed in both places with hours and a lane, it runs the// owner's run to the end and cleans up its ComfyUI's history; another program on the GPU (per-process memory [N/A])-// pauses it and its ComfyUI is gone within 10 s; with the automatic resume off it stays paused, and a resume by hand-// brings it back; pause --now sends a running job back in line and stops its ComfyUI; a port another program holds is+// pauses it and its ComfyUI is gone within 10 s; with the automatic resume off it stays paused, a resume by hand+// brings it back, and with it turned on from the website it comes back by itself after the cool-down;+// pause --now sends a running job back in line and stops its ComfyUI; a port another program holds is// never used or connected to.import { spawn } from "node:child_process";import fs from "node:fs";@@ -105,7 +106,7 @@ try {// This PC: set up (as `worker setup` writes it), paused here at first.fs.mkdirSync(home, { recursive: true });- fs.writeFileSync(path.join(home, "worker.json"), JSON.stringify({ site: SITE, token: added.body.token, comfyDir: workDir, workDir, modelDirs: [], port: COMFY_PORT, nvidiaSmi: [process.execPath, path.join(root, "tests/helpers/fake-nvidia-smi.mjs"), smiState], autoResume: false, busyVramMb: 1024 }));+ fs.writeFileSync(path.join(home, "worker.json"), JSON.stringify({ site: SITE, token: added.body.token, comfyDir: workDir, workDir, modelDirs: [], port: COMFY_PORT, nvidiaSmi: [process.execPath, path.join(root, "tests/helpers/fake-nvidia-smi.mjs"), smiState], autoResume: false, resumeAfterMin: 0.1, busyVramMb: 1024 }));fs.writeFileSync(path.join(home, "control.json"), JSON.stringify({ paused: true }));smi({ usedMb: 300, tempC: 45, apps: [] });startWorker();@@ -154,6 +155,19 @@ try {await cli("resume");check("a resume by hand brings it back", !!(await until(comfyUp, 30_000)));+ // The owner turns the automatic resume on in Settings → Workers (a 6 s cool-down in this worker.json): busy, then free,+ // and it comes back by itself.+ await owner(`/api/admin/workers/${id}`, { method: "PATCH", body: JSON.stringify({ autoResume: true }) });+ check("the website shows the automatic resume on", (await view()).autoResume === true);+ await sleep(7_000); // one beat carries it to the worker+ smi({ usedMb: 6000, tempC: 60, apps: [{ pid: 999999, name: "blender.exe", usedMb: null }] });+ check("with it on, a busy GPU still stops its ComfyUI", !!(await until(async () => !(await comfyUp()), 15_000)));+ smi({ usedMb: 300, tempC: 45, apps: [] });+ const t2 = Date.now();+ const back2 = await until(comfyUp, 45_000);+ check("after the cool-down it resumes by itself", !!back2 && Date.now() - t2 >= 6_000, `${Date.now() - t2} ms`);+ await owner(`/api/admin/workers/${id}`, { method: "PATCH", body: JSON.stringify({ autoResume: null }) });+// pause --now: a running job goes back in line and its ComfyUI stops within 30 s.await stopWorker();startWorker(60);diff --git a/tests/workers-pool.test.ts b/tests/workers-pool.test.tsindex df8e3c1a..44ce31e3 100644--- a/tests/workers-pool.test.ts+++ b/tests/workers-pool.test.ts@@ -238,6 +238,18 @@ describe("losing a worker (checks 3, 4, 5)", () => {expect(pool.workerState(row(w), clock).words).toBe("Your GPU is busy (python.exe)");});+ it("the automatic resume: the PC's own setting until the owner sets it on the website", () => {+ const w = worker("auto");+ expect(beat(w).worker.autoResume).toBeNull();+ expect(pool.patchWorker(w.id, { autoResume: true }).view?.autoResume).toBe(true);+ expect(beat(w).worker.autoResume).toBe(true);+ pool.patchWorker(w.id, { autoResume: false });+ expect(beat(w).worker.autoResume).toBe(false);+ pool.patchWorker(w.id, { autoResume: null });+ expect(beat(w).worker.autoResume).toBeNull();+ expect(() => pool.patchWorker(w.id, { autoResume: "yes" as unknown as boolean })).toThrow();+ });+it("a task past its wait limit fails, not charged", () => {const id = task({ notAfter: clock + MIN });clock += 2 * MIN;