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
Feed: the time left counts down between progress reports
Claude788c9afa2b0b
diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsxindex b8ad8c90..b96e2a1f 100644--- a/src/components/studio/feed.tsx+++ b/src/components/studio/feed.tsx@@ -14,7 +14,7 @@ import {import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";import { useCreateGeneration, useGenerationActions } from "@/lib/api";-import { elapsed, formatCost, leftLabel, ratioValue, timeAgo, timeLeft } from "@/lib/format";+import { elapsed, formatCost, leftLabel, notePace, ratioValue, timeAgo, timeLeft } from "@/lib/format";import { downloadHref, downloadName, userTitle } from "@/lib/library";import { isLayered, nextSteps, shownOutputs } from "@/lib/output-actions";import { cn } from "@/lib/utils";@@ -41,10 +41,13 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {const now = useNow(1000);const pct = g.progress != null ? Math.round(g.progress * 100) : null;const label = g.status === "queued" ? (g.message ?? "Queued") : (g.message ?? "Generating…");- // The first progress this tile saw: with the latest one it gives the pace, so the time left.- const [first, setFirst] = useState<{ at: number; progress: number } | null>(null);- if (!first && g.progress != null && g.status === "running") setFirst({ at: g.updatedAt, progress: g.progress });- const left = first && g.progress != null ? timeLeft(first, { at: g.updatedAt, progress: g.progress }, now) : null;+ // When progress moved (not every poll: each one rewrites updatedAt) gives the pace, so the time left.+ // Keyed by id: a chain's tile moves on to its next step's generation.+ const report = g.status === "running" ? g.progress : null;+ const [track, setTrack] = useState(() => ({ id: g.id, pace: notePace(null, g.updatedAt, report) }));+ const pace = track.id === g.id ? notePace(track.pace, g.updatedAt, report) : notePace(null, g.updatedAt, report);+ if (track.id !== g.id || pace !== track.pace) setTrack({ id: g.id, pace });+ const left = pace.first && pace.last ? timeLeft(pace.first, pace.last, now) : null;return (<div className="relative h-full overflow-hidden rounded-xl bg-muted" style={{ aspectRatio: ratio }}><div className="skeleton-sweep absolute inset-0 animate-skeleton" />diff --git a/src/lib/format.ts b/src/lib/format.tsindex 94936f0d..5ef173bb 100644--- a/src/lib/format.ts+++ b/src/lib/format.ts@@ -34,11 +34,40 @@ export function untitledName(taken: readonly string[], base = "Untitled project"for (let i = 2; ; i++) if (!used.has(`${base} ${i}`.toLowerCase())) return `${base} ${i}`;}+/** A progress report: when it was written (the generation's updatedAt) and how far the job was. */+export interface ProgressMark {+ at: number;+ progress: number;+}++/**+ * What a running tile remembers of its job's progress: the last value it saw, where the pace starts+ * (`first`) and when progress last moved (`last`). The runner rewrites updatedAt on every poll even+ * when progress stands still, so only a change moves `last`, and between changes the time left+ * counts down instead of growing. A tile that opens on a job already part-way through can't know+ * when that value was reached, so it starts at the first change it sees; progress going back (a new+ * stage) starts over.+ */+export interface Pace {+ seen: number | null;+ first: ProgressMark | null;+ last: ProgressMark | null;+}++/** The pace after one more report (`progress` null while queued or unknown); the same object when nothing moved. */+export function notePace(pace: Pace | null, at: number, progress: number | null): Pace {+ if (!pace) return { seen: progress, first: null, last: null };+ if (progress == null || progress === pace.seen) return pace;+ const mark = { at, progress };+ if (!pace.first || progress < (pace.seen ?? 0)) return { seen: progress, first: mark, last: null };+ return { seen: progress, first: pace.first, last: mark };+}+/**- * Seconds left on a running job, from how fast its progress moved: between the first report the- * page saw (`first`) and the latest one (`last`, at the generation's updatedAt), counted down to- * `now`. Null until there's a rate to go on (two reports a second or more apart, 5 % done), and at 0- * it stays 0 ("almost done") rather than going negative.+ * Seconds left on a running job, from how fast its progress moved between `first` and `last` (the+ * latest change, see notePace), counted down to `now`. Null until there's a rate to go on (two+ * changes a second or more apart, 5 % done), and at 0 it stays 0 ("almost done") rather than going+ * negative.*/export function timeLeft(first: { at: number; progress: number }, last: { at: number; progress: number }, now = Date.now()): number | null {const dp = last.progress - first.progress;diff --git a/tests/ux-flows.test.ts b/tests/ux-flows.test.tsindex a9f35508..0c3a03f1 100644--- a/tests/ux-flows.test.ts+++ b/tests/ux-flows.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from "vitest";import { directorPicks } from "@/components/cinema/draft";import type { Generation, OutputFile } from "@/lib/catalog/types";-import { leftLabel, timeLeft, untitledName } from "@/lib/format";+import { leftLabel, notePace, timeLeft, untitledName, type Pace } from "@/lib/format";import { toggleAll } from "@/lib/library";import { nextSteps, videoPoster } from "@/lib/output-actions";@@ -86,6 +86,39 @@ describe("time left on a running tile", () => {expect(timeLeft({ at: 1000, progress: 0.2 }, { at: 3000, progress: 1 }, 3000)).toBeNull();});+ it("counts down while a step runs: a poll that rewrites updatedAt with the same progress isn't a report", () => {+ // A ComfyUI-like job: 5 % per 30 s sampler step, polled every 1.5 s, each poll bumping updatedAt.+ let pace: Pace = notePace(null, 0, null);+ const seen: number[] = [];+ for (let t = 1500; t <= 120_000; t += 1500) {+ const progress = Math.floor(t / 30_000) * 0.05 || null;+ const next = notePace(pace, t, progress);+ if (progress === pace.seen) expect(next).toBe(pace);+ pace = next;+ if (pace.first && pace.last) seen.push(timeLeft(pace.first, pace.last, t)!);+ }+ // From 60 s on (two changes seen): 0.9 to go at 0.05 / 30 s is 540 s, and it only goes down from there.+ expect(seen[0]).toBe(540);+ for (let i = 1; i < seen.length; i++) expect(seen[i]).toBeLessThanOrEqual(seen[i - 1]);+ // At 2 min, 20 % done: 0.8 to go at the same pace is 480 s.+ expect(seen.at(-1)).toBe(480);+ });++ it("starts at the first change when the tile opens part-way, and over when progress goes back", () => {+ // Opened at 40 %: when 40 % was reached is unknown, so no anchor until it moves.+ let pace = notePace(null, 10_000, 0.4);+ expect(pace.first).toBeNull();+ pace = notePace(pace, 12_000, 0.45);+ expect(pace).toMatchObject({ first: { at: 12_000, progress: 0.45 }, last: null });+ pace = notePace(pace, 42_000, 0.5);+ expect(timeLeft(pace.first!, pace.last!, 42_000)).toBe(300);+ // A new stage restarts at 10 %: the old pace no longer applies.+ pace = notePace(pace, 50_000, 0.1);+ expect(pace).toMatchObject({ first: { at: 50_000, progress: 0.1 }, last: null });+ // Queued or unknown progress changes nothing.+ expect(notePace(pace, 60_000, null)).toBe(pace);+ });+it("reads as minutes and seconds", () => {expect(leftLabel(12)).toBe("12s left");expect(leftLabel(75)).toBe("1m 15s left");