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.

Auto: lettering a prompt rules out no longer sends it to Ideogram 4; workers report their slowest nodes

Adarsh06315ad8b367
diff --git a/docs/admin-api.md b/docs/admin-api.md
index 24f08952..d42aa5e3 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -108,7 +108,7 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `PATCH /api/admin/accounts/{id}` | exactly one of `{ disabled: boolean }` or `{ signOut: true }` | the account (no numbers) |
| `DELETE /api/admin/accounts/{id}` | | 204 |
| `GET /api/admin/generations` | `account` (one account), else `whose` (`people`: accounts' and guests' runs, the default; `ours`: the owner's own; `everyone`); `source` (the owner's runs only: `hands-on`, or `batch` for any automated run: `batch`, `drill`, `example`, `test`, `api`); `where` (`pool`: this install's GPUs, the owner's runs on its ComfyUI too; `provider`: a cloud provider; `own`: an account's own GPU); `status` (`finished` or `done`, `failed`, `canceled`, `waiting`, `started`, and `running` for waiting and started); `kind` (`image`, `video`, `audio`, `model3d`, `text`); `model` (letters of the model id); `from` and `to` (`yyyy-mm-dd` in UTC, both days included); `q` (words of the prompt, or a run id); `ids` (a comma list of up to 100 run ids: those runs, whoever's they are); `before` (the last page's `next`); `limit` (1 to 100, default 30) | `{ items, next }`; `next` is null on the last page. Each run has `whose`: `account`, `guest` or `owner`. Each output has a `state`: `shown`, `held` (hidden, or waiting for its check) or `removed` (its file is gone). A failed run on this install's GPUs (and the owner's own failed run) also has `detail`: the technical reason, which the account never sees. `account` is `{ id, email }` (`email` null: a deleted account), `{ id, emailHidden: true }` without `accounts:read`, or `null` for the owner's own run, which has `source` too (`hands-on` from the site; `batch`, `drill`, `example`, `test` as its script said; `api` for a run sent with an API token that said none) and `sourceName` when its script gave one |
-| `GET /api/admin/generations/{id}` | needs `runs:read` and `outputs:view` | One run in full, an account's, a guest's or the owner's own: `{ run, stored, fix, trouble, where, model, preset, studio, prompt, negativePrompt, asked, settings, inputs, batch, near, chain, sent, timing, jobs, workerLog, money, madeBy, surface, providerId, progress, checks }`. `stored.detail` is the technical reason for the owner; `comfyReason`, when there is one, is ComfyUI's own reason in one short line (a node that isn't installed, a model file not in its list, an error in a node), and each of `jobs` has it as `comfyWhy`. `inputs` lists each input file by slot, with its `state` (`kept` with its `url`, `removed`, `example`, `inline`, `link`). `chain` is `{ before, after }`: the steps it waits for and the steps that wait for it. Keys, tokens and GPU addresses are never part of it. 404 for an unknown run |
+| `GET /api/admin/generations/{id}` | needs `runs:read` and `outputs:view` | One run in full, an account's, a guest's or the owner's own: `{ run, stored, fix, trouble, where, model, preset, studio, prompt, negativePrompt, asked, settings, inputs, batch, near, chain, sent, timing, jobs, workerLog, money, madeBy, surface, providerId, progress, checks }`. `stored.detail` is the technical reason for the owner; `comfyReason`, when there is one, is ComfyUI's own reason in one short line (a node that isn't installed, a model file not in its list, an error in a node), and each of `jobs` has it as `comfyWhy`. A job on one of this site's workers may have `nodes`: its slowest nodes, slowest first, each `{ node, type, ms, beforeStepsMs, steps }` (`beforeStepsMs` and `steps` for a node with steps; [gpu-workers.md](gpu-workers.md)). `inputs` lists each input file by slot, with its `state` (`kept` with its `url`, `removed`, `example`, `inline`, `link`). `chain` is `{ before, after }`: the steps it waits for and the steps that wait for it. Keys, tokens and GPU addresses are never part of it. 404 for an unknown run |
| `DELETE /api/admin/generations/{id}` | | 204; 404 for an unknown run or the owner's own |
| `POST /api/admin/outputs/hide` | `{ assetIds?, generationIds? }` (up to 500 each) | `{ hidden }` |
| `POST /api/admin/outputs/unhide` | the same | `{ shown }` |
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index d7b8dfc4..6bda9c3f 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -994,6 +994,11 @@ its target), at most once an hour each.
than once counts once: the attempt whose result was kept. The studio keeps at most the run ceiling of the job's lane,
and at most the time since the job was sent to its ComfyUI (plus a minute, because ComfyUI starts a job a moment
before the studio hears that it was sent).
+ - `finished` can carry `nodes`: the job's slowest nodes (at most 12), as the worker timed them from its ComfyUI's live
+ socket (`src/lib/node-times.ts`). Each has the node's id, its class, its time, and for a node with steps its step
+ count and the time before its first step (its models loading). Only ids, classes, times and counts: never a prompt
+ or a file name. The studio keeps them with the job (a job sent again keeps the last ones) and shows them only to the
+ owner, in the run's details ("Slowest steps"), so a slow run shows where its time went.
- `running` can carry `preview`: the latest preview picture of the job, a JPEG of at most 64 KB as base64, at most
one every 2 seconds (see "Live previews"). A progress report with a preview may weigh up to about 91 KB (the
preview as base64 and a few KB more); any other stays under the small limit. A claim says `reportPreview: true` when the run shows one: only with hosted runs on
diff --git a/scripts/lib/worker-build.mjs b/scripts/lib/worker-build.mjs
index 40442bcc..280cbca1 100644
--- a/scripts/lib/worker-build.mjs
+++ b/scripts/lib/worker-build.mjs
@@ -27,7 +27,7 @@ import { unruledPathInputs } from "./catalog-checks.mjs";
import { allowedNodeList, filePins, inputRules, missingRules, readCatalog } from "./worker-catalog.mjs";
export const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
-export const SOURCES = ["computer-runner", "engine-error", "comfy-reason", "comfy-guard", "comfy-ws", "fetch-within", "local-comfy", "relay", "lanes", "worker-hours", "finish-ticket", "camera-path", "path-splat", "scene3d"];
+export const SOURCES = ["computer-runner", "engine-error", "comfy-reason", "comfy-guard", "comfy-ws", "node-times", "fetch-within", "local-comfy", "relay", "lanes", "worker-hours", "finish-ticket", "camera-path", "path-splat", "scene3d"];
/**
* What the worker learns from the catalog: its node allowlist, its input rules and its file pins. Throws when an input
diff --git a/src/app/api/gpu/computer/tasks/[id]/report/route.ts b/src/app/api/gpu/computer/tasks/[id]/report/route.ts
index 62c02b04..657c2195 100644
--- a/src/app/api/gpu/computer/tasks/[id]/report/route.ts
+++ b/src/app/api/gpu/computer/tasks/[id]/report/route.ts
@@ -1,3 +1,4 @@
+import { cleanNodeTimes } from "@/lib/node-times";
import { GIVE_BACK, PREVIEW_LIMITS, previewOf, RELAY_LIMITS, TAB_FAILURES, type ReportEvent } from "@/lib/relay";
import { gateAsProxy, readBodyWithin } from "@/server/direct-gate";
import { callerKey, principalOf, rateOf, relayAnswer } from "@/server/computer/http";
@@ -44,8 +45,11 @@ function eventOf(b: Record<string, unknown>): ReportEvent | null {
const preview = previewOf(b.preview);
return { event: e, value: num(b.value), max: num(b.max), nodesDone: num(b.nodesDone), ...(typeof b.node === "string" && { node: b.node }), ...(preview && { preview }) };
}
- case "finished":
- return b.entry && typeof b.entry === "object" ? { event: e, entry: b.entry as never, ...(num(b.peakVramBytes) !== undefined && { peakVramBytes: num(b.peakVramBytes) }), ...exec, ...why } : null;
+ case "finished": {
+ // A worker's slowest nodes, as its ComfyUI's socket timed them (cleaned: ids, classes, times and step counts only).
+ const nodes = cleanNodeTimes(b.nodes);
+ return b.entry && typeof b.entry === "object" ? { event: e, entry: b.entry as never, ...(num(b.peakVramBytes) !== undefined && { peakVramBytes: num(b.peakVramBytes) }), ...exec, ...why, ...(nodes && { nodes }) } : null;
+ }
case "passes":
return Array.isArray(b.entries) && b.entries.length <= 64 ? { event: e, running: b.running === true, entries: b.entries as never, ...(b.running !== true && { ...exec, ...why }) } : null;
case "give-back":
diff --git a/src/components/run-details.tsx b/src/components/run-details.tsx
index b83a9e82..3c6aadcc 100644
--- a/src/components/run-details.tsx
+++ b/src/components/run-details.tsx
@@ -760,6 +760,19 @@ function Jobs({ jobs }: { jobs: RunJob[] }) {
{j.estMs !== undefined && <span className="text-muted-foreground"> (expected {dur(j.estMs)})</span>}
</JobFact>
)}
+ {j.nodes?.length ? (
+ <JobFact label="Slowest steps">
+ <ul className="space-y-0.5 tabular-nums">
+ {j.nodes.slice(0, 6).map((n) => (
+ <li key={n.node}>
+ {n.type ?? "Node"} <span className="text-muted-foreground">#{n.node}</span> · {dur(n.ms)}
+ {n.steps !== undefined && <span className="text-muted-foreground"> · {n.steps} steps</span>}
+ {n.beforeStepsMs !== undefined && n.beforeStepsMs >= 1000 && <span className="text-muted-foreground"> · {dur(n.beforeStepsMs)} before its first step</span>}
+ </li>
+ ))}
+ </ul>
+ </JobFact>
+ ) : null}
<JobFact label="Times">
<span className="tabular-nums">
{[
diff --git a/src/lib/auto-image.ts b/src/lib/auto-image.ts
index 9be809e6..60a21b4c 100644
--- a/src/lib/auto-image.ts
+++ b/src/lib/auto-image.ts
@@ -115,8 +115,22 @@ export function matchedPattern(prompt: string, patterns: readonly { line: string
return patterns.find((p) => p.re.test(prompt))?.line;
}
-/** Is this prompt about lettering (posters, logos, signs, typography, words in quotes)? */
-export const asksForText = (prompt: string): boolean => TEXT_WORDS.test(prompt) || QUOTED.test(prompt);
+/** The words TEXT_WORDS knows, plus watermarks, for the "no …" lists below. */
+const TEXT_NOUN = String.raw`(?:text|texts|typography|typeface|fonts?|lettering|letters|logos?|logotypes?|wordmarks?|monograms?|signage|signs?|banners?|headlines?|captions?|calligraphy|graffiti|labels?|watermarks?|words|writing)`;
+/**
+ * A prompt that only rules lettering out ("no text, no watermark", "without any logos or captions", "text-free"): these
+ * words don't ask for it, so they are left out before TEXT_WORDS reads the prompt.
+ */
+const NO_TEXT = new RegExp(
+ String.raw`\b(?:no|not any|without(?: any)?|free of|zero|avoid(?:ing)?|minus)\s+(?:(?:any|visible|readable|legible|added|extra|stray|on-?screen|overlaid|overlay)\s+)*${TEXT_NOUN}(?:\s*(?:,|\/|or|and|nor)\s*(?:(?:no|any)\s+)?${TEXT_NOUN})*\b|\b${TEXT_NOUN}-?(?:free|less)\b`,
+ "gi",
+);
+
+/** Is this prompt about lettering (posters, logos, signs, typography, words in quotes)? Lettering it rules out doesn't count. */
+export const asksForText = (prompt: string): boolean => {
+ const asked = prompt.replace(NO_TEXT, " ");
+ return TEXT_WORDS.test(asked) || QUOTED.test(asked);
+};
export interface AutoAsk {
prompt?: string;
diff --git a/src/lib/computer-runner.ts b/src/lib/computer-runner.ts
index 9e9a25aa..775bb5e5 100644
--- a/src/lib/computer-runner.ts
+++ b/src/lib/computer-runner.ts
@@ -13,6 +13,7 @@ import { withoutLocalPaths } from "./engine-error";
import { FINISH_RUN_MS, finishProblem, type FinishResult, type FinishStats } from "./finish-ticket";
import { fetchWithin } from "./fetch-within";
import { parseComfyBinary, parseComfyText } from "./comfy-ws";
+import { NodeClock } from "./node-times";
import { graphProblem, localBase, mayDownload, readPath, statsFacts, viewPath, writePath, type SystemStats } from "./local-comfy";
import {
DONE_SHOWN_MS,
@@ -348,6 +349,8 @@ export class ComputerRunner {
private ws: SocketLike | null = null;
private wsOpen = false;
private events = new Map<string, { value?: number; max?: number; node?: string; nodesDone: number; done?: boolean }>();
+ /** Each prompt's node times from the socket (a worker sends them with its "finished" report); the latest few. */
+ private clocks = new Map<string, NodeClock>();
private factsSentAt = 0;
private factsWithLoras = 0;
private foundAt = 0;
@@ -497,6 +500,7 @@ export class ComputerRunner {
else if (e.type === "executing" && e.node) Object.assign(cur, { node: e.node, nodesDone: cur.nodesDone + 1, value: undefined, max: undefined });
else if (e.type === "success" || e.type === "error" || e.type === "interrupted" || (e.type === "executing" && !e.node)) cur.done = true;
this.events.set(e.promptId, cur);
+ this.clockEvent(e);
return;
}
const p = parseComfyBinary(m.data as ArrayBuffer);
@@ -508,6 +512,30 @@ export class ComputerRunner {
};
}
+ /** A socket event on its prompt's node clock (the newest 32 prompts keep theirs). */
+ private clockEvent(e: ReturnType<typeof parseComfyText>) {
+ if (!e || !("promptId" in e) || !e.promptId) return;
+ const now = this.now();
+ let clock = this.clocks.get(e.promptId);
+ if (!clock) {
+ if (e.type !== "execution_start" && e.type !== "executing") return;
+ clock = new NodeClock();
+ this.clocks.set(e.promptId, clock);
+ while (this.clocks.size > 32) this.clocks.delete(this.clocks.keys().next().value!);
+ }
+ if (e.type === "executing") clock.executing(e.node, now);
+ else if (e.type === "progress") clock.progress(e.node, e.max, now);
+ else if (e.type === "success" || e.type === "error" || e.type === "interrupted") clock.end(now);
+ }
+
+ /** The slowest nodes of a prompt as its socket timed them (a worker's "finished" report carries them), then forgotten. */
+ private nodeTimes(promptId: string, entry: HistoryEntryLike) {
+ const clock = this.clocks.get(promptId);
+ this.clocks.delete(promptId);
+ const nodes = clock?.times(entry.prompt?.[2]);
+ return nodes?.length ? { nodes } : {};
+ }
+
/** Where a prompt is on ComfyUI here. */
private async where(promptId: string, prefix?: string): Promise<{ s: "pending"; ahead: number } | { s: "running" } | { s: "done"; entry: HistoryEntryLike } | { s: "absent" }> {
if (this.jobsApi === undefined) this.jobsApi = await this.read("/api/jobs").then(() => true, () => false);
@@ -1258,7 +1286,7 @@ export class ComputerRunner {
// A worker keeps the results first: a stop from here on uploads them again instead of running the job again.
if (worker && !t.metaBatch && w.entry.status?.status_str !== "error") await this.keep(t, { kind: "finished", entries: [w.entry], execMs: ms });
const why = w.entry.status?.status_str === "error" ? entryReason(w.entry, { graph: t.graph }) : null;
- const a = await this.report(t, { event: "finished", entry: slim(w.entry), ...exec(ms), ...(why && { why }) });
+ const a = await this.report(t, { event: "finished", entry: slim(w.entry), ...exec(ms), ...(worker && this.nodeTimes(t.promptId, w.entry)), ...(why && { why }) });
if (a.stop) throw new Stopped();
if (a.follow) {
following = a.follow;
diff --git a/src/lib/node-times.ts b/src/lib/node-times.ts
new file mode 100644
index 00000000..ae73055a
--- /dev/null
+++ b/src/lib/node-times.ts
@@ -0,0 +1,112 @@
+/**
+ * Node times: how long each node of a job ran on a worker's ComfyUI, from its live socket (each "executing" event starts
+ * a node and ends the one before; a node's first "progress" event is its first step, so the time before it is the node's
+ * own loading). A worker sends the slowest nodes with its "finished" report, and the run's details show them to the
+ * owner, so a slow run says where its time went (a model loading, its steps, its decode). Only node ids, class names,
+ * times and step counts: never a prompt, a file name or a value.
+ *
+ * Pure: the job runner (src/lib/computer-runner.ts, in the worker build), the server and the tests share it.
+ */
+
+/** One node's time on its ComfyUI. */
+export interface NodeTime {
+ /** The node's id in the graph. */
+ node: string;
+ /** Its class (KSampler, VAEDecode, …), when the graph says. */
+ type?: string;
+ /** From its start to the next node's start (or the prompt's end). */
+ ms: number;
+ /** A node with steps: the time before its first step (its models loading, its text encoding), and its steps. */
+ beforeStepsMs?: number;
+ steps?: number;
+}
+
+/** The most nodes a report carries (the slowest), and the shortest time worth naming. */
+export const NODE_TIMES = { most: 12, minMs: 50 } as const;
+
+const NODE_ID = /^[\w:.-]{1,64}$/;
+const TYPE = /^[\w .:+()-]{1,80}$/;
+
+/** One prompt's clock, fed with its socket's events in order (`now` is the worker's own clock). */
+export class NodeClock {
+ private current: { node: string; at: number; firstStepAt?: number; steps?: number } | null = null;
+ private readonly done = new Map<string, NodeTime>();
+
+ /** A node starts (`null`: the prompt is done): the one before it ends now. */
+ executing(node: string | null, now: number): void {
+ this.close(now);
+ if (node && NODE_ID.test(node)) this.current = { node, at: now };
+ }
+
+ /** A step: the running node's (ComfyUI sends a step while the node that makes it runs; the id it names isn't needed). */
+ progress(_node: string | undefined, max: number, now: number): void {
+ const c = this.current;
+ if (!c) return;
+ if (c.firstStepAt === undefined) c.firstStepAt = now;
+ if (Number.isFinite(max) && max > 0) c.steps = Math.round(max);
+ }
+
+ /** The prompt ended (done, failed or stopped). */
+ end(now: number): void {
+ this.close(now);
+ }
+
+ private close(now: number) {
+ const c = this.current;
+ this.current = null;
+ if (!c) return;
+ const ms = Math.max(0, now - c.at);
+ // A node that runs twice in one prompt (a loop) adds up.
+ const before = this.done.get(c.node);
+ const beforeSteps = c.firstStepAt !== undefined ? Math.max(0, c.firstStepAt - c.at) : undefined;
+ this.done.set(c.node, {
+ node: c.node,
+ ms: (before?.ms ?? 0) + ms,
+ ...((beforeSteps !== undefined || before?.beforeStepsMs !== undefined) && { beforeStepsMs: (before?.beforeStepsMs ?? 0) + (beforeSteps ?? 0) }),
+ ...((c.steps ?? before?.steps) !== undefined && { steps: c.steps ?? before?.steps }),
+ });
+ }
+
+ /**
+ * The slowest nodes, slowest first, each with its class from the graph when it has one (`graph`: the prompt as its
+ * ComfyUI ran it, node id → { class_type }).
+ */
+ times(graph?: unknown): NodeTime[] {
+ const types = graph && typeof graph === "object" ? (graph as Record<string, { class_type?: unknown } | undefined>) : {};
+ return [...this.done.values()]
+ .filter((t) => t.ms >= NODE_TIMES.minMs)
+ .sort((a, b) => b.ms - a.ms)
+ .slice(0, NODE_TIMES.most)
+ .map((t) => {
+ const type = types[t.node]?.class_type;
+ return typeof type === "string" && TYPE.test(type) ? { ...t, type } : t;
+ });
+ }
+}
+
+const ms = (v: unknown, most: number) => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.min(Math.round(v), most) : undefined);
+
+/**
+ * Node times as a report or the database holds them, cleaned: at most NODE_TIMES.most, ids and classes in their plain
+ * shapes, each time at most `mostMs` (the job's own limit). Anything else is left out; undefined when nothing is left.
+ */
+export function cleanNodeTimes(v: unknown, mostMs = 24 * 3_600_000): NodeTime[] | undefined {
+ if (!Array.isArray(v)) return undefined;
+ const out: NodeTime[] = [];
+ for (const x of v.slice(0, NODE_TIMES.most)) {
+ if (!x || typeof x !== "object") continue;
+ const r = x as Record<string, unknown>;
+ const time = ms(r.ms, mostMs);
+ if (typeof r.node !== "string" || !NODE_ID.test(r.node) || time === undefined) continue;
+ const before = ms(r.beforeStepsMs, time);
+ const steps = typeof r.steps === "number" && Number.isInteger(r.steps) && r.steps > 0 && r.steps <= 100_000 ? r.steps : undefined;
+ out.push({
+ node: r.node,
+ ...(typeof r.type === "string" && TYPE.test(r.type) && { type: r.type }),
+ ms: time,
+ ...(before !== undefined && { beforeStepsMs: before }),
+ ...(steps !== undefined && { steps }),
+ });
+ }
+ return out.length ? out : undefined;
+}
diff --git a/src/lib/relay.ts b/src/lib/relay.ts
index 475fc076..1eb35538 100644
--- a/src/lib/relay.ts
+++ b/src/lib/relay.ts
@@ -9,6 +9,7 @@
import type { FinishTicket } from "./finish-ticket";
import type { Ceiling, JobTicket } from "./job-ticket";
+import type { NodeTime } from "./node-times";
/** Where a task is. */
export type RelayState = "waiting" | "sending" | "queued" | "running" | "collecting" | "done" | "failed" | "canceled";
@@ -67,9 +68,10 @@ export type ReportEvent =
/**
* Finished: its /history entry. A worker adds the most VRAM it took (for the benchmarks), how long its ComfyUI spent
* executing the job (`execMs`: execution only, no waits, no uploads), its GPU's name (`device`), and `kept` when the
- * results are ones it kept from an earlier try (their time doesn't count toward the lane's times).
+ * results are ones it kept from an earlier try (their time doesn't count toward the lane's times). `nodes`: its slowest
+ * nodes as its ComfyUI's socket timed them (src/lib/node-times.ts), for the owner's run details.
*/
- | { event: "finished"; entry: HistoryEntryLike; peakVramBytes?: number; execMs?: number; device?: string; kept?: boolean; why?: string }
+ | { event: "finished"; entry: HistoryEntryLike; peakVramBytes?: number; execMs?: number; device?: string; kept?: boolean; why?: string; nodes?: NodeTime[] }
/**
* A meta-batch job (VHS re-queues it pass by pass): whether a pass is still queued, and the passes' entries so far. The
* last one (not running) is the job's end: a worker adds `execMs`, `device` and `kept` as for "finished".
diff --git a/src/server/computer/tasks.ts b/src/server/computer/tasks.ts
index ad3fbf4c..713e2c44 100644
--- a/src/server/computer/tasks.ts
+++ b/src/server/computer/tasks.ts
@@ -26,6 +26,7 @@ import {
previewOf,
} from "@/lib/relay";
import { reasonText } from "@/lib/comfy-reason";
+import { cleanNodeTimes } from "@/lib/node-times";
import type { FinishTicket } from "@/lib/finish-ticket";
import type { JobTicket } from "@/lib/job-ticket";
import { DATA_DIR, db, WORKER_JOBS_KEEP_MS } from "../db";
@@ -117,6 +118,8 @@ export interface TaskRow {
* cleaned again here): for the owner only, never part of what the run's person reads.
*/
comfy_why?: string | null;
+ /** A worker's slowest nodes for the job, as JSON (src/lib/node-times.ts): for the owner only, like comfy_why. */
+ exec_nodes?: string | null;
stop: number;
attempts: number;
down_at: number | null;
@@ -1016,6 +1019,9 @@ function reportOnce(t: TaskRow, e: ReportEvent, plan: (entries: HistoryEntryLike
// device are never kept as the run's GPU time.
const cpuWork = t.slot === "cpu" || !!t.finish_json;
if (t.pools && t.worker_id && (!("follow" in p) || !t.meta_batch)) logWorkerJob("finished", t, t.worker_id, now, cpuWork ? {} : (execFields(e, t, now) ?? {}));
+ // Its slowest nodes, as its worker timed them (the owner's run details show where a slow run's time went).
+ const nodes = t.pools && t.worker_id && e.event === "finished" && !e.kept ? cleanNodeTimes(e.nodes, runCeilingMs(t.lane)) : undefined;
+ if (nodes) setTask(t.id, { exec_nodes: JSON.stringify(nodes) });
if ("follow" in p) {
if (!t.meta_batch) {
endTask(t.id, "failed", { error: "This run finished without a result. Press Retry." });
diff --git a/src/server/db.ts b/src/server/db.ts
index 86ef2a55..0e0cde6c 100644
--- a/src/server/db.ts
+++ b/src/server/db.ts
@@ -1108,6 +1108,8 @@ const RELAY_COLUMNS: [string, string, string][] = [
["relay_tasks", "preview_at", "INTEGER"],
// ComfyUI's own reason a job failed, in one short line (src/lib/comfy-reason.ts): the owner's only.
["relay_tasks", "comfy_why", "TEXT"],
+ // A worker's slowest nodes for the job, as JSON (src/lib/node-times.ts): the owner's only.
+ ["relay_tasks", "exec_nodes", "TEXT"],
// A pool worker's next token (workers.ts offerNextToken) and where its token was used from (hashed networks).
["relay_workers", "next_token_hash", "TEXT"],
["relay_workers", "next_expires_at", "INTEGER"],
diff --git a/src/server/run-details.ts b/src/server/run-details.ts
index e0bfb5f7..6d40dcb8 100644
--- a/src/server/run-details.ts
+++ b/src/server/run-details.ts
@@ -3,6 +3,7 @@ import fs from "node:fs";
import { getModel, getPreset } from "@/lib/catalog";
import { presetRoutes } from "@/lib/catalog/preset-recipe-routes";
import { AUTO_IMAGE } from "@/lib/auto-image";
+import { cleanNodeTimes, type NodeTime } from "@/lib/node-times";
import type { AutoWhy, Engine, GenerationRequest, MediaKind } from "@/lib/catalog/types";
import { madeOfRun } from "@/lib/catalog/fitted";
import type { SettingChange } from "@/lib/catalog/made";
@@ -197,6 +198,8 @@ export interface RunJob {
note?: string;
/** ComfyUI's own reason this job failed, in one short line, as its worker or tab reported it. */
comfyWhy?: string;
+ /** Its slowest nodes as its worker timed them (src/lib/node-times.ts), slowest first. */
+ nodes?: NodeTime[];
/** Its computer's ComfyUI didn't answer, since when (and why, when it said). */
down?: { at: number; why?: string };
}
@@ -558,6 +561,7 @@ interface TaskFacts {
down_why: string | null;
progress_json: string | null;
comfy_why: string | null;
+ exec_nodes: string | null;
created_at: number;
claimed_at: number | null;
sent_at: number | null;
@@ -587,7 +591,7 @@ const col = (have: Set<string>, name: string) => (have.has(name) ? name : `NULL
function jobsOf(id: string, url?: string): { jobs: RunJob[]; log: WorkerEvent[]; tasks: TaskFacts[] } {
const have = columnsOf("relay_tasks");
if (!have.size) return { jobs: [], log: [], tasks: [] };
- const cols = ["slot", "lane", "class", "requeues", "tried_json", "est_ms", "progress_json", "comfy_why"].map((c) => col(have, c)).join(", ");
+ const cols = ["slot", "lane", "class", "requeues", "tried_json", "est_ms", "progress_json", "comfy_why", "exec_nodes"].map((c) => col(have, c)).join(", ");
const tasks = db()
.prepare(
`SELECT id, state, workflow_id, attempts, error, note, down_at, down_why, created_at, claimed_at, sent_at, started_at, finished_at, ${cols}
@@ -605,6 +609,7 @@ function jobsOf(id: string, url?: string): { jobs: RunJob[]; log: WorkerEvent[];
const worker = finished?.worker_name ?? taker?.worker_name;
const device = finished?.device ?? taker?.device;
const tried = parse(t.tried_json);
+ const nodes = t.exec_nodes ? cleanNodeTimes(parse(t.exec_nodes)) : undefined;
return {
state: t.state,
slot: t.slot === "cpu" ? "cpu" : "gpu",
@@ -626,6 +631,7 @@ function jobsOf(id: string, url?: string): { jobs: RunJob[]; log: WorkerEvent[];
...(t.error && { error: scrub(t.error) }),
...(t.note && { note: scrub(t.note) }),
...(t.comfy_why && { comfyWhy: scrub(t.comfy_why) }),
+ ...(nodes && { nodes }),
...(t.down_at != null && { down: { at: t.down_at, ...(t.down_why && { why: t.down_why }) } }),
};
});
diff --git a/tests/auto-image.test.ts b/tests/auto-image.test.ts
index 6453d4d6..9f7f9193 100644
--- a/tests/auto-image.test.ts
+++ b/tests/auto-image.test.ts
@@ -105,6 +105,22 @@ describe("what Auto picks", () => {
expect(pick(words), words).toMatchObject({ models: ["oss-ideogram-4", ...AUTO_FALLBACKS], why: "plain" });
});
+ it("lettering a prompt only rules out doesn't count as asking for it", () => {
+ for (const words of [
+ "editorial portrait of a model in a camel coat, sharp focus, no text, no watermark.",
+ "a beach at dawn without any text or logos",
+ "studio photo, no visible text, no captions, no watermarks",
+ "a clean product shot, text-free, logo-free",
+ "a misty forest, avoid text and labels",
+ ])
+ expect(pick(words), words).toMatchObject({ models: ["oss-ideogram-4", ...AUTO_FALLBACKS], why: "plain" });
+ const acct = autoCandidates({ prompt: "full-body photograph of a model on a bed, soft daylight, no text, no watermark.", account: true }, defaults);
+ expect(acct).toMatchObject({ models: [...AUTO_FALLBACKS, "oss-ideogram-4"], why: "plain" });
+ // A prompt that rules some lettering out and asks for other lettering still asks for it.
+ for (const words of ['a poster that says "OPEN", no watermark', "a neon sign above a bar, no logos", "no text on the shirt, a logo on the cap"])
+ expect(pick(words), words).toMatchObject({ why: "text" });
+ });
+
it("an account's plain prompt starts on Krea 2 Realism; its lettering and edits route as the owner's", () => {
const acct = (prompt: string, more: { op?: "t2i" | "edit"; images?: number } = {}) => autoCandidates({ prompt, ...more, account: true }, defaults);
for (const words of ["a koi pond at night, neon rain", "a woman in a red evening gown on a staircase"])
diff --git a/tests/node-times.test.ts b/tests/node-times.test.ts
new file mode 100644
index 00000000..a39faafd
--- /dev/null
+++ b/tests/node-times.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from "vitest";
+import { cleanNodeTimes, NODE_TIMES, NodeClock } from "@/lib/node-times";
+
+describe("node times", () => {
+ it("times each node from its start to the next, with the time before its first step", () => {
+ const c = new NodeClock();
+ c.executing("11", 0); // text encoder
+ c.executing("3", 4_000); // sampler: loads its model, then 6 steps
+ c.progress("3", 6, 54_000);
+ c.progress("3", 6, 60_000);
+ c.executing("8", 86_000); // decode
+ c.executing(null, 89_000);
+ const graph = { "3": { class_type: "KSampler" }, "8": { class_type: "VAEDecode" }, "11": { class_type: "CLIPTextEncode" } };
+ expect(c.times(graph)).toEqual([
+ { node: "3", type: "KSampler", ms: 82_000, beforeStepsMs: 50_000, steps: 6 },
+ { node: "11", type: "CLIPTextEncode", ms: 4_000 },
+ { node: "8", type: "VAEDecode", ms: 3_000 },
+ ]);
+ });
+
+ it("ends the last node with the prompt, adds up a node that runs twice, and leaves out the quick ones", () => {
+ const c = new NodeClock();
+ c.executing("5", 0);
+ c.executing("6", 10);
+ c.executing("5", 1_010);
+ c.end(2_010);
+ expect(c.times()).toEqual([
+ { node: "5", ms: 1_010 },
+ { node: "6", ms: 1_000 },
+ ]);
+ });
+
+ it("keeps at most the slowest few; a step before any node, or after the end, counts for none", () => {
+ const c = new NodeClock();
+ c.progress("1", 4, 0);
+ for (let i = 0; i < 20; i++) c.executing(String(i), i * 1_000 + i * i);
+ c.end(30_000);
+ c.progress("19", 4, 30_001);
+ const t = c.times();
+ expect(t).toHaveLength(NODE_TIMES.most);
+ expect(t[0].node).toBe("19");
+ expect(t.every((n) => n.steps === undefined)).toBe(true);
+ });
+
+ it("cleans what a report or the database holds", () => {
+ expect(cleanNodeTimes(undefined)).toBeUndefined();
+ expect(cleanNodeTimes([{ node: "3", ms: 5 }, { node: "../x", ms: 1 }, { node: "4", ms: -1 }, { node: "5", type: "<b>", ms: 2.6, beforeStepsMs: 9, steps: 1.5 }])).toEqual([
+ { node: "3", ms: 5 },
+ { node: "5", ms: 3, beforeStepsMs: 3 },
+ ]);
+ expect(cleanNodeTimes([{ node: "3", type: "KSampler", ms: 9e9, steps: 6 }], 60_000)).toEqual([{ node: "3", type: "KSampler", ms: 60_000, steps: 6 }]);
+ expect(cleanNodeTimes(Array.from({ length: 40 }, (_, i) => ({ node: String(i), ms: i })))).toHaveLength(NODE_TIMES.most);
+ });
+});
diff --git a/tests/worker-runner.test.ts b/tests/worker-runner.test.ts
index 6b687a5f..f06f12dd 100644
--- a/tests/worker-runner.test.ts
+++ b/tests/worker-runner.test.ts
@@ -156,6 +156,9 @@ describe("a worker's runner", () => {
expect(finished.device).toMatch(/\S/);
expect(String(finished.device)).not.toMatch(/^cuda:|cudaMallocAsync/);
expect(tasks.execOf(state(id))).toEqual({ ms: finished.execMs, device: finished.device });
+ // Its slowest nodes, as the socket timed them: the sampler with its steps, kept for the owner's run details.
+ expect(finished.nodes).toEqual([expect.objectContaining({ node: expect.any(String), steps: 4 })]);
+ expect(JSON.parse(String(state(id).exec_nodes))).toEqual(finished.nodes);
});
it("a browser tab's runner (no worker hooks) reports as it always did", async () => {