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
Queue: a run that loads an optional file goes only to a worker that has it
Adarsh4c6b0d043936
diff --git a/src/lib/runtime-files.ts b/src/lib/runtime-files.tsindex 511bcdeb..cc8bc1aa 100644--- a/src/lib/runtime-files.ts+++ b/src/lib/runtime-files.ts@@ -70,6 +70,33 @@ export function runtimeNeeds(names: readonly string[], index: Pick<RequirementInreturn { files: [...out.values()], unknown };}+/**+ * The optional files of a workflow that this run's graph loads (an opt-in Prompt helper's model when it is on, a decoder or+ * a card's own transformer an option picks), as a worker must have them: only a worker that verified each one takes the+ * task, as for a run-time file. A worker checks every file a graph loads, so one without them would refuse the job.+ */+export function graphOptionalNeeds(+ graph: Record<string, { class_type?: unknown; inputs?: Record<string, unknown> } | null | undefined>,+ index: Pick<RequirementIndex, "files" | "workflows">,+ workflowId: string,+): FileNeed[] {+ const wf = index.workflows[workflowId];+ if (!wf?.optional?.length) return [];+ const loaded = new Set<string>();+ for (const node of Object.values(graph ?? {})) {+ if (!node || typeof node.class_type !== "string" || !node.inputs) continue;+ for (const v of Object.values(node.inputs)) if (typeof v === "string" && v) loaded.add(v.replace(/\\/g, "/"));+ }+ const own = new Set(wf.files);+ const out: FileNeed[] = [];+ for (const key of wf.optional) {+ const f = index.files[key];+ if (!f || own.has(key) || !loaded.has(f.file)) continue;+ out.push({ folder: f.folder, name: f.file, size: f.sizeBytes, sha256: f.sha256 ?? null });+ }+ return out;+}+/** The node inputs that name a LoRA file (LoraLoader's and LoraLoaderModelOnly's lora_name, WanVideoLoraSelect's lora). */const LORA_INPUT = /^lora(_name)?$/;diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.tsindex 8373fcb7..15759506 100644--- a/src/server/providers/comfyui.ts+++ b/src/server/providers/comfyui.ts@@ -15,7 +15,7 @@ import { H3_LATENT_DRAFT_WORKFLOW, REGEN_COPY, REGEN_LATENT_WORKFLOW, REGEN_WORKimport { fixFromPromptError } from "@/lib/gpu/fix-codes";import { loadIndex } from "../gpu/index-file";import type { FileNeed } from "@/lib/lanes";-import { graphLoraNames, runtimeNeeds } from "@/lib/runtime-files";+import { graphLoraNames, graphOptionalNeeds, runtimeNeeds } from "@/lib/runtime-files";import { installedDbs, type DbsModel } from "@/lib/av/split";import { installedReuse, type ReuseModel } from "@/lib/av/clean-voice";import { RTX_FRAMEGEN_WORKFLOW, RTX_HDR_WORKFLOW, RTX_MISSING } from "@/lib/catalog/rtx-video";@@ -2105,8 +2105,10 @@ export const comfyProvider: ProviderAdapter = {if (forPool && workersCanRun(manifest.id) && !workersCanRun(manifest.id, { size: prepared.size })) throw new ProviderError(computer === "owner" ? NO_WORKER_FOR_SIZE : POOL_TOO_BIG);// The files the graph loads beyond its workflow's own (a look's, a motion's or a recipe's LoRAs): only a worker that// verified each one takes the task, and a job no worker could take is refused now, never left to wait for nothing- // (or refused by a worker for a file it hasn't verified).- const runtime = forPool ? runtimeNeeds(graphLoraNames(wf), loadIndex(), manifest.id) : null;+ // (or refused by a worker for a file it hasn't verified). The workflow's optional files the graph loads count too (a+ // Prompt helper's model when it is on, a decoder an option picks): only a worker that has them takes the task.+ const loras = forPool ? runtimeNeeds(graphLoraNames(wf), loadIndex(), manifest.id) : null;+ const runtime = loras && { ...loras, files: [...loras.files, ...graphOptionalNeeds(wf, loadIndex(), manifest.id).filter((f) => !loras.files.some((l) => l.folder === f.folder && l.name === f.name))] };if (runtime && workersCanRun(manifest.id) && (runtime.unknown.length || !workersCanRun(manifest.id, { files: runtime.files }))) {const lacking = [...runtime.unknown, ...runtime.files.filter((f) => !workersCanRun(manifest.id, { files: [f] })).map((f) => f.name)];throw new ProviderError(computer === "owner" ? noWorkerForFiles(lacking.length ? lacking : runtime.files.map((f) => f.name)) : POOL_NO_FILES);diff --git a/tests/graph-optional-needs.test.ts b/tests/graph-optional-needs.test.tsnew file mode 100644index 00000000..24964559--- /dev/null+++ b/tests/graph-optional-needs.test.ts@@ -0,0 +1,32 @@+import { describe, expect, it } from "vitest";+import { PROMPT_HELPER_FILES } from "@/lib/comfy";+import { graphOptionalNeeds } from "@/lib/runtime-files";+import { loadIndex } from "@/server/gpu/index-file";++/**+ * A workflow's optional files that a run's graph loads (an opt-in Prompt helper's model when it is on, a decoder an option+ * picks) are files that run needs on the worker: a worker checks every file a graph loads, so the queue offers the task+ * only to a worker that verified them.+ */++const node = (class_type: string, inputs: Record<string, unknown>) => ({ class_type, inputs });++describe("graphOptionalNeeds", () => {+ it.each(["minimax-h3-image-edit", "minimax-h3-image-t2i"])("%s: the Prompt helper's model when the graph loads it, nothing when it doesn't", (id) => {+ const index = loadIndex();+ const wf = index.workflows[id];+ expect(wf, id).toBeTruthy();+ const helper = index.files[PROMPT_HELPER_FILES[id] as keyof typeof index.files];+ expect(helper, "the helper's file is pinned in the index").toBeTruthy();+ expect(wf.optional).toContain(PROMPT_HELPER_FILES[id]);+ const base = Object.fromEntries(wf.files.map((k, i) => [String(i + 1), node("Loader", { name: index.files[k]?.file ?? k })]));+ expect(graphOptionalNeeds(base, index, id)).toEqual([]);+ const on = { ...base, "10": node("CLIPLoader", { clip_name: helper.file, type: "qwen_image" }) };+ expect(graphOptionalNeeds(on, index, id)).toEqual([{ folder: helper.folder, name: helper.file, size: helper.sizeBytes, sha256: helper.sha256 ?? null }]);+ });++ it("an unknown workflow, or one with no optional files, needs nothing more", () => {+ const index = loadIndex();+ expect(graphOptionalNeeds({ "1": node("CLIPLoader", { clip_name: "x.safetensors" }) }, index, "no-such-workflow")).toEqual([]);+ });+});