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.

Workers: each allowed lane may carry its own longest clip

Adarsh4eb2240b6b00
diff --git a/src/components/workers-admin.tsx b/src/components/workers-admin.tsx
index 576f6fcc..78121428 100644
--- a/src/components/workers-admin.tsx
+++ b/src/components/workers-admin.tsx
@@ -25,6 +25,9 @@ import { cn } from "@/lib/utils";
type Hours = { always: true } | { tz: string; days: Record<string, [string, string][]> };
+/** A lane a worker may run: how long a job waits before it takes it, and the longest clip it takes there (none: no limit). */
+type LaneAllow = { delayMs: number; maxSeconds?: number };
+
interface WorkerView {
id: string;
name: string;
@@ -38,7 +41,7 @@ interface WorkerView {
/** Its RAM guard (a server from before sends none). */
ramGuard?: boolean;
hours: Hours | null;
- allow: Record<string, { delayMs: number }>;
+ allow: Record<string, LaneAllow>;
/** Its pick order: above 0, it gets first pick of the jobs it can run while it is free (a server from before sends none). */
pickOrder?: number;
/** The workflows it takes only with every weight on its card, newest first (a server from before sends none). */
@@ -187,15 +190,15 @@ export const runnableLanes = (w: LaneSource): string[] => [...new Set([...w.lane
* The lanes Allow all it can run allows: each one it can run any workflow of (a task goes only to a worker that can run
* its own workflow, so a lane it runs part of is safe to allow), each keeping a wait it already had.
*/
-export function allowAllItCanRun(w: LaneSource, allow: Record<string, { delayMs: number }>): Record<string, { delayMs: number }> {
- const next: Record<string, { delayMs: number }> = {};
+export function allowAllItCanRun(w: LaneSource, allow: Record<string, LaneAllow>): Record<string, LaneAllow> {
+ const next: Record<string, LaneAllow> = {};
for (const lane of runnableLanes(w)) next[lane] = allow[lane] ?? { delayMs: 0 };
return next;
}
const FIT_RANK = { all: 0, some: 1, none: 2 } as const;
-export function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]; onSave: (allow: Record<string, { delayMs: number }>) => void }) {
+export function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]; onSave: (allow: Record<string, LaneAllow>) => void }) {
const [allow, setAllow] = useState(w.allow);
// Every workflow first, then some of them, then none; by name within each.
const sorted = [...lanes].sort((a, b) => FIT_RANK[laneFit(w, a.lane).kind] - FIT_RANK[laneFit(w, b.lane).kind] || a.label.localeCompare(b.label));
@@ -245,11 +248,29 @@ export function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]
className="h-7 w-14"
inputMode="numeric"
value={String(Math.round((allow[l.lane]?.delayMs ?? 0) / 1000))}
- onChange={(e) => setAllow({ ...allow, [l.lane]: { delayMs: Math.max(0, Number(e.target.value) || 0) * 1000 } })}
+ onChange={(e) => setAllow({ ...allow, [l.lane]: { ...allow[l.lane], delayMs: Math.max(0, Number(e.target.value) || 0) * 1000 } })}
/>
s first
</label>
)}
+ {l.lane in allow && (
+ <label className="flex items-center gap-1 text-[12px] text-muted-foreground">
+ clips up to
+ <Input
+ aria-label={`Longest clip for ${l.label}`}
+ className="h-7 w-14"
+ inputMode="decimal"
+ placeholder="any"
+ value={allow[l.lane]?.maxSeconds ? String(allow[l.lane]!.maxSeconds) : ""}
+ onChange={(e) => {
+ const most = Number(e.target.value);
+ const { maxSeconds: _was, ...rest } = allow[l.lane] ?? { delayMs: 0 };
+ setAllow({ ...allow, [l.lane]: { ...rest, ...(Number.isFinite(most) && most > 0 && { maxSeconds: most }) } });
+ }}
+ />
+ s
+ </label>
+ )}
</li>
);
})}
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index b908b682..502203ea 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -171,9 +171,16 @@ export function slotFor(t: Pick<TaskRow, "slot" | "finish_json">, w: Pick<Worker
interface Allow {
delayMs: number;
+ /** The longest clip this worker takes in this lane, in seconds (none: as long as its PC's ceiling allows). */
+ maxSeconds?: number;
}
const allowOf = (w: WorkerRow) => json<Record<string, Allow>>(w.allow_json, {});
+/** Is the job longer than this worker takes in its lane (the lane's own clip limit)? */
+const pastLaneLimit = (allow: Record<string, Allow>, lane: string, size?: { seconds?: number } | null) => {
+ const most = allow[lane]?.maxSeconds;
+ return !!most && (size?.seconds ?? 0) > most + 1e-9;
+};
/** The lanes and workflows its files let it run, and the requirements index they were worked out with (none: an older row). */
/** `sets`: the file sets it has whole of each workflow with model variants (lanesFor). Lanes worked out without it: its own files only. */
const capableOf = (w: Pick<WorkerRow, "lanes_json">) => json<{ lanes: string[]; workflows: string[]; index?: string; sets?: Record<string, (string | null)[]> }>(w.lanes_json, { lanes: [], workflows: [] });
@@ -1063,13 +1070,13 @@ function estOn(t: TaskRow, w: WorkerRow): number | null {
/**
* Why a worker can't run a task (fitWhy, fitSlotWhy), the first reason found: "pool" (not one of the task's pools),
- * "elsewhere" (sent to another worker), "stopped", "lane-off" (its lane isn't allowed there), "ceiling" (beyond what its
- * PC may ever run), "version" (its worker program or catalog doesn't take the job's ticket), "refused" (it refused the
- * job before), "files" (it hasn't the workflow's files), "run-files" (it hasn't the files the run adds), "memory" (too
- * little GPU memory, streaming from RAM counted), "finish" (no slot of it runs this finishing step), "delay" (its delays
- * haven't passed yet).
+ * "elsewhere" (sent to another worker), "stopped", "lane-off" (its lane isn't allowed there), "ceiling" (beyond what
+ * its PC may ever run), "clip" (longer than the clips its lane takes there), "version" (its worker program or catalog
+ * doesn't take the job's ticket), "refused" (it refused the job before), "files" (it hasn't the workflow's files),
+ * "run-files" (it hasn't the files the run adds), "memory" (too little GPU memory, streaming from RAM counted),
+ * "finish" (no slot of it runs this finishing step), "delay" (its delays haven't passed yet).
*/
-export type FitCode = "pool" | "elsewhere" | "stopped" | "lane-off" | "ceiling" | "version" | "refused" | "files" | "run-files" | "memory" | "finish" | "delay";
+export type FitCode = "pool" | "elsewhere" | "stopped" | "lane-off" | "ceiling" | "clip" | "version" | "refused" | "files" | "run-files" | "memory" | "finish" | "delay";
/**
* May this worker run this task: its pool, its lane allowed and capable, its PC's ceiling (the lanes or workflows it
@@ -1086,6 +1093,7 @@ function fitWhy(t: TaskRow, w: WorkerRow, now: number): FitCode | null {
const cap = capableOf(w);
const needs = json<Needs | null>(t.needs_json, null);
if (ceilingProblem(ceilingOf(w), { workflowId: needs?.workflowId, lane, size: needs?.size })) return "ceiling";
+ if (pastLaneLimit(allow, lane, needs?.size)) return "clip";
// A ticket made for another catalog than the worker's goes only to a worker that checks the graph itself
// (GRAPH_PROTOCOL), with the ticket's graph fingerprint to check. One that found the graph changed gave the job back
// (refusedBy, below) and isn't offered it again until it is updated.
@@ -1141,6 +1149,7 @@ export const FIT_WORDS: Record<Exclude<FitCode, "pool">, string> = {
stopped: "stopped",
"lane-off": "not allowed this kind of job",
ceiling: "beyond what its PC may run",
+ clip: "takes shorter clips of this kind",
version: "needs its worker program updated",
refused: "refused it before",
files: "lacks its model files",
@@ -1846,7 +1855,14 @@ export function workersHold(workflowId: string): boolean {
* where one of them has no limit, and for a workflow none of them runs. Said before Run with a size they don't make.
*/
export function workersMost(workflowId: string): { maxMegapixels?: number; maxSeconds?: number; maxOutputs?: number } {
- const ceilings = ableWorkers(workflowId).map(ceilingOf);
+ const lane = poolLane(workflowId);
+ // Each worker's PC ceiling, its longest clip narrowed to its lane's own limit when it has one.
+ const ceilings = ableWorkers(workflowId).map((w): Ceiling | null => {
+ const c = ceilingOf(w);
+ const laneMost = allowOf(w)[lane]?.maxSeconds;
+ if (!laneMost) return c;
+ return { ...c, maxSeconds: c?.maxSeconds ? Math.min(c.maxSeconds, laneMost) : laneMost };
+ });
const most = (k: "maxMegapixels" | "maxSeconds" | "maxOutputs"): number | undefined => {
if (!ceilings.length || ceilings.some((c) => !c?.[k])) return undefined;
return Math.max(...ceilings.map((c) => c![k]!));
@@ -1875,6 +1891,7 @@ function ableWorkers(workflowId: string | null, o: { size?: Needs["size"]; ticke
const ceiling = ceilingOf(w);
if (workflowId === null) return cap.workflows.some((id) => poolLane(id) in allow && insideCeiling(ceiling, { workflowId: id, lane: poolLane(id) }));
if (!needs || !(lane! in allow) || !cap.workflows.includes(workflowId) || ceilingProblem(ceiling, { workflowId, lane, size: o.size })) return false;
+ if (pastLaneLimit(allow, lane!, o.size)) return false;
if (o.files?.length && !hasFiles(inventoryOf(w), o.files)) return false;
if (hasVariants(loadIndex(), workflowId)) return !!workerFiles(w, workflowId, bytesOf(o.files));
return memoryFor(needs, w, bytesOf(o.files));
@@ -2519,7 +2536,11 @@ export function patchWorker(id: string, p: WorkerPatch, now = Date.now(), by = "
for (const [lane, v] of Object.entries(p.allow as Record<string, unknown>)) {
if (!/^[0-9a-f]{12}$|^small$/.test(lane)) throw new Error(`No such lane: ${lane}`);
const delay = Number((v as { delayMs?: unknown })?.delayMs ?? 0);
- allow[lane] = { delayMs: Number.isFinite(delay) && delay >= 0 ? Math.min(delay, 24 * 3_600_000) : 0 };
+ const most = Number((v as { maxSeconds?: unknown })?.maxSeconds ?? 0);
+ allow[lane] = {
+ delayMs: Number.isFinite(delay) && delay >= 0 ? Math.min(delay, 24 * 3_600_000) : 0,
+ ...(Number.isFinite(most) && most > 0 && { maxSeconds: Math.min(most, 86_400) }),
+ };
}
set.allow_json = JSON.stringify(allow);
}
diff --git a/tests/worker-tickets.test.ts b/tests/worker-tickets.test.ts
index efe59f32..f4482249 100644
--- a/tests/worker-tickets.test.ts
+++ b/tests/worker-tickets.test.ts
@@ -351,6 +351,28 @@ describe("the line hands out tickets inside each PC's ceiling", () => {
expect(row(String((own.meta as { relay: string }).relay)).state).toBe("waiting");
});
+ it("a lane's own clip limit: a longer job is never claimed there, and every PC's most says it", async () => {
+ const w = addWorker();
+ beat(w);
+ const allow = Object.fromEntries(Object.entries(pool.workerView(workerRow(w)).allow).map(([l, a]) => [l, l === LANE ? { ...a, maxSeconds: 5 } : a]));
+ pool.patchWorker(w.id, { allow });
+ expect(pool.workerView(workerRow(w)).allow[LANE]).toEqual({ delayMs: 0, maxSeconds: 5 });
+ expect(pool.workersMost("selftest-image").maxSeconds).toBe(5);
+ expect(pool.workersCanRun("selftest-image", { size: { megapixels: 1, seconds: 5, outputs: 1 } })).toBe(true);
+ expect(pool.workersCanRun("selftest-image", { size: { megapixels: 1, seconds: 8, outputs: 1 } })).toBe(false);
+ const mine = await accountTask();
+ const needs = JSON.parse(row(mine.id).needs_json!) as { size: { seconds: number } };
+ db().prepare("UPDATE relay_tasks SET needs_json = ? WHERE id = ?").run(JSON.stringify({ ...needs, size: { ...needs.size, seconds: 8 } }), mine.id);
+ expect(beat(w).claimableNow).toBe(0);
+ expect(claim(w)).toBeNull();
+ // Within it: claimed. A limit of 0 or none is no limit.
+ db().prepare("UPDATE relay_tasks SET needs_json = ? WHERE id = ?").run(JSON.stringify({ ...needs, size: { ...needs.size, seconds: 5 } }), mine.id);
+ expect(claim(w)?.id).toBe(mine.id);
+ pool.patchWorker(w.id, { allow: { ...allow, [LANE]: { delayMs: 0, maxSeconds: 0 } } });
+ expect(pool.workerView(workerRow(w)).allow[LANE]).toEqual({ delayMs: 0 });
+ expect(pool.workersMost("selftest-image").maxSeconds).toBeUndefined();
+ });
+
it("a waiting task whose ticket was made for the catalog before an update gets its ticket made again, with its place kept", async () => {
const { noteCatalogProcess, processStart, refreshTickets } = await import("@/server/computer/ticket-refresh");
// The app process before the update said its catalog version when it ran.