Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(create): Sampling wird erst behauptet, wenn ComfyUI wirklich sampelt

Davidde6be639cb6c
diff --git a/src/lib/__tests__/render-phase-labels.test.ts b/src/lib/__tests__/render-phase-labels.test.ts
index e9b337a5..1e064d1b 100644
--- a/src/lib/__tests__/render-phase-labels.test.ts
+++ b/src/lib/__tests__/render-phase-labels.test.ts
@@ -1,8 +1,15 @@
/**
- * R16 Befund 3, measured on the Windows box (2026-08-30, 12 GB GPU, 16 GB RAM,
- * z_image_bf16 at 11.46 GB), five image runs: a STILL IMAGE was told "Decoding
- * frames, the last long stretch...". It has no frames, and that section ran
- * 2.5 s to 3.7 s, the shortest of the whole render, not the longest.
+ * R16 Befund 3 und 4, measured on the Windows box (2026-08-30, 12 GB GPU,
+ * 16 GB RAM, z_image_bf16 at 11.46 GB), five image runs:
+ *
+ * - Befund 3: a STILL IMAGE was told "Decoding frames, the last long
+ * stretch...". It has no frames, and that section ran 2.5 s to 3.7 s,
+ * the shortest of the whole render, not the longest.
+ *
+ * - Befund 4: "Sampling..." stood on screen from +34 s while the first real
+ * sampling step arrived at +74 s. The label hung on ComfyUI entering the
+ * KSampler node, which is where it moves the weights into memory, not on
+ * sampling.
*
* Run: npx vitest run src/lib/__tests__/render-phase-labels.test.ts
*/
@@ -11,7 +18,7 @@ import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
-import { phaseForExecutingNode } from '../render-phase-labels'
+import { phaseForExecutingNode, phaseForProgressStep } from '../render-phase-labels'
const here = dirname(fileURLToPath(import.meta.url))
const repo = resolve(here, '../../..')
@@ -42,6 +49,56 @@ describe('the decode phase (Befund 3)', () => {
})
})
+describe('the sampling claim (Befund 4)', () => {
+ it('entering the sampler is called a load, because that is what runs there', () => {
+ const step = phaseForExecutingNode('KSampler', 'image')
+ expect(step).toEqual({ phase: 'loading-model', pct: 32, label: 'Loading model...' })
+ // Every sampler ComfyUI reports, not just the plain one.
+ for (const n of ['KSamplerAdvanced', 'SamplerCustom', 'SamplerCustomAdvanced']) {
+ expect(phaseForExecutingNode(n, 'image')!.phase).toBe('loading-model')
+ }
+ })
+
+ it('NEGATIVE: nothing says sampling before a step has been reported', () => {
+ // The 40 s lie. Entering the node is not sampling in it.
+ for (const n of ['KSampler', 'KSamplerAdvanced', 'SamplerCustom', 'SamplerCustomAdvanced']) {
+ for (const mode of ['image', 'video'] as const) {
+ expect(phaseForExecutingNode(n, mode)!.label).not.toMatch(/sampl/i)
+ expect(phaseForExecutingNode(n, mode)!.phase).not.toBe('sampling')
+ }
+ }
+ })
+
+ it('the first reported step is what turns the phase into sampling', () => {
+ const step = phaseForProgressStep(1, 20, 'loading-model')
+ expect(step).toEqual({ phase: 'sampling', pct: 38, label: 'Sampling step 1/20...' })
+ expect(phaseForProgressStep(20, 20, 'sampling')).toEqual({
+ phase: 'sampling', pct: 90, label: 'Sampling step 20/20...',
+ })
+ })
+
+ it('NEGATIVE: a decode that reports steps does not walk the render back into sampling', () => {
+ // A tiled VAE decode reports progress too. Repainting the label there
+ // would put "Sampling step 3/8" over a render that is already writing
+ // the picture out.
+ expect(phaseForProgressStep(3, 8, 'decoding')).toBeNull()
+ })
+
+ it('NEGATIVE: a broken step count changes nothing', () => {
+ expect(phaseForProgressStep(1, 0, 'queued')).toBeNull()
+ expect(phaseForProgressStep(Number.NaN, 20, 'queued')).toBeNull()
+ })
+
+ it('the load phases keep their own words', () => {
+ expect(phaseForExecutingNode('UNETLoader', 'image')!.label).toBe('Loading model...')
+ expect(phaseForExecutingNode('DualCLIPLoader', 'image')!.label).toBe('Loading text encoder...')
+ expect(phaseForExecutingNode('VAELoader', 'image')!.label).toBe('Loading VAE...')
+ // A node with nothing to say leaves the label where it was.
+ expect(phaseForExecutingNode('CLIPTextEncode', 'image')).toBeNull()
+ expect(phaseForExecutingNode('SaveImage', 'image')).toBeNull()
+ })
+})
+
describe('the Create tab uses this module and holds no labels of its own', () => {
it('useCreate asks for the phase instead of writing one', () => {
const src = read('src/hooks/useCreate.ts')
@@ -50,8 +107,9 @@ describe('the Create tab uses this module and holds no labels of its own', () =>
expect(src).toMatch(/phaseForProgressStep\(value, max, st\.progressPhase\)/)
})
- it('NEGATIVE: the wrong line is gone from the hook', () => {
+ it('NEGATIVE: the two wrong lines are gone from the hook', () => {
const src = read('src/hooks/useCreate.ts')
expect(src).not.toContain('Decoding frames, the last long stretch')
+ expect(src).not.toContain("setPhase(35, 'Sampling...')")
})
})
diff --git a/src/lib/render-phase-labels.ts b/src/lib/render-phase-labels.ts
index 8f9ac48a..6f3f43cb 100644
--- a/src/lib/render-phase-labels.ts
+++ b/src/lib/render-phase-labels.ts
@@ -2,16 +2,26 @@
* What the Create tab is allowed to say a local render is doing right now.
*
* The waiting area used to name its phases straight from ComfyUI's `executing`
- * events, and one of those names was wrong on the machine it was shown on.
- * R16 Befund 3, re-measured on the Windows box (2026-08-30, 12 GB GPU, 16 GB
- * RAM, z_image_bf16 at 11.46 GB): a still image showed "Decoding frames, the
- * last long stretch". There are no frames in a still image, and that stretch
- * was not long: it ran 2.5 s to 3.7 s and was the SHORTEST section of every
- * one of the five runs. Two claims, both false, in one line.
+ * events, and two of those names were wrong on the machine they were shown on.
+ * R16 re-measure on the Windows box (2026-08-30, 12 GB GPU, 16 GB RAM,
+ * z_image_bf16 at 11.46 GB):
*
- * This is text and phase policy, nothing else, so it lives here as plain
- * functions instead of inside useCreate's 300 line WS closure where the only
- * way to test it is to drive a whole render.
+ * - Befund 3: a still image showed "Decoding frames, the last long stretch".
+ * There are no frames in a still image, and that stretch was not long: it
+ * ran 2.5 s to 3.7 s and was the SHORTEST section of every one of the five
+ * runs. Two claims, both false, in one line.
+ *
+ * - Befund 4: "Sampling..." appeared at +34 s while the first real sampling
+ * step arrived at +74 s. Forty seconds of a lie, because the label was
+ * hung on ComfyUI ENTERING the sampler node, not on the sampler doing
+ * anything. Entering a KSampler is where ComfyUI moves the weights into
+ * memory (measured on the box: RAM climbing from 672 MB to 7.68 GB in that
+ * window), so the honest name for it is a load, and sampling may only be
+ * claimed once a step has actually been reported.
+ *
+ * Both fixes are text and phase policy, nothing else, so they live here as
+ * plain functions instead of inside useCreate's 300 line WS closure where the
+ * only way to test them is to drive a whole render.
*/
import type { ProgressPhase } from '../stores/createStore'
@@ -32,6 +42,11 @@ export interface RenderPhaseStep {
/**
* The phase a node ComfyUI just entered puts the render in, or null when the
* node says nothing worth a label (a text encode, a save, a resize).
+ *
+ * `executing` fires BEFORE the node runs, which is the whole reason the
+ * sampler branch below does not say sampling: at that moment the sampler has
+ * not sampled anything. It reads as a load because that is what ComfyUI does
+ * there, and the first `progress` event is what proves sampling started.
*/
export function phaseForExecutingNode(classType: string, mode: RenderMode): RenderPhaseStep | null {
if (LOADER_NODES.has(classType)) {
@@ -44,7 +59,11 @@ export function phaseForExecutingNode(classType: string, mode: RenderMode): Rend
return { phase: 'loading-vae', pct: 30, label: 'Loading VAE...' }
}
if (SAMPLER_NODES.has(classType)) {
- return { phase: 'sampling', pct: 35, label: 'Sampling...' }
+ // Befund 4. The sampler is loaded, not sampling. Same words and same
+ // phase as the loader nodes above, because to the user it is one
+ // uninterrupted load, and it lets the waiting area's load line explain a
+ // wait that the box measured at 40 s.
+ return { phase: 'loading-model', pct: 32, label: 'Loading model...' }
}
if (DECODE_NODES.has(classType)) {
// Befund 3. A still image has no frames, and nothing here is known to be
@@ -60,13 +79,20 @@ export function phaseForExecutingNode(classType: string, mode: RenderMode): Rend
return null
}
-/** The phase a reported sampling step puts the render in. */
+/**
+ * The phase a reported step puts the render in, or null to leave the label
+ * alone.
+ *
+ * Null during decoding on purpose: a tiled VAE decode reports steps too, and
+ * letting those repaint the label would walk a finished render backwards into
+ * "Sampling step 3/8" while it is writing the picture out.
+ */
export function phaseForProgressStep(
value: number,
max: number,
current: ProgressPhase,
): RenderPhaseStep | null {
- void current
+ if (current === 'decoding') return null
if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) return null
const pct = Math.round(35 + (value / max) * 55) // 35% to 90%
return { phase: 'sampling', pct, label: `Sampling step ${value}/${max}...` }