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 on your own GPU or key: a step of a longer run that waited stops after a restart instead of moving

Adarsh598e1a59af80
diff --git a/src/server/generations.ts b/src/server/generations.ts
index b785ca1b..40c2c02f 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -1775,6 +1775,14 @@ async function advanceDependents(): Promise<void> {
const mode = chainMode(prepared, deps as Pick<Row, "provider">[], original);
if (mode.error) throw new Error(mode.error);
const p = mode.forceDemo ? { ...prepared, demo: true, providerId: "mock" as const, cost: 0 } : prepared;
+ // A step that waited, planned for another provider now (its GPU disconnected or moved, its keys changed): its wait
+ // was for the one it was made for, and nobody asked for the other, so it stops as a waiting run taken over does.
+ const own = ownAccountOf(stored);
+ if (heal && own && p.providerId !== r.provider) {
+ stopReplanned(r.id, r.provider, own, p, "chain");
+ dropUnused(allIds);
+ continue;
+ }
// Its wait goes on with what is left of it (its tries and its time), where it still goes; its tile keeps its words.
const resume = heal && !mode.forceDemo && p.providerId === r.provider ? heal : undefined;
update(r.id, {
@@ -3166,13 +3174,7 @@ function takeOver(r: Pick<Row, "id" | "provider" | "model_id" | "op" | "request_
// Planned for another provider now (its GPU disconnected, another key): its polls would ask the provider it was made
// for, so it stops, as a run whose GPU changed while it waited does.
if (p.providerId !== r.provider) {
- if (r.provider === "comfyui") {
- const gpu = accountGpu(account);
- const end = diagnoseGpuJob({ kind: gpu ? "moved" : "disconnected" }, { kind: "link", url: gpuLink(gpu)?.url ?? "" });
- failRun(r.id, new Error("moved"), end, account, { provider: r.provider, model: p.plan.model.id, op: p.plan.op, stage: "submit" });
- } else if (updateIfGoing(r.id, { status: "failed", error: "This run stopped because your keys changed while it waited. Press Retry.", completed_at: Date.now(), message: null }, " AND external_id IS NULL")) {
- ownFailed(r.id, account, { provider: r.provider, model: p.plan.model.id, op: p.plan.op, stage: "submit" }, "keys-changed");
- }
+ stopReplanned(r.id, r.provider, account, p, "submit");
return true;
}
submitting().add(r.id);
@@ -3180,6 +3182,22 @@ function takeOver(r: Pick<Row, "id" | "provider" | "model_id" | "op" | "request_
return true;
}
+/**
+ * A run that waited for its own GPU or key, planned again after a restart or a deploy (takeOver, or advanceDependents for
+ * a step of a longer run), that would now go to another provider than the one it waited for: it stops in plain words and
+ * is never sent there, since nobody pressed Run there. `was`: the provider it was made for.
+ */
+function stopReplanned(id: string, was: string, account: string, p: { plan: { model: { id: string }; op: string } }, stage: "submit" | "chain"): void {
+ const facts: RunFacts = { provider: was, model: p.plan.model.id, op: p.plan.op, stage };
+ if (was === "comfyui") {
+ const gpu = accountGpu(account);
+ const end = diagnoseGpuJob({ kind: gpu ? "moved" : "disconnected" }, { kind: "link", url: gpuLink(gpu)?.url ?? "" });
+ failRun(id, new Error("moved"), end, account, facts);
+ } else if (updateIfGoing(id, { status: "failed", error: "This run stopped because your keys changed while it waited. Press Retry.", completed_at: Date.now(), message: null }, " AND external_id IS NULL")) {
+ ownFailed(id, account, facts, "keys-changed");
+ }
+}
+
declare global {
/** The renewal of this instance's holds (pointed at the newest code after a hot reload). */
var __fuobeLeaseRenew: (() => void) | undefined;
diff --git a/tests/own-gpu-graceful.test.ts b/tests/own-gpu-graceful.test.ts
index d82c4417..aab34b65 100644
--- a/tests/own-gpu-graceful.test.ts
+++ b/tests/own-gpu-graceful.test.ts
@@ -37,6 +37,7 @@ const generationRoute = await import("@/app/api/generations/[id]/route");
const smallerRoute = await import("@/app/api/generations/[id]/smaller/route");
const { asAccount, CHAINED_RUN, cancelGeneration, createGenerations, getGeneration, LEASE, OWN_QUEUE, SELF_HEAL, STALE_SUBMIT } = await import("@/server/generations");
const { ownRunNote } = await import("@/server/run-events");
+const { removeAccountKey, saveAccountKey } = await import("@/server/account-keys");
const { cleanGpuAddress, checkGpuAddress, visitorStatus } = await import("@/server/account-gpu");
const { comfyProvider, onOwnGpu, queuePlace } = await import("@/server/providers/comfyui");
const { db } = await import("@/server/db");
@@ -966,6 +967,54 @@ describe("a wait survives a restart or a deploy", () => {
}
});
+ it("so is a step of a longer run that waited: planned for another provider after a restart, it stops, and nothing is sent", async () => {
+ fake.opts.output = "both";
+ const gone = () => ({ by: "gone", until: Date.now() - 1 });
+ const waited = (words: string) => ({ since: Date.now() - 60_000, deadline: Date.now() + 60_000, firstSeen: {}, tries: 3, next: 0, index: 0, words });
+ /** A later step of the run `first` on the account's keys: a still from its frame. */
+ const onKeys = (first: string) => asAccount(a, () => createGenerations({ feature: "image", modelId: "nano-banana-pro", engine: "cloud", prompt: "the same look at night" }, { dependsOn: first }))[0].id;
+ try {
+ const first = await startRun();
+ expect((await settle(first))?.status).toBe("succeeded");
+ // Made for its fal.ai key (it has a Replicate key too), which it waited for on an instance that is gone. Meanwhile
+ // the account removed that key: the next instance would plan it on Replicate, which nobody pressed Run for.
+ saveAccountKey(a, "fal", "acct-fal-graceful");
+ saveAccountKey(a, "replicate", "acct-rep-graceful");
+ const second = onKeys(first);
+ expect(getGeneration(second)?.provider).toBe("fal");
+ setPending(second, { heal: waited("Waiting for fal.ai"), lease: gone() });
+ removeAccountKey(a, "fal");
+ fake.log.length = 0;
+ fetched.length = 0;
+ const g = await settle(second);
+ expect(g?.status).toBe("failed");
+ expect(g?.error).toBe("This run stopped because your keys changed while it waited. Press Retry.");
+ expect(fetched.filter((u) => /fal\.(ai|run|media)|replicate\.com/.test(u))).toEqual([]);
+ expect(getGeneration(second)?.provider).toBe("fal");
+ expect(ownRunNote(second)).toMatchObject({ cause: "keys-changed", stage: "chain" });
+ // One made for its GPU (the row says so), planned on its key now that the account disconnected that GPU: it stops,
+ // saying so, and its key is never used.
+ saveAccountKey(a, "fal", "acct-fal-graceful");
+ const third = onKeys(first);
+ db().prepare("UPDATE generations SET provider = 'comfyui' WHERE id = ?").run(third);
+ setPending(third, { heal: { ...waited("Waiting for your GPU"), firstSeen: { "gpu-off": Date.now() - 60_000 } }, lease: gone() });
+ auth.setAccountGpu(a, null);
+ fake.log.length = 0;
+ fetched.length = 0;
+ const h = await settle(third);
+ expect(h?.status).toBe("failed");
+ expect(h?.error).toBe("You disconnected your GPU, so this run stopped. Connect it again, then press Retry.");
+ expect(h?.trouble?.actions[0]).toMatchObject({ kind: "gpu-settings", label: "Connect your GPU" });
+ expect(fake.log.filter((e) => e.path === "/prompt" || e.path === "/upload/image")).toHaveLength(0);
+ expect(fetched.filter((u) => /fal\.(ai|run|media)|replicate\.com/.test(u))).toEqual([]);
+ expect(ownRunNote(third)).toMatchObject({ cause: "gpu-moved", stage: "chain" });
+ } finally {
+ removeAccountKey(a, "fal");
+ removeAccountKey(a, "replicate");
+ fake.opts.output = undefined;
+ }
+ });
+
it("a deploy's old instance hands its waiting run to the new one, which goes on with it and runs it once", async () => {
SELF_HEAL.scale = 0.01;
LEASE.ms = 400;