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.

Runs: progress never goes backwards

Adarshed6a5fb9408b
diff --git a/src/lib/run-progress.ts b/src/lib/run-progress.ts
index 3b26483e..da4a930f 100644
--- a/src/lib/run-progress.ts
+++ b/src/lib/run-progress.ts
@@ -301,6 +301,28 @@ export const isPoolRunWords = (m: string | null | undefined): m is string => {
return words === POOL_WORDS.working || words === POOL_WORDS.gettingReady || words === POOL_WORDS.finishing || POOL_PERCENT.test(words);
};
+/** Has a person's run on this install's GPUs started, as these words say ("Creating", a percent, "Almost done")? */
+export const startedWords = (m: string | null | undefined): boolean => isPoolRunWords(m) && !m.startsWith(POOL_WORDS.gettingReady);
+
+/**
+ * A person's run on this install's GPUs once it has started (`peak`: the highest share it was shown since; null: not
+ * started yet), as it is shown: it never goes back. Taken up again after its GPU let it go (in line, getting ready, or
+ * running below the peak), it shows "Creating" with no percent (the time left may stay) and the peak's share (none at
+ * 0), until the new attempt passes the peak. Null: shown as it is.
+ */
+export function heldRun(
+ r: { status: string; message: string | null; progress: number | null },
+ peak: number | null | undefined,
+ ready: boolean,
+): { status: "running"; message: string; progress: number | null } | null {
+ if (peak === null || peak === undefined || (r.status !== "queued" && r.status !== "running")) return null;
+ const running = r.status === "running" && !ready && startedWords(r.message);
+ // Running at or past the peak, or finishing with no share to show (a count of nodes is none): as it is.
+ if (running && (r.progress === null ? r.message!.startsWith(POOL_WORDS.finishing) : r.progress >= peak - 1e-9)) return null;
+ const left = running ? (/ · about \d+ min left$/.exec(r.message ?? "")?.[0] ?? "") : "";
+ return { status: "running", message: `${POOL_WORDS.working}${left}`, progress: peak > 0 ? peak : null };
+}
+
/** The owner's words while a run's model loads. */
export const OWNER_LOADING_WORDS = "Loading the model";
diff --git a/src/server/db.ts b/src/server/db.ts
index fc68e731..3df784e5 100644
--- a/src/server/db.ts
+++ b/src/server/db.ts
@@ -1342,6 +1342,10 @@ function open(): Database.Database {
if (!(db.prepare("PRAGMA table_info(account_canvases)").all() as { name: string }[]).some((c) => c.name === "summary_json")) {
addColumn(db, "ALTER TABLE account_canvases ADD COLUMN summary_json TEXT");
}
+ // The highest share a person's run on this install's GPUs was shown once it started (generations.ts notePeak).
+ if (!(db.prepare("PRAGMA table_info(generations)").all() as { name: string }[]).some((c) => c.name === "shown_peak")) {
+ addColumn(db, "ALTER TABLE generations ADD COLUMN shown_peak REAL");
+ }
// A billing hold's rows are found through this index (only rows that have one are in it).
try {
db.exec("CREATE INDEX IF NOT EXISTS generations_hold ON generations(json_extract(request_json, '$.hold')) WHERE json_extract(request_json, '$.hold') IS NOT NULL");
diff --git a/src/server/generations.ts b/src/server/generations.ts
index dac075ad..f049a3f5 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -155,7 +155,7 @@ import { accountSend } from "./account-send";
import { stamped, stampOf, withoutStamp, withRunStamp, type RunStamp } from "./run-stamp";
import { anyHeld, dropGone, dropHold, HELD, NOT_HELD } from "./pool-holds";
import { FILE_TROUBLE_WORDS, POOL_WORDS, RELAY_WORDS } from "@/lib/relay";
-import { isPoolRunWords } from "@/lib/run-progress";
+import { heldRun, isPoolRunWords, startedWords } from "@/lib/run-progress";
import { heldLine, placeInLine, poolOnWorkers, poolRunsProvider, poolWaitMs, requestFileKinds, runOnPool, type FileKind } from "./hosted";
import { hostedRunsOn } from "./hosted-switch";
import { claimSiteFallback, movedFields } from "./site-fallback";
@@ -214,6 +214,13 @@ interface Row {
* shows failure details to people (settings.ts runFailureDetail).
*/
detail?: string | null;
+ /** On this install's GPUs: the highest share of its progress its person was shown once it started (NULL: not yet). */
+ shown_peak?: number | null;
+}
+
+/** Keep the highest share a person's run on this install's GPUs was shown once it started (Row.shown_peak). */
+export function notePeak(id: string, share: number): void {
+ db().prepare("UPDATE generations SET shown_peak = MAX(COALESCE(shown_peak, 0), ?) WHERE id = ?").run(Math.max(0, Math.min(1, share)), id);
}
/** Trash and folder columns, joined onto every library read. */
@@ -254,6 +261,8 @@ export function toGeneration(r: Row): Generation {
// makes it (never In line: nobody pressed Run again). One that waits for the account's own GPU to come back shows that.
const meta = r.external_meta_json?.includes('"declined"') ? readMeta(r.external_meta_json) : undefined;
const again = (r.status === "queued" || r.status === "running") && !(r.status === "queued" && !r.external_id && meta?.heal) ? declinedWords(meta ?? {}) : undefined;
+ // Once it started, a run on this install's GPUs never shows In line, Getting ready or a lower share again (heldRun).
+ const held = pool && !checking && !again ? heldRun(r, r.shown_peak, ready) : null;
return {
id: r.id,
batchId: r.batch_id,
@@ -264,10 +273,10 @@ export function toGeneration(r: Row): Generation {
provider: r.provider,
op: r.op,
kind: r.kind,
- status: again ? "running" : r.status,
- // In line on this install's GPUs (again, after an attempt): no progress.
- progress: pool && r.status === "queued" ? null : r.progress,
- message: again ?? (pool ? poolMessage(r, ready) : r.message),
+ status: held ? held.status : again ? "running" : r.status,
+ // In line on this install's GPUs (before it started): no progress.
+ progress: held ? held.progress : pool && r.status === "queued" ? null : r.progress,
+ message: again ?? (held ? held.message : pool ? poolMessage(r, ready) : r.message),
prompt: r.prompt,
request,
// Held for the moderation service's check: nothing of it is shown until it passes.
@@ -307,7 +316,7 @@ export function toGeneration(r: Row): Generation {
// On this install's GPUs the output check is part of "Creating": no word of its own.
...(checking && !pool && { stage: "checking" as const }),
// Waiting in line on this install's GPUs: its place and the wait, about.
- ...(stored.place === "pool" && (r.status === "queued" || r.status === "running") && !checking && !again && poolQueue(r.id)),
+ ...(stored.place === "pool" && (r.status === "queued" || r.status === "running") && !checking && !again && !held && poolQueue(r.id)),
// The owner's own job on the workers, waiting: its place in their line (in the list as after a refresh).
...(stored.place !== "pool" && r.status === "queued" && r.provider === "comfyui" && !again && workerQueue(r.id)),
// Working on this install's GPUs: the address of its latest preview picture, while there is one. None for a run
@@ -4660,7 +4669,11 @@ async function pollOne(r: Row): Promise<void> {
// install's GPUs each poll of a running try says its share; one that says none (its files still going to the GPU, a
// new try not started yet) shows none, never the share of the try before.
// (An Ideogram 4 run made again after it declined says so while it works.)
- updateLive(r.id, { status: res.state, progress: ownClocks ? (res.state === "queued" ? null : (res.progress ?? null)) : (res.progress ?? r.progress), message: declinedWords(ctx.meta) ?? res.message ?? null });
+ const progress = ownClocks ? (res.state === "queued" ? null : (res.progress ?? null)) : (res.progress ?? r.progress);
+ const wrote = updateLive(r.id, { status: res.state, progress, message: declinedWords(ctx.meta) ?? res.message ?? null });
+ // A person's run on this install's GPUs, shown started ("Creating", a share): the highest share shown is kept with the
+ // run, so an attempt after its GPU let it go never shows less, even after a reload (toGeneration's heldRun).
+ if (wrote && onPool && res.state === "running" && startedWords(res.message) && !gettingReady(r.id)) notePeak(r.id, progress ?? 0);
return;
}
if (res.state === "failed") {
diff --git a/tests/pool-account-runs.test.ts b/tests/pool-account-runs.test.ts
index b85546f6..f9d3e659 100644
--- a/tests/pool-account-runs.test.ts
+++ b/tests/pool-account-runs.test.ts
@@ -437,7 +437,7 @@ describe("the line", () => {
expect(g.message).toBe(POOL_WORDS.inLine);
});
- it("back in line after an attempt, it shows In line with no progress from the attempt before", async () => {
+ it("back in line after it started, it never goes backwards: Creating at its highest share, across a reload, until the new attempt passes it", async () => {
const w = standInWorker();
const r = await run({ feature: "image", modelId: "oss-z-image-turbo", prompt: "a lighthouse at dusk" });
expect(r.status, JSON.stringify(r.body)).toBe(201);
@@ -459,16 +459,32 @@ describe("the line", () => {
db().prepare("SELECT * FROM relay_workers WHERE id = ?").get(w.id) as never,
pool.cleanBeat({ device: `wkr-${w.id}`, protocol: 3, version: "1", local: { paused: true, why: "here-now", until: null }, gpu: {}, running: [{ task: t.id }], stopped: [] }),
);
- const back = await until(() => {
- const g = getGeneration(id);
- return g?.status === "queued" ? g : null;
- });
- expect(back?.message).toBe(POOL_WORDS.inLine);
- expect(back?.progress).toBeNull();
- expect((db().prepare("SELECT progress FROM generations WHERE id = ?").get(id) as { progress: number | null }).progress).toBeNull();
- // A row in line never shows a progress it kept from before.
- db().prepare("UPDATE generations SET progress = 0.6 WHERE id = ?").run(id);
- expect(getGeneration(id)?.progress).toBeNull();
+ const raw = () => db().prepare("SELECT status, progress, message FROM generations WHERE id = ?").get(id) as { status: string; progress: number | null; message: string | null };
+ await until(() => raw().status === "queued");
+ // The run itself is back in line, with no progress (the owner's views read that)…
+ expect(raw()).toMatchObject({ status: "queued", progress: null, message: POOL_WORDS.inLine });
+ // …while its person sees it still being made, at the highest share shown, with no percent and no place in line.
+ const peak = working!.progress!;
+ const back = getGeneration(id)!;
+ expect(back).toMatchObject({ status: "running", message: POOL_WORDS.working, progress: peak });
+ expect(back.queue).toBeUndefined();
+ // A reload reads the same (the highest share is kept with the run).
+ expect(toGeneration(db().prepare("SELECT * FROM generations WHERE id = ?").get(id) as never)).toMatchObject({ status: "running", message: POOL_WORDS.working, progress: peak });
+ // A worker takes it again: below the highest share, still no percent and the same share…
+ beatAs(w);
+ const again = claimAs(w)!;
+ expect(again.id).toBe(t.id);
+ tasks.report(rowOf(t.id), { event: "sent", promptId: again.promptId }, () => ({ error: "unused" }));
+ tasks.report(rowOf(t.id), { event: "running", value: 1, max: 4 }, () => ({ error: "unused" }));
+ await until(() => raw().status === "running" && (raw().progress ?? 0) > 0);
+ expect(raw().progress!).toBeLessThan(peak);
+ expect(getGeneration(id)).toMatchObject({ status: "running", message: POOL_WORDS.working, progress: peak });
+ // …and past it, its percent climbs again.
+ tasks.report(rowOf(t.id), { event: "running", value: 4, max: 4 }, () => ({ error: "unused" }));
+ await until(() => (raw().progress ?? 0) > peak);
+ const past = getGeneration(id)!;
+ expect(past.message).toBe("Creating · 100%");
+ expect(past.progress!).toBeGreaterThan(peak);
});
it("place and wait count every task ahead in the order the workers serve them, whatever its lane", () => {
diff --git a/tests/pool-line-order.test.ts b/tests/pool-line-order.test.ts
index 5c6d27ca..b0164e38 100644
--- a/tests/pool-line-order.test.ts
+++ b/tests/pool-line-order.test.ts
@@ -598,9 +598,11 @@ describe("the run ceiling", () => {
await tick();
const g = getGeneration(id)!;
expect(g.status).toBe("running");
- // Taken afresh by a worker whose beats name no model loaded: getting ready (no progress of the attempt before).
- expect(g.message).toBe(POOL_WORDS.gettingReady);
- expect(g.progress).toBeNull();
+ // Taken afresh by a worker whose beats name no model loaded: getting ready, while its person, who saw it started,
+ // still reads Creating at the share shown before (never backwards).
+ expect(pool.gettingReady(id)).toBe(true);
+ expect(g.message).toBe(POOL_WORDS.working);
+ expect(g.progress).toBe((db().prepare("SELECT shown_peak FROM generations WHERE id = ?").get(id) as { shown_peak: number }).shown_peak);
});
it("a worker with another model loaded: Getting ready until the first step reports; with its model loaded, Creating at once", async () => {
diff --git a/tests/run-held.test.ts b/tests/run-held.test.ts
new file mode 100644
index 00000000..66b6e647
--- /dev/null
+++ b/tests/run-held.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from "vitest";
+import { heldRun, startedWords } from "@/lib/run-progress";
+import { POOL_WORDS } from "@/lib/relay";
+
+describe("a person's run never goes backwards once it started", () => {
+ it("started: Creating, a percent or Almost done; not In line or Getting ready", () => {
+ expect(startedWords("Creating")).toBe(true);
+ expect(startedWords("Creating · 40% · about 3 min left")).toBe(true);
+ expect(startedWords(POOL_WORDS.finishing)).toBe(true);
+ expect(startedWords(POOL_WORDS.gettingReady)).toBe(false);
+ expect(startedWords(POOL_WORDS.inLine)).toBe(false);
+ expect(startedWords(null)).toBe(false);
+ });
+
+ it("not started yet: shown as it is", () => {
+ expect(heldRun({ status: "queued", message: POOL_WORDS.inLine, progress: null }, null, false)).toBeNull();
+ expect(heldRun({ status: "running", message: POOL_WORDS.gettingReady, progress: null }, undefined, true)).toBeNull();
+ });
+
+ it("back in line, or getting ready again: Creating with no percent, at the highest share shown", () => {
+ expect(heldRun({ status: "queued", message: POOL_WORDS.inLine, progress: null }, 0.42, false)).toEqual({ status: "running", message: "Creating", progress: 0.42 });
+ expect(heldRun({ status: "running", message: "Creating", progress: 0.03 }, 0.42, true)).toEqual({ status: "running", message: "Creating", progress: 0.42 });
+ // Started before any share was shown: Creating, and still no share.
+ expect(heldRun({ status: "queued", message: POOL_WORDS.inLine, progress: null }, 0, false)).toEqual({ status: "running", message: "Creating", progress: null });
+ });
+
+ it("a new attempt below the peak: no percent, the time left may stay; past it, its own words and share again", () => {
+ expect(heldRun({ status: "running", message: "Creating · 20% · about 4 min left", progress: 0.2 }, 0.42, false)).toEqual({ status: "running", message: "Creating · about 4 min left", progress: 0.42 });
+ expect(heldRun({ status: "running", message: "Creating · 60%", progress: 0.5 }, 0.42, false)).toBeNull();
+ expect(heldRun({ status: "running", message: "Creating · 40%", progress: 0.42 }, 0.42, false)).toBeNull();
+ });
+
+ it("finishing with no share to show stays Almost done; a run that ended is shown as it is", () => {
+ expect(heldRun({ status: "running", message: POOL_WORDS.finishing, progress: null }, 0.9, false)).toBeNull();
+ expect(heldRun({ status: "succeeded", message: null, progress: 1 }, 0.9, false)).toBeNull();
+ expect(heldRun({ status: "failed", message: null, progress: null }, 0.9, false)).toBeNull();
+ });
+});