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: sending a job again never moves its attempt's deadline
Adarshf7f55e313953
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex 19175b40..e9dfd738 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -61,7 +61,10 @@ export const classRank = (t: Pick<TaskRow, "class" | "account">): number => (t.cconst LINE_ORDER = `${CLASS_RANK}, rank_at, created_at, id`;/** The columns the line's counts read (never a task's graph or files). */const LINE_COLS = "id, principal, pools, only_worker, stop, lane, needs_json, created_at, rank_at, est_ms, tried_json, worker_id, claimed_at, account, class";-/** A task a worker took that is still sending its files to its ComfyUI this long after the claim goes back in line. */+/**+ * A task a worker took that is still sending its files to its ComfyUI this long after the claim (or after its ComfyUI lost+ * it and it began sending them again on the same claim) goes back in line.+ */export const SENDING_MS = 15 * 60_000;/** The time a worker has to send a finished job's results up. */export const SAVING_MS = 15 * 60_000;@@ -519,6 +522,7 @@ export function backInLine(t: TaskRow, o: { blame: boolean; why?: string; last?:worker_id: null,requeues,sent_at: null,+ sending_since: null,started_at: null,down_at: null,down_why: null,@@ -534,7 +538,8 @@ export function backInLine(t: TaskRow, o: { blame: boolean; why?: string; last?:/*** 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 goes back in line; a task no worker has taken+ * minutes, or that is still sending its files 15 minutes after the claim (or after it began sending them again) goes+ * back in line; a task no worker has taken* yet that is still waiting past its wait limit fails, not charged. (Once a worker took it, the wait limit is over: a* task back in line waits in its place until a worker runs it, or its attempts run out.)*/@@ -555,7 +560,9 @@ function sweepLine(d: ReturnType<typeof db>, now: number): void {for (const t of held) {const silent = !t.w_seen || now - t.w_seen > RELAY_TIMES.poolSilentMs || !!t.w_revoked;const down = !!t.down_at && now - t.down_at > RELAY_TIMES.poolComfyDownMs;- const stuck = t.state === "sending" && !!t.claimed_at && now - t.claimed_at > SENDING_MS;+ // Sending since its claim, or since its ComfyUI lost it and it began sending again on the same claim.+ const sendingSince = t.sending_since ?? t.claimed_at;+ const stuck = t.state === "sending" && !!sendingSince && now - sendingSince > SENDING_MS;if (silent || down || stuck) {backInLine(t, { blame: true, why: silent ? "The GPU running this stopped answering, three times. Press Retry." : down ? "ComfyUI kept stopping on the GPUs. Press Retry." : "The GPUs couldn't start this run. Press Retry.", ...(silent && !t.w_revoked && { lostAt: now }) });}diff --git a/src/server/computer/tasks.ts b/src/server/computer/tasks.tsindex 58830caa..7a7eadd7 100644--- a/src/server/computer/tasks.ts+++ b/src/server/computer/tasks.ts@@ -113,6 +113,8 @@ export interface TaskRow {created_at: number;updated_at: number;claimed_at: number | null;+ /** A worker's task sending its files again on the same claim (its ComfyUI lost it): since when. NULL: since its claim. */+ sending_since: number | null;sent_at: number | null;started_at: number | null;finished_at: number | null;@@ -531,8 +533,9 @@ export function takeTask(t: TaskRow, device: string, now: number, fields: Partiaconst resume = t.state === "waiting" || t.device !== device ? undefined : (t.state as ClaimedTask["resume"]);const fresh = t.state === "waiting" || t.device !== device;// A worker's task taken afresh starts its own count of sends: its ComfyUI may lose it once and get it again on this- // claim (the report "gone"). Across claims, only its requeues count (pool.ts MAX_ATTEMPTS).- setTask(t.id, { device, lease_hash: hash(lease), state: t.state === "waiting" ? "sending" : t.state, claimed_at: now, device_seen_at: now, ...(fresh && t.pools && { attempts: 0 }), ...fields });+ // claim (the report "gone"). Across claims, only its requeues count (pool.ts MAX_ATTEMPTS). Its sending clock starts at+ // the claim.+ setTask(t.id, { device, lease_hash: hash(lease), state: t.state === "waiting" ? "sending" : t.state, claimed_at: now, device_seen_at: now, ...(fresh && t.pools && { attempts: 0, sending_since: null }), ...fields });if (fresh) rdb().prepare("UPDATE relay_inputs SET reads = 0 WHERE task_id = ?").run(t.id);const inputs: TaskInput[] = inputsOf(t.id).map((i) => ({ n: i.n!, name: i.name, size: i.size, sha256: i.sha256, contentType: i.content_type }));return {@@ -654,8 +657,9 @@ function reportOnce(t: TaskRow, e: ReportEvent, plan: (entries: HistoryEntryLikecase "sent": {const promptId = typeof e.promptId === "string" && UUID.test(e.promptId) ? e.promptId : typeof e.promptId === "string" && /^[\w-]{1,64}$/.test(e.promptId) ? e.promptId : null;if (!promptId) throw new RelayError(400, "Bad prompt id");- // Results a worker kept from an earlier try go up instead: no new attempt.- setTask(t.id, { ...seen, state: "queued", prompt_id: promptId, sent_at: now, attempts: t.attempts + (t.pools && e.kept ? 0 : 1) });+ // Results a worker kept from an earlier try go up instead of a new render. Each send counts toward this claim's+ // sends all the same, so a ComfyUI that "loses" a job twice on one claim (a resend after each) sends it back in line.+ setTask(t.id, { ...seen, state: "queued", prompt_id: promptId, sent_at: now, attempts: t.attempts + 1 });return { ok: true };}case "refused":@@ -715,8 +719,9 @@ function reportOnce(t: TaskRow, e: ReportEvent, plan: (entries: HistoryEntryLikereturn { ok: true };case "gone":if (t.attempts < 2 && t.state !== "sending") {- // A worker's task sends its files again: its sending clock (pool.ts SENDING_MS) starts again too.- setTask(t.id, { ...seen, state: "sending", note: "resent", started_at: null, ...(t.pools && { claimed_at: now }) });+ // A worker's task sends its files again: its sending clock (pool.ts SENDING_MS) starts again from now. The+ // attempt's own deadline stays where its claim put it (pool.ts attemptDeadline).+ setTask(t.id, { ...seen, state: "sending", note: "resent", started_at: null, ...(t.pools && { sending_since: now }) });rdb().prepare("UPDATE relay_inputs SET reads = 0 WHERE task_id = ?").run(t.id);return { ok: true };}diff --git a/src/server/db.ts b/src/server/db.tsindex 2451ffb5..dbb9d74c 100644--- a/src/server/db.ts+++ b/src/server/db.ts@@ -1007,6 +1007,8 @@ const RELAY_COLUMNS: [string, string, string][] = [["relay_tasks", "worker_id", "TEXT"],// The class a task waits in: "paid", "free" or "owner" (pool.ts LINE_ORDER).["relay_tasks", "class", "TEXT"],+ // Since when a worker's task has been sending its files again on the same claim (NULL: since its claim).+ ["relay_tasks", "sending_since", "INTEGER"],// A pool worker's next token (workers.ts offerNextToken) and where its token was used from (hashed networks).["relay_workers", "next_token_hash", "TEXT"],["relay_workers", "next_expires_at", "INTEGER"],diff --git a/tests/workers-pool.test.ts b/tests/workers-pool.test.tsindex d14cf0c0..d1c3312d 100644--- a/tests/workers-pool.test.ts+++ b/tests/workers-pool.test.ts@@ -499,6 +499,81 @@ describe("a worker whose model folder isn't there yet (a drive still locked afte});});+describe("a job its worker's ComfyUI keeps losing", () => {+ const unused = () => ({ error: "unused" });+ const say = (id: string, e: Parameters<typeof tasks.report>[1]) => tasks.report(state(id), e, unused, clock);++ it("sending it again never moves the attempt's deadline, and a second loss on one claim puts it back in line", () => {+ const id = task({ account: "acct-lost" });+ const w = worker("loses-jobs");+ const c = claim(w)!;+ const claimedAt = state(id).claimed_at!;+ const deadline = pool.attemptDeadline(state(id))!.at;+ expect(deadline).toBe(claimedAt + pool.attemptLimitMs(LANE_A));+ // Results kept from before go up (no new render), then its ComfyUI "loses" the job: it sends its files again.+ say(id, { event: "sent", promptId: c.promptId, kept: true });+ clock += MIN;+ say(id, { event: "gone" });+ expect(state(id).state).toBe("sending");+ expect(state(id).claimed_at).toBe(claimedAt);+ expect(pool.attemptDeadline(state(id))!.at).toBe(deadline);+ // The second loss on this claim: back in line with its place kept, counted as an attempt.+ say(id, { event: "sent", promptId: c.promptId, kept: true });+ clock += MIN;+ say(id, { event: "gone" });+ expect(state(id).state).toBe("waiting");+ expect(state(id).requeues).toBe(1);+ });++ it("a worker that sends kept results and then says it lost them, again and again, can't hold a person's run: it ends", () => {+ const id = task({ account: "acct-loop" });+ const w = worker("loops");+ const firstDeadline = (() => {+ claim(w);+ return pool.attemptDeadline(state(id))!.at;+ })();+ for (let i = 0; i < 200 && !["failed", "done", "canceled"].includes(state(id).state); i++) {+ beat(w);+ if (state(id).state === "waiting") claim(w);+ const now = state(id);+ if (now.state === "sending") say(id, { event: "sent", promptId: now.prompt_id ?? "p", kept: true });+ else if (now.state === "queued") say(id, { event: "gone" });+ clock += MIN;+ }+ const end = state(id);+ expect(end.state).toBe("failed");+ expect(end.requeues).toBe(3);+ // Long before what its first attempt's deadline would have allowed.+ expect(clock).toBeLessThan(firstDeadline);+ });++ it("a job sending its files again for 15 minutes on the same claim goes back in line", () => {+ const id = task({ account: "acct-resend" });+ const w = worker("slow-resend");+ const c = claim(w)!;+ say(id, { event: "sent", promptId: c.promptId });+ // The worker beats every minute meanwhile (a silent one would lose the job for that instead).+ const minutes = (n: number) => {+ for (let i = 0; i < n; i++) {+ clock += MIN;+ beat(w, {}, [id]);+ }+ };+ // Lost after 10 minutes: it sends again from then, so 6 more minutes (16 since the claim) is not yet too long.+ minutes(10);+ say(id, { event: "gone" });+ minutes(6);+ pool.sweepPool(clock);+ expect(state(id).state).toBe("sending");+ expect(state(id).requeues).toBe(0);+ // 16 minutes of sending again: back in line, counted as an attempt.+ minutes(10);+ pool.sweepPool(clock);+ expect(state(id).state).toBe("waiting");+ expect(state(id).requeues).toBe(1);+ });+});+describe("a worker's list of model files", () => {const inventoryRoute = () => import("@/app/api/gpu/computer/inventory/route");const beatWith = (w: W, inventoryHash: string | null) =>@@ -826,7 +901,7 @@ describe("a worker's own reports: giving a job back, its execution time, the inpexpect((await fourth.say({ event: "give-back", why: "stalled" })).body.state).toBe("waiting");});- it("results kept from an earlier try go up as no new attempt, keep their own time, and add no time to the lane", async () => {+ it("results kept from an earlier try go up without running again, keep their own time, and add no time to the lane", async () => {clock = Date.now();const entry = { status: { status_str: "success", completed: true }, outputs: {} };// Made 10 minutes ago; it ran, its worker stopped before the studio heard, and it went back in line.@@ -837,10 +912,12 @@ describe("a worker's own reports: giving a job back, its execution time, the inpexpect(state(id).attempts).toBe(1);pool.backInLine(state(id), { blame: true });const again = await routed(w, id);- // A new claim starts its own count of sends, and results kept from an earlier try add none.+ // A new claim starts its own count of sends. Results kept from an earlier try count as one send of this claim (a+ // ComfyUI that then "loses" them twice sends the job back in line), and are not another try in line.expect(state(id).attempts).toBe(0);expect((await again.say({ event: "sent", promptId: again.t.promptId, kept: true })).status).toBe(200);- expect(state(id).attempts).toBe(0);+ expect(state(id).attempts).toBe(1);+ expect(state(id).requeues).toBe(1);const done = await again.say({ event: "finished", entry, execMs: 4 * MIN, device: "Test GPU <b>", kept: true });expect(done.status).toBe(200);expect(state(id).state).not.toBe("queued");