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
Fix faces after a clip: only the finished clips get the step
Adarsh0588c4427ee5
diff --git a/src/server/generations.ts b/src/server/generations.tsindex c0d10bdf..c725db13 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -469,6 +469,24 @@ function waitingOf(r: Pick<Row, "id" | "depends_on" | "batch_id" | "request_json/** A run whose job was being sent when it stopped (a server cut off in the middle of the send): its provider may have it. */const maybeSent = (r: Pick<Row, "error" | "external_meta_json">): boolean => r.error === CUT_OFF_SENDING || typeof readMeta(r.external_meta_json).heal?.sending === "number";+/** The ids a run waits for (its depends_on: one id, or a JSON list). */+function dependsOnIds(dependsOn: string | null | undefined): string[] {+ if (!dependsOn) return [];+ if (!dependsOn.startsWith("[")) return [dependsOn];+ try {+ return (JSON.parse(dependsOn) as unknown[]).filter((x): x is string => typeof x === "string");+ } catch {+ return [];+ }+}++/** The finished clips among the runs one request made: videos that no other of those runs waits for. */+export function finalClips(runs: Generation[]): Generation[] {+ const q = db().prepare("SELECT depends_on FROM generations WHERE id = ?").pluck();+ const waitedOn = new Set(runs.flatMap((g) => dependsOnIds(q.get(g.id) as string | null | undefined)));+ return runs.filter((g) => g.kind === "video" && !waitedOn.has(g.id));+}+/*** A run that is one step of a longer one: it waits for an earlier step, or a later step (queued or running) waits for it.* Run with your key can't move such a step alone (the route answers 409 CHAINED_RUN, and its tile doesn't offer it).@@ -1713,9 +1731,11 @@ export function createGenerations(sent: GenerationRequest, opts: CreateOptions =const extra = { ...original.params?.extra };delete extra[FIX_FACES_AFTER_PARAM];const takes = createGenerations({ ...original, params: { ...original.params, extra } }, { batchId });+ // Only the finished clips get Fix faces: a take can come with earlier steps of its own (a picture made first for its+ // end frame, say), which have no video to fix.const fixed: Generation[] = [];try {- for (const t of takes) fixed.push(...createGenerations(fixFacesAfterStep(original), { batchId, dependsOn: t.id }));+ for (const t of finalClips(takes)) fixed.push(...createGenerations(fixFacesAfterStep(original), { batchId, dependsOn: t.id }));} catch (e) {for (const g of [...fixed, ...takes]) void cancelGeneration(g.id);throw e;diff --git a/tests/fix-faces-after-chain.test.ts b/tests/fix-faces-after-chain.test.tsnew file mode 100644index 00000000..0f18efc4--- /dev/null+++ b/tests/fix-faces-after-chain.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from "vitest";+import { tempDir } from "./helpers/temp-dir";++process.env.FUOBE_DATA_DIR = tempDir("fuobe-fix-faces-chain-");++const { db } = await import("@/server/db");+const { finalClips } = await import("@/server/generations");++const add = (id: string, kind: "image" | "video", dependsOn: string | null) => {+ const now = Date.now();+ db()+ .prepare(+ "INSERT INTO generations (id, feature, model_id, engine, provider, op, kind, status, request_json, outputs_json, created_at, updated_at, depends_on) VALUES (?, 'studio', 'm', 'open', 'comfyui', 'x', ?, 'queued', '{}', '[]', ?, ?, ?)",+ )+ .run(id, kind, now, now, dependsOn);+ return { id, kind } as never;+};++describe("Fix faces after a clip goes only on the finished clips", () => {+ it("leaves out a picture made first for the clip's end frame", () => {+ const still = add("still-1", "image", null);+ const clip = add("clip-1", "video", "still-1");+ expect(finalClips([still, clip]).map((g: { id: string }) => g.id)).toEqual(["clip-1"]);+ });++ it("leaves out clip parts another step joins, and keeps each take of a plain run", () => {+ const a = add("part-a", "video", null);+ const b = add("part-b", "video", null);+ const joined = add("joined", "video", JSON.stringify(["part-a", "part-b"]));+ expect(finalClips([a, b, joined]).map((g: { id: string }) => g.id)).toEqual(["joined"]);+ const t1 = add("take-1", "video", null);+ const t2 = add("take-2", "video", null);+ expect(finalClips([t1, t2]).map((g: { id: string }) => g.id)).toEqual(["take-1", "take-2"]);+ });+});