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
Workers: a lane the worker can run part of shows its count and can be allowed
Adarshde19d34eeffc
diff --git a/src/components/workers-admin.tsx b/src/components/workers-admin.tsxindex ee8711b8..a5899be9 100644--- a/src/components/workers-admin.tsx+++ b/src/components/workers-admin.tsx@@ -36,7 +36,10 @@ interface WorkerView {autoResume: boolean | null;hours: Hours | null;allow: Record<string, { delayMs: number }>;+ /** The lanes it can run every workflow of. */lanes: string[];+ /** The lanes it can run only some workflows of (a server from before sends none). */+ partLanes?: Record<string, { runnable: number; of: number }>;warmLane: string | null;facts: { device?: string; vramBytes?: number; version?: string };seenAt: number | null;@@ -136,62 +139,98 @@ function HoursEditor({ w, onSave }: { w: WorkerView; onSave: (hours: Hours | nul);}-function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]; onSave: (allow: Record<string, { delayMs: number }>) => void }) {+/** How much of a lane a worker can run: every workflow, some of them, or none (its files are missing). */+export type LaneFit = { kind: "all" } | { kind: "some"; runnable: number; of: number } | { kind: "none" };++type LaneSource = Pick<WorkerView, "lanes" | "partLanes">;++export function laneFit(w: LaneSource, lane: string): LaneFit {+ if (w.lanes.includes(lane)) return { kind: "all" };+ const part = w.partLanes?.[lane];+ return part && part.runnable > 0 ? { kind: "some", runnable: part.runnable, of: part.of } : { kind: "none" };+}++/** The note after a lane's name: none when it runs every workflow, "(24 of 26 workflows)", or "(files missing)". */+export function laneNote(fit: LaneFit): string | null {+ if (fit.kind === "all") return null;+ return fit.kind === "some" ? `(${fit.runnable} of ${fit.of} workflows)` : "(files missing)";+}++/** Every lane it can run at least one workflow of. */+export const runnableLanes = (w: LaneSource): string[] => [...new Set([...w.lanes, ...Object.keys(w.partLanes ?? {})])];++/**+ * 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 }> = {};+ 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 }) {const [allow, setAllow] = useState(w.allow);- const capable = new Set(w.lanes);- const sorted = [...lanes].sort((a, b) => Number(capable.has(b.lane)) - Number(capable.has(a.lane)) || a.label.localeCompare(b.label));+ // 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));+ const runnable = runnableLanes(w).length;return (<details className="text-[13px]"><summary className="cursor-pointer text-muted-foreground">- Lanes it may run: {Object.keys(w.allow).length} of {lanes.length} ({w.lanes.length} it has the files for)+ Lanes it may run: {Object.keys(w.allow).length} of {lanes.length} ({runnable} it can run)</summary><ul className="mt-2 max-h-72 space-y-1 overflow-y-auto">- {sorted.map((l) => (- <li key={l.lane} className="flex flex-wrap items-center gap-2">- <label className="flex min-w-0 flex-1 items-center gap-2">- <input- type="checkbox"- checked={l.lane in allow}- onChange={(e) => {- const next = { ...allow };- if (e.target.checked) next[l.lane] = { delayMs: 0 };- else delete next[l.lane];- setAllow(next);- }}- />- <span className={cn("truncate", !capable.has(l.lane) && "text-muted-foreground")}>{l.label}</span>- {!capable.has(l.lane) && <span className="text-[11px] text-muted-foreground">(files missing)</span>}- </label>- {l.lane in allow && (- <label className="flex items-center gap-1 text-[12px] text-muted-foreground">- wait- <Input- aria-label={`Delay for ${l.label}`}- 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 } })}+ {sorted.map((l) => {+ const fit = laneFit(w, l.lane);+ const note = laneNote(fit);+ return (+ <li key={l.lane} className="flex flex-wrap items-center gap-2">+ <label className="flex min-w-0 flex-1 items-center gap-2">+ <input+ type="checkbox"+ checked={l.lane in allow}+ onChange={(e) => {+ const next = { ...allow };+ if (e.target.checked) next[l.lane] = { delayMs: 0 };+ else delete next[l.lane];+ setAllow(next);+ }}/>- s first+ <span className={cn("truncate", fit.kind === "none" && "text-muted-foreground")}>{l.label}</span>+ {note && <span className="text-[11px] text-muted-foreground">{note}</span>}</label>- )}- </li>- ))}+ {l.lane in allow && (+ <label className="flex items-center gap-1 text-[12px] text-muted-foreground">+ wait+ <Input+ aria-label={`Delay for ${l.label}`}+ 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 } })}+ />+ s first+ </label>+ )}+ </li>+ );+ })}</ul><div className="mt-2 flex flex-wrap items-center gap-2">- {/* One click for every lane the PC has the files for (each keeps a wait it already had), saved at once. */}+ {/* One click for every lane the PC can run any workflow of (each keeps a wait it already had), saved at once. */}<Buttonsize="sm"className="h-8"- disabled={!w.lanes.length}+ disabled={!runnable}onClick={() => {- const next: Record<string, { delayMs: number }> = {};- for (const lane of w.lanes) next[lane] = allow[lane] ?? { delayMs: 0 };+ const next = allowAllItCanRun(w, allow);setAllow(next);onSave(next);}}>- Allow all it can run ({w.lanes.length})+ Allow all it can run ({runnable})</Button><Button size="sm" variant="ghost" className="h-8" disabled={!Object.keys(allow).length} onClick={() => setAllow({})}>Cleardiff --git a/src/lib/lanes.ts b/src/lib/lanes.tsindex a5d96c3b..64a5dee6 100644--- a/src/lib/lanes.ts+++ b/src/lib/lanes.ts@@ -160,3 +160,22 @@ export function lanesFor(const missing = [...lacking].map(([lane, m]) => ({ lane, label: laneLabel(index, lane, sha), files: [...m.keys()].sort(), bytes: [...m.values()].reduce((a, b) => a + b, 0) }));return { lanes, workflows: workflows.sort(), missing };}++/**+ * The lanes a worker can run only some workflows of (`workflows`: the ones it can run, as lanesFor gives them): how many+ * it runs, of how many (isolated workflows left out, as lanesFor does). A task goes only to a worker that can run its+ * own workflow, so such a lane may be allowed: its other workflows never reach that worker.+ */+export function partLanes(index: RequirementIndex, workflows: readonly string[], sha: Sha): Record<string, { runnable: number; of: number }> {+ const can = new Set(workflows);+ const by = new Map<string, { runnable: number; of: number }>();+ for (const id of Object.keys(index.workflows)) {+ if (index.workflows[id].isolated) continue;+ const lane = laneOf(index, id, sha)!;+ const n = by.get(lane) ?? { runnable: 0, of: 0 };+ n.of++;+ if (can.has(id)) n.runnable++;+ by.set(lane, n);+ }+ return Object.fromEntries([...by].filter(([, n]) => n.runnable > 0 && n.runnable < n.of).sort(([a], [b]) => a.localeCompare(b)));+}diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex 7806796a..d399f468 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -2,7 +2,7 @@ import "server-only";import crypto from "node:crypto";import { FINISH_KINDS, type FinishTicket } from "@/lib/finish-ticket";import { ceilingProblem, cleanCeiling, insideCeiling, lanesInside, type Ceiling } from "@/lib/job-ticket";-import { allLanes, laneLabel, lanesFor, MEDIA_KINDS, needsOf, type Inventory, type Needs } from "@/lib/lanes";+import { allLanes, laneLabel, lanesFor, MEDIA_KINDS, needsOf, partLanes, type Inventory, type Needs } from "@/lib/lanes";import { RELAY_TIMES, SENT_STATES, type BeatAnswer, type ClaimedTask, type ComputerFacts, type CpuSlot, type WorkerAnswer, type WorkerBeat } from "@/lib/relay";import { clock, hoursAt, parseHours, type Hours } from "@/lib/worker-hours";import { db } from "../db";@@ -1212,7 +1212,13 @@ export interface WorkerView {claimAfterMs: number;switchAfterMs: number;warmLane: string | null;+ /** The lanes it can run every workflow of. */lanes: string[];+ /**+ * The lanes it can run only some workflows of: how many, of how many. Allowing one is safe (a task goes only to a+ * worker that can run its own workflow), so Settings offers them with the count.+ */+ partLanes: Record<string, { runnable: number; of: number }>;/** What its PC may ever run (null: no ceiling of its own), and the allowed lanes inside it. */ceiling: Ceiling | null;lanesInside: string[];@@ -1252,6 +1258,7 @@ export function workerView(w: WorkerRow, now = Date.now()): WorkerView {switchAfterMs: w.switch_after_ms,warmLane: w.warm_lane,lanes: capableOf(w).lanes,+ partLanes: partLanes(loadIndex(), capableOf(w).workflows, sha),ceiling: ceilingOf(w),lanesInside: lanesInside(Object.keys(allowOf(w)), ceilingOf(w)),cpuSlot: cpuSlotOf(w),diff --git a/tests/workers-lanes-editor.test.ts b/tests/workers-lanes-editor.test.tsnew file mode 100644index 00000000..a2ba9e4e--- /dev/null+++ b/tests/workers-lanes-editor.test.ts@@ -0,0 +1,74 @@+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it, vi } from "vitest";++/*+ * Settings → Workers, the lanes a worker may run: a lane it can run every workflow of shows plainly, one it can run some+ * workflows of says how many ("24 of 26 workflows") and is offered like the others, and only a lane it can run none of+ * says its files are missing. Allow all it can run takes every lane it can run any workflow of.+ */++vi.mock("next/navigation", () => ({+ useRouter: () => ({ prefetch: () => {}, push: () => {}, replace: () => {}, back: () => {}, refresh: () => {} }),+ usePathname: () => "/settings/workers",+ useSearchParams: () => new URLSearchParams(),+}));++const { LanesEditor, allowAllItCanRun, laneFit, laneNote } = await import("@/components/workers-admin");++const FULL = "aaaaaaaaaaaa";+const PART = "bbbbbbbbbbbb";+const NONE = "cccccccccccc";+const worker = { lanes: [FULL], partLanes: { [PART]: { runnable: 24, of: 26 } } };++describe("a worker's lanes in Settings", () => {+ it("every workflow: no note; some: how many of how many; none: files missing", () => {+ expect(laneFit(worker, FULL)).toEqual({ kind: "all" });+ expect(laneFit(worker, PART)).toEqual({ kind: "some", runnable: 24, of: 26 });+ expect(laneFit(worker, NONE)).toEqual({ kind: "none" });+ expect(laneNote(laneFit(worker, FULL))).toBeNull();+ expect(laneNote(laneFit(worker, PART))).toBe("(24 of 26 workflows)");+ expect(laneNote(laneFit(worker, NONE))).toBe("(files missing)");+ // A server from before sends no part lanes: only full lanes, as before.+ expect(laneFit({ lanes: [FULL] }, PART)).toEqual({ kind: "none" });+ });++ it("Allow all it can run takes the part lanes too, each keeping a wait it had, and leaves out lanes it can't run", () => {+ const next = allowAllItCanRun(worker, { [PART]: { delayMs: 5000 }, [NONE]: { delayMs: 0 } });+ expect(next).toEqual({ [FULL]: { delayMs: 0 }, [PART]: { delayMs: 5000 } });+ });++ it("the list shows the count on a part lane, files missing only where none runs, and the button counts the part lanes", () => {+ const w = {+ id: "w1",+ name: "Owner PC",+ pool: "pool",+ state: "ready",+ words: "Ready",+ pausedServer: false,+ pausedLocal: false,+ drain: false,+ autoResume: null,+ hours: null,+ allow: {},+ warmLane: null,+ facts: {},+ seenAt: null,+ version: null,+ current: null,+ ...worker,+ };+ const lanes = [+ { lane: FULL, label: "Full lane", workflows: 3 },+ { lane: PART, label: "Qwen Image 2.1", workflows: 26 },+ { lane: NONE, label: "Missing lane", workflows: 2 },+ ];+ const html = renderToStaticMarkup(createElement(LanesEditor, { w, lanes, onSave: () => {} }));+ expect(html).toContain("(24 of 26 workflows)");+ expect(html.match(/\(files missing\)/g)).toHaveLength(1);+ expect(html.indexOf("Missing lane")).toBeGreaterThan(html.indexOf("Qwen Image 2.1"));+ expect(html.indexOf("(files missing)")).toBeGreaterThan(html.indexOf("Missing lane"));+ expect(html).toContain("Allow all it can run (2)");+ expect(html).toContain("(2 it can run)");+ });+});diff --git a/tests/workers-pool.test.ts b/tests/workers-pool.test.tsindex 08905a70..b7343f4c 100644--- a/tests/workers-pool.test.ts+++ b/tests/workers-pool.test.ts@@ -1003,3 +1003,46 @@ describe("a worker's own reports: giving a job back, its execution time, the inpexpect(JSON.parse(row(w).inventory_json ?? "{}").media).toEqual(["image"]);});});++describe("a lane a worker can run only some workflows of", () => {+ const sha = (s: string) => crypto.createHash("sha256").update(s).digest("hex");+ /** A real lane of the catalog with at least two workflows (isolated ones left out, as lanesFor does). */+ function sharedLane() {+ const index = loadIndex();+ const by = new Map<string, string[]>();+ for (const id of Object.keys(index.workflows)) {+ if (index.workflows[id].isolated) continue;+ const lane = laneOf(index, id, sha)!;+ by.set(lane, [...(by.get(lane) ?? []), id]);+ }+ const [lane, ids] = [...by].find(([, ids]) => ids.length >= 2)!;+ return { index, lane, ids: [...ids].sort() };+ }++ it("is counted per workflow: every one, some, or none of them", () => {+ const { index, lane, ids } = sharedLane();+ const some = ids.slice(0, -1);+ expect(lanesModule.partLanes(index, some, sha)[lane]).toEqual({ runnable: some.length, of: ids.length });+ // Every workflow, or none: not a part lane (the first is in lanesFor's lanes, the second has its files missing).+ expect(lanesModule.partLanes(index, ids, sha)[lane]).toBeUndefined();+ expect(lanesModule.partLanes(index, [], sha)[lane]).toBeUndefined();+ });++ it("the owner's view says how many it runs, and a task of a workflow it runs is claimed there once the lane is allowed", () => {+ const { lane, ids } = sharedLane();+ const runs = ids.slice(0, -1);+ const missing = ids.at(-1)!;+ const w = worker("part-lane", { lanes: [lane], workflows: runs });+ // Its full lanes stay as they were (none here); the part lane comes with its count.+ db().prepare("UPDATE relay_workers SET lanes_json = ? WHERE id = ?").run(JSON.stringify({ lanes: [], workflows: runs }), w.id);+ const view = pool.listWorkers(clock).find((x) => x.id === w.id)!;+ expect(view.lanes).not.toContain(lane);+ expect(view.partLanes[lane]).toEqual({ runnable: runs.length, of: ids.length });+ // A task of the workflow it lacks never reaches it; one of a workflow it runs does.+ const lacking = task({ lane, workflow: missing });+ expect(claim(w)).toBeNull();+ expect(state(lacking).state).toBe("waiting");+ const runnable = task({ lane, workflow: runs[0] });+ expect(claim(w)?.id).toBe(runnable);+ });+});