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
Hosted runs: Run says "Starting soon" while every worker that could run it is away
Adarsh4109ed8fe50e
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.mdindex 290bb7cb..a1cbffa3 100644--- a/docs/gpu-workers.md+++ b/docs/gpu-workers.md@@ -354,6 +354,13 @@ worker that has its model files first. The same check keeps an account's run outtake it: a worker must be allowed the lane, its last list of files must have the workflow's files and node packs, andit 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+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.+**The place in line.** A waiting job's place counts every job that a worker able to run it would serve first, whateverits lane: one GPU serves every lane it has in this order. The wait adds the rest of the jobs those workers run now,the lane's load time when none has it warm, and the job's own run (the lane's median on the quickest worker, else thediff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex 3a139b67..48ad1767 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -745,10 +745,15 @@ export function poolLane(workflowId: string): string {* waits in line for it). A run that no worker could ever take is refused before Run, never left to wait for nothing.*/export function workersCanRun(workflowId: string | null): boolean {+ return ableWorkers(workflowId).length > 0;+}++/** The workers that may and can run this workflow (any workflow: null), whatever their state now (workersCanRun). */+function ableWorkers(workflowId: string | null): WorkerRow[] {const needs = workflowId ? needsOf(loadIndex(), workflowId) : null;const lane = workflowId ? poolLane(workflowId) : null;// (Runs made here go to the "pool" pool: poolFields.)- return poolWorkers().some((w) => {+ return poolWorkers().filter((w) => {if (w.pool !== "pool") return false;const allow = allowOf(w);const cap = capableOf(w);@@ -758,6 +763,37 @@ export function workersCanRun(workflowId: string | null): boolean {});}+/**+ * Is a worker on to take work soon: connected and heard from within the silence limit, paused neither on the website+ * nor on its PC (a game or another program on its GPU counts as paused), not draining, new enough, and inside its+ * hours? A worker that makes room for local ComfyUI work first is on: people's runs keep their place and it takes them+ * next.+ */+function onSoon(w: WorkerRow, now: number): boolean {+ return (+ !w.revoked_at &&+ !(w.expires_at && w.expires_at <= now) &&+ !w.paused_server &&+ !w.paused_local &&+ !w.drain &&+ (w.protocol ?? 0) >= MIN_PROTOCOL &&+ !!w.seen_at &&+ now - w.seen_at <= RELAY_TIMES.poolSilentMs &&+ hoursAt(hoursOf(w), now).inside+ );+}++/**+ * 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.+ */+export function workersAway(workflowId: string | null, now = Date.now()): boolean {+ const able = ableWorkers(workflowId);+ return able.length > 0 && !able.some((w) => onSoon(w, now));+}+/*** What the workers allowed a lane have (any lane: `lane` null), for shaping a graph that each of them can run: the least* VRAM and RAM among those that said, and their device when they all name the same kind. Nothing known: empty.diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.tsindex f8a5228f..af4b23a9 100644--- a/src/server/hosted-run.ts+++ b/src/server/hosted-run.ts@@ -29,7 +29,7 @@ import { PLACE_ASK_HEADER } from "@/lib/guest-access";import { createGenerations, outputKind, plannedSteps, previewGeneration, type PlannedStep } from "./generations";import { loadIndex } from "./gpu/index-file";import { poolLane } from "./computer/pool";-import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, poolAllows, poolAllowsRun, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTakesFiles, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";+import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, poolAllows, poolAllowsRun, poolAway, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTakesFiles, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";import { withRunStamp } from "./run-stamp";import { hostedRunsOn } from "./hosted-switch";import { checkRun, moderationConfigured } from "./moderation";@@ -327,6 +327,10 @@ export async function decidePlace(account: Account, asked: GenerationRequest, wiconst error = gateWords(gate.reason, false);return gate.reason === "model3d" ? { kind: "refuse", refusal: { status: 403, body: { error, code: "own-gpu-tool" }, headers: {} } } : notOffered(error);}+ // 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) };// 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) };@@ -445,6 +449,9 @@ export interface PoolLine {etaSeconds: number | null;}+/** A price check's answer while every GPU that could run it is off for now: Run is off, and the wait is said. */+const startingSoonQuote = (): Quote => ({ allowed: false, amount: 0, priceVersion: "", text: HOSTED_WORDS.startingSoon, code: "busy", etaS: null });+/** A price check's answer for a run this install's GPUs won't take, in the words the run itself would get. */const notOfferedQuote = (text: string): Quote => ({ allowed: false, amount: 0, priceVersion: "", text, code: "not-offered" });@@ -489,6 +496,12 @@ export async function poolQuote(if (hasGpu && wish !== "pool") return null;return { planned, quote: notOfferedQuote(gateWords(gate.reason, !account)), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };}+ // 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 (hasGpu && wish !== "pool") return null;+ return { planned, quote: startingSoonQuote(), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };+ }// Light work only (joins, trims): free, and never counted against the policy's limits, so the service isn't asked.if (lightRun(gate.steps)) {const queue = queueFacts(account?.id ?? null, planned.route.endpoint);diff --git a/src/server/hosted.ts b/src/server/hosted.tsindex 14e811bf..6b702948 100644--- a/src/server/hosted.ts+++ b/src/server/hosted.ts@@ -5,7 +5,7 @@ import { h3Canvas, isH3Graph } from "@/lib/h3-prompt";import { imageSize } from "@/lib/image-size";import type { GenerationRequest } from "@/lib/catalog/types";import { billingConfigured, type Policy, type QueueFacts, type RunFacts } from "./billing";-import { lineFacts, poolLane, queueOfGeneration, workersCanRun } from "./computer/pool";+import { lineFacts, poolLane, queueOfGeneration, workersAway, workersCanRun } from "./computer/pool";import { db } from "./db";import { loadIndex } from "./gpu/index-file";import { hostedRunsOn } from "./hosted-switch";@@ -84,6 +84,18 @@ export function poolTakes(endpoint: string | undefined): boolean {return picks.length > 0 && picks.every((id) => workersCanRun(id));}+/**+ * 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.+ */+export function poolAway(endpoint: string | undefined): boolean {+ if (!endpoint || !poolOnWorkers()) return false;+ if (!endpoint.includes("{")) return workersAway(endpoint);+ const picks = workflowPicks(endpoint);+ return picks.length > 0 && picks.every((id) => workersAway(id));+}+/*** The steps a run on this install's GPUs can carry out there: ComfyUI's. The price check, the run's admission and its* submit read this one table, so a run is refused before Run when a step of it couldn't run there (a text step, a step@@ -112,6 +124,8 @@ export const HOSTED_WORDS = {rtxCard: "This one needs an NVIDIA RTX card, and this studio's GPUs can't run it right now. Connect your own GPU in Settings, or pick another choice.",notHosted: "Runs on this studio's GPUs aren't open to this account. Connect your own GPU in Settings.",waitedTooLong: "This studio's GPUs were busy, so it didn't run. Not charged.",+ /** Every GPU that could run it is off for now: Run opens again by itself once one is back. */+ startingSoon: "Starting soon",};/** The same refusals for a guest, who has no Settings to connect a GPU in yet. */diff --git a/tests/pool-account-runs.test.ts b/tests/pool-account-runs.test.tsindex c687b5dd..5dfac42e 100644--- a/tests/pool-account-runs.test.ts+++ b/tests/pool-account-runs.test.ts@@ -120,6 +120,8 @@ function standInWorker(name = "stand-in", o: { paused?: boolean } = {}) {db().prepare("UPDATE relay_workers SET lanes_json = ?, facts_json = ? WHERE id = ?").run(JSON.stringify({ lanes: lanes.map((l) => l.lane), workflows: loadManifest().workflows.map((x) => x.id) }), JSON.stringify({ vramBytes: 96 * 2 ** 30 }), w.id);+ // Connected: its worker program beat a moment ago.+ db().prepare("UPDATE relay_workers SET seen_at = ?, protocol = ?, paused_local = 0 WHERE id = ?").run(Date.now(), pool.MIN_PROTOCOL, w.id);return w;}diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.tsindex 9f080d38..a9793fd9 100644--- a/tests/pool-limits.test.ts+++ b/tests/pool-limits.test.ts@@ -104,6 +104,8 @@ function standInWorker() {db().prepare("UPDATE relay_workers SET lanes_json = ?, facts_json = ? WHERE id = ?").run(JSON.stringify({ lanes: lanes.map((l) => l.lane), workflows: loadManifest().workflows.map((x) => x.id) }), JSON.stringify({ vramBytes: 96 * 2 ** 30 }), w.id);+ // Connected: its worker program beat a moment ago.+ db().prepare("UPDATE relay_workers SET seen_at = ?, protocol = ?, paused_local = 0 WHERE id = ?").run(Date.now(), pool.MIN_PROTOCOL, w.id);return w;}diff --git a/tests/pool-line-order.test.ts b/tests/pool-line-order.test.tsindex 1d2177ee..997460df 100644--- a/tests/pool-line-order.test.ts+++ b/tests/pool-line-order.test.ts@@ -101,6 +101,8 @@ function standInWorker(name = "stand-in") {db().prepare("UPDATE relay_workers SET lanes_json = ?, facts_json = ? WHERE id = ?").run(JSON.stringify({ lanes: lanes.map((l) => l.lane), workflows: loadManifest().workflows.map((x) => x.id) }), JSON.stringify({ vramBytes: 96 * 2 ** 30 }), w.id);+ // Connected: its worker program beat a moment ago.+ db().prepare("UPDATE relay_workers SET seen_at = ?, protocol = ?, paused_local = 0 WHERE id = ?").run(Date.now(), pool.MIN_PROTOCOL, w.id);return w;}type WorkerRow = import("@/server/computer/workers").WorkerRow;diff --git a/tests/recovery-server.test.ts b/tests/recovery-server.test.tsindex 49cf5b49..c45f6ae3 100644--- a/tests/recovery-server.test.ts+++ b/tests/recovery-server.test.ts@@ -8,7 +8,7 @@ import { plainFailure, RunWatch, type RunLike } from "./helpers/run-watch";import { FREE_RUNS_POLICY, startStandInBilling, type StandInBilling } from "./helpers/standin-billing";import { startStandInComfy, type StandInComfy } from "./helpers/standin-comfy";import { tempDir } from "./helpers/temp-dir";-import { workerDriver, type WorkerDriver } from "./helpers/worker-driver";+import { DRIVER_PROTOCOL, workerDriver, type WorkerDriver } from "./helpers/worker-driver";/*** Recovery checks for accounts' runs on this install's GPUs, on the studio's side: a stand-in ComfyUI, the worker's@@ -68,6 +68,7 @@ const { loadIndex } = await import("@/server/gpu/index-file");const { allLanes } = await import("@/lib/lanes");const { getModel } = await import("@/lib/catalog");const { POOL_WORDS } = await import("@/lib/relay");+const { HOSTED_WORDS } = await import("@/server/hosted");const { ACCOUNT_MESSAGES } = await import("@/server/account-files");type TaskRow = import("@/server/computer/tasks").TaskRow;@@ -147,14 +148,18 @@ afterEach(() => {// ---------------------------------------------------------------------------// The studio's side-/** A worker the owner added and resumed, allowed every lane (or `lanes`), able to run every workflow. */-function standInWorker(name = "stand-in", o: { paused?: boolean; lanes?: string[] } = {}) {+/**+ * A worker the owner added and resumed, allowed every lane (or `lanes`), able to run every workflow, and connected (its+ * worker program beat a moment ago: `connected` false, never).+ */+function standInWorker(name = "stand-in", o: { paused?: boolean; lanes?: string[]; connected?: boolean } = {}) {const w = pool.addWorker(name);const lanes = o.lanes ?? allLanes(loadIndex(), sha).map((l) => l.lane);pool.patchWorker(w.id, { paused: !!o.paused, hours: { always: true }, allow: Object.fromEntries(lanes.map((l) => [l, { delayMs: 0 }])), claimAfterMs: 0 });db().prepare("UPDATE relay_workers SET lanes_json = ?, facts_json = ? WHERE id = ?").run(JSON.stringify({ lanes, workflows: loadManifest().workflows.map((x) => x.id) }), JSON.stringify({ vramBytes: 96 * 2 ** 30 }), w.id);+ if (o.connected !== false) db().prepare("UPDATE relay_workers SET seen_at = ?, protocol = ?, paused_local = 0 WHERE id = ?").run(Date.now(), DRIVER_PROTOCOL, w.id);return w;}@@ -654,12 +659,19 @@ describe("the worker steps aside for another program", () => {const back = taskOf(id)!;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's run comes in.+ // 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.await pass(35 * MIN, [d], watch);- const theirs = (await pressRun(IMAGE, b1)).id;+ 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(all()).toBe(rows);+ expect(svc.holds.size).toBe(holds);await pass(5 * MIN, [d], watch);expect(getGeneration(id)).toMatchObject({ status: "queued", message: POOL_WORDS.inLine, queue: { place: 1 } });- expect(getGeneration(theirs)?.queue?.place).toBe(2);// The game ends: it runs first, in its place, and settles against the hold it was given at Run.const hold = holdOf(id);d.pause(null);@@ -782,24 +794,45 @@ describe("a run that can never succeed here", () => {});describe("no worker online", () => {- it("with every worker paused, the price check says Free and nothing of the wait today, so Run stays on", async () => {+ it("with every worker paused, the price check says it starts soon, so Run is off", async () => {standInWorker("paused", { paused: true });const q = await priceCheck(IMAGE);expect(q.status, JSON.stringify(q.body)).toBe(200);expect(q.body.place).toBe("pool");- expect(q.body.quote).toMatchObject({ allowed: true, text: "Free" });- expect(q.body.quote?.code).toBeUndefined();+ expect(q.body.quote).toMatchObject({ allowed: false, code: "busy", text: HOSTED_WORDS.startingSoon });+ // A guest is told the same.+ const g = await priceCheck(IMAGE, "");+ expect(g.body.quote).toMatchObject({ allowed: false, code: "busy", text: HOSTED_WORDS.startingSoon });});- it("a run made while every worker is paused waits In line in its place, then ends at its wait limit today", async () => {- clock();- standInWorker("paused", { paused: true });+ 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 () => {+ const away = [+ standInWorker("paused here", { connected: true }),+ standInWorker("never connected", { connected: false }),+ standInWorker("silent", {}),+ standInWorker("outside its hours", {}),+ ];+ db().prepare("UPDATE relay_workers SET paused_local = 1, local_why = 'gpu-busy:game.exe' WHERE id = ?").run(away[0].id);+ db().prepare("UPDATE relay_workers SET seen_at = ? WHERE id = ?").run(Date.now() - 3 * MIN, away[2].id);+ pool.patchWorker(away[3].id, { hours: { tz: "UTC", days: {} } });+ const rows = made();+ 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" });+ 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.+ db().prepare("UPDATE relay_workers SET seen_at = ? WHERE id = ?").run(Date.now(), away[2].id);+ expect((await priceCheck(IMAGE)).body.quote).toMatchObject({ allowed: true, text: "Free" });const { id } = await pressRun();- const watch = watchOf(id);- await pass(10 * MIN, [], watch);- expect(watch.problems({ place: 1 })).toEqual([]);- await pass(15 * MIN, [], watch);- await expectFreeFailure(id);+ expect(getGeneration(id)).toMatchObject({ status: "queued", message: POOL_WORDS.inLine, queue: { place: 1 } });+ });++ it("a worker making room for local work first is on: the run goes in line", async () => {+ const w = standInWorker();+ db().prepare("UPDATE relay_workers SET local_why = 'waiting-for-yield' WHERE id = ?").run(w.id);+ expect((await priceCheck(IMAGE)).body.quote).toMatchObject({ allowed: true, text: "Free" });});});