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.

Hosted runs: Run pressed while every worker is away promises no start

Adarshe7e74c3771ab
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index 409520b4..b62b94aa 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -357,8 +357,9 @@ it must have the VRAM.
When every worker that could run an account's run is away right now (paused on the website or on its PC, draining,
outside its hours, silent for over 2 minutes, or never connected), the price check says "Starting soon" and Run is
-off. Run pressed then makes no run and gives the same words (503, code `busy`). The price check asks again by itself,
-and Run comes back on once one of those workers is back. A worker that waits for local ComfyUI work to make room is
+off. When those workers go away between the price check and a press of Run, the press makes no run. Its answer is
+"Try again in a moment." (503, code `busy`), with no billing card, and the page asks the price check again, which now
+says "Starting soon". The price check asks again by itself, and Run comes back on once one of those workers is back. A worker that waits for local ComfyUI work to make room is
not away: runs go in line for it. An account with its own GPU gets its run there instead, unless it asked for this
install's GPUs.
diff --git a/src/lib/api.ts b/src/lib/api.ts
index f306aed3..f646c842 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -598,6 +598,9 @@ export function useCreateGeneration() {
// The runs going and the line changed: the price check before the next Run asks again.
refreshPriceChecks(qc);
},
+ // Refused (every GPU that could run it went away since the price check, a limit, a new price): the price check asks
+ // again, so Run and its words show where things stand now.
+ onError: () => refreshPriceChecks(qc),
});
}
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index aa539d69..2bbc974b 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -786,8 +786,8 @@ function onSoon(w: WorkerRow, now: number): boolean {
/**
* Is every worker that could run this workflow (any workflow: null) away now: paused, draining, outside its hours,
* silent, or never connected? A run made then would wait for nothing until its wait limit ended it, so the price check
- * and Run say "Starting soon" instead and nothing is made. False when no worker could run it at all (workersCanRun
- * refuses that) or one is on.
+ * says "Starting soon" (Run is off), and a press of Run makes nothing. False when no worker could run it at all
+ * (workersCanRun refuses that) or one is on.
*/
export function workersAway(workflowId: string | null, now = Date.now()): boolean {
const able = ableWorkers(workflowId);
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 0311ff76..0708288f 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -95,6 +95,13 @@ const OWN: PlaceDecision = { kind: "own" };
/** What an account whose own GPU didn't answer is asked, when its run named no place (never moved and charged unasked). */
export const OWN_GPU_QUIET = "Your GPU isn't answering right now. Run this on this studio's GPUs instead, or try again when your GPU is back.";
+/**
+ * Run pressed while every GPU here that could run it is away (it was there when the price check before Run asked): no
+ * run is made, and the answer promises no start. It is no billing refusal, so no card opens for it: the page says the
+ * words and asks the price check again, which now says "Starting soon" with Run off until one of those GPUs is back.
+ */
+const awayRefusal = (): Refusal => ({ status: 503, body: { error: BILLING_WAIT.run, code: "busy" }, headers: { "Retry-After": "15" } });
+
/** A run this install's GPUs won't take, refused in the words the price check before Run gives too. */
const notOffered = (error: string): PlaceDecision => ({ kind: "refuse", refusal: { status: 403, body: { error, code: "not-offered" }, headers: { [BILLING_HEADER]: "not-offered" } } });
@@ -343,8 +350,8 @@ 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 (runAway(planned, gate.steps)) return ownFallback ? OWN : { kind: "refuse", refusal: billingRefusal("busy", HOSTED_WORDS.startingSoon) };
+ // made (awayRefusal).
+ if (runAway(planned, gate.steps)) return ownFallback ? OWN : { kind: "refuse", refusal: awayRefusal() };
// 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) };
diff --git a/src/server/hosted.ts b/src/server/hosted.ts
index 6b702948..64e9e4b9 100644
--- a/src/server/hosted.ts
+++ b/src/server/hosted.ts
@@ -86,8 +86,8 @@ export function poolTakes(endpoint: string | undefined): boolean {
/**
* Are this install's GPUs all away for this endpoint now (on the workers: every worker that could run it paused, silent or
- * outside its hours)? Then a run waits for nothing: the price check and Run say "Starting soon" and nothing is made. On
- * this install's own ComfyUI: never.
+ * outside its hours)? Then a run waits for nothing: the price check says "Starting soon" (Run is off), and a press of
+ * Run makes nothing. On this install's own ComfyUI: never.
*/
export function poolAway(endpoint: string | undefined): boolean {
if (!endpoint || !poolOnWorkers()) return false;
diff --git a/tests/hosted-quote-refresh.test.ts b/tests/hosted-quote-refresh.test.ts
index 058e5c63..8695d98f 100644
--- a/tests/hosted-quote-refresh.test.ts
+++ b/tests/hosted-quote-refresh.test.ts
@@ -92,4 +92,23 @@ describe("the price check asks again by itself", () => {
vi.stubGlobal("window", new EventTarget());
}
});
+
+ it("a press of Run that is refused asks it again too (every GPU that could run it went away since it was asked)", async () => {
+ vi.stubGlobal("fetch", async () => Response.json({ error: "Try again in a moment.", code: "busy" }, { status: 503 }));
+ try {
+ const qc = new QueryClient();
+ qc.setQueryData([HOSTED_QUOTE_KEY, body], free);
+ let create: ReturnType<typeof useCreateGeneration> | undefined;
+ function Probe() {
+ create = useCreateGeneration();
+ return null;
+ }
+ renderToStaticMarkup(createElement(QueryClientProvider, { client: qc }, createElement(Probe)));
+ await expect(create!.mutateAsync({ feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox" })).rejects.toThrow("Try again in a moment.");
+ expect(qc.getQueryState([HOSTED_QUOTE_KEY, body])?.isInvalidated).toBe(true);
+ } finally {
+ vi.unstubAllGlobals();
+ vi.stubGlobal("window", new EventTarget());
+ }
+ });
});
diff --git a/tests/recovery-server.test.ts b/tests/recovery-server.test.ts
index 0aeaa1f3..efaf3b92 100644
--- a/tests/recovery-server.test.ts
+++ b/tests/recovery-server.test.ts
@@ -181,7 +181,7 @@ const request = (url: string, o: { method?: string; body?: unknown; cookie?: str
/** Press Run (POST /api/generations) as a session. */
async function run(body: Record<string, unknown>, cookie = a1) {
const r = await generationsRoute.POST(request("/api/generations", { body, cookie }));
- return { status: r.status, body: (await r.json()) as { items?: { id: string }[]; code?: string; error?: string } };
+ return { status: r.status, headers: r.headers, body: (await r.json()) as { items?: { id: string }[]; code?: string; error?: string } };
}
/** The price check before Run. */
@@ -1063,14 +1063,15 @@ describe("the worker steps aside for another program", () => {
expect(back.state).toBe("waiting");
expect(back.requeues, "a step aside costs no attempt").toBe(0);
// The game runs for 40 minutes, past the run's 20 minute wait limit. Near its end, another account presses Run: with
- // the only worker stepped aside, it is told the run starts soon, and no run is made that would wait for nothing.
+ // the only worker stepped aside, no run is made that would wait for nothing (the price check says it starts soon).
await pass(35 * MIN, [d], watch);
const all = () => (db().prepare('SELECT COUNT(*) AS n FROM generations').get() as { n: number }).n;
const rows = all();
const holds = svc.holds.size;
const theirs = await run(IMAGE, b1);
expect(theirs.status, JSON.stringify(theirs.body)).toBe(503);
- expect(theirs.body).toMatchObject({ error: HOSTED_WORDS.startingSoon, code: "busy" });
+ expect(theirs.body).toMatchObject({ error: billing.BILLING_WAIT.run, code: "busy" });
+ expect((await priceCheck(IMAGE, b1)).body.quote).toMatchObject({ allowed: false, code: "busy", text: HOSTED_WORDS.startingSoon });
expect(all()).toBe(rows);
expect(svc.holds.size).toBe(holds);
await pass(5 * MIN, [d], watch);
@@ -1208,7 +1209,7 @@ describe("no worker online", () => {
expect(g.body.quote).toMatchObject({ allowed: false, code: "busy", text: HOSTED_WORDS.startingSoon });
});
- it("Run pressed while every worker is away makes no run that would wait for nothing, in the same words; once one is back, Run works", async () => {
+ it("Run pressed while every worker is away makes no run that would wait for nothing, and promises no start; once one is back, Run works", async () => {
const away = [
standInWorker("paused here", { connected: true }),
standInWorker("never connected", { connected: false }),
@@ -1222,7 +1223,11 @@ describe("no worker online", () => {
const holds = svc.holds.size;
const r = await run(IMAGE);
expect(r.status, JSON.stringify(r.body)).toBe(503);
- expect(r.body).toMatchObject({ error: HOSTED_WORDS.startingSoon, code: "busy" });
+ // Plain words that promise no start (no run was made), and no billing card: the price check, asked again, says
+ // "Starting soon" with Run off.
+ expect(r.body).toEqual({ error: billing.BILLING_WAIT.run, code: "busy" });
+ expect(r.headers.get("x-fuobe-billing")).toBeNull();
+ expect((await priceCheck(IMAGE)).body.quote).toMatchObject({ allowed: false, code: "busy", text: HOSTED_WORDS.startingSoon });
expect(made()).toBe(rows);
expect(svc.holds.size).toBe(holds);
// The silent one beats again: Run is back on, and the run goes in line.