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
Worker turns: a fresh "yielding" answer is an answer
Adarshd9fd50865b43
diff --git a/bin/lib/worker/turns.mjs b/bin/lib/worker/turns.mjsindex 4c90b34a..e67ba849 100644--- a/bin/lib/worker/turns.mjs+++ b/bin/lib/worker/turns.mjs@@ -76,6 +76,8 @@ export class SiteTurns {this.interrupt = false;this.waitSince = null;this.waitingSince = null;+ /** When the helper's last fresh "yielding" for this turn was seen (null: none while it waits). */+ this.answeredAt = null;this.savedAt = 0;this.saved = this.load();}@@ -145,6 +147,7 @@ export class SiteTurns {this.neededYield = false;this.interrupt = false;this.waitingSince = null;+ this.answeredAt = null;}this.lastWantAt = t;} else if (this.active && (!may || t - this.lastWantAt >= (this.o.graceMs ?? TURNS.graceMs))) {@@ -153,6 +156,7 @@ export class SiteTurns {this.active = false;this.interrupt = false;this.waitingSince = null;+ this.answeredAt = null;this.save(t);}if (!this.active) {@@ -174,6 +178,7 @@ export class SiteTurns {}} else {this.waitingSince = null;+ this.answeredAt = null;if (yielded) this.interrupt = false;}// The helper answered after the interrupt was allowed (it is making room, or has): the interrupt has been seen.@@ -187,6 +192,9 @@ export class SiteTurns {this.waitSince = claimable > 0 ? (this.waitSince ?? t) : null;const oldestWaitS = this.waitSince === null ? 0 : Math.round((t - this.waitSince) / 1000);const y = waitForYield ? readYielded(this.o.folder) : null;+ // The helper is making room: a "yielding" for this turn, written within freshMs (it writes one every few seconds+ // while local work finishes its job). "No answer" only after lateMs with no such answer at all.+ if (y?.state === "yielding" && y.at >= this.startAt - 1000 && y.at <= t + 60_000 && t - y.at <= TURNS.freshMs) this.answeredAt = t;return {// Jobs it may not take now (paused, with one still finishing) don't count.siteWaiting: Math.max(1, (may ? claimable : 0) + (f.busy ? 1 : 0)),@@ -194,7 +202,7 @@ export class SiteTurns {interrupt: this.interrupt,interruptAt: this.interrupt ? this.saved.lastInterruptAt : null,waitForYield,- late: waitForYield && t - this.waitingSince >= TURNS.lateMs,+ late: waitForYield && t - Math.max(this.waitingSince, this.answeredAt ?? -Infinity) >= TURNS.lateMs,startsAt: y?.state === "yielding" && y.at >= this.startAt - 1000 ? y.startsAt : null,ended,};diff --git a/tests/worker-turns.test.ts b/tests/worker-turns.test.tsindex 51689be1..8edf5bd0 100644--- a/tests/worker-turns.test.ts+++ b/tests/worker-turns.test.ts@@ -227,6 +227,26 @@ describe("turns", () => {expect(turns.step(T0 + 4000 + TURNS.graceMs, { ...facts, claimable: 0 })).toMatchObject({ siteWaiting: 0, ended: "idle" });});+ it("a helper that keeps answering \"yielding\" is never 'no answer', however long local work's job runs; silence is", () => {+ const { folder, turns } = setup();+ expect(turns.step(T0, facts)).toMatchObject({ waitForYield: true, late: false });+ // Local work's job runs 10 minutes; the helper writes "yielding" with its estimate every 5 s all along.+ for (let t = T0 + 5000; t <= T0 + 10 * 60_000; t += 5000) {+ answer(folder, { state: "yielding", at: t - 1000, startsAt: T0 + 11 * 60_000 });+ expect(turns.step(t, facts)).toMatchObject({ waitForYield: true, late: false, startsAt: T0 + 11 * 60_000 });+ }+ // Then the helper goes quiet: its last answer stops counting after 15 s, and 3 minutes after it, "no answer".+ const last = T0 + 10 * 60_000;+ expect(turns.step(last + TURNS.lateMs - 1000, facts).late).toBe(false);+ expect(turns.step(last + TURNS.lateMs, facts).late).toBe(true);+ // An answer from before this turn, however fresh it was then, never counts: 3 minutes of silence is late.+ const other = setup();+ answer(other.folder, { state: "yielding", at: T0 - 2000, startsAt: T0 + 60_000 });+ other.turns.step(T0, facts);+ expect(other.turns.step(T0 + 10_000, facts).late).toBe(false);+ expect(other.turns.step(T0 + TURNS.lateMs, facts).late).toBe(true);+ });+it("the GPU free of local work: no waiting, and siteWaiting still says the studio wants it", () => {const { turns } = setup();expect(turns.step(T0, { ...facts, workHolds: false, workThere: true })).toMatchObject({ siteWaiting: 2, waitForYield: false });