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.

Workers: one busy reading neither begins nor ends a turn

Adarsh81817243f3ad
diff --git a/bin/lib/worker/run.mjs b/bin/lib/worker/run.mjs
index 9d4fa854..b197a8be 100644
--- a/bin/lib/worker/run.mjs
+++ b/bin/lib/worker/run.mjs
@@ -471,8 +471,9 @@ export async function runWorker(cfg, deps) {
const workHolds = (split?.workMb ?? 0) > busyMb;
const was = turn;
turn = turns.step(t, {
- // A busy reading that may still turn into a pause asks for nothing.
- may: turnsReady(t) && !pause.paused && !!mayWork() && gpu.busyInARow === 0,
+ may: turnsReady(t) && !pause.paused && !!mayWork(),
+ // A busy reading that may still turn into a pause begins no turn and ends none (no new job starts either).
+ unsure: gpu.busyInARow > 0,
claimable: s.claimable,
busy: busyJob && jobUsesGpu && !stopNow,
workHolds,
diff --git a/bin/lib/worker/turns.mjs b/bin/lib/worker/turns.mjs
index e3c4ea29..1b8b94de 100644
--- a/bin/lib/worker/turns.mjs
+++ b/bin/lib/worker/turns.mjs
@@ -122,7 +122,8 @@ export class SiteTurns {
* `f`: { may (the worker may ask for a turn now: the folder is there, the studio says what it can take, nothing pauses
* it), claimable (the beat's claimableNow), busy (a studio job runs here), workHolds (local ComfyUI work holds more
* than busyVramMb), workThere (local ComfyUI work listens at all), serverInterrupt, oldestWaitS (the studio's, when
- * it says) }.
+ * it says), unsure (another program showed in one reading, which may still become a pause: no new turn begins, and a
+ * turn that has begun goes on, so one reading never makes the helper let go and ask again) }.
*/
step(t, f) {
const day = dayOf(t);
@@ -131,7 +132,7 @@ export class SiteTurns {
this.lastTickAt = t;
const may = !!f.may && this.capLeft(t);
const claimable = Math.max(0, Math.floor(Number(f.claimable) || 0));
- const want = (may && claimable > 0) || !!f.busy;
+ const want = ((may && claimable > 0) || !!f.busy) && (this.active || !f.unsure);
let ended = null;
if (want) {
if (!this.active) {
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index 35aebadf..bc6859d7 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -173,7 +173,9 @@ The worker never connects to your other ComfyUIs. It reads three things only:
a process that it doesn't know holds GPU memory.
2. **Windows' GPU counters** (`\GPU Process Memory(pid_<n>_*)\Dedicated Usage`, read with `typeperf`). These are the
numbers that Task Manager shows for each process. `nvidia-smi` gives the total only, because its per-process memory
- reads `[N/A]` on Windows.
+ reads `[N/A]` on Windows. The worker reads the graphics card whose processes hold the most memory. On a PC with
+ more than one card, set `gpuLuid` to the card's part of the counter name (for example
+ `0x00000000_0x0000d1b5_0`, the luid and the phys number).
3. **A GPU lock file** (`gpuLockFile`), only when the counters or the port table can't be read. If the first word of
the lock names an owner in `gpuLockComfyOwners`, the GPU's memory counts as local ComfyUI work. Any other owner
counts as another program, and so does no lock at all.
@@ -182,7 +184,8 @@ Every 5 seconds, the worker splits the GPU's used memory three ways. **Others**
minus local ComfyUI work, minus the desktop's usual share (`desktopBaselineMb`). Run `fuobe worker baseline` once,
with no game open, to measure that share. Local ComfyUI work may stay open while you measure.
-- If others are above `busyVramMb` in two readings in a row, the worker pauses as before ("Your GPU is busy").
+- If others are above `busyVramMb` in two readings in a row, the worker pauses as before ("Your GPU is busy"). After
+ one such reading, it starts no new job, and a turn stays as it is: it doesn't begin, and it doesn't end.
- If only local ComfyUI work holds more than `busyVramMb`, the worker asks for a turn and waits. While it waits, its
jobs keep their place in the line. This is not a pause: there is no cool-down, and the studio does not send its jobs
back.
diff --git a/tests/worker-turns-run.test.ts b/tests/worker-turns-run.test.ts
index 9d4127a5..ef73d180 100644
--- a/tests/worker-turns-run.test.ts
+++ b/tests/worker-turns-run.test.ts
@@ -7,11 +7,13 @@
* claims within 5 s of the answer; a minute after the last job it lets go and writes 0.
* - A game holds the GPU: the busy pause, and no turn is asked for.
* - The studio doesn't say what the worker can take: local ComfyUI work pauses it, as before.
+ * - Me first: the pause shortcut during a turn writes siteWaiting 0, and the job keeps its place.
* - The counters fail: a lock that names ComfyUI work leads to a turn.
*/
import fs from "node:fs";
import path from "node:path";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
+import { worker } from "../bin/lib/worker/index.mjs";
import { runWorker } from "../bin/lib/worker/run.mjs";
import { inputRules, readCatalog } from "../scripts/lib/worker-catalog.mjs";
import { FAKE_PNG } from "./helpers/fake-local-comfy";
@@ -298,6 +300,27 @@ describe("studio jobs first", () => {
expect(p.logs.some((l) => /no longer keeps it paused/.test(l))).toBe(true);
});
+ it("me first: the pause shortcut during a turn writes siteWaiting 0 and keeps the job in line; a resume asks again", async () => {
+ const w = addWorker();
+ const p = pc();
+ const id = addTask();
+ start(w, p, fakeGpu(p, { workMb: 9000 }));
+ await until(() => workerRow(w).local_why === "waiting-for-yield");
+ expect(site(p)?.siteWaiting).toBe(1);
+ const io = { env: { FUOBE_WORKER_HOME: p.home }, home: p.home, stdout: { write: () => {} }, stderr: { write: () => {} }, ask: async () => "2" };
+ expect(await worker(["pause", "--choose"], io)).toBe(0);
+ await until(() => workerRow(w).local_why === "here-now");
+ await until(() => site(p)?.siteWaiting === 0);
+ expect(workerRow(w).local_until).toBeGreaterThan(Date.now() + 3_500_000);
+ // An answer that comes now starts nothing: the pause by hand wins.
+ fs.writeFileSync(path.join(p.turns, "yielded.json"), JSON.stringify({ state: "yielded", at: Date.now() }));
+ await sleep(1500);
+ expect(task(id).state).toBe("waiting");
+ expect(site(p)?.siteWaiting).toBe(0);
+ expect(await worker(["resume"], io)).toBe(0);
+ await until(() => (site(p)?.siteWaiting ?? 0) >= 1);
+ });
+
it("the counters fail: a lock that names ComfyUI work leads to a turn, any other owner to the busy pause", async () => {
const w = addWorker();
const p = pc();
diff --git a/tests/worker-turns.test.ts b/tests/worker-turns.test.ts
index e44f8875..a397171d 100644
--- a/tests/worker-turns.test.ts
+++ b/tests/worker-turns.test.ts
@@ -198,6 +198,19 @@ describe("turns", () => {
expect(turns.step(T0 + 3000, { ...facts, may: false })).toMatchObject({ siteWaiting: 0, waitForYield: false });
});
+ it("one reading that may still become a pause begins no turn and ends none", () => {
+ const { folder, turns } = setup();
+ // Not in a turn: an unsure reading asks for nothing.
+ expect(turns.step(T0, { ...facts, unsure: true })).toMatchObject({ siteWaiting: 0, waitForYield: false });
+ // In a turn, with the answer in: the reading leaves it as it is, and the answer still counts.
+ expect(turns.step(T0 + 1000, facts)).toMatchObject({ siteWaiting: 2, waitForYield: true });
+ answer(folder, { state: "yielded", at: T0 + 1500 });
+ expect(turns.step(T0 + 20_000, { ...facts, unsure: true })).toMatchObject({ siteWaiting: 2, waitForYield: false, ended: null });
+ expect(turns.step(T0 + 25_000, facts)).toMatchObject({ siteWaiting: 2, waitForYield: false, ended: null });
+ // The second busy reading pauses the worker: the turn ends at once.
+ expect(turns.step(T0 + 30_000, { ...facts, may: false, unsure: true })).toMatchObject({ siteWaiting: 0, ended: "stopped" });
+ });
+
it("asks for an interrupt only when the studio does, at most once per gap, and never when the PC says never", () => {
const a = setup({ interruptGapMin: 30 });
expect(a.turns.step(T0, { ...facts, serverInterrupt: true }).interrupt).toBe(true);