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.

feat(create): a local ComfyUI edit makes as many pictures as the batch size says (B35)

purple9cf378e59aa3
diff --git a/src/api/__tests__/edit-batch.test.ts b/src/api/__tests__/edit-batch.test.ts
new file mode 100644
index 00000000..0040220d
--- /dev/null
+++ b/src/api/__tests__/edit-batch.test.ts
@@ -0,0 +1,94 @@
+/**
+ * B35 (3.0.9, Discord 29.10.2026): "Edit gives only 1 image despite batch 8".
+ * A local ComfyUI edit starts from the encoded source, a latent of one, so
+ * batchSize changed nothing. applyEditBatch repeats that latent; the graphs
+ * here are the ones the local Edit lane really builds.
+ *
+ * Run: npx vitest run src/api/__tests__/edit-batch.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+
+vi.mock('../comfyui-nodes', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('../comfyui-nodes')>()
+ return { ...actual, getAllNodeInfo: vi.fn() }
+})
+vi.mock('../backend', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('../backend')>()
+ return { ...actual, localFetch: vi.fn(), comfyuiUrl: (p: string) => `http://test${p}` }
+})
+
+import { buildDynamicWorkflow } from '../dynamic-workflow'
+import { applyEditBatch } from '../edit-batch'
+import { applyNativeHiresFix, NativeHiresFixError } from '../hires-fix'
+import { getAllNodeInfo } from '../comfyui-nodes'
+import { nodeInput, type ComfyApiGraph } from '../../types/comfy-graph'
+import { nodeOf, nodesOf } from './graph-test-support'
+
+const CHECKPOINT_NODES: Record<string, unknown> = {
+ CheckpointLoaderSimple: { input: { required: { ckpt_name: [['sdxl.safetensors']] } } },
+ CLIPTextEncode: { input: { required: {} } },
+ KSampler: { input: { required: {} } },
+ EmptyLatentImage: { input: { required: {} } },
+ LoadImage: { input: { required: { image: [[]] } } },
+ LoadImageMask: { input: { required: { image: [[]] } } },
+ VAEEncode: { input: { required: {} } },
+ VAEEncodeForInpaint: { input: { required: {} } },
+ VAEDecode: { input: { required: {} } },
+ SaveImage: { input: { required: {} } },
+}
+const sdxl = {
+ model: 'sdxl.safetensors', prompt: 'a red jacket', negativePrompt: 'blurry',
+ sampler: 'euler', scheduler: 'normal', width: 1024, height: 1024, steps: 20, cfgScale: 7, seed: 1, batchSize: 4,
+}
+
+beforeEach(() => {
+ vi.clearAllMocks()
+ vi.mocked(getAllNodeInfo).mockResolvedValue(CHECKPOINT_NODES as never)
+})
+
+const samplerLatentSource = (wf: ComfyApiGraph) => {
+ const sampler = nodeOf(wf, 'KSampler')?.[1]
+ const ref = nodeInput(sampler, 'latent_image') as [string, number]
+ return wf[ref[0]]
+}
+
+describe('B35: a local edit makes as many pictures as the batch size says', () => {
+ it('the edit graph alone starts from a latent of one (the bug)', async () => {
+ const wf = await buildDynamicWorkflow({ ...sdxl, inputImage: 'photo.png', denoise: 0.6 } as never)
+ expect(samplerLatentSource(wf).class_type).toBe('VAEEncode')
+ expect(nodesOf(wf, 'EmptyLatentImage')).toHaveLength(0)
+ })
+
+ it('SDXL edit, batch 4: the sampler starts from the source latent repeated four times', async () => {
+ const wf = applyEditBatch(await buildDynamicWorkflow({ ...sdxl, inputImage: 'photo.png', denoise: 0.6 } as never), 4)
+ const repeat = samplerLatentSource(wf)
+ expect(repeat.class_type).toBe('RepeatLatentBatch')
+ expect(repeat.inputs?.amount).toBe(4)
+ const from = repeat.inputs?.samples as [string, number]
+ expect(wf[from[0]].class_type).toBe('VAEEncode')
+ })
+
+ it('a masked edit is repeated too, and Native HiRes still sees the mask', async () => {
+ const wf = applyEditBatch(await buildDynamicWorkflow({ ...sdxl, inputImage: 'photo.png', maskImage: 'mask.png', denoise: 0.6 } as never), 3)
+ const repeat = samplerLatentSource(wf)
+ expect(repeat.class_type).toBe('RepeatLatentBatch')
+ expect(() => applyNativeHiresFix(wf, { baseWidth: 1024, baseHeight: 1024, scale: 1.5, denoise: 0.5, steps: 12, upscaleMethod: 'nearest-exact' }))
+ .toThrow(NativeHiresFixError)
+ })
+
+ it('batch 1 leaves the graph as it is; more than 8 is capped at 8', async () => {
+ const wf = await buildDynamicWorkflow({ ...sdxl, inputImage: 'photo.png', denoise: 0.6 } as never)
+ expect(applyEditBatch(wf, 1)).toBe(wf)
+ expect(samplerLatentSource(applyEditBatch(wf, 20)).inputs?.amount).toBe(8)
+ })
+
+ it('a text-to-image graph (empty latent) and a second stage are left alone', () => {
+ const wf: ComfyApiGraph = {
+ '1': { class_type: 'EmptyLatentImage', inputs: { width: 512, height: 512, batch_size: 2 } },
+ '2': { class_type: 'KSampler', inputs: { latent_image: ['1', 0] } },
+ '3': { class_type: 'KSampler', inputs: { latent_image: ['2', 0] } },
+ }
+ const out = applyEditBatch(wf, 4)
+ expect(nodesOf(out, 'RepeatLatentBatch')).toHaveLength(0)
+ })
+})
diff --git a/src/api/edit-batch.ts b/src/api/edit-batch.ts
new file mode 100644
index 00000000..ae0e412c
--- /dev/null
+++ b/src/api/edit-batch.ts
@@ -0,0 +1,50 @@
+// B35 (3.0.9, Discord 29.10.2026): a local ComfyUI edit made one picture
+// whatever the batch size said. Generate puts batch_size into its empty
+// latent; an edit starts from the encoded source, a latent of one. This
+// repeats that latent for every sampler that starts from it (ComfyUI core
+// node RepeatLatentBatch, which also repeats an inpaint mask and gives each
+// copy its own noise), so one edit run yields `count` pictures, the same
+// way a local Generate batch does.
+import {
+ apiNodes,
+ isComfyLinkRef,
+ linkTarget,
+ type ComfyApiGraph,
+ type ComfyLinkRef,
+} from '../types/comfy-graph'
+
+/** Highest count of one local edit run, the local batch limit. */
+const EDIT_BATCH_MAX = 8
+
+/** A starting latent that already is a batch of its own: an empty latent
+ * carries batch_size, a sampler's output (a second stage) is the batch of
+ * the stage before it. */
+const BATCHED_ALREADY = /^Empty.*Latent|Sampler|^RepeatLatentBatch$/
+
+export function applyEditBatch(source: ComfyApiGraph, count: number): ComfyApiGraph {
+ const amount = Math.max(1, Math.min(EDIT_BATCH_MAX, Math.floor(count) || 1))
+ if (amount === 1) return source
+ const graph: ComfyApiGraph = structuredClone(source)
+ const repeats = new Map<string, string>()
+ let next = Math.max(0, ...Object.keys(graph).map((k) => Number(k)).filter(Number.isFinite)) + 1
+ for (const [, node] of apiNodes(graph)) {
+ const latent = node.inputs?.latent_image
+ if (!isComfyLinkRef(latent)) continue
+ const from = linkTarget(latent)
+ const fromNode = from ? graph[from] : undefined
+ if (!from || !fromNode || BATCHED_ALREADY.test(fromNode.class_type)) continue
+ const key = `${from}:${latent[1]}`
+ let repeatId = repeats.get(key)
+ if (!repeatId) {
+ repeatId = String(next++)
+ graph[repeatId] = {
+ class_type: 'RepeatLatentBatch',
+ inputs: { samples: [from, latent[1]] as ComfyLinkRef, amount },
+ _meta: { title: 'LU edit batch' },
+ }
+ repeats.set(key, repeatId)
+ }
+ node.inputs = { ...node.inputs, latent_image: [repeatId, 0] }
+ }
+ return graph
+}
diff --git a/src/api/hires-fix.ts b/src/api/hires-fix.ts
index 126b43d8..c522c26f 100644
--- a/src/api/hires-fix.ts
+++ b/src/api/hires-fix.ts
@@ -284,7 +284,13 @@ export function applyNativeHiresFix(
}
const latentRef = nodeInput(firstSampler, 'latent_image')
- const latentSource = isComfyLinkRef(latentRef) ? nodeAt(workflow, String(latentRef[0])) : undefined
+ let latentSource = isComfyLinkRef(latentRef) ? nodeAt(workflow, String(latentRef[0])) : undefined
+ // An edit batch (api/edit-batch) repeats the source latent; the mask is
+ // the one of the latent it repeats.
+ if (latentSource?.class_type === 'RepeatLatentBatch') {
+ const repeated = nodeInput(latentSource, 'samples')
+ latentSource = isComfyLinkRef(repeated) ? nodeAt(workflow, String(repeated[0])) : undefined
+ }
if (latentSource && MASKED_LATENT_NODES.has(latentSource.class_type)) {
throw new NativeHiresFixError(
'Native HiRes runs on edits of the whole picture. Clear the mask, or turn Native HiRes off for this edit.',
diff --git a/src/components/create/experimental/ImageCountChip.tsx b/src/components/create/experimental/ImageCountChip.tsx
index d15cac97..d9ae2c13 100644
--- a/src/components/create/experimental/ImageCountChip.tsx
+++ b/src/components/create/experimental/ImageCountChip.tsx
@@ -1,7 +1,6 @@
import { useRef, useState } from 'react'
import { motion, AnimatePresence } from 'framer-motion'
import { Images } from 'lucide-react'
-import { isMlxImageHost } from '../../../api/mlx-image'
import { useCreateStore } from '../../../stores/createStore'
import { clampImageCount, composerImageCountMax } from '../../../lib/render/image-count'
import { usePopoverPlatz } from '../../../hooks/usePopoverPlatz'
@@ -34,7 +33,7 @@ export function ImageCountChip() {
const panel = usePopoverPlatz(panelRef, open, { bevorzugt: 'oben', abstand: 6 })
useClickAway(ref, () => setOpen(false), open)
- const max = composerImageCountMax(backend, intent, backend === 'local' && isMlxImageHost())
+ const max = composerImageCountMax(backend, intent)
if (max == null) return null
const cloud = backend === 'cloud'
const value = cloud ? clampImageCount(cloudImageCount) : Math.max(1, Math.min(max, batchSize))
diff --git a/src/components/create/experimental/__tests__/composer-image-count.test.tsx b/src/components/create/experimental/__tests__/composer-image-count.test.tsx
index d39ea042..6aa65f4f 100644
--- a/src/components/create/experimental/__tests__/composer-image-count.test.tsx
+++ b/src/components/create/experimental/__tests__/composer-image-count.test.tsx
@@ -80,20 +80,22 @@ describe('the image count in the Composer', () => {
expect(useCreateStore.getState().batchSize).toBe(1)
})
- it('no chip where a run makes one result: video, local Edit on ComfyUI, utilities', () => {
+ it('no chip where a run makes one result: video, utilities', () => {
useCreateStore.getState().setIntent('video')
composer()
expect(chip()).toBeNull()
cleanup()
- useCreateStore.getState().setIntent('edit')
- composer()
- expect(chip()).toBeNull()
- cleanup()
useCreateStore.getState().setIntent('removebg')
composer()
expect(chip()).toBeNull()
})
+ it('local Edit offers the count on ComfyUI too (B35)', () => {
+ useCreateStore.getState().setIntent('edit')
+ composer()
+ expect(chip()).not.toBeNull()
+ })
+
it('the Mac edits one picture per image, so local Edit offers the count there', () => {
host.mac = true
useCreateStore.getState().setIntent('edit')
@@ -104,11 +106,11 @@ describe('the image count in the Composer', () => {
describe('composerImageCountMax', () => {
it('follows the lanes', () => {
- expect(composerImageCountMax('local', 'image', false)).toBe(8)
- expect(composerImageCountMax('local', 'edit', false)).toBeNull()
- expect(composerImageCountMax('local', 'edit', true)).toBe(8)
- expect(composerImageCountMax('cloud', 'edit', false)).toBe(4)
- expect(composerImageCountMax('cloud', 'video', false)).toBeNull()
- expect(composerImageCountMax('local', 'music', false)).toBeNull()
+ expect(composerImageCountMax('local', 'image')).toBe(8)
+ // B35: a local ComfyUI edit repeats its source latent (api/edit-batch).
+ expect(composerImageCountMax('local', 'edit')).toBe(8)
+ expect(composerImageCountMax('cloud', 'edit')).toBe(4)
+ expect(composerImageCountMax('cloud', 'video')).toBeNull()
+ expect(composerImageCountMax('local', 'music')).toBeNull()
})
})
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index 733b118f..168ee8e8 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -103,6 +103,7 @@ import { useWorkflowStore } from '../stores/workflowStore'
import { useSettingsStore } from '../stores/settingsStore'
import { renderStallLimitMs, renderStallMessage } from '../lib/tool-timeout'
import { injectParameters, injectLaneParameters } from '../api/workflows'
+import { applyEditBatch } from '../api/edit-batch'
import { applyNativeHiresFix, latentDownscale } from '../api/hires-fix'
import { editHiresBase } from '../lib/edit-hires'
import { lorasForRun, skippedLorasLine } from '../lib/lora-stack'
@@ -2067,6 +2068,12 @@ export function useCreate() {
}
}
+ // B35: an edit starts from a latent of one; the batch size repeats it,
+ // so an edit run makes as many pictures as a Generate run (api/edit-batch).
+ if (intent === 'edit' && isI2I && !isRemoveBg && effInputImage) {
+ workflow = applyEditBatch(workflow, batchSize)
+ }
+
// Native HiRes is a graph transform, not a special workflow. Apply
// it after Auto/custom workflow construction so the same switch works on
// every compatible local text-to-image graph. Unsupported custom graphs
diff --git a/src/lib/render/image-count.ts b/src/lib/render/image-count.ts
index 3d4021d1..9c0a5238 100644
--- a/src/lib/render/image-count.ts
+++ b/src/lib/render/image-count.ts
@@ -38,12 +38,11 @@ export const LOCAL_BATCH_MAX = 8
* Null heisst: dieser Lauf kennt keine Anzahl, also kein Regler.
* Cloud: Bild und Bearbeiten, 1 bis MAX_IMAGE_COUNT (runImageCount).
* Mac lokal: Bild und Bearbeiten, je Bild ein eigener Lauf (useCreate).
- * ComfyUI lokal: nur Bild, dort geht batchSize in den leeren Latent; ein
- * Edit startet vom Quellbild und macht immer eines.
+ * ComfyUI lokal: Bild (batchSize im leeren Latent) und Bearbeiten (B35:
+ * der Latent des Quellbilds wird wiederholt, api/edit-batch).
*/
-export function composerImageCountMax(backend: 'local' | 'cloud', intent: string, macLocal: boolean): number | null {
+export function composerImageCountMax(backend: 'local' | 'cloud', intent: string): number | null {
if (backend === 'cloud') return imageCountApplies(intent) ? MAX_IMAGE_COUNT : null
- if (intent === 'image') return LOCAL_BATCH_MAX
- if (macLocal && intent === 'edit') return LOCAL_BATCH_MAX
+ if (intent === 'image' || intent === 'edit') return LOCAL_BATCH_MAX
return null
}