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.

Revert "Admin: pause a running run and put it back in line"

Adarsh6c3632a36a6e
diff --git a/docs/admin-api.md b/docs/admin-api.md
index f7a1f88c..d0c56791 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -49,7 +49,7 @@ Keep the token out of URLs, logs and shared files. Send it only in the `Authoriz
| `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, 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/queue/pause`, `POST /api/admin/generations/{id}/again`: who the GPUs serve first, runs and people sent first or held, pausing or cancelling a run ([gpu-workers.md](gpu-workers.md#who-goes-first)), and running a person's run again for them |
+| `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 |
| `audit:read` | `GET /api/admin/audit` |
@@ -122,7 +122,6 @@ 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 |
-| `POST /api/admin/queue/pause` | `{ generationId }` | `{ generationId, override, replaced, sentBack }`: the run is held (a run hold override, as `POST /api/admin/queue/overrides` makes), and each of its jobs that a worker's GPU runs now goes back in line: no attempt is counted, it keeps its place, and the worker takes it off its ComfyUI at its next beat. `sentBack` is how many jobs went back. A run that waits in line is only held. To resume it, end the hold (`DELETE /api/admin/queue/overrides/{id}`): it runs again from the start. 404 for no such run; 409 for a run that ended, one that isn't in this install's line, or one that is saving its results now |
| `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` |
@@ -142,7 +141,7 @@ A log row is `{ id, at, actor: "owner" | "token" | "system", token: { id, name }
`token.name` is the name the token had at the time. Actions: `account.disable`, `account.enable`, `account.signout`, `account.password`, `account.email`,
`account.delete`, `run.delete`, `outputs.hide`, `outputs.unhide`, `outputs.remove`, `worker.add`, `worker.change`,
`worker.rotate`, `worker.revoke`, `worker.revoke_all` (Sign everyone out with every API token), `queue.settings` (with
-the values before and after), `queue.mode`, `queue.override`, `queue.override.end`, `queue.cancel`, `queue.pause` (with the `override` id and how many jobs were `sentBack`), `run.again` (the run as its target, with the account, the new run's `ids`, `place`, the `changed` settings and whether a `notice` was given), `queue.mode.end`
+the values before and after), `queue.mode`, `queue.override`, `queue.override.end`, `queue.cancel`, `run.again` (the run as its target, with the account, the new run's `ids`, `place`, the `changed` settings and whether a `notice` was given), `queue.mode.end`
(actor `system` when a mode, a hold or a boost ended by itself), `site.uploads` (the upload switches, with the values before and after), `site.runs` (what people read when a run fails, with the values before and after), `token.create`, `token.revoke`,
`token.revoke_all`, `settings.comfy_where` (where ComfyUI runs, with the values before and after), `settings.run_failure_detail` (Settings → Failed runs, changed in the owner's browser, with the values before and after); a token's reads
`accounts.list`, `accounts.csv`, `account.read`, `runs.list`, `reports.list`, `audit.read` (one row per token and action
diff --git a/src/app/api/admin/queue/pause/route.ts b/src/app/api/admin/queue/pause/route.ts
deleted file mode 100644
index e231bc26..00000000
--- a/src/app/api/admin/queue/pause/route.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { adminAccess, audit } from "@/server/admin-tokens";
-import { pauseRun } from "@/server/computer/pool";
-import { overrideView } from "@/server/computer/queue-controls";
-
-const NO_STORE = { "Cache-Control": "no-store" };
-
-/**
- * Pause a run (owner only, or an admin token with queue:control): `{ generationId }`. It is held, and a job of it that a
- * worker's GPU runs now goes back in line with no attempt counted and its place kept; the worker takes it off its
- * ComfyUI at its next beat (src/server/computer/pool.ts pauseRun). Ending the hold (DELETE
- * /api/admin/queue/overrides/{id}) resumes it: it runs again from the start. 404 for no such run; 409 for one that
- * ended, one that isn't in this site's line, or one saving its results now.
- */
-export async function POST(request: Request) {
- const access = adminAccess(request, "queue:control", "Only the studio's owner changes the queue");
- if (access instanceof Response) return access;
- const by = access.actor.kind === "token" ? access.actor.name : "owner";
- const body = (await request.json().catch(() => null)) as { generationId?: unknown } | null;
- const id = body && typeof body === "object" && typeof body.generationId === "string" && /^[\w-]{1,80}$/.test(body.generationId) ? body.generationId : null;
- const now = Date.now();
- if (!id) {
- audit(access.actor, "queue.pause", null, null, 400, now);
- return Response.json({ error: "generationId is a run's id" }, { status: 400, headers: NO_STORE });
- }
- const r = pauseRun(id, by, now);
- if ("error" in r) {
- audit(access.actor, "queue.pause", id, null, r.status, now);
- return Response.json({ error: r.error }, { status: r.status, headers: NO_STORE });
- }
- audit(access.actor, "queue.pause", id, { override: r.override.id, sentBack: r.sentBack.length, replaced: r.replaced.map((x) => x.id) }, 200, now);
- return Response.json({ generationId: id, override: overrideView(r.override), replaced: r.replaced.map(overrideView), sentBack: r.sentBack.length }, { headers: NO_STORE });
-}
diff --git a/src/server/admin-tokens.ts b/src/server/admin-tokens.ts
index 4c299b3b..53bdd710 100644
--- a/src/server/admin-tokens.ts
+++ b/src/server/admin-tokens.ts
@@ -59,7 +59,7 @@ export const SCOPE_LABELS: Record<Scope, string> = {
"workers:tokens": "Add workers and give them new tokens (a worker runs accounts' queued jobs, with their files)",
"queue:read": "See the queue and its settings",
"queue:write": "Change the queue's settings: the run ceiling, the owner's wait limit, fair share, the pick allowance and the paused budget",
- "queue:control": "Choose who the GPUs serve first: the mode (people first, people only, our work first, balanced), a run next, pinned or held, a person's runs first or held, pause or cancel a run, and run a person's run again for them",
+ "queue:control": "Choose who the GPUs serve first: the mode (people first, people only, our work first, balanced), a run next, pinned or held, a person's runs first or held, cancel a waiting run, and run a person's run again for them",
"site:read": "See the site's switches: the upload fitting steps",
"site:write": "Switch the upload fitting steps off and on: convert, offer a part, offer a crop",
"audit:read": "See the admin log",
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index d9aa62cb..51df5848 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -18,7 +18,7 @@ import { cleanFacts, dropProgress, endTask, json, logWorkerJob, noteCold, notePr
import { queueSettings, runCeilingMs } from "../queue-settings";
import { createWorker, offerNextToken, revokeWorker, rotateWorker, type WorkerRow } from "./workers";
import { modelLabel } from "./queue-live";
-import { addOverride, effectiveMode, runRows, workerModeOf, LOCAL_WORK, lineControls, liveOverrides, modeClass, modeClassSql, overrideTargets, plainLine, poolMode, sweepControls, taskControl, DEFAULT_MODE, type EffectiveMode, type LineControls, type QueueMode, type QueueOverride, type TaskControl } from "./queue-controls";
+import { effectiveMode, workerModeOf, LOCAL_WORK, lineControls, liveOverrides, modeClass, modeClassSql, overrideTargets, plainLine, poolMode, sweepControls, taskControl, DEFAULT_MODE, type EffectiveMode, type LineControls, type QueueMode, type TaskControl } from "./queue-controls";
import type { LocalWork } from "@/lib/relay";
import { cleanLogLines, lastEventOf, lastOfKind, logWorkerEvent, logWorkerEvents, setEventNames, type NewWorkerEvent, type WorkerEventKind } from "./worker-events";
@@ -406,8 +406,6 @@ export function workerBeat(w: WorkerRow, b: WorkerBeat, now = Date.now()): BeatA
promptId: s.prompt_id,
...(s.prefix && { prefix: s.prefix }),
}));
- // Runs paused on the website (pauseRun) that this worker's GPU ran: their prompts come off its ComfyUI now, once.
- stops.push(...takePausedOff(w.id));
const fresh = d.prepare("SELECT * FROM relay_workers WHERE id = ?").get(w.id) as WorkerRow;
// Stop now (the website, or the worker paused itself with --now / a busy GPU): its jobs go back in line at no cost,
// and the worker takes their prompts off its ComfyUI.
@@ -1000,66 +998,6 @@ export function backInLine(t: TaskRow, o: { blame: boolean; why?: string; whyKin
}).immediate();
}
-/** The words a run paused on the website goes back in line with (the workers' log). */
-export const PAUSED_WORDS = "paused on the website";
-
-/**
- * Pause a run (POST /api/admin/queue/pause): it is held, as a run's Hold holds it, and each of its jobs a worker's GPU
- * runs now goes back in line as People first sends the owner's jobs back: no attempt counted, no blame, its place kept.
- * The worker takes the prompt off its ComfyUI at its next beat. When the hold ends, it runs again from the start. A job
- * saving its results, and light CPU work, go on: a run with only those going can't be paused now (409). A run that
- * waits in line is only held.
- */
-export function pauseRun(
- generationId: string,
- by: string,
- now = Date.now(),
-): { override: QueueOverride; replaced: QueueOverride[]; sentBack: string[] } | { error: string; status: number } {
- const d = db();
- return d.transaction(() => {
- const run = runRows(generationId);
- if (!run) return { error: "No such run", status: 404 };
- if (run.status !== "queued" && run.status !== "running") return { error: "That run has ended", status: 409 };
- const live = d
- .prepare(
- `SELECT * FROM relay_tasks WHERE generation_id IN (${run.generations.map(() => "?").join(",")}) AND pools IS NOT NULL AND state IN ('waiting','sending','queued','running','collecting')`,
- )
- .all(...run.generations) as TaskRow[];
- const onGpu = live.filter((t) => t.worker_id && t.state !== "waiting" && t.state !== "collecting" && t.slot !== "cpu" && !t.finish_json);
- if (!onGpu.length && !live.some((t) => t.state === "waiting"))
- return { error: live.length ? "This run is saving its results now, so it can't be paused" : "Only a run in this site's line can be paused", status: 409 };
- const r = addOverride({ kind: "run", generationId, action: "hold", worker: null, until: null }, by, now);
- if ("error" in r) return r;
- const sentBack: string[] = [];
- for (const t of onGpu) {
- if (!backInLine(t, { blame: false, sentBack: PAUSED_WORDS })) continue;
- sentBack.push(t.id);
- const back = taskById(t.id);
- if (back && t.prompt_id) {
- const pausedOff = { worker: t.worker_id, promptId: t.prompt_id, ...(t.prefix && { prefix: t.prefix }), at: now };
- setTask(t.id, { extra_json: JSON.stringify({ ...json<Record<string, unknown>>(back.extra_json, {}), pausedOff }) });
- }
- }
- return { ...r, sentBack };
- }).immediate();
-}
-
-/** The prompts of paused runs (pauseRun) that worker `workerId` may still have on its ComfyUI: each handed out once. */
-function takePausedOff(workerId: string): BeatAnswer["stops"] {
- const rows = db()
- .prepare(`SELECT id, extra_json FROM relay_tasks WHERE pools IS NOT NULL AND state IN ('waiting','sending','queued','running','collecting') AND INSTR(extra_json, '"pausedOff"') > 0`)
- .all() as Pick<TaskRow, "id" | "extra_json">[];
- const stops: BeatAnswer["stops"] = [];
- for (const t of rows) {
- const { pausedOff, ...extra } = json<{ pausedOff?: { worker?: unknown; promptId?: unknown; prefix?: unknown } } & Record<string, unknown>>(t.extra_json, {});
- if (pausedOff?.worker !== workerId) continue;
- setTask(t.id, { extra_json: JSON.stringify(extra) });
- if (typeof pausedOff.promptId === "string" && pausedOff.promptId)
- stops.push({ task: t.id, promptId: pausedOff.promptId, ...(typeof pausedOff.prefix === "string" && pausedOff.prefix && { prefix: pausedOff.prefix }) });
- }
- return stops;
-}
-
/**
* The workers' clocks: a task whose worker went silent for 2 minutes (or was revoked), whose ComfyUI was down for 2
* minutes, or that is still sending its files 15 minutes after the claim (or after it began sending them again) goes
diff --git a/tests/queue-controls.test.ts b/tests/queue-controls.test.ts
index 71d3a03c..8785fa71 100644
--- a/tests/queue-controls.test.ts
+++ b/tests/queue-controls.test.ts
@@ -380,62 +380,6 @@ describe("the admin routes", () => {
expect((await post(cancelRoute, "/api/admin/queue/cancel", { generationId: a.gid }, controller)).status).toBe(409);
});
- it("pause: a running run goes back in line held, with no attempt counted and its place kept; the worker hears the stop once; ending the hold runs it again", async () => {
- const pauseRoute = await import("@/app/api/admin/queue/pause/route");
- const reader = admin.createAdminToken({ name: "reader3", scopes: ["queue:read"], expiresInDays: null }).token;
- const controller = admin.createAdminToken({ name: "controller4", scopes: ["queue:control"], expiresInDays: null }).token;
- const w = worker("w1");
- const a = job({ account: alice, agoMs: 30 * MIN });
- const b = job({ account: bob, agoMs: 1 * MIN });
- beat(w);
- expect(claim(w)?.id).toBe(a.id);
- db().prepare("UPDATE relay_tasks SET state = 'running', started_at = ? WHERE id = ?").run(Date.now(), a.id);
- const before = taskRow(a.id);
- expect((await post(pauseRoute, "/api/admin/queue/pause", { generationId: a.gid }, reader)).status).toBe(403);
- expect((await post(pauseRoute, "/api/admin/queue/pause", { generationId: "nope" }, controller)).status).toBe(404);
- expect((await post(pauseRoute, "/api/admin/queue/pause", {}, controller)).status).toBe(400);
- const r = await post(pauseRoute, "/api/admin/queue/pause", { generationId: a.gid }, controller);
- expect(r.status).toBe(200);
- const body = (await r.json()) as { generationId: string; sentBack: number; override: { id: string; action: string; generationId: string; by: string } };
- expect(body).toMatchObject({ generationId: a.gid, sentBack: 1, override: { action: "hold", generationId: a.gid, by: "controller4" } });
- const back = taskRow(a.id);
- expect(back).toMatchObject({ state: "waiting", worker_id: null, lease_hash: null, requeues: 0, rank_at: before.rank_at, stop: 0 });
- expect(liveQueue().queued.find((q) => q.task === a.id)).toMatchObject({ code: "held", override: { id: body.override.id } });
- // The worker's next beat takes the prompt off its ComfyUI, once.
- expect(beat(w).stops).toEqual([{ task: a.id, promptId: before.prompt_id }]);
- expect(beat(w).stops).toEqual([]);
- // Held: the next run goes first, and the paused one waits.
- expect(served(w)).toEqual([b.id]);
- const del = await overrideRoute.DELETE(
- new NextRequest(`http://localhost:3000/api/admin/queue/overrides/${body.override.id}`, { method: "DELETE", headers: { authorization: `Bearer ${controller}` } }),
- { params: Promise.resolve({ id: body.override.id }) } as never,
- );
- expect(del.status).toBe(200);
- expect(served(w)).toEqual([a.id]);
- expect(taskRow(a.id).requeues).toBe(0);
- db().prepare("UPDATE generations SET status = 'succeeded' WHERE id = ?").run(a.gid);
- expect((await post(pauseRoute, "/api/admin/queue/pause", { generationId: a.gid }, controller)).status).toBe(409);
- expect(db().prepare("SELECT status FROM admin_audit WHERE action = 'queue.pause' ORDER BY id").all()).toEqual([{ status: 404 }, { status: 400 }, { status: 200 }, { status: 409 }]);
- });
-
- it("pause: a run waiting in line is only held; a run not in the line can't be paused", async () => {
- const pauseRoute = await import("@/app/api/admin/queue/pause/route");
- const controller = admin.createAdminToken({ name: "controller5", scopes: ["queue:control"], expiresInDays: null }).token;
- const w = worker("w1");
- const a = job({ account: alice });
- const r = await post(pauseRoute, "/api/admin/queue/pause", { generationId: a.gid }, controller);
- expect(r.status).toBe(200);
- expect(await r.json()).toMatchObject({ sentBack: 0, override: { action: "hold" } });
- expect(served(w)).toEqual([]);
- const gid = "ctl-gen-own";
- db()
- .prepare("INSERT INTO generations (id, feature, model_id, engine, provider, op, kind, status, request_json, outputs_json, created_at, updated_at) VALUES (?, 'image', 'm', 'open', 'comfyui', 't2i', 'image', 'running', '{}', '[]', ?, ?)")
- .run(gid, Date.now(), Date.now());
- const none = await post(pauseRoute, "/api/admin/queue/pause", { generationId: gid }, controller);
- expect(none.status).toBe(409);
- expect(qc.liveOverrides().filter((o) => o.target === gid)).toEqual([]);
- });
-
it("GET /api/admin/queue shows the controls: each pool's mode, each worker's, the overrides, and why each run stands where it does", async () => {
const w = worker("w1");
job({ account: alice });