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: a longest-clip setting

Adarsh6eeebadc73b7
diff --git a/docs/admin-api.md b/docs/admin-api.md
index 2e3a8a43..e187c868 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -48,7 +48,7 @@ Keep the token out of URLs, logs and shared files. Send it only in the `Authoriz
| `workers:update` | `POST /api/admin/workers/{id}/update` only: ask a worker to update its program now |
| `workers:tokens` | `POST /api/admin/workers`, and `PATCH /api/admin/workers/{id}` with `rotate`: both answer with a worker token. A worker receives accounts' queued jobs with their input files and sends back the results, so give this scope only to a tool you'd trust with those |
| `queue:read` | `GET /api/admin/queue`, `GET /api/admin/queue/settings`, `GET /api/admin/queue/overrides` |
-| `queue:write` | `PATCH /api/admin/queue/settings`: the run ceiling, the owner's wait limit, fair share, the pick allowance and the paused budget (`pausedBudgetS`: how long a run that has started may spend back in line) |
+| `queue:write` | `PATCH /api/admin/queue/settings`: the run ceiling, the owner's wait limit, fair share, the pick allowance, the paused budget (`pausedBudgetS`: how long a run that has started may spend back in line) and the longest clip (`longestClipS`: the longest video clip a person's run on this install's GPUs may make) |
| `queue:control` | `POST /api/admin/queue/mode`, `POST /api/admin/queue/overrides`, `DELETE /api/admin/queue/overrides/{id}`, `POST /api/admin/queue/cancel`, `POST /api/admin/generations/{id}/again`: who the GPUs serve first, runs and people sent first or held, cancelling a run ([gpu-workers.md](gpu-workers.md#who-goes-first)), and running a person's run again for them |
| `site:read` | `GET /api/admin/site/uploads`, `GET /api/admin/site/runs` |
| `site:write` | `PATCH /api/admin/site/uploads`: the upload switches; `PATCH /api/admin/site/runs`: what people read when a run fails |
@@ -122,8 +122,8 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `POST /api/admin/queue/overrides` | `{ kind: "run", generationId, action: "next" | "hold", worker?, forMin? }` or `{ kind: "person", person | account, action: "boost" | "hold", forMin }` (`forMin` is needed for a boost) | 201 `{ override, replaced }`; 404 for no such run, worker or person with a run on the GPUs; 409 for a run that ended |
| `DELETE /api/admin/queue/overrides/{id}` | | `{ override }` (ended now); 404 when it isn't in effect |
| `POST /api/admin/queue/cancel` | `{ generationId }` | `{ generationId, status }`: the run ends as the person's own Cancel ends it; 404 for no such run, 409 for one that ended |
-| `GET /api/admin/queue/settings` | | `{ settings: { runCeilingS: { default, lanes }, ownerWaitLimitS, fairShare, pickAllowanceMs, pausedBudgetS } }` ([gpu-workers.md](gpu-workers.md#the-queue)) |
-| `PATCH /api/admin/queue/settings` | any of `runCeilingS: { default, lanes? }` (seconds, 60 to 86400; a given `runCeilingS` replaces the default and every lane's value), `ownerWaitLimitS` (seconds, 60 to 604800, or `null` for no limit), `fairShare` (boolean), `pickAllowanceMs` (0 to 3600000), `pausedBudgetS` (seconds, 0 to 604800) | `{ settings }`; 400 with the reason for a value out of bounds, an unknown setting or an unknown lane |
+| `GET /api/admin/queue/settings` | | `{ settings: { runCeilingS: { default, lanes }, ownerWaitLimitS, fairShare, pickAllowanceMs, pausedBudgetS, longestClipS } }` ([gpu-workers.md](gpu-workers.md#the-queue)) |
+| `PATCH /api/admin/queue/settings` | any of `runCeilingS: { default, lanes? }` (seconds, 60 to 86400; a given `runCeilingS` replaces the default and every lane's value), `ownerWaitLimitS` (seconds, 60 to 604800, or `null` for no limit), `fairShare` (boolean), `pickAllowanceMs` (0 to 3600000), `pausedBudgetS` (seconds, 0 to 604800), `longestClipS` (seconds, 1 to 3600, or `null` for no limit) | `{ settings }`; 400 with the reason for a value out of bounds, an unknown setting or an unknown lane |
| `GET /api/admin/site/uploads` | | `{ switches: { soundConvert, soundTrim, videoTrim, photoConvert, photoCrop } }`: what a browser may do to a file that doesn't fit a tool before it is uploaded (convert a sound to MP3, offer a part of a sound or clip, convert or shrink a photo, offer a crop). All `true` by default. Every visitor reads the same values at `GET /api/site/uploads` |
| `PATCH /api/admin/site/uploads` | any of the five, each `true` or `false` | `{ switches }`; 400 with the reason for an unknown switch or a value that isn't a boolean. A switch that is off leaves that kind of file as it is: the tool says why it can't take it, and the server's checks apply. Browsers pick it up when they next load a page |
| `GET /api/admin/site/runs` | | `{ failureDetail }`: what a person reads when a run of theirs on this install's GPUs fails. `full`: the plain sentence and, under it, the cleaned technical reason (ComfyUI's own: no folders, addresses, keys or prompt text); `friendly`: the plain sentence only. Settings → Failed runs is the same choice. A new install starts with `full`; an install that had runs or settings before this choice existed keeps `friendly` |
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index d50bc3af..4e4ec3fd 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -458,6 +458,7 @@ in that class came.
| `fairShare` | Each class goes round its accounts (above). Off: strict order | `false` |
| `pickAllowanceMs` | How long a job in a worker's warm lane may go ahead of an older one (above). 0: strict order | `0` |
| `pausedBudgetS` | How long, in all, a run that has started may spend back in line while its worker steps aside, and still be inside the deadline its hold asks for ([billing-hook.md](billing-hook.md)). A run past it still delivers its result | `7200` (2 hours) |
+| `longestClipS` | The longest video clip a person's run on these GPUs may make, in seconds (1 to 3600). Longer lengths stay offered: they read "This length runs self-hosted", and Run opens Connect your GPU ([public-signup.md](public-signup.md#hosted-runs)). The owner's own runs have no limit. `null`: no limit | `null` |
A worker's run limit for one attempt is 3 times the lane's 90th percentile on that worker plus its model load, at
least 10 minutes and never past the lane's run ceiling. With no measured run in the lane yet, it is the ceiling.
diff --git a/docs/public-signup.md b/docs/public-signup.md
index 006d9d88..f9cd08ed 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -877,6 +877,13 @@ With it on:
- a size bigger than every GPU here makes (each worker's PC ceiling: megapixels, seconds, results at once), said
before Run: "This size runs on your own GPU", tooltip "Up to 8 megapixels on our GPUs. Pick a smaller size, or
run it on your own GPU." The run's own size check stays as the last guard;
+ - a video clip longer than the longest the owner lets a run here make (`longestClipS` in the queue's settings,
+ [gpu-workers.md](gpu-workers.md#the-queue); no limit unless set): "This length runs self-hosted", tooltip "Up to
+ 5 s clips on our GPUs. Pick a shorter length, or run it on your own GPU." Every length stays in the pickers, and an
+ untouched length starts within the limit. The length a person or a script asks for is never cut down: the answer
+ is the same as for any other run these GPUs don't take (below). The length counted is the one asked for, else the
+ model's default; for shots made as separate clips and joined, the longest shot. A clip made from a clip (a swap, a
+ restyle, an upscale) has no length to pick and isn't counted;
- a 3D model no worker finishes (Image to 3D, and Refine detail on its model run there only while a worker's CPU
slot finishes them, and only when the policy allows 3D, `kinds.model3d`; Any Angle's 3D view runs there like a
picture): "Runs on your own GPU · 24 GB".
diff --git a/src/app/api/admin/queue/settings/route.ts b/src/app/api/admin/queue/settings/route.ts
index c472ab49..d8837e11 100644
--- a/src/app/api/admin/queue/settings/route.ts
+++ b/src/app/api/admin/queue/settings/route.ts
@@ -6,7 +6,8 @@ const NO_STORE = { "Cache-Control": "no-store" };
/**
* The line's settings (owner only, or an admin token with queue:read): the run ceiling (a default and per lane, in
- * seconds), the owner's wait limit, fair share, the pick allowance and the paused budget (src/server/queue-settings.ts).
+ * seconds), the owner's wait limit, fair share, the pick allowance, the paused budget and the longest clip a person's run
+ * may make there (src/server/queue-settings.ts).
*/
export async function GET(request: Request) {
await connection();
@@ -17,8 +18,8 @@ export async function GET(request: Request) {
/**
* Change them (owner only, or an admin token with queue:write): any of `{ runCeilingS: { default, lanes },
- * ownerWaitLimitS, fairShare, pickAllowanceMs, pausedBudgetS }`. A given runCeilingS replaces the default and every lane's value. Each
- * change is written to the admin log with the values before and after. It applies to new claims and clocks at once.
+ * ownerWaitLimitS, fairShare, pickAllowanceMs, pausedBudgetS, longestClipS }`. A given runCeilingS replaces the default and every lane's value. Each
+ * change is written to the admin log with the values before and after. It applies to new claims, clocks and runs at once.
*/
export async function PATCH(request: Request) {
const access = adminAccess(request, "queue:write", "Only the studio's owner changes the queue");
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index bdc763ce..68df5154 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -38,7 +38,7 @@ import { PlaceIntro } from "./place-intro";
import { PoolNote } from "./pool-note";
import { EndFrameNote } from "./end-frame-note";
import { modelOwnSetup, pickerRules } from "@/lib/pool-rules";
-import { carryParams, closestHere, HERE_SET_UP, hereDefault, hereReason, hereRunLabel, hereSetup, runsHere } from "@/lib/runnable-here";
+import { carryParams, closestHere, HERE_SET_UP, hereClipStart, hereDefault, hereReason, hereRunLabel, hereSetup, runsHere } from "@/lib/runnable-here";
import { useHere } from "@/hooks/use-pool-rules";
import { controlSetup, keyOnlySetup } from "@/lib/own-setup-controls";
import { ownSetupDetail, ownSetupLabel, ownSetupShort } from "@/lib/own-setup";
@@ -1287,6 +1287,12 @@ export function Composer({ docked }: { docked: boolean }) {
// Enhance writes a scene; a tool's optional words (FLUX.3 Upscale's details) stay as typed.
const baseShape = settingsShape(model, effectiveOp, config.kind, showPrompt && !config.hidePrompt, p, config.ops, studioFormats);
const shape = framesCtx ? framesShape(baseShape, framesCtx.chained) : layoutOn ? layoutShape(baseShape) : baseShape;
+ // The longest clip this install's GPUs make (the owner's setting): an untouched length starts within it there. Longer
+ // lengths stay in the picker; picked, the price check says where they run and Run opens that setup.
+ const clipStart = model?.kind === "video" && model.engine === "open" && p.duration === undefined ? hereClipStart(here, shape.duration, model.defaults?.duration ?? shape.duration?.[0]) : undefined;
+ useEffect(() => {
+ if (clipStart !== undefined) setDraft((d) => (d.params.duration === undefined ? { params: { ...d.params, duration: clipStart } } : {}));
+ }, [clipStart, setDraft]);
const outcome = config.clipFacts && draft.slots.video?.ref ? clipOutcome(effectiveOp, facts, p, model, today) : null;
const video = draft.slots.video?.ref;
const alternative = config.comfyOnly?.alternative;
diff --git a/src/lib/api.ts b/src/lib/api.ts
index c23b5eeb..3f142b0a 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1060,6 +1060,8 @@ export interface StatusInfo {
cardText?: string;
/** What this studio's GPUs keep off, for a viewer with no GPU of its own: its pickers leave it out (src/lib/pool-rules.ts). */
pool?: PoolRules;
+ /** The longest video clip a run on this studio's GPUs makes, in seconds (the owner's setting). Only with `hosted`. */
+ clipS?: number;
/** The billing service's words for the account's balance (src/server/billing.ts). */
balance?: HostedBalance;
links?: BillingAction[];
diff --git a/src/lib/runnable-here.ts b/src/lib/runnable-here.ts
index 3f219efe..05b610ea 100644
--- a/src/lib/runnable-here.ts
+++ b/src/lib/runnable-here.ts
@@ -18,11 +18,13 @@ export interface Here {
rules: PoolRules | undefined;
/** The pool's owner: his runs go to the workers; what they lack now is a worker's files, never his own GPU or key. */
owner: boolean;
+ /** The longest video clip a visitor's run here makes, in seconds (the owner's setting; absent: no limit). */
+ clipS?: number;
}
/** The parts of GET /api/status this reads. */
export interface HereStatus {
- viewer?: { hosted?: boolean; prefer?: "pool"; runOn?: string; gpu: { connected: boolean }; pool?: PoolRules };
+ viewer?: { hosted?: boolean; prefer?: "pool"; runOn?: string; gpu: { connected: boolean }; pool?: PoolRules; clipS?: number };
/** The owner's view of the workers (sent only while his ComfyUI runs on them): the open models they can't run now. */
pool?: PoolRules;
}
@@ -35,7 +37,20 @@ export function hereOf(s: HereStatus | undefined, owner: boolean): Here | null {
if (!s) return null;
if (owner) return s.pool ? { rules: s.pool, owner: true } : null;
const v = s.viewer;
- return v && runsGoHere(v) ? { rules: v.pool, owner: false } : null;
+ return v && runsGoHere(v) ? { rules: v.pool, owner: false, ...(v.clipS ? { clipS: v.clipS } : {}) } : null;
+}
+
+/**
+ * Where an untouched clip length starts for a run here (`current`: the length the run would make with nothing picked),
+ * or undefined when it stays: within the longest clip here (Here.clipS), the longest of the picker's own lengths
+ * (`lengths`, each one the model takes, so a model's own grid stays whole), else nothing (no length here fits: the
+ * price check's label says how to run it). A length the person picks is never changed: it keeps its label instead.
+ */
+export function hereClipStart(here: Here | null | undefined, lengths: readonly number[] | null | undefined, current: number | undefined): number | undefined {
+ const limit = here?.clipS;
+ if (!limit || !lengths?.length || current === undefined || current <= limit + 0.05) return undefined;
+ const fits = lengths.filter((l) => l <= limit + 0.05);
+ return fits.length ? Math.max(...fits) : undefined;
}
/**
diff --git a/src/server/account-gpu.ts b/src/server/account-gpu.ts
index 8541ca45..92be5c32 100644
--- a/src/server/account-gpu.ts
+++ b/src/server/account-gpu.ts
@@ -17,7 +17,7 @@ import { redactKey } from "./provider-keys";
import { networkCode, recordRunEvent } from "./run-events";
import { isInstallHost, REFUSED_ADDRESS } from "./gpu/hosts";
import { balance as billingBalance, policy as billingPolicy, type Action, type Balance } from "./billing";
-import { poolHasFiles, poolReady, poolTakes } from "./hosted";
+import { poolClipLimitS, poolHasFiles, poolReady, poolTakes } from "./hosted";
import { placeName } from "./place-name";
import { helperKnown } from "./text-helper";
import { poolOwnModels, poolOwnPresets, type PresetPress } from "./pool-own-setup";
@@ -370,6 +370,11 @@ export interface VisitorView {
* own: its pickers leave those out instead of failing at Run. Absent: nothing is kept off, or it has a GPU of its own.
*/
pool?: PoolRules;
+ /**
+ * The longest video clip a run on this install's GPUs makes, in seconds (queue-settings.ts longestClipS). Only with
+ * `hosted`, and only when the owner set one: the pickers start an untouched length within it there.
+ */
+ clipS?: number;
/** The billing service's words for the account's balance (billing.ts): the top bar's chip and the account menu. */
balance?: Balance;
/** Extra links the billing service sends for the menu. */
@@ -479,6 +484,8 @@ export async function visitorStatus(account: Account | null) {
// there first too, and the label says what runs on its own GPU instead.
const rules = p?.hosted ? poolRulesOf(p, presetModels(), poolOwnModels(), poolOwnPresets(presetPresses(), poolTakes, poolHasFiles)) : undefined;
if (rules) viewer.pool = rules;
+ const clipS = p?.hosted ? poolClipLimitS() : null;
+ if (clipS) viewer.clipS = clipS;
if (account && p?.links?.length) viewer.links = p.links;
if (account && p?.notice) viewer.notice = p.notice;
// The service's display copy (wait and limit lines), for guests and accounts alike.
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 9a214af8..c5ddd2cf 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -44,7 +44,7 @@ import { loadIndex } from "./gpu/index-file";
import { attemptLimitMs, MAX_ATTEMPTS, poolLane } from "./computer/pool";
import { poolFinishes3d } from "./computer/finish";
import { holdTiming } from "./queue-settings";
-import { hostedDetails, hostedGuestWords, hostedWords, isOutputsWords, outputsWords, poolAllows, poolAllowsRun, poolAway, poolFitsSize, poolHasFiles, poolMostWords, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTakesKind, poolTicketsReady, POOL_LANE, queueFacts, requestFileKinds, runFacts, runOnPool, workflowPicks, type JobSize } from "./hosted";
+import { clipPastLimit, hostedDetails, hostedGuestWords, hostedWords, isOutputsWords, outputsWords, poolAllows, poolAllowsRun, poolAway, poolFitsSize, poolHasFiles, poolMostWords, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTakesKind, poolTicketsReady, POOL_LANE, queueFacts, requestFileKinds, runFacts, runOnPool, workflowPicks, type JobSize } from "./hosted";
import { withRunStamp } from "./run-stamp";
import { hostedRunsOn } from "./hosted-switch";
import { checkRun, moderationConfigured } from "./moderation";
@@ -353,16 +353,18 @@ export function pricedSteps(steps: PlannedStep[]): NonNullable<RunFacts["steps"]
* LoRAs a look, a motion or a recipe adds at run time, src/lib/runtime-files.ts), a kind of file, more outputs at once
* than a run there makes (`outputs`: a tool's run, which can't be cut down the way the studios' own runs are), one
* that runs on the visitor's own setup only (`ownSetup`: a static item of own-setup.ts, or a workflow none of this
- * install's GPUs can run right now: none holds its files, serves its lane, or has the memory). Each is a label the
- * visitor reads before Run, with the setup that runs it. A run these GPUs take but can't start right now (every one
- * that could is away, or being updated) is no reason: it waits in line (runWaits).
+ * install's GPUs can run right now: none holds its files, serves its lane, or has the memory), a clip longer than the
+ * longest the owner lets a run there make (`length`: queue-settings.ts longestClipS). Each is a label the visitor reads
+ * before Run, with the setup that runs it. A run these GPUs take but can't start right now (every one that could is
+ * away, or being updated) is no reason: it waits in line (runWaits).
*/
-export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "files" | "inputs" | "size" | "outputs" | "ownSetup";
+export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "files" | "inputs" | "size" | "length" | "outputs" | "ownSetup";
/**
* A gate's refusal: its reason, and the visitor's own setup that would run it (`setup`: always with "ownSetup" and
* "model3d"; with the others, a GPU of its own, which runs what this install's GPUs don't take). `cap`: with "outputs",
- * the most a run there makes at once. `most`: with "size", the largest those GPUs make, in words ("8 megapixels").
+ * the most a run there makes at once. `most`: with "size" and "length", the largest those GPUs make, in words
+ * ("8 megapixels", "5 s clips").
*/
export type GateRefusal = { ok: false; reason: GateReason; setup?: OwnSetup; cap?: number; most?: string };
@@ -430,6 +432,10 @@ export function poolGate(
// file it hasn't verified runs on the visitor's own GPU instead, said before Run (never dropped without a word).
if (!poolHasFiles(planned.route.endpoint, runLoraFiles(planned, req.params?.extra))) return { ok: false, reason: "files", setup: gpu };
if (!requestFileKinds(req).every((k) => poolTakesKind(k, p))) return { ok: false, reason: "inputs", setup: gpu };
+ // A clip longer than the longest the owner lets a run here make: a label before Run, and Run opens Connect your GPU.
+ // The length is never cut down without a word: the person picks a shorter one, or runs it on their own setup.
+ const clipLimit = clipPastLimit(req, planned.model.id, kind);
+ if (clipLimit !== null) return { ok: false, reason: "length", setup: gpu, most: `${clipLimit} s clips` };
// A size bigger than every GPU here that runs it makes (their PCs' ceilings): said before Run as a label, never a run
// that fails once pressed (the run's own check stays the last guard: comfyui.ts POOL_TOO_BIG).
const size = sizeOf ? safeSize(sizeOf) : null;
diff --git a/src/server/hosted.ts b/src/server/hosted.ts
index 228814bc..a3816560 100644
--- a/src/server/hosted.ts
+++ b/src/server/hosted.ts
@@ -1,5 +1,6 @@
import "server-only";
import { getModel } from "@/lib/catalog";
+import { lengthRange } from "@/lib/catalog/clip-lengths";
import { computeDimensions, fitCanvas } from "@/lib/comfy";
import { h3Canvas, isH3Graph } from "@/lib/h3-prompt";
import { imageSize } from "@/lib/image-size";
@@ -13,6 +14,7 @@ import { loadIndex } from "./gpu/index-file";
import { hostedRunsOn } from "./hosted-switch";
import { holdOf, NOT_HELD, type HoldReason } from "./pool-holds";
import { poolRunCounts } from "./pool-limits";
+import { queueSettings } from "./queue-settings";
import { getWorkflow, installComfyLocal, onInstallComfy, workerFor, workersTake } from "./providers/comfyui";
import { getSetting, withCandidates } from "./settings";
import { modelFormat, modelTaken } from "./model-input";
@@ -209,6 +211,7 @@ export function hostedWords(place: Place) {
inputs: "This file runs self-hosted",
rtxCard: "Self-hosted · RTX GPU",
size: "This size runs self-hosted",
+ length: "This length runs self-hosted",
notHosted: `Your account can't run on ${place.text} right now. Your own GPU or key still works.`,
};
}
@@ -225,13 +228,37 @@ export function hostedDetails(place: Place, most?: string | null) {
inputs: "Connect your GPU to use it, or use a picture.",
rtxCard: "This one needs an NVIDIA RTX card.",
size: `${most ? `Up to ${most} on ${place.text}. ` : ""}Pick a smaller size, or run it on your own GPU.`,
+ length: `${most ? `Up to ${most} on ${place.text}. ` : ""}Pick a shorter length, or run it on your own GPU.`,
};
}
/** The labels for a guest: the same as an account's (Run opens the sign-up for that label). */
export function hostedGuestWords() {
- const { notOffered, rtxCard, loras, files, inputs, size } = hostedWords({ label: "", text: "" });
- return { notOffered, rtxCard, loras, files, inputs, size };
+ const { notOffered, rtxCard, loras, files, inputs, size, length } = hostedWords({ label: "", text: "" });
+ return { notOffered, rtxCard, loras, files, inputs, size, length };
+}
+
+/** The longest video clip a person's run on this install's GPUs may make, in seconds (queue-settings.ts; null: no limit). */
+export const poolClipLimitS = (): number | null => queueSettings().longestClipS;
+
+/**
+ * The seconds of the longest clip one job of a request makes, for the clip limit: a video model with a length to pick
+ * (its durations, or a range of whole seconds), the length asked for, else its default; shots rendered as clips of their
+ * own and joined, the longest shot. 0 for anything else (a clip made from a clip as long as its source, sound, pictures).
+ */
+export function requestClipSeconds(req: Pick<GenerationRequest, "params">, modelId: string, kind: string): number {
+ const model = getModel(modelId);
+ if (kind !== "video" || !model || !(model.options.durations?.length || lengthRange(model))) return 0;
+ const shots = (req.params?.shots ?? []).filter((s) => s.prompt?.trim());
+ if (shots.length && model.options.multiShot?.mode === "concat") return Math.max(...shots.map((s) => Number(s.duration) || 0));
+ const asked = Number(req.params?.duration ?? model.defaults?.duration ?? model.options.durations?.[0]);
+ return Number.isFinite(asked) && asked > 0 ? asked : 0;
+}
+
+/** The clip limit a request passes (poolClipLimitS), or null when it fits, or there is none. */
+export function clipPastLimit(req: Pick<GenerationRequest, "params">, modelId: string, kind: string, limit: number | null = poolClipLimitS()): number | null {
+ if (!limit) return null;
+ return requestClipSeconds(req, modelId, kind) > limit + 0.05 ? limit : null;
}
/**
diff --git a/src/server/queue-settings.ts b/src/server/queue-settings.ts
index 67fb5c33..72f468f6 100644
--- a/src/server/queue-settings.ts
+++ b/src/server/queue-settings.ts
@@ -15,6 +15,9 @@ import { db } from "./db";
* - `pausedBudgetS`: how long, in all, a run that has started may spend back in line while its worker steps aside (another
* program on its GPU, a pause) and still be inside its hold's deadline. With the run ceiling, it sets the time a run
* asks its hold to stay open (holdTiming). A run past it still delivers its result.
+ * - `longestClipS`: the longest video clip a person's run on this install's GPUs may make, in seconds (null: no limit).
+ * A longer length stays offered: it reads as a length that runs on the person's own GPU, and Run opens Connect your
+ * GPU, as for any other run these GPUs don't take (hosted-run.ts poolGate). The owner's own runs have no such limit.
*
* Kept in the settings table under one key, as JSON. Nothing set: the defaults, which are today's fixed values.
*/
@@ -25,9 +28,10 @@ export interface QueueSettings {
fairShare: boolean;
pickAllowanceMs: number;
pausedBudgetS: number;
+ longestClipS: number | null;
}
-export const QUEUE_DEFAULTS: QueueSettings = { runCeilingS: { default: 2700, lanes: {} }, ownerWaitLimitS: null, fairShare: false, pickAllowanceMs: 0, pausedBudgetS: 7200 };
+export const QUEUE_DEFAULTS: QueueSettings = { runCeilingS: { default: 2700, lanes: {} }, ownerWaitLimitS: null, fairShare: false, pickAllowanceMs: 0, pausedBudgetS: 7200, longestClipS: null };
/** The bounds each value may take. */
export const QUEUE_BOUNDS = {
@@ -35,6 +39,7 @@ export const QUEUE_BOUNDS = {
ownerWaitS: { min: 60, max: 7 * 24 * 3600 },
pickAllowanceMs: { min: 0, max: 3_600_000 },
pausedBudgetS: { min: 0, max: 7 * 24 * 3600 },
+ longestClipS: { min: 1, max: 3600 },
lanes: 200,
};
@@ -79,7 +84,7 @@ const inRange = (v: unknown, b: { min: number; max: number }): v is number => wh
export function checkQueuePatch(body: unknown, base: QueueSettings = queueSettings()): { settings: QueueSettings } | { error: string } {
if (!body || typeof body !== "object" || Array.isArray(body)) return { error: "Send the settings as an object" };
const b = body as Record<string, unknown>;
- const known = ["runCeilingS", "ownerWaitLimitS", "fairShare", "pickAllowanceMs", "pausedBudgetS"];
+ const known = ["runCeilingS", "ownerWaitLimitS", "fairShare", "pickAllowanceMs", "pausedBudgetS", "longestClipS"];
const unknown = Object.keys(b).filter((k) => !known.includes(k));
if (unknown.length) return { error: `Unknown setting: ${unknown[0]}` };
const out = copy(base);
@@ -120,6 +125,11 @@ export function checkQueuePatch(body: unknown, base: QueueSettings = queueSettin
if (!inRange(b.pausedBudgetS, p)) return { error: `pausedBudgetS is ${p.min} to ${p.max} seconds` };
out.pausedBudgetS = b.pausedBudgetS;
}
+ if (b.longestClipS !== undefined) {
+ const c = QUEUE_BOUNDS.longestClipS;
+ if (b.longestClipS !== null && !inRange(b.longestClipS, c)) return { error: `longestClipS is ${c.min} to ${c.max} seconds, or null for no limit` };
+ out.longestClipS = b.longestClipS as number | null;
+ }
return { settings: out };
}
diff --git a/tests/hosted-words.test.ts b/tests/hosted-words.test.ts
index bc0a9540..d678da3c 100644
--- a/tests/hosted-words.test.ts
+++ b/tests/hosted-words.test.ts
@@ -113,7 +113,7 @@ afterEach(() => notePlaceName(null));
/** Every sentence a visitor reads from the server's word tables, for a place. */
function serverWords(place: ReturnType<typeof placeOf>): string[] {
- const reasons = ["notOffered", "rtxCard", "loras", "files", "inputs", "size", "model3d"] as const;
+ const reasons = ["notOffered", "rtxCard", "loras", "files", "inputs", "size", "length", "model3d"] as const;
const setups = [needsGpu(), { need: "gpu" as const, vramGb: 48 }, { need: "gpu" as const, vramGb: 24, orKey: "fal" as const }, { need: "key" as const, provider: "fal" }];
return [
...Object.values(hostedWords(place)),
diff --git a/tests/longest-clip.test.ts b/tests/longest-clip.test.ts
new file mode 100644
index 00000000..c230ac0e
--- /dev/null
+++ b/tests/longest-clip.test.ts
@@ -0,0 +1,85 @@
+import { describe, expect, it } from "vitest";
+import { tempDir } from "./helpers/temp-dir";
+
+/**
+ * The longest clip a person's run on this install's GPUs may make (queue-settings.ts longestClipS): the setting's checks,
+ * the length a request is counted at, and where an untouched length starts in the pickers. The run's own answer (a
+ * label before Run, Connect your GPU at Run) is in pool-limits.test.ts.
+ */
+
+process.env.FUOBE_DATA_DIR = tempDir("fuobe-longest-clip-");
+
+const qs = await import("@/server/queue-settings");
+const { clipPastLimit, requestClipSeconds } = await import("@/server/hosted");
+const { hereClipStart, hereOf } = await import("@/lib/runnable-here");
+const { getModel } = await import("@/lib/catalog");
+
+describe("the setting", () => {
+ it("is off unless set, takes whole seconds from 1 to 3600 or null, and keeps the other settings", () => {
+ expect(qs.QUEUE_DEFAULTS.longestClipS).toBeNull();
+ expect(qs.queueSettings().longestClipS).toBeNull();
+ const ok = qs.checkQueuePatch({ longestClipS: 5 }, qs.QUEUE_DEFAULTS);
+ expect("settings" in ok && ok.settings).toEqual({ ...qs.QUEUE_DEFAULTS, longestClipS: 5 });
+ const off = qs.checkQueuePatch({ longestClipS: null }, { ...qs.QUEUE_DEFAULTS, longestClipS: 5 });
+ expect("settings" in off && off.settings.longestClipS).toBeNull();
+ for (const bad of [0, -5, 3601, 2.5, "5", true]) expect(qs.checkQueuePatch({ longestClipS: bad }, qs.QUEUE_DEFAULTS), String(bad)).toEqual({ error: "longestClipS is 1 to 3600 seconds, or null for no limit" });
+ qs.saveQueueSettings({ ...qs.QUEUE_DEFAULTS, longestClipS: 10 });
+ expect(qs.queueSettings().longestClipS).toBe(10);
+ qs.saveQueueSettings(qs.QUEUE_DEFAULTS);
+ expect(qs.queueSettings().longestClipS).toBeNull();
+ });
+});
+
+describe("the length a request is counted at", () => {
+ it("is the length asked for, else the model's default; shots made as clips of their own count their longest", () => {
+ expect(requestClipSeconds({ params: { duration: 15 } }, "oss-minimax-h3", "video")).toBe(15);
+ expect(requestClipSeconds({ params: {} }, "oss-minimax-h3", "video")).toBe(getModel("oss-minimax-h3")!.defaults!.duration);
+ const shots = [
+ { prompt: "she turns", duration: 5 },
+ { prompt: "she walks", duration: 10 },
+ ];
+ expect(getModel("oss-ltx25")!.options.multiShot?.mode).toBe("concat");
+ expect(requestClipSeconds({ params: { shots: [{ ...shots[0] }, { ...shots[1], duration: 8 }], duration: 13 } }, "oss-ltx25", "video")).toBe(8);
+ // Pictures, sound, and a clip made from a clip (no length to pick) aren't counted.
+ expect(requestClipSeconds({ params: { duration: 15 } }, "oss-z-image-turbo", "image")).toBe(0);
+ expect(requestClipSeconds({ params: { duration: 120 } }, "oss-ace-step", "audio")).toBe(0);
+ expect(requestClipSeconds({ params: { duration: 15 } }, "oss-h3-character-swap-relay", "video")).toBe(0);
+ });
+
+ it("passes the limit only past it; no limit, nothing passes", () => {
+ expect(clipPastLimit({ params: { duration: 15 } }, "oss-minimax-h3", "video", 5)).toBe(5);
+ expect(clipPastLimit({ params: { duration: 5 } }, "oss-minimax-h3", "video", 5)).toBeNull();
+ expect(clipPastLimit({ params: { duration: 3 } }, "oss-minimax-h3", "video", 5)).toBeNull();
+ expect(clipPastLimit({ params: { duration: 15 } }, "oss-minimax-h3", "video", null)).toBeNull();
+ });
+});
+
+describe("where an untouched length starts in the pickers", () => {
+ const status = (clipS?: number) => ({ viewer: { hosted: true, gpu: { connected: false }, ...(clipS ? { clipS } : {}) } });
+ const H3_LENGTHS = getModel("oss-minimax-h3")!.options.durations!;
+
+ it("only for a visitor whose runs go to this install's GPUs, and only with a limit set", () => {
+ expect(hereOf(status(5), false)).toEqual({ rules: undefined, owner: false, clipS: 5 });
+ expect(hereOf(status(), false)).toEqual({ rules: undefined, owner: false });
+ // A visitor whose runs go to its own GPU, and the owner's own runs: no limit here.
+ expect(hereOf({ viewer: { hosted: true, gpu: { connected: true }, clipS: 5 } }, false)).toBeNull();
+ expect(hereOf({ pool: {} }, true)?.clipS).toBeUndefined();
+ expect(hereClipStart(hereOf(status(), false), H3_LENGTHS, 15)).toBeUndefined();
+ expect(hereClipStart(null, H3_LENGTHS, 15)).toBeUndefined();
+ });
+
+ it("is the longest of the model's own lengths within the limit, so MiniMax H3's frame grid stays whole", () => {
+ expect(H3_LENGTHS).toEqual([3, 5, 10, 15]);
+ const at = (limit: number, current: number) => hereClipStart(hereOf(status(limit), false), H3_LENGTHS, current);
+ expect(at(5, 15)).toBe(5);
+ expect(at(5, 10)).toBe(5);
+ expect(at(7, 10)).toBe(5);
+ expect(at(4, 5)).toBe(3);
+ expect(at(12, 15)).toBe(10);
+ // Already within it: it stays.
+ expect(at(5, 5)).toBeUndefined();
+ expect(at(10, 3)).toBeUndefined();
+ // No length of the model's fits: it stays, and the price check's label says how to run it.
+ expect(at(2, 5)).toBeUndefined();
+ });
+});
diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.ts
index ad46b06d..935e3d16 100644
--- a/tests/pool-limits.test.ts
+++ b/tests/pool-limits.test.ts
@@ -1005,6 +1005,54 @@ describe("the price check before Run and the run itself", async () => {
}
});
+ it("a clip longer than the longest clip set for these GPUs is its label before Run, the press opens Connect your GPU, and nothing is cut down", async () => {
+ const qs = await import("@/server/queue-settings");
+ withBilling({ limits: NO_LIMITS });
+ const a = account();
+ const acct = auth.accountById(a.id)!;
+ const H3 = { feature: "video", modelId: "oss-minimax-h3", op: "t2v", prompt: "a dancer turns slowly in the light" };
+ const at = (duration: number) => ({ ...H3, params: { duration }, account: a.id }) as never;
+ // No limit set (the default): every length runs here as before.
+ expect(qs.queueSettings().longestClipS).toBeNull();
+ expect((await hostedRun.decidePlace(acct, at(15), undefined)).kind).toBe("pool");
+ expect((await hostedRun.poolQuote(acct, at(15), undefined))?.quote.allowed).toBe(true);
+ qs.saveQueueSettings({ ...qs.QUEUE_DEFAULTS, longestClipS: 5 });
+ try {
+ // Within it: taken.
+ expect((await hostedRun.decidePlace(acct, at(5), undefined)).kind).toBe("pool");
+ expect((await hostedRun.poolQuote(acct, at(5), undefined))?.quote.allowed).toBe(true);
+ // Past it: the price check says where it runs, in words, and Run opens Connect your GPU.
+ const check = await hostedRun.poolQuote(acct, at(15), undefined);
+ expect(check?.quote).toMatchObject({ allowed: false, code: "not-offered", text: "This length runs self-hosted", ownSetup: { need: "gpu" } });
+ expect((check?.quote as { sub?: string }).sub).toBe("Up to 5 s clips on our GPUs. Pick a shorter length, or run it on your own GPU.");
+ // A guest reads the same label (its Run opens the sign-up).
+ expect((await hostedRun.poolQuote(null, { ...H3, params: { duration: 10 } } as never, undefined))?.quote).toMatchObject({ allowed: false, text: "This length runs self-hosted" });
+ const run = await hostedRun.decidePlace(acct, at(10), undefined);
+ expect(run.kind).toBe("refuse");
+ if (run.kind === "refuse") {
+ expect(run.refusal.body).toMatchObject({ code: "connect-gpu", error: "This length runs self-hosted", ownSetup: { need: "gpu" } });
+ expect(run.refusal.headers[CONNECT_GPU_HEADER]).toBe("1");
+ }
+ // Asked for anyway (a script, an old link): the same answer; nothing is held, made, or made shorter.
+ const holds = fake.holds.size;
+ const r = await post({ ...H3, params: { duration: 15 }, place: "pool", ...SHOWN }, a.cookie);
+ expect(r.status, JSON.stringify(r.body)).toBe(403);
+ expect(r.body.code).toBe("connect-gpu");
+ expect(poolRuns(a.id)).toBe(0);
+ expect(fake.holds.size).toBe(holds);
+ // An account whose own GPU answers: the run goes there at its own length, no question.
+ const g = account({ gpu: "online" });
+ expect((await hostedRun.decidePlace(auth.accountById(g.id)!, { ...H3, params: { duration: 15 }, account: g.id } as never, undefined)).kind).toBe("own");
+ // Pictures have no length: untouched by it.
+ expect((await hostedRun.decidePlace(acct, { ...IMAGE, account: a.id } as never, undefined)).kind).toBe("pool");
+ // The visitor's status says the limit, so an untouched length starts within it.
+ expect((await visitorStatus(acct)).viewer.clipS).toBe(5);
+ } finally {
+ qs.saveQueueSettings(qs.QUEUE_DEFAULTS);
+ }
+ expect((await visitorStatus(acct)).viewer.clipS).toBeUndefined();
+ });
+
it("a 3D model runs here only while a worker's CPU slot finishes it, and then as the policy's kinds say; a splat or a scene never does", async () => {
const a = account();
const acct = auth.accountById(a.id)!;
diff --git a/tests/pool-line-order.test.ts b/tests/pool-line-order.test.ts
index 078b7aaa..db610252 100644
--- a/tests/pool-line-order.test.ts
+++ b/tests/pool-line-order.test.ts
@@ -682,14 +682,14 @@ describe("GET and PATCH /api/admin/queue/settings", () => {
const res = await settingsRoute.GET(req({ cookie: ownerCookie() }));
expect(res.status).toBe(200);
expect(res.headers.get("cache-control")).toBe("no-store");
- expect(await res.json()).toEqual({ settings: { runCeilingS: { default: 2700, lanes: {} }, ownerWaitLimitS: null, fairShare: false, pickAllowanceMs: 0, pausedBudgetS: 7200 } });
+ expect(await res.json()).toEqual({ settings: { runCeilingS: { default: 2700, lanes: {} }, ownerWaitLimitS: null, fairShare: false, pickAllowanceMs: 0, pausedBudgetS: 7200, longestClipS: null } });
});
it("the owner changes them; each change is logged with the values before and after", async () => {
const lane = allLanes(loadIndex(), sha)[0].lane;
- const res = await settingsRoute.PATCH(req({ method: "PATCH", cookie: ownerCookie(), body: { runCeilingS: { default: 3000, lanes: { [lane]: 3600 } }, ownerWaitLimitS: 86_400, fairShare: true, pausedBudgetS: 3600 } }));
+ const res = await settingsRoute.PATCH(req({ method: "PATCH", cookie: ownerCookie(), body: { runCeilingS: { default: 3000, lanes: { [lane]: 3600 } }, ownerWaitLimitS: 86_400, fairShare: true, pausedBudgetS: 3600, longestClipS: 10 } }));
expect(res.status).toBe(200);
- const want = { runCeilingS: { default: 3000, lanes: { [lane]: 3600 } }, ownerWaitLimitS: 86_400, fairShare: true, pickAllowanceMs: 0, pausedBudgetS: 3600 };
+ const want = { runCeilingS: { default: 3000, lanes: { [lane]: 3600 } }, ownerWaitLimitS: 86_400, fairShare: true, pickAllowanceMs: 0, pausedBudgetS: 3600, longestClipS: 10 };
expect(await res.json()).toEqual({ settings: want });
expect(qs.queueSettings()).toEqual(want);
const row = audits().at(-1)!;
@@ -712,6 +712,8 @@ describe("GET and PATCH /api/admin/queue/settings", () => {
{ pickAllowanceMs: 1.5 },
{ pausedBudgetS: -1 },
{ pausedBudgetS: 8 * 24 * 3600 },
+ { longestClipS: 0 },
+ { longestClipS: 7200 },
{ somethingElse: 1 },
[1, 2],
null,