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: a run stopped while its result is saved stays stopped, and a chain's later step is checked for away workers

Adarshe32319221387
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 896a647c..032a56d4 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -2671,23 +2671,29 @@ async function pollOne(r: Row): Promise<void> {
// An image-to-3D GLB from ComfyUI gets the server's finish first (the web GLB, seconds): the outputs are
// stored now and the row stays running until it's done, so a restart resumes it from them. The turntable
// is rendered after the job has succeeded (src/server/model3d-finish.ts).
+ // Stopped (or taken over by another app process) while its results were saved: the files saved here belong to no run,
+ // so they go now instead of filling the account's space.
+ const dropSaved = () => {
+ for (const kept of outputs) if (kept.assetId) deleteAsset(kept.assetId);
+ };
if (modelToFinish(r, outputs) >= 0) {
- updateLive(r.id, { outputs_json: JSON.stringify(outputs), external_meta_json: JSON.stringify({ ...ctx.meta, finishing: true }), message: "Finishing the 3D model" });
+ if (!updateLive(r.id, { outputs_json: JSON.stringify(outputs), external_meta_json: JSON.stringify({ ...ctx.meta, finishing: true }), message: "Finishing the 3D model" })) return dropSaved();
resumeFinish({ ...r, outputs_json: JSON.stringify(outputs) });
return;
}
// The moderation service asked to see this run's outputs first: they are held, and the row waits ("Checking").
if (stored.checkOutputs && moderationConfigured()) {
- holdForCheck(r.id, outputs);
+ if (!holdForCheck(r.id, outputs, { live: true })) dropSaved();
return;
}
- updateLive(r.id, {
+ const saved = updateLive(r.id, {
status: "succeeded",
outputs_json: JSON.stringify(outputs),
progress: 1,
message: dropped ? `Kept ${ACCOUNT_LIMITS.outputsPerJob} of ${ACCOUNT_LIMITS.outputsPerJob + dropped} results` : null,
completed_at: Date.now(),
});
+ if (!saved) dropSaved();
}
/**
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 9b768288..cf1d4b06 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -158,6 +158,16 @@ export function stepsProblem(p: Policy, steps: PlannedStep[]): string | null {
return null;
}
+/**
+ * Are the workers that could run some GPU step of a run all away now (paused, silent, outside their hours): its own
+ * model's, or a later step's of a chain? Then the run would wait for nothing at that step, so it isn't made. Light steps
+ * (a join, a trim) are left out, as they cost nothing.
+ */
+export function runAway(planned: Pick<Planned, "route">, steps: PlannedStep[] | null | undefined): boolean {
+ if (poolAway(planned.route.endpoint)) return true;
+ return (steps ?? []).some((s) => s.provider === "comfyui" && !freeStep(s) && poolAway(stepEndpoint(s)));
+}
+
/**
* Is a run light work only: every step it makes a ComfyUI step that needs no model and no graphics memory (a filter, a
* trim, a join, adding sound, a Ken Burns move)? Such a run is free and never counts against the policy's limits on runs
@@ -331,7 +341,7 @@ export async function decidePlace(account: Account, asked: GenerationRequest, wi
// Every GPU here that could run it is off for now (paused, silent, outside its hours): a run made now would only wait
// until its wait limit ended it. It goes to the account's own GPU as any run these GPUs can't take now, else it isn't
// made, in the words the price check gave before Run.
- if (poolAway(planned.route.endpoint)) return ownFallback ? OWN : { kind: "refuse", refusal: billingRefusal("busy", HOSTED_WORDS.startingSoon) };
+ if (runAway(planned, gate.steps)) return ownFallback ? OWN : { kind: "refuse", refusal: billingRefusal("busy", HOSTED_WORDS.startingSoon) };
// Its own GPU didn't answer the check: asked, never moved to this install's GPUs (and charged) without a word.
if (ownOffline) return { kind: "refuse", refusal: askPlace() };
return { kind: "pool", planned, policy: p, steps: gate.steps ? pricedSteps(gate.steps) : undefined, req, capped, light: lightRun(gate.steps) };
@@ -503,7 +513,7 @@ export async function poolQuote(
}
// Every GPU here that could run it is off for now: Run is off and says it starts soon (the price check asks again by
// itself, and Run comes back on once one is back), never a run that would wait for nothing.
- if (poolAway(planned.route.endpoint)) {
+ if (runAway(planned, gate.steps)) {
if (hasGpu && wish !== "pool") return null;
return { planned, quote: startingSoonQuote(), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };
}
diff --git a/src/server/output-checks.ts b/src/server/output-checks.ts
index 0383a2c3..d48779d6 100644
--- a/src/server/output-checks.ts
+++ b/src/server/output-checks.ts
@@ -21,18 +21,26 @@ export const HIDDEN_WORDS = "This result was removed by the studio's checks. Not
export const UNCHECKED_WORDS = "This result couldn't be checked in time, so it was removed. Not charged.";
export const CHECKING_WORDS = "Checking";
-/** Hold a finished run's files for their check (the runner calls it instead of marking the row succeeded). */
-export function holdForCheck(generationId: string, outputs: OutputFile[], now = Date.now()): void {
+/**
+ * Hold a finished run's files for their check (the runner calls it instead of marking the row succeeded). `live`: only
+ * while the run still goes (queued or running), as the runner saves it: a run stopped meanwhile stays stopped, nothing of
+ * it is held, and the caller removes its files. Returns whether the files were held.
+ */
+export function holdForCheck(generationId: string, outputs: OutputFile[], o: { live?: boolean; now?: number } = {}): boolean {
+ const now = o.now ?? Date.now();
const d = db();
const ids = outputs.map((o) => o.assetId).filter((x): x is string => !!x);
- d.transaction(() => {
+ const live = o.live ? " AND status IN ('queued', 'running')" : "";
+ return d.transaction((): boolean => {
+ const held = d.prepare(`UPDATE generations SET status = 'running', stage = 'checking', progress = 0.99, message = ?, outputs_json = ?, updated_at = ? WHERE id = ?${live}`).run(CHECKING_WORDS, JSON.stringify(outputs), now, generationId).changes > 0;
+ if (!held) return false;
for (const id of ids) {
d.prepare("UPDATE assets SET held = 1 WHERE id = ?").run(id);
d.prepare("INSERT OR IGNORE INTO output_checks (asset_id, generation_id, state, asked_at, tries, next_at) VALUES (?, ?, 'waiting', ?, 0, ?)").run(id, generationId, now, now);
}
- d.prepare("UPDATE generations SET status = 'running', stage = 'checking', progress = 0.99, message = ?, outputs_json = ?, updated_at = ? WHERE id = ?").run(CHECKING_WORDS, JSON.stringify(outputs), now, generationId);
// A run with no saved file (words only) has nothing to check: it succeeds as it is.
if (!ids.length) d.prepare("UPDATE generations SET status = 'succeeded', stage = NULL, progress = 1, message = NULL, completed_at = ?, updated_at = ? WHERE id = ?").run(now, now, generationId);
+ return true;
})();
}
diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.ts
index a9793fd9..ddc9f4c9 100644
--- a/tests/pool-limits.test.ts
+++ b/tests/pool-limits.test.ts
@@ -788,6 +788,32 @@ describe("the price check before Run and the run itself", async () => {
}
});
+ it("a chain whose later step only away workers could run is told it starts soon, though a worker for its first step is on", async () => {
+ const endpointOf = (id: string) => getModel(id)!.routes.find((r) => r.provider === "comfyui")!.endpoint;
+ const first = endpointOf("oss-z-image-turbo");
+ const later = endpointOf("oss-rtx-video-upscale");
+ const laterLane = pool.poolLane(later);
+ expect(pool.poolLane(first)).not.toBe(laterLane);
+ const lanes = allLanes(loadIndex(), sha).map((l) => l.lane);
+ // The worker that is on may run every lane but the later step's; the only one that may run that lane is away.
+ pool.patchWorker(worker.id, { allow: Object.fromEntries(lanes.filter((l) => l !== laterLane).map((l) => [l, { delayMs: 0 }])) });
+ const away = standInWorker();
+ pool.patchWorker(away.id, { allow: { [laterLane]: { delayMs: 0 } } });
+ db().prepare("UPDATE relay_workers SET paused_local = 1, local_why = 'gpu-busy:game.exe' WHERE id = ?").run(away.id);
+ const chain = [
+ { id: "s0", modelId: "oss-z-image-turbo", op: "t2i", provider: "comfyui", kind: "image", presetId: null, waits: false },
+ { id: "s1", modelId: "oss-rtx-video-upscale", op: "upscale-video", provider: "comfyui", kind: "video", presetId: null, waits: true },
+ ];
+ const planned = { route: { endpoint: first } };
+ expect(hostedRun.runAway(planned as never, [chain[0]])).toBe(false);
+ expect(hostedRun.runAway(planned as never, chain)).toBe(true);
+ // A step that isn't on this install's GPUs (a cloud step) is not looked at.
+ expect(hostedRun.runAway(planned as never, [chain[0], { ...chain[1], provider: "fal" }])).toBe(false);
+ // The away worker is back: the chain may be made.
+ db().prepare("UPDATE relay_workers SET paused_local = 0, local_why = NULL WHERE id = ?").run(away.id);
+ expect(hostedRun.runAway(planned as never, chain)).toBe(false);
+ });
+
it("a guest's price check plans every step of a chain too, and words its refusals for someone with no Settings yet", async () => {
withBilling({ limits: NO_LIMITS });
expect((await hostedRun.poolQuote(null, EFFECT as never, undefined))?.quote.allowed).toBe(true);