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(comfyui): FLUX v1 via DualCLIPLoader on modern ComfyUI (C2, aldrich follow-up)

purpleb9b0971fc076
diff --git a/src/api/__tests__/dynamic-workflow-clip-missing.test.ts b/src/api/__tests__/dynamic-workflow-clip-missing.test.ts
index 91475873..23025f9e 100644
--- a/src/api/__tests__/dynamic-workflow-clip-missing.test.ts
+++ b/src/api/__tests__/dynamic-workflow-clip-missing.test.ts
@@ -19,14 +19,16 @@ vi.mock('../comfyui-nodes', async (importOriginal) => {
})
vi.mock('../comfyui', async (importOriginal) => {
const actual = await importOriginal<typeof import('../comfyui')>()
- return { ...actual, findMatchingCLIP: vi.fn(), findMatchingVAE: vi.fn() }
+ return { ...actual, findMatchingCLIP: vi.fn(), findMatchingVAE: vi.fn(), findFluxCLIPPair: vi.fn() }
})
import { buildDynamicWorkflow, WorkflowUnavailableError } from '../dynamic-workflow'
import { getAllNodeInfo } from '../comfyui-nodes'
-import { findMatchingCLIP, findMatchingVAE } from '../comfyui'
+import { findMatchingCLIP, findMatchingVAE, findFluxCLIPPair } from '../comfyui'
// Minimal /object_info that categorizes to a FLUX unet strategy.
+// Deliberately NO DualCLIPLoader → exercises the legacy single-CLIPLoader
+// fallback (pre-FLUX-era ComfyUI whose CLIPLoader enum still has 'flux').
const FLUX_NODES = {
UNETLoader: { input: { required: { unet_name: [[]] } } },
CLIPLoader: { input: { required: { clip_name: [[]] } } },
@@ -38,6 +40,13 @@ const FLUX_NODES = {
SaveImage: { input: { required: {} } },
}
+// Modern instance (ComfyUI ≥ v0.12: single CLIPLoader has NO 'flux' type —
+// FLUX v1 must go through DualCLIPLoader). C2 repro environment.
+const FLUX_NODES_DUAL = {
+ ...FLUX_NODES,
+ DualCLIPLoader: { input: { required: { clip_name1: [[]], clip_name2: [[]], type: [[]] } } },
+}
+
const fluxParams = {
model: 'flux1-dev-fp8.safetensors',
prompt: 'a cat', negativePrompt: '',
@@ -68,3 +77,51 @@ describe('buildDynamicWorkflow — Bug C: missing FLUX text encoder', () => {
expect(clipLoader?.inputs.clip_name).not.toBe('')
})
})
+
+describe('buildDynamicWorkflow — C2: FLUX v1 on modern ComfyUI uses DualCLIPLoader', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ vi.mocked(getAllNodeInfo).mockResolvedValue(FLUX_NODES_DUAL as never)
+ vi.mocked(findMatchingVAE).mockResolvedValue('ae.safetensors')
+ })
+
+ it('emits DualCLIPLoader (t5 + clip_l, type flux) instead of single CLIPLoader', async () => {
+ vi.mocked(findFluxCLIPPair).mockResolvedValue({
+ t5: 't5xxl_fp8_e4m3fn.safetensors',
+ clipL: 'clip_l.safetensors',
+ })
+ const wf = await buildDynamicWorkflow(fluxParams)
+ const nodes = Object.values(wf) as { class_type: string; inputs: Record<string, unknown> }[]
+ const dual = nodes.find((n) => n.class_type === 'DualCLIPLoader')
+ expect(dual?.inputs).toEqual({
+ clip_name1: 't5xxl_fp8_e4m3fn.safetensors',
+ clip_name2: 'clip_l.safetensors',
+ type: 'flux',
+ })
+ // No single CLIPLoader with the (now invalid) type 'flux' may remain.
+ const singleFlux = nodes.find((n) => n.class_type === 'CLIPLoader' && n.inputs.type === 'flux')
+ expect(singleFlux).toBeUndefined()
+ expect(vi.mocked(findMatchingCLIP)).not.toHaveBeenCalled()
+ })
+
+ it('propagates the actionable per-encoder error (e.g. missing CLIP-L)', async () => {
+ vi.mocked(findFluxCLIPPair).mockRejectedValue(
+ new Error('No FLUX CLIP-L text encoder found. Download "clip_l.safetensors" from the Model Manager.'),
+ )
+ await expect(buildDynamicWorkflow(fluxParams)).rejects.toBeInstanceOf(WorkflowUnavailableError)
+ await expect(buildDynamicWorkflow(fluxParams)).rejects.toThrow(/clip_l\.safetensors/)
+ })
+
+ it('keeps the single CLIPLoader for flux2 (its type IS valid there)', async () => {
+ vi.mocked(findMatchingCLIP).mockResolvedValue('qwen_3_4b_fp4_flux2.safetensors')
+ const wf = await buildDynamicWorkflow({
+ ...(fluxParams as Record<string, unknown>),
+ model: 'flux-2-klein-base-4b.safetensors',
+ } as never)
+ const nodes = Object.values(wf) as { class_type: string; inputs: Record<string, unknown> }[]
+ expect(nodes.find((n) => n.class_type === 'DualCLIPLoader')).toBeUndefined()
+ const single = nodes.find((n) => n.class_type === 'CLIPLoader')
+ expect(single?.inputs.type).toBe('flux2')
+ expect(vi.mocked(findFluxCLIPPair)).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/api/comfyui.ts b/src/api/comfyui.ts
index d6d5eb92..6d7258df 100644
--- a/src/api/comfyui.ts
+++ b/src/api/comfyui.ts
@@ -690,6 +690,26 @@ export async function findMatchingVAE(modelType: ModelType): Promise<string> {
return vaes[0]
}
+/**
+ * Resolve the FLUX v1 text-encoder PAIR for DualCLIPLoader (C2, aldrich
+ * follow-up): modern ComfyUI removed 'flux' from the single CLIPLoader's type
+ * enum, so FLUX v1 conditioning must come from DualCLIPLoader, which needs
+ * BOTH encoders — clip_name1 = T5-XXL, clip_name2 = CLIP-L. Throws the same
+ * actionable "download <file> from the Model Manager" errors as
+ * findMatchingCLIP so buildDynamicWorkflow surfaces a fix path per missing
+ * encoder instead of a raw ComfyUI rejection.
+ */
+export async function findFluxCLIPPair(): Promise<{ t5: string; clipL: string }> {
+ const clips = await getCLIPModels()
+ if (clips.length === 0) throw new Error('No text encoder models found. Download a CLIP/T5 model for your model type from the Model Manager.')
+ const lower = (s: string) => s.toLowerCase()
+ const t5 = clips.find(c => lower(c).includes('t5') && !lower(c).includes('umt5') && !lower(c).includes('oldt5'))
+ const clipL = clips.find(c => lower(c).includes('clip_l'))
+ if (!t5) throw new Error(`No FLUX text encoder (T5) found. Download "t5xxl_fp8_e4m3fn.safetensors" from the Model Manager.`)
+ if (!clipL) throw new Error(`No FLUX CLIP-L text encoder found. Download "clip_l.safetensors" from the Model Manager.`)
+ return { t5, clipL }
+}
+
/**
* Pick the right text encoder for a model.
*
diff --git a/src/api/dynamic-workflow.ts b/src/api/dynamic-workflow.ts
index 30668948..b3961110 100644
--- a/src/api/dynamic-workflow.ts
+++ b/src/api/dynamic-workflow.ts
@@ -1,4 +1,4 @@
-import { classifyModel, findMatchingVAE, findMatchingCLIP } from './comfyui'
+import { classifyModel, findMatchingVAE, findMatchingCLIP, findFluxCLIPPair } from './comfyui'
import type { ModelType, GenerateParams, VideoParams } from './comfyui'
import { log } from '../lib/logger'
import {
@@ -325,19 +325,42 @@ export async function buildDynamicWorkflow(
// Resolve the text encoder from the LIVE ComfyUI node enum. CRITICAL
// (Bug C / aldrich "CLIPLoader: Value not in list"): do NOT silently fall
// back to models.clips[0] / '' on a miss — an empty or wrong clip_name makes
- // ComfyUI reject the prompt with that exact cryptic error. findMatchingCLIP
- // already throws an actionable "download <encoder>" message; propagate it as
- // a WorkflowUnavailableError so the user gets the download hint instead of a
+ // ComfyUI reject the prompt with that exact cryptic error. The resolvers
+ // throw actionable "download <encoder>" messages; propagate them as a
+ // WorkflowUnavailableError so the user gets the download hint instead of a
// raw rejection. Pass the active UNet filename so the resolver prefers the
// matching quant tier (fp4 model → fp4 encoder; fp8/bf16 → full precision).
- let clip: string
- try {
- clip = await findMatchingCLIP(type, params.model)
- } catch (clipErr) {
- throw new WorkflowUnavailableError(
- clipErr instanceof Error ? clipErr.message : 'Required text encoder not found in ComfyUI.',
- strategy,
- )
+ //
+ // C2 (aldrich follow-up, v2.5.3 fix #5): modern ComfyUI (v0.12.0 confirmed)
+ // removed 'flux' from the single CLIPLoader's type enum — FLUX v1 text
+ // encoding lives in DualCLIPLoader (clip_name1 = T5-XXL, clip_name2 =
+ // CLIP-L, type 'flux'), which has shipped with every FLUX-era ComfyUI.
+ // Emit it whenever the instance has the node; the single-CLIPLoader path
+ // stays as the fallback for pre-FLUX-era instances (whose CLIPLoader enum
+ // still contains 'flux'). Same pattern as the HunyuanVideo DualCLIPLoader
+ // below.
+ const useDualFluxClip = type === 'flux' && nodes.loaders.includes('DualCLIPLoader')
+
+ let clip = ''
+ let fluxPair: { t5: string; clipL: string } | null = null
+ if (useDualFluxClip) {
+ try {
+ fluxPair = await findFluxCLIPPair()
+ } catch (clipErr) {
+ throw new WorkflowUnavailableError(
+ clipErr instanceof Error ? clipErr.message : 'Required text encoder not found in ComfyUI.',
+ strategy,
+ )
+ }
+ } else {
+ try {
+ clip = await findMatchingCLIP(type, params.model)
+ } catch (clipErr) {
+ throw new WorkflowUnavailableError(
+ clipErr instanceof Error ? clipErr.message : 'Required text encoder not found in ComfyUI.',
+ strategy,
+ )
+ }
}
// VAE is only loaded for strategies with a separate VAELoader — LTX bakes it
@@ -360,10 +383,15 @@ export async function buildDynamicWorkflow(
class_type: 'UNETLoader',
inputs: { unet_name: params.model, weight_dtype: 'default' },
}
- workflow[clipId] = {
- class_type: 'CLIPLoader',
- inputs: { clip_name: clip, type: clipType, device: 'default' },
- }
+ workflow[clipId] = useDualFluxClip && fluxPair
+ ? {
+ class_type: 'DualCLIPLoader',
+ inputs: { clip_name1: fluxPair.t5, clip_name2: fluxPair.clipL, type: 'flux' },
+ }
+ : {
+ class_type: 'CLIPLoader',
+ inputs: { clip_name: clip, type: clipType, device: 'default' },
+ }
let vaeId: string
if (needsVAELoader) {