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: a running job's progress follows its sampler's steps
Adarsh81acabab4f57
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.tsindex 219f2b26..504ecbe2 100644--- a/src/server/providers/comfyui.ts+++ b/src/server/providers/comfyui.ts@@ -640,6 +640,19 @@ export function queuePlace(pending: unknown[][], promptId: string): number {return pending.filter((q) => typeof q[0] === "number" && q[0] < n).length;}+/**+ * A running job's progress (0 to 0.99), or undefined when nothing says yet: the share of the graph's nodes run so far+ * (`nodesDone` of `total`, the running node counting as part done by its steps), and never less than the running+ * node's own steps (`value` of `max`). The sampler takes most of a job's time while it is one node of many, so step 3+ * of 8 shows as 3/8, not 3/8 of one node's share.+ */+export function runProgress(p: { nodesDone?: number; value?: number; max?: number } | undefined, total: number): number | undefined {+ const stepFrac = p?.max ? Math.min(1, Math.max(0, (p.value ?? 0) / p.max)) : 0;+ const nodeFrac = total > 0 ? (Math.max(1, p?.nodesDone ?? 1) - 1 + stepFrac) / total : 0;+ const v = Math.min(0.99, Math.max(stepFrac, nodeFrac));+ return v > 0 ? v : undefined;+}+// ---------------------------------------------------------------------------// Outputs@@ -1845,10 +1858,7 @@ async function pollTask(principal: Principal, t: TaskRow, meta: Record<string, ucase "queued":return { state: "queued", message: down ?? queueWords(p?.position), ...(sentAt && { sentAt }) };case "running": {- const total = Number(meta.nodeCount ?? 0);- const stepFrac = p?.max ? (p.value ?? 0) / p.max : 0;- const value = total ? Math.min(0.99, (Math.max(1, p?.nodesDone ?? 1) - 1 + stepFrac) / total) : stepFrac || undefined;- return { state: "running", progress: value && value > 0 ? value : undefined, message: down ?? makingWords(kind, p?.value, p?.max), ...(sentAt && { sentAt }) };+ return { state: "running", progress: runProgress(p, Number(meta.nodeCount ?? 0)), message: down ?? makingWords(kind, p?.value, p?.max), ...(sentAt && { sentAt }) };}case "collecting": {const got = receivedOf(t);@@ -2116,12 +2126,9 @@ export const comfyProvider: ProviderAdapter = {const busy = queue.queue_running?.[0]?.[1];return { state: "queued", position: pendingIdx, ...(typeof busy === "string" && { busyWith: busy.slice(0, 64) }), message: pendingIdx === 0 ? "Next in ComfyUI's queue" : `In ComfyUI's queue · ${pendingIdx} ahead` };}- const total = Number(meta.nodeCount ?? 0);- const stepFrac = p && p.max ? p.value / p.max : 0;- const progressValue = total ? Math.min(0.99, ((p?.nodesDone ?? 0) - 1 + stepFrac) / total) : stepFrac || undefined;return {state: "running",- progress: progressValue && progressValue > 0 ? progressValue : undefined,+ progress: runProgress(p, Number(meta.nodeCount ?? 0)),message: p?.max ? `Sampling ${p.value}/${p.max}` : worker === "isolated" ? "Running on the isolated ComfyUI worker" : "Running on ComfyUI",};},diff --git a/tests/comfy-provider.test.ts b/tests/comfy-provider.test.tsindex 3d26bafd..7de4b211 100644--- a/tests/comfy-provider.test.ts+++ b/tests/comfy-provider.test.ts@@ -11,7 +11,7 @@ process.env.FUOBE_DATA_DIR = dir;process.env.COMFYUI_URL = "http://comfy.test:8188";const { setSetting } = await import("@/server/settings");-const { comfyProvider, collectOutputs, getWorkflow, loadManifest, mediaInfoFor, prepareWorkflow } = await import("@/server/providers/comfyui");+const { comfyProvider, collectOutputs, getWorkflow, loadManifest, mediaInfoFor, prepareWorkflow, runProgress } = await import("@/server/providers/comfyui");const { MODELS } = await import("@/lib/catalog");const { computeFrames } = await import("@/lib/comfy");@@ -148,6 +148,31 @@ describe("ComfyUI websocket (S15)", () => {});});+describe("a running job's progress", () => {+ it("step 3 of 8 in the sampler shows as 3/8, not 3/8 of one node's share", () => {+ expect(runProgress({ nodesDone: 1, value: 3, max: 8 }, 10)).toBeCloseTo(0.375);+ // Most nodes run already: the node share wins over the sampler's own steps.+ expect(runProgress({ nodesDone: 9, value: 1, max: 8 }, 10)).toBeCloseTo((8 + 1 / 8) / 10);+ // Nothing yet says how far it is.+ expect(runProgress(undefined, 10)).toBeUndefined();+ expect(runProgress({ nodesDone: 0 }, 10)).toBeUndefined();+ // With no node count, the steps alone; never past 0.99.+ expect(runProgress({ value: 4, max: 8 }, 0)).toBeCloseTo(0.5);+ expect(runProgress({ nodesDone: 12, value: 8, max: 8 }, 10)).toBe(0.99);+ });++ it("a poll during sampling says step 3 of 8 as 0.375", async () => {+ handler = (url) => (url.includes("/history/") ? json({}) : json({ queue_running: [[0, "p-steps"]], queue_pending: [] }));+ await comfyProvider.poll(pollCtx("p-steps", { workflowId: "selftest-image", nodeCount: 10 }));+ const ws = FakeSocket.all.at(-1)!;+ ws.emit({ type: "executing", data: { prompt_id: "p-steps", node: "3" } });+ ws.emit({ type: "progress", data: { prompt_id: "p-steps", value: 3, max: 8, node: "3" } });+ const running = await comfyProvider.poll(pollCtx("p-steps", { workflowId: "selftest-image", nodeCount: 10 }));+ expect(running.state).toBe("running");+ expect((running as { progress?: number }).progress).toBeCloseTo(0.375);+ });+});+describe("ComfyUI reachability (S16)", () => {it("answers the first routing question for a server from a real probe, not a pending one", async () => {// A stand-in ComfyUI on its own thread (a real one is another process): the probe blocks this thread.