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 per-worker RAM guard switch; noStream becomes a preference
Adarsh12d675f8b914
diff --git a/docs/admin-api.md b/docs/admin-api.mdindex 84edefc9..06dd6376 100644--- a/docs/admin-api.md+++ b/docs/admin-api.md@@ -129,10 +129,10 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control| `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` || `PATCH /api/admin/site/runs` | `{ "failureDetail": "full" \| "friendly" }` | `{ failureDetail }`; 400 for any other body. Runs read it the next time they are shown. A person only ever sees the details of their own runs |-| `GET /api/admin/workers` | | `{ workers, lanes }`. Each worker adds `pickOrder`, `noStream` (the workflows it takes only with every weight on its card, newest first: `[{ workflowId, at }]`, [gpu-workers.md](gpu-workers.md#streaming-from-ram)), `asked: { at, words }` or null, `jobs` (each job it holds: `{ taskId, generationId, slot, lane, laneLabel, stage, state, claimedAt, startedAt, progress, progressAt, movedAt, gpuBusy, stallMs, doing, typicalMs, etaS, owners, feature?, modelName?, op?, kind? }`: `doing` is what its ComfyUI runs now (`{ node, nodeClass, nodeTitle, value?, max?, pass? }`, or null), for the owner only; `movedAt` is when the worker last saw the job move, on the site clock, or null from an older worker; `gpuBusy` is its GPU use from 0 to 100, or null; past `stallMs` without a move the worker gives the job back; `etaS` is more than 0 or null, never 0 for a running job) and `lastEvent: { at, kind, event, words }` or null |+| `GET /api/admin/workers` | | `{ workers, lanes }`. Each worker adds `ramGuard` (its RAM guard switch, `false` by default, [gpu-workers.md](gpu-workers.md#this-pcs-memory)), `pickOrder`, `noStream` (the workflows it takes only with every weight on its card, newest first: `[{ workflowId, at }]`, [gpu-workers.md](gpu-workers.md#streaming-from-ram)), `asked: { at, words }` or null, `jobs` (each job it holds: `{ taskId, generationId, slot, lane, laneLabel, stage, state, claimedAt, startedAt, progress, progressAt, movedAt, gpuBusy, stallMs, doing, typicalMs, etaS, owners, feature?, modelName?, op?, kind? }`: `doing` is what its ComfyUI runs now (`{ node, nodeClass, nodeTitle, value?, max?, pass? }`, or null), for the owner only; `movedAt` is when the worker last saw the job move, on the site clock, or null from an older worker; `gpuBusy` is its GPU use from 0 to 100, or null; past `stallMs` without a move the worker gives the job back; `etaS` is more than 0 or null, never 0 for a running job) and `lastEvent: { at, kind, event, words }` or null || `POST /api/admin/workers` | `{ name, pool? }` | 201 `{ id, token }`: the worker's token, once || `POST /api/admin/workers/{id}/update` | none | `{ worker }`: its next beat answer asks it to update now. It looks for new code at once and restarts on it after the job in hand (a person's job is never cut off). Each worker in `GET /api/admin/workers` has `update`: `state` (`current`, `updating` while behind the site's version for under 3 minutes, `behind` after), `since`, `behindMs`, `site`, `worker`, `commit` (first 12 hex), `peopleHeld`, `peopleWaiting`, `askedAt`, `words` and `needsOwner` |-| `PATCH /api/admin/workers/{id}` | any of `paused`, `pauseNow`, `drain`, `autoResume`, `hours`, `allow`, `claimAfterMs`, `switchAfterMs`, `pickOrder` (a whole number from -100 to 100, 0 by default: a free worker with a higher one gets first pick, [gpu-workers.md](gpu-workers.md#who-picks-first)), `clearNoStream` (`true` for its whole `noStream` list, or a list of workflow ids: it may stream them from RAM again), `rotate` (needs `workers:tokens`), `revoke` | `{ worker, token? }`: a new worker token after `rotate`, once. 400 with the reason for a value that isn't allowed |+| `PATCH /api/admin/workers/{id}` | any of `paused`, `pauseNow`, `drain`, `autoResume`, `ramGuard` (`true` or `false`: the worker's RAM guard, which its next beat answer carries; its numbers stay in its `worker.json`, [gpu-workers.md](gpu-workers.md#this-pcs-memory)), `hours`, `allow`, `claimAfterMs`, `switchAfterMs`, `pickOrder` (a whole number from -100 to 100, 0 by default: a free worker with a higher one gets first pick, [gpu-workers.md](gpu-workers.md#who-picks-first)), `clearNoStream` (`true` for its whole `noStream` list, or a list of workflow ids: it may stream them from RAM again), `rotate` (needs `workers:tokens`), `revoke` | `{ worker, token? }`: a new worker token after `rotate`, once. 400 with the reason for a value that isn't allowed || `GET /api/admin/workers/jobs` | `before`, `limit` (1 to 200, 50), `worker`, `generation` | `{ items, next }`: the workers' log, newest first. Each item: `{ id, at, event, workerId, workerName, taskId, generationId, principal, lane, execMs, device }` ([gpu-workers.md](gpu-workers.md)) || `GET /api/admin/workers/events` | `worker`, `kinds` (a comma list of `state`, `job`, `stage`, `looking`, `admin`, `version`, `log`; all when not given), `before`, `after`, `generation`, `limit` (1 to 500, 100) | `{ items, next, latest }`: the workers' timeline, newest first. Each item: `{ id, at, workerId, workerName, kind, event, words, taskId, generationId, lane, laneLabel, state, detail }`. `next` pages back (as `before`); `latest` is the newest row id (as `after`, for new rows only) ([gpu-workers.md](gpu-workers.md)) || `GET /api/admin/audit` | `before` (the last page's `next`), `limit` (1 to 200, default 50), `actor` (`owner`, `token` or `system`), `token` (a token id), `action`, `changes=1` (changes only: no reads, file views or refusals) | `{ items, next }` |diff --git a/src/app/api/admin/workers/[id]/route.ts b/src/app/api/admin/workers/[id]/route.tsindex 6248e61f..cb748545 100644--- a/src/app/api/admin/workers/[id]/route.ts+++ b/src/app/api/admin/workers/[id]/route.ts@@ -4,11 +4,11 @@ import { patchWorker, type WorkerPatch } from "@/server/computer/pool";const NO_STORE = { "Cache-Control": "no-store" };/** The changes a worker takes: the log names which were sent, never their values (a rotate's token least of all). */-const KEYS = ["paused", "pauseNow", "drain", "autoResume", "hours", "allow", "claimAfterMs", "switchAfterMs", "pickOrder", "clearNoStream", "rotate", "revoke"] as const;+const KEYS = ["paused", "pauseNow", "drain", "autoResume", "ramGuard", "hours", "allow", "claimAfterMs", "switchAfterMs", "pickOrder", "clearNoStream", "rotate", "revoke"] as const;/*** Change a worker (owner only, or an admin token with workers:write):- * `{ paused, pauseNow, drain, autoResume, hours, allow, claimAfterMs, switchAfterMs, pickOrder, clearNoStream, rotate, revoke }`.+ * `{ paused, pauseNow, drain, autoResume, ramGuard, hours, allow, claimAfterMs, switchAfterMs, pickOrder, clearNoStream, rotate, revoke }`.* Each reaches the worker at its next beat. Rotate answers with the new token, once (an admin token needs* workers:tokens for it); revoke stops the old token at once and puts its job back in line.*/diff --git a/src/app/api/gpu/computer/claim/route.ts b/src/app/api/gpu/computer/claim/route.tsindex 6f7b4489..7412061f 100644--- a/src/app/api/gpu/computer/claim/route.ts+++ b/src/app/api/gpu/computer/claim/route.ts@@ -23,7 +23,7 @@ export async function POST(request: Request) {if (worker?.kind === "pool") await refreshTicketsBeforeClaim();// A shared GPU takes the best task it can run from its pool (pool.ts), for its GPU or for its CPU slot (`slot`:// "cpu"); a person's computer, their own oldest. A worker whose PC's memory is in use (`noStream`, its RAM guard)- // takes only a job whose weights fit whole on its card.+ // prefers a job whose weights fit whole on its card, and takes one it streams when no other worker could now.const task = worker?.kind === "pool" ? workerClaim(worker, running, Date.now(), body?.slot === "cpu" ? "cpu" : "gpu", { noStream: body?.noStream === true }) : claim(principal, String(body?.device ?? ""), running);if (!task) return new Response(null, { status: 204, headers: { "Cache-Control": "no-store" } });return Response.json({ task }, { headers: { "Cache-Control": "no-store" } });diff --git a/src/components/workers-admin.tsx b/src/components/workers-admin.tsxindex 898dfc9d..576f6fcc 100644--- a/src/components/workers-admin.tsx+++ b/src/components/workers-admin.tsx@@ -35,6 +35,8 @@ interface WorkerView {pausedLocal: boolean;drain: boolean;autoResume: boolean | null;+ /** Its RAM guard (a server from before sends none). */+ ramGuard?: boolean;hours: Hours | null;allow: Record<string, { delayMs: number }>;/** 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). */@@ -420,6 +422,23 @@ function WorkerCard({ w, lanes, onToken }: { w: WorkerView; lanes: Lane[]; onTok</span></span></label>+ {w.ramGuard !== undefined && (+ <label className="flex items-start gap-2 text-[13px]">+ <input+ type="checkbox"+ className="mt-0.5 size-4 accent-[var(--primary)]"+ checked={w.ramGuard}+ disabled={patch.isPending}+ onChange={(e) => patch.mutate({ ramGuard: e.target.checked })}+ />+ <span>+ RAM guard+ <span className="block text-[12px] text-muted-foreground">+ For a PC someone also works on. While other programs use a lot of its memory, this worker lets go of its own memory before each job and gives jobs that need extra memory to another worker when one is free. It keeps taking work, so nobody waits.+ </span>+ </span>+ </label>+ )}{w.pickOrder !== undefined && (<label className="flex items-start gap-2 text-[13px]"><inputdiff --git a/src/lib/computer-runner.ts b/src/lib/computer-runner.tsindex 48b13935..64b2b0dc 100644--- a/src/lib/computer-runner.ts+++ b/src/lib/computer-runner.ts@@ -792,7 +792,7 @@ export class ComputerRunner {/*** Ask for a job and run it (one at a time). True when there was one. Only while ComfyUI here answers to this site: a* computer whose ComfyUI is closed, or runs without Fuobe's setting, keeps its place but takes nothing. `noStream`: a- * worker whose PC's memory is in use (its RAM guard) asks for no job that streams its weights from RAM.+ * worker whose PC's memory is in use (its RAM guard) prefers no job that streams its weights from RAM.*/async claimAndRun(o: { onlyHeld?: boolean; noStream?: boolean } = {}): Promise<boolean> {if (!this.alive || this.busy || this.o.access) return false;diff --git a/src/lib/relay.ts b/src/lib/relay.tsindex c0678da8..397abdfb 100644--- a/src/lib/relay.ts+++ b/src/lib/relay.ts@@ -270,6 +270,12 @@ export interface WorkerAnswer {drain: boolean;/** The automatic resume after a busy GPU, as the owner set it; null: the worker's own setting. */autoResume: boolean | null;+ /**+ * The owner's RAM guard switch (off by default; a studio from before sends none: off). On, with other programs above+ * its worker.json's line of the PC's memory, it prefers jobs that fit whole on its card and its ComfyUI lets go of its+ * memory before each job and when idle.+ */+ ramGuard?: boolean;insideHours: boolean;/** When its hours start or end next. */nextChangeAt: number | null;@@ -314,7 +320,7 @@ export interface WorkerBeat {why: string | null;/*** Its own pause switch: by hand ("here", "here-until:<ms>", "here-now"), by itself ("gpu-busy:<process>",- * "ram-busy:<process>": its RAM guard, other programs use the PC's memory; its job in hand goes on, "comfy-crashes", "port-busy", "models-not-ready": a model folder isn't there yet, "self-check": its face detector's+ * "comfy-crashes", "port-busy", "models-not-ready": a model folder isn't there yet, "self-check": its face detector's* check failed twice). Not paused, `why` may say that it waits for local ComfyUI work to make room* ("waiting-for-yield", "waiting-for-yield:no-answer").*/diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex b47f3a10..ba53520c 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -223,8 +223,6 @@ export function workerState(w: WorkerRow, now = Date.now()): { state: WorkerStatconst why = w.local_why ?? "";if (w.paused_local) {if (why.startsWith("gpu-busy")) return { state: "gpu-busy", words: `Your GPU is busy${why.includes(":") ? ` (${why.split(":").slice(1).join(":")})` : ""}` };- // Its RAM guard: other programs use the PC's memory. The same kind of pause as a busy GPU: it resumes by itself.- if (why.startsWith("ram-busy")) return { state: "gpu-busy", words: `This PC's memory is in use${why.includes(":") ? ` (${why.split(":").slice(1).join(":")})` : ""}` };if (why === "comfy-crashes") return { state: "comfy-down", words: "ComfyUI keeps stopping" };if (why === "port-busy") return { state: "comfy-down", words: "Its ComfyUI port is taken by another program" };if (why === "self-check") return { state: "comfy-down", words: "Its face check didn't pass after a restart: it checks again within 5 minutes" };@@ -572,6 +570,8 @@ export function workerBeat(w: WorkerRow, b: WorkerBeat, now = Date.now()): BeatApauseNow: stopNow,drain: !!fresh.drain,autoResume: fresh.auto_resume === null || fresh.auto_resume === undefined ? null : !!fresh.auto_resume,+ // The owner's RAM guard switch for this worker (its numbers stay in its worker.json).+ ramGuard: !!fresh.ram_guard,insideHours: h.inside,nextChangeAt: h.nextChangeAt,lanes: Object.keys(allowOf(fresh)),@@ -844,24 +844,53 @@ export function workerClaim(w: WorkerRow, running: string[], now = Date.now(), sif (mine) return claimed(mine, fresh, device, now);if (held.length) return null;if (!eligible(fresh, now)) {- if (slot === "gpu") noteAsked(fresh, "blocked", `Asked for work: not taking work (${blockedWhy(fresh, now)})`, now);+ if (slot === "gpu") noteAsked(fresh, "blocked", `Asked for work: not taking work (${blockedWhy(fresh, now)})`, now, noStream ? { noStream: true } : {});return null;}// First pick: its GPU leaves a job for a free worker with a higher pick order that would take it next, for a short// grace (firstPicks), and takes its own next best.const left = slot === "gpu" ? firstPicks(fresh, now) : new Map<string, string>();- // Its PC's memory is in use (the worker's RAM guard): this claim streams nothing from its RAM, so it takes only a job- // whose weights fit whole on its card (and a model variant that does), and leaves the rest for another worker.+ const leave = new Set(left.keys());+ // Its PC's memory is in use (the worker's RAM guard, `noStream`): a preference, never a wait. Its best job as+ // always; when that one would stream its weights from this worker's RAM, the jobs that would stream here and that+ // another worker takes next (streamTakers) are left for it, and it takes its best of the rest. A streamed job no other+ // worker could take now is still its own (marked streamed, so the fallback after running out of memory applies).const asking = noStream ? withoutStreaming(fresh) : fresh;- const { task: t, looked } = pick(asking, now, slot, new Set(left.keys()));+ const wholeHere = (x: TaskRow) => fitsSlot(x, asking, now, slot);+ let { task: t, looked } = pick(fresh, now, slot, leave);+ if (noStream && t && !wholeHere(t)) {+ const taken = streamTakers(fresh, now, leave);+ if (taken.has(t.id)) t = pick(fresh, now, slot, leave, (x) => wholeHere(x) || !taken.has(x.id)).task;+ }+ const streamed = noStream && !!t && !wholeHere(t);const many = `${looked}${looked >= LOOK_AT ? "+" : ""}`;const none = left.size ? `Asked for work: ${many} waiting, ${left.size === 1 ? "1 left" : `${left.size} left`} for a worker that picks first` : `Asked for work: ${many} waiting, none it can run now`;- const memory = noStream ? " (its PC's memory is in use: only jobs that fit whole on its card)" : "";+ const memory = !noStream ? "" : streamed ? " (its PC's memory is in use: no other worker could take this job now)" : " (its PC's memory is in use: it prefers jobs that fit whole on its card)";if (slot === "gpu") noteAsked(fresh, t ? "found" : "nothing", `${t ? `Asked for work: took 1 of ${many} waiting` : looked ? none : "Asked for work: nothing waiting"}${memory}`, now, { waiting: looked, ...(left.size && { leftFor: [...new Set(left.values())] }), ...(noStream && { noStream: true }) });- return t ? claimed(t, asking, device, now) : null;+ // A job that fits whole on its card is taken as such (a model variant too); one it streams, with its RAM counted.+ return t ? claimed(t, noStream && !streamed ? asking : fresh, device, now) : null;}).immediate();}+/**+ * The jobs other workers take next, now (a claim with `noStream`): each other pool worker that is free now (freeNow, as+ * for first pick: may take work, nothing holds it back, its GPU's slot empty), with the job its own claim would take+ * next (pick: its pool, lanes and delays, mode, files and memory, the retry rule and its hours), each job counted once.+ * A worker whose own last claim asked for no streaming (its RAM guard too) counts only with what fits whole on its card,+ * so two such workers never leave a job to each other. A worker busy with a job can't take one now, as for first pick.+ */+function streamTakers(w: WorkerRow, now: number, leave: ReadonlySet<string>): Set<string> {+ const taken = new Set(leave);+ const others = db().prepare("SELECT * FROM relay_workers WHERE kind = 'pool' AND revoked_at IS NULL AND id != ? AND pool = ? ORDER BY pick_order DESC, id").all(w.id, w.pool) as WorkerRow[];+ for (const x of others) {+ if (!freeNow(x, now)) continue;+ const t = pick(x.asked_no_stream ? withoutStreaming(x) : x, now, "gpu", taken).task;+ if (t) taken.add(t.id);+ }+ for (const id of leave) taken.delete(id);+ return taken;+}+/*** The worker as one claim sees it when its PC's memory is in use (its RAM guard, the claim's `noStream`): no RAM to* stream weights from, so the memory rule (memoryFit) passes only what fits whole on its card. Nothing is saved.@@ -888,7 +917,7 @@ function blockedWhy(w: WorkerRow, now: number): string {*/function noteAsked(w: WorkerRow, answer: "found" | "nothing" | "blocked", words: string, now: number, detail: Record<string, unknown> = {}): void {try {- db().prepare("UPDATE relay_workers SET asked_at = ?, asked_words = ? WHERE id = ?").run(now, words, w.id);+ db().prepare("UPDATE relay_workers SET asked_at = ?, asked_words = ?, asked_no_stream = ? WHERE id = ?").run(now, words, detail.noStream === true ? 1 : 0, w.id);const last = lastOfKind(w.id, "looking");if (last && last.event === answer && (answer !== "blocked" || last.words === words)) return;logWorkerEvent({ kind: "looking", event: answer, workerId: w.id, words, detail }, now);@@ -1100,16 +1129,17 @@ function beforeWindowEnds(t: TaskRow, w: WorkerRow, now: number): boolean {* never makes a person wait: while any person's run waits that this worker can take, it takes the best of them. Only* among the owner's own jobs may one in the lane it has loaded go ahead of the best one, while the best one has waited* less than the pick allowance (the install's setting, capped by this worker's switch_after_ms; 0: strict order).- * `leave`: the tasks it leaves for a worker that picks first (firstPicks).+ * `leave`: the tasks it leaves for a worker that picks first (firstPicks); `also`: one more test a task must pass (a+ * claim with `noStream`: workerClaim).*/-function pick(w: WorkerRow, now: number, slot: WorkerSlot = "gpu", leave?: ReadonlySet<string>): { task: TaskRow | null; looked: number } {+function pick(w: WorkerRow, now: number, slot: WorkerSlot = "gpu", leave?: ReadonlySet<string>, also?: (t: TaskRow) => boolean): { task: TaskRow | null; looked: number } {const settings = queueSettings(now);// The owner's controls: this worker's mode, and the runs and people sent first or held.const c = controlsOf(w, now);// Each slot looks only at its own tasks.const rows = lineRows("*", `pools IS NOT NULL AND state = 'waiting' AND stop = 0 AND INSTR(',' || pools || ',', ?) > 0 ${slotWhere(w, slot)}`, [`,${w.pool},`], c, LOOK_AT);const looked = rows.length;- const ok = controlledOrder(rows, settings.fairShare, c, w.id).filter((t) => !leave?.has(t.id) && fitsSlot(t, w, now, slot) && retryOk(t, w, now) && beforeWindowEnds(t, w, now));+ const ok = controlledOrder(rows, settings.fairShare, c, w.id).filter((t) => !leave?.has(t.id) && fitsSlot(t, w, now, slot) && retryOk(t, w, now) && beforeWindowEnds(t, w, now) && (!also || also(t)));if (!ok.length) return { task: null, looked };const best = ok[0];const allowance = Math.min(w.switch_after_ms, settings.pickAllowanceMs);@@ -2016,6 +2046,11 @@ export interface WorkerView {localWhy: string | null;drain: boolean;autoResume: boolean | null;+ /**+ * Its RAM guard (off by default): with other programs above its line of the PC's memory (its worker.json's numbers),+ * it prefers jobs that fit whole on its card and its ComfyUI lets go of its memory before each job and when idle.+ */+ ramGuard: boolean;hours: Hours | null;allow: Record<string, Allow>;claimAfterMs: number;@@ -2268,6 +2303,7 @@ export function workerView(w: WorkerRow, now = Date.now(), typical: (lane: strinlocalWhy: w.local_why,drain: !!w.drain,autoResume: w.auto_resume === null || w.auto_resume === undefined ? null : !!w.auto_resume,+ ramGuard: !!w.ram_guard,hours: hoursOf(w),allow: allowOf(w),claimAfterMs: w.claim_after_ms,@@ -2327,6 +2363,8 @@ export interface WorkerPatch {drain?: boolean;/** true or false sets the automatic resume for this worker; null leaves it to the worker's worker.json. */autoResume?: boolean | null;+ /** Its RAM guard on or off (WorkerView.ramGuard). */+ ramGuard?: boolean;hours?: unknown;allow?: unknown;claimAfterMs?: number;@@ -2382,6 +2420,10 @@ export function patchWorker(id: string, p: WorkerPatch, now = Date.now(), by = "if (p.autoResume !== null && typeof p.autoResume !== "boolean") throw new Error("The automatic resume is on, off or the PC's own setting");set.auto_resume = p.autoResume === null ? null : p.autoResume ? 1 : 0;}+ if (p.ramGuard !== undefined) {+ if (typeof p.ramGuard !== "boolean") throw new Error("The RAM guard is on or off");+ set.ram_guard = p.ramGuard ? 1 : 0;+ }if (p.hours !== undefined) {if (p.hours !== null && !parseHours(p.hours)) throw new Error("Hours need a time zone and windows like 01:00–09:00");set.hours_json = p.hours === null ? null : JSON.stringify(parseHours(p.hours));@@ -2419,7 +2461,7 @@ export function patchWorker(id: string, p: WorkerPatch, now = Date.now(), by = "if (p.paused === false) actions.push(["resume", "Resumed on the website"]);if (p.drain === true) actions.push(["drain", "Set to finish its job, then pause"]);else if (p.drain === false) actions.push(["undrain", "No longer pausing after its job"]);- const edited = (["autoResume", "hours", "allow", "claimAfterMs", "switchAfterMs", "pickOrder"] as const).filter((k) => p[k] !== undefined);+ const edited = (["autoResume", "ramGuard", "hours", "allow", "claimAfterMs", "switchAfterMs", "pickOrder"] as const).filter((k) => p[k] !== undefined);if (edited.length) actions.push(["edit", `Settings changed: ${edited.join(", ")}`, { keys: edited }]);if (p.clearNoStream !== undefined) {const cleared = p.clearNoStream === true ? Object.keys(noStreamOf(w)) : p.clearNoStream.filter((k) => noStreamOf(w)[k] !== undefined);diff --git a/src/server/computer/workers.ts b/src/server/computer/workers.tsindex b3fb107f..9a3c14df 100644--- a/src/server/computer/workers.ts+++ b/src/server/computer/workers.ts@@ -63,6 +63,8 @@ export interface WorkerRow {pick_order?: number;/** The workflows it no longer takes by streaming from RAM, as JSON: workflow id → when (pool.ts noStreamOf). */no_stream_json?: string | null;+ /** The owner's RAM guard switch for it: 1 on, 0 off (pool.ts; its numbers are in its worker.json). */+ ram_guard?: number;state: string;seen_at: number | null;/** A pool worker's next token (its SHA-256), offered in a beat answer and not used yet; its expiry; when it was made. */@@ -85,6 +87,8 @@ export interface WorkerRow {/** Its last claim for its GPU's slot, and the answer in words (pool.ts workerClaim). */asked_at?: number | null;asked_words?: string | null;+ /** 1: that claim asked for no streaming from RAM (its RAM guard; pool.ts streamTakers). */+ asked_no_stream?: number;/** The owner's mode for this worker (queue-controls.ts ModeSetting), winning over its pool's while it lasts. NULL: none. */mode_json?: string | null;/** Local work on its PC (a queue of the owner's own), as its last beat said (src/lib/relay.ts LocalWork). NULL: none. */diff --git a/src/server/db.ts b/src/server/db.tsindex 83b92bf4..2ce2bf6c 100644--- a/src/server/db.ts+++ b/src/server/db.ts@@ -1154,6 +1154,10 @@ const RELAY_COLUMNS: [string, string, string][] = [// The workflows a worker no longer takes by streaming its weights from RAM (a job of one ran out of memory that way):// workflow id → when, as JSON (pool.ts noStreamOf). The owner clears it in Settings → Workers.["relay_workers", "no_stream_json", "TEXT"],+ // The owner's RAM guard switch for a worker (pool.ts; off by default), and whether its last GPU claim asked for no+ // streaming from RAM (its RAM guard: pool.ts streamTakers).+ ["relay_workers", "ram_guard", "INTEGER NOT NULL DEFAULT 0"],+ ["relay_workers", "asked_no_stream", "INTEGER NOT NULL DEFAULT 0"],];declare global {diff --git a/tests/stream-needs.test.ts b/tests/stream-needs.test.tsindex 00123ba0..62dbe674 100644--- a/tests/stream-needs.test.ts+++ b/tests/stream-needs.test.ts@@ -348,18 +348,69 @@ describe("which workers qualify on memory (the claim)", () => {expect(claim(worker("ampere-low-ram", KREA, { vramBytes: 10 * GB, ramBytes: 16 * GB, gpuGen: "8.6" }))).toBeNull();});- it("a claim that asks for no streaming (the worker's RAM guard): only a job whose weights fit whole on its card, said in its claim's words", () => {+ // A claim with noStream (the worker's RAM guard): a preference, never a wait.+ const noStream = (w: W) => pool.workerClaim(row(w), [], clock, "gpu", { noStream: true });+ const streamedOf = (id: string) => JSON.parse(tasks.taskById(id)!.extra_json ?? "{}").streamed;++ it("no streaming asked, and no other worker could take the job now: it takes it streamed all the same, said in its claim's words", () => {const id = job(FLEX);const small = worker("flex-shared-pc", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });- expect(pool.workerClaim(row(small), [], clock, "gpu", { noStream: true })).toBeNull();- expect(row(small).asked_words).toMatch(/its PC's memory is in use: only jobs that fit whole on its card/);- expect(tasks.taskById(id)!.state).toBe("waiting");- // Its facts are as they were: the next claim without it streams as before.+ expect(noStream(small)?.id).toBe(id);+ // Marked streamed: the fallback after running out of memory applies.+ expect(streamedOf(id)).toBe(true);+ expect(row(small).asked_words).toMatch(/its PC's memory is in use: no other worker could take this job now/);+ // Its facts are as they were.expect(JSON.parse(row(small).facts_json ?? "{}").ramBytes).toBe(31.9 * GB);- expect(pool.workerClaim(row(small), [], clock)?.id).toBe(id);- expect(JSON.parse(tasks.taskById(id)!.extra_json ?? "{}").streamed).toBe(true);- // A card that holds it whole takes it whatever the claim says.+ // A card that holds it whole takes it whatever the claim says, not streamed.const whole = job(FLEX);- expect(pool.workerClaim(row(worker("flex-whole", FLEX, { vramBytes: 32 * GB, ramBytes: 16 * GB })), [], clock, "gpu", { noStream: true })?.id).toBe(whole);+ expect(noStream(worker("flex-whole", FLEX, { vramBytes: 32 * GB, ramBytes: 16 * GB }))?.id).toBe(whole);+ expect(streamedOf(whole)).toBeUndefined();+ });++ it("no streaming asked, and another free worker takes that job next: it leaves the job for it", () => {+ const id = job(FLEX);+ const small = worker("flex-shared-pc", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ const big = worker("flex-whole", FLEX, { vramBytes: 32 * GB, ramBytes: 16 * GB });+ expect(noStream(small)).toBeNull();+ expect(row(small).asked_words).toMatch(/its PC's memory is in use: it prefers jobs that fit whole on its card/);+ expect(tasks.taskById(id)!.state).toBe("waiting");+ expect(claim(big)?.id).toBe(id);+ expect(streamedOf(id)).toBeUndefined();+ // Another worker that streams it too counts: it is free, and the job is its next.+ const next = job(FLEX);+ const other = worker("flex-other", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ expect(noStream(small)).toBeNull();+ expect(claim(other)?.id).toBe(next);+ });++ it("a worker that isn't free now doesn't count: paused, or busy with a job (as for first pick)", () => {+ const first = job(FLEX);+ const small = worker("flex-shared-pc", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ const big = worker("flex-whole", FLEX, { vramBytes: 32 * GB, ramBytes: 16 * GB });+ pool.patchWorker(big.id, { paused: true }, clock);+ expect(noStream(small)?.id).toBe(first);+ // Busy: its GPU's slot holds a job.+ pool.patchWorker(big.id, { paused: false }, clock);+ const busy = job(FLEX);+ expect(claim(big)?.id).toBe(busy);+ const third = job(FLEX);+ const small2 = worker("flex-shared-pc-2", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ expect(noStream(small2)?.id).toBe(third);+ expect(streamedOf(third)).toBe(true);+ });++ it("two workers that both ask for no streaming never leave a job to each other", () => {+ const id = job(FLEX);+ const a = worker("flex-a", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ const b = worker("flex-b", FLEX, { vramBytes: 10 * GB, ramBytes: 31.9 * GB });+ // b's claim: a's last claim asked for nothing, so a could stream it: b leaves it.+ expect(noStream(b)).toBeNull();+ expect(row(b).asked_no_stream).toBe(1);+ // a's claim: b asks for no streaming too, so b counts only with what fits whole on its card: a takes it.+ expect(noStream(a)?.id).toBe(id);+ expect(streamedOf(id)).toBe(true);+ // A claim without it clears the mark.+ expect(claim(b)).toBeNull();+ expect(row(b).asked_no_stream).toBe(0);});});