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: a run that can't be kept for lack of disk says one sentence, own-GPU results keep their room, and run counts forget a run two hours on
Adarsh0a59980cb7cd
diff --git a/docs/billing-hook.md b/docs/billing-hook.mdindex 115e6e3d..368ada6f 100644--- a/docs/billing-hook.md+++ b/docs/billing-hook.md@@ -83,7 +83,8 @@ The policy's limits count runs on this install's GPUs only, never runs on the acinstall's own limits). A run is one press of Run: its jobs and chain steps count once. `activeRuns` counts runs goingnow (waiting or running), `waiting` those not started yet, `runsPerHour` those started in the last hour, and`addressRunsPerHour` those started from one client address in the last hour, across accounts (only when the install-trusts its proxy, `FUOBE_TRUST_PROXY=1`; the address is kept as a salted hash for two hours). 0 or absent means no such+trusts its proxy, `FUOBE_TRUST_PROXY=1`; the address is kept as a salted hash, and every run's entry is removed two+hours on, whether or not more runs come). 0 or absent means no suchlimit. Fuobe counts them in its database together with making the run's rows, so requests that arrive together (orreach two servers during a deploy) never pass a limit together. They apply with or without a billing service.diff --git a/src/server/generations.ts b/src/server/generations.tsindex b3d45834..f4e80cc8 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -77,6 +77,7 @@ import { CONNECT_GPU_MESSAGE, GUEST_RUN_MESSAGE, OWN_GPU_TOOL_MESSAGE } from "@/import { outsideTenant, runAsTenant, tenant, tenantAccount } from "./tenant";import { generationAccount } from "./account-library";import { ACCOUNT_LIMITS, ACCOUNT_MESSAGES, accountTotalBytes, accountUsage, diskHasRoom, filesFullMessage } from "./account-files";+import { prunePoolAdmissions } from "./pool-limits";import { checkAccountLoras } from "./account-loras";import { missingFilesMessage, type MissingFiles } from "@/lib/missing-files";import { Readable } from "node:stream";@@ -230,7 +231,7 @@ function poolMessage(r: Pick<Row, "status" | "message">): string | null {/*** A pool row's failure as the account reads it: Fuobe's own plain words about the account's side (its files are full, a* picture it can't use, it stopped the run) and the output check's words (a result it removed) as they are; anything- * else (whatever the GPUs, ComfyUI or a worker said) one plain sentence.+ * else (whatever the GPUs, ComfyUI, a worker or the server's own state said) one plain sentence.*/function poolError(id: string, error: string | null): string | null {if (!error) return error;@@ -239,11 +240,24 @@ function poolError(id: string, error: string | null): string | null {return checked ? error : POOL_WORDS.failed;}+/**+ * The words a pool row's failure keeps as they are: about the account's own side only (a file it sent, its files full,+ * it stopped the run) and the safety and output checks. Words about the server's own state (its disk, its upload or+ * finish limits) become the one plain sentence.+ */const PLAIN_POOL_ERRORS = (() => {let set: Set<string> | undefined;+ const m = ACCOUNT_MESSAGES;return () =>(set ??= new Set<string>([- ...Object.values(ACCOUNT_MESSAGES),+ m.imageTooBig,+ m.imageTooManyPixels,+ m.audioTooBig,+ m.videoTooBig,+ m.fileTooBig,+ m.wrongType,+ m.uploadsFull,+ m.filesFull,RELAY_WORDS.stopped,POOL_WORDS.failed,BLOCKED_CARD_MESSAGE,@@ -2202,6 +2216,12 @@ async function tick(): Promise<void> {// service. Neither does anything while no service is set.if (moderationConfigured()) await sweepOutputChecks();void sweepBilling();+ // The hourly run counts forget a run (and the client address it came from) two hours on, whether more runs come.+ try {+ prunePoolAdmissions();+ } catch (e) {+ console.warn(`[generations] run counts: ${(e as Error).message}`);+ }} finally {state.busy = false;}diff --git a/src/server/pool-limits.ts b/src/server/pool-limits.tsindex 389817b9..46f23f67 100644--- a/src/server/pool-limits.ts+++ b/src/server/pool-limits.ts@@ -63,6 +63,22 @@ export function poolRunCounts(accountId: string): { active: number; waiting: numreturn { active: r.active, waiting: r.waiting };}+declare global {+ /** When this process last forgot old admissions (prunePoolAdmissions). */+ var __fuobePoolAdmissionsPruned: number | undefined;+}++/**+ * Forget the runs (and the client addresses, kept as salted hashes) older than KEEP_MS: the hourly counts read only the+ * last hour. The runner calls this on every turn, so nothing stays longer, whether or not another run comes; it looks at+ * most once a minute in each process (`force`: now).+ */+export function prunePoolAdmissions(now = Date.now(), force = false): number {+ if (!force && now - (globalThis.__fuobePoolAdmissionsPruned ?? 0) < 60_000) return 0;+ globalThis.__fuobePoolAdmissionsPruned = now;+ return db().prepare("DELETE FROM pool_admissions WHERE at < ?").run(now - KEEP_MS).changes;+}+/** The salt the client addresses are kept under: made once per install, never sent anywhere. */function salt(): string {const d = db();@@ -138,7 +154,7 @@ export function admitRun<T>(o: { accountId: string; pool: { policy: Pick<Policy,const value = make();if (o.pool) {d.prepare("INSERT INTO pool_admissions (account, addr, at) VALUES (?, ?, ?)").run(o.accountId, o.pool.addr, now);- d.prepare("DELETE FROM pool_admissions WHERE at < ?").run(now - KEEP_MS);+ prunePoolAdmissions(now, true);}return { ok: true, value };})diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.tsindex 0c774c18..5cc2c99c 100644--- a/src/server/providers/comfyui.ts+++ b/src/server/providers/comfyui.ts@@ -2375,18 +2375,23 @@ export function planRelayOutputs(t: Pick<TaskRow, "id" | "workflow_id" | "meta_bif (frames.length > ACCOUNT_LIMITS.framesPerJob) return { error: `Your ComfyUI made ${frames.length} EXR frames. A run on your GPU keeps up to ${ACCOUNT_LIMITS.framesPerJob}: export a shorter clip.` };outputs = [...outputs.filter((o) => o.meta?.role !== "frames").slice(0, ACCOUNT_LIMITS.outputsPerJob), ...frames];if (!diskHasRoom()) return { error: ACCOUNT_MESSAGES.diskLow };- budget = Math.min(accountTotalBytes(account) - accountUsage(account).total, diskFreeBytes() - diskFloorBytes());+ budget = accountTotalBytes(account) - accountUsage(account).total;if (budget <= 0) return { error: filesFullMessage(account) };- } else {- // The owner's job: never past the disk's free floor. On the workers also never more results than its workflow says- // it makes (at least 16), and EXR frames up to the same number as an account's: a worker token that reports a- // made-up history can't fill the server's disk. (The owner's own computer keeps every result, as before.)+ // On the workers, never past the disk's free floor either: a worker token that reports a made-up history can't fill+ // the server's disk. (A run on the account's own GPU keeps the room its files have, as before.)if (t.pools) {- const frames = outputs.filter((o) => o.meta?.role === "frames");- if (frames.length > ACCOUNT_LIMITS.framesPerJob) return { error: `ComfyUI made ${frames.length} EXR frames. A run keeps up to ${ACCOUNT_LIMITS.framesPerJob}: export a shorter clip.` };- const declared = extraOf(t).outputs ?? 0;- outputs = [...outputs.filter((o) => o.meta?.role !== "frames").slice(0, Math.max(ACCOUNT_LIMITS.outputsPerJob, declared)), ...frames];+ const disk = diskFreeBytes() - diskFloorBytes();+ if (disk <= 0) return { error: ACCOUNT_MESSAGES.diskLow };+ budget = Math.min(budget, disk);}+ } else if (t.pools) {+ // The owner's job on the workers: never past the disk's free floor, never more results than its workflow says it+ // makes (at least 16), and EXR frames up to the same number as an account's: a worker token that reports a made-up+ // history can't fill the server's disk. (The owner's own computer keeps every result, as before.)+ const frames = outputs.filter((o) => o.meta?.role === "frames");+ if (frames.length > ACCOUNT_LIMITS.framesPerJob) return { error: `ComfyUI made ${frames.length} EXR frames. A run keeps up to ${ACCOUNT_LIMITS.framesPerJob}: export a shorter clip.` };+ const declared = extraOf(t).outputs ?? 0;+ outputs = [...outputs.filter((o) => o.meta?.role !== "frames").slice(0, Math.max(ACCOUNT_LIMITS.outputsPerJob, declared)), ...frames];budget = diskFreeBytes() - Math.min(diskFloorBytes(), OWNER_DISK_FLOOR_BYTES);if (budget <= 0) return { error: "There's no room on this server's disk to keep this result. Free some space, then press Retry." };}diff --git a/tests/pool-account-runs.test.ts b/tests/pool-account-runs.test.tsindex 81301e72..6886afa3 100644--- a/tests/pool-account-runs.test.ts+++ b/tests/pool-account-runs.test.ts@@ -52,7 +52,8 @@ const pool = await import("@/server/computer/pool");const hosted = await import("@/server/hosted");const billing = await import("@/server/billing");const { listAccountRuns } = await import("@/server/account-admin");-const { loadManifest, withoutSaveMetadata, planRelayOutputs, onComputer } = await import("@/server/providers/comfyui");+const { loadManifest, withoutSaveMetadata, planRelayOutputs, onComputer, OWN_OUTPUT_LIMITS } = await import("@/server/providers/comfyui");+const { accountTotalBytes, accountUsage, diskFloorBytes } = await import("@/server/account-files");const { loadIndex } = await import("@/server/gpu/index-file");const { allLanes } = await import("@/lib/lanes");const { ComputerRunner } = await import("@/lib/computer-runner");@@ -508,6 +509,30 @@ describe("graphs and results for the workers", () => {try {const full = onComputer("owner", () => planRelayOutputs(t, [entry], false));expect("error" in full && full.error).toMatch(/no room/);+ // The owner's own computer keeps its results whatever the disk has free, as before.+ const ownLow = onComputer("owner", () => planRelayOutputs({ ...t, pools: null }, [entry], false));+ expect("wanted" in ownLow && ownLow.wanted.length).toBe(40);+ } finally {+ globalThis.__fuobeTestDiskFree = 1e13;+ }+ });++ it("an account's result from its own GPU has the room its files have, as before; on the workers, never past the disk's free floor", () => {+ const entry = { status: { status_str: "success", completed: true }, outputs: { "9": { images: [{ filename: "x_0.png", subfolder: "", type: "output" }] } } };+ const t = { id: "acct-task-00001x", workflow_id: loadManifest().workflows.find((x) => x.outputs.length === 1)!.id, meta_batch: 0, prefix: null, extra_json: JSON.stringify({ outputs: 1 }), pools: null };+ // The disk has a megabyte more than the free space it keeps.+ globalThis.__fuobeTestDiskFree = diskFloorBytes() + 2 ** 20;+ try {+ const own = onComputer(`acct:${accountId}`, () => planRelayOutputs(t, [entry], false));+ const room = Math.min(OWN_OUTPUT_LIMITS.maxBytes, accountTotalBytes(accountId) - accountUsage(accountId).total);+ expect(room).toBeGreaterThan(2 ** 20);+ expect("wanted" in own && own.wanted.map((w) => w.maxBytes)).toEqual([room]);+ const pooled = onComputer(`acct:${accountId}`, () => planRelayOutputs({ ...t, pools: "pool" }, [entry], false));+ expect("wanted" in pooled && pooled.wanted.map((w) => w.maxBytes)).toEqual([2 ** 20]);+ // Right at the floor: its own GPU's result still has its room (never told its files are full).+ globalThis.__fuobeTestDiskFree = diskFloorBytes();+ const atFloor = onComputer(`acct:${accountId}`, () => planRelayOutputs(t, [entry], false));+ expect("wanted" in atFloor && atFloor.wanted.length).toBe(1);} finally {globalThis.__fuobeTestDiskFree = 1e13;}diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.tsindex d3fceb6b..47b5a397 100644--- a/tests/pool-limits.test.ts+++ b/tests/pool-limits.test.ts@@ -297,6 +297,21 @@ describe("runs waiting, runs an hour, runs from one address", () => {expect(kept.length).toBeGreaterThan(0);expect(kept.every((r) => /^[0-9a-f]{32}$/.test(r.addr) && !r.addr.includes("203"))).toBe(true);});++ it("a run's address hash goes two hours on, even when no other run comes", async () => {+ withBilling({ limits: { activeRuns: 0, waiting: 0, runsPerHour: 0, addressRunsPerHour: 5 } });+ process.env.FUOBE_TRUST_PROXY = "1";+ const a = account();+ expect((await post({ ...IMAGE, ...SHOWN }, a.cookie, { "x-forwarded-for": "203.0.113.77" })).status).toBe(201);+ const kept = () => (db().prepare("SELECT COUNT(*) AS n FROM pool_admissions WHERE account = ?").get(a.id) as { n: number }).n;+ expect(kept()).toBe(1);+ // Two hours and a minute pass with no other run here; the runner turns as it always does.+ db().prepare("UPDATE pool_admissions SET at = ? WHERE account = ?").run(Date.now() - 121 * 60_000, a.id);+ globalThis.__fuobePoolAdmissionsPruned = 0;+ await tick();+ expect(kept()).toBe(0);+ expect((db().prepare("SELECT COUNT(*) AS n FROM pool_admissions WHERE at < ?").get(Date.now() - 120 * 60_000) as { n: number }).n).toBe(0);+ });});describe("where a run goes", () => {diff --git a/tests/recovery-server.test.ts b/tests/recovery-server.test.tsindex e38f8af5..eb8010cd 100644--- a/tests/recovery-server.test.ts+++ b/tests/recovery-server.test.ts@@ -64,6 +64,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 { ACCOUNT_MESSAGES } = await import("@/server/account-files");type TaskRow = import("@/server/computer/tasks").TaskRow;@@ -792,6 +793,29 @@ describe("the run ceiling per lane", () => {});});+describe("the server's disk is low when the result comes", () => {+ it("the run ends in the one plain sentence, never words about uploads or a pause", async () => {+ const w = standInWorker();+ const { id } = await pressRun();+ const d = driver(w);+ d.onStep(async (step) => {+ await tick();+ // While it renders, the server's disk drops below the free space it keeps.+ if (step === "running") globalThis.__fuobeTestDiskFree = 1;+ });+ try {+ await workAll(d);+ const g = await ended(id);+ expect(g?.status).toBe("failed");+ } finally {+ globalThis.__fuobeTestDiskFree = 1e13;+ }+ const g = await expectFreeFailure(id);+ expect(g.error).not.toBe(ACCOUNT_MESSAGES.diskLow);+ expect(db().prepare("SELECT error FROM generations WHERE id = ?").get(id)).toEqual({ error: ACCOUNT_MESSAGES.diskLow });+ });+});+describe("a deploy while results are being sent", () => {it("a burst of 503s while the result is sent ends the run today: the worker gives up after 3 failed parts in a row", async () => {const w = standInWorker();