Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([qwen-image-edit-init-image-required]): require a source image for edit-only models

[._.]/ Adam Eivy8e6d7c5479d7
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index 494663c84c..1d74af0e85 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -494,6 +494,11 @@ export default function ImageGen() {
const currentModel = models.find((m) => m.id === modelId);
const isFlux2Model = currentModel?.runner === RUNNER_FAMILIES.FLUX2;
+ // Edit-only models (Qwen-Image-Edit) require a source image — submitting
+ // text-only crashes the runner, so the server rejects it and we gate the
+ // submit button + show a hint rather than letting the user hit a failed job.
+ const isEditOnlyModel = currentModel?.editOnly === true;
+ const editImageMissing = isLocalMode && isEditOnlyModel && initImage.source == null;
// mflux is the default runner for entries with no explicit `runner` field.
// LoraPicker filters compatible weights itself; we just pass the family.
const currentRunnerFamily = currentModel?.runner || RUNNER_FAMILIES.MFLUX;
@@ -1004,7 +1009,10 @@ export default function ImageGen() {
{isLocalMode && (
<div>
<label className="block text-xs font-medium text-gray-400 mb-1">
- Init image <span className="text-gray-500 font-normal">(image-to-image — Flux only)</span>
+ {isEditOnlyModel ? 'Source image' : 'Init image'}{' '}
+ <span className={`font-normal ${isEditOnlyModel ? 'text-port-warning' : 'text-gray-500'}`}>
+ {isEditOnlyModel ? '(required — this model edits an existing image)' : '(image-to-image — Flux only)'}
+ </span>
</label>
{initImage.previewUrl ? (
<div className="flex items-start gap-3">
@@ -1127,12 +1135,16 @@ export default function ImageGen() {
<div className="flex items-center gap-2 pt-1 flex-wrap">
<button
type="submit"
- disabled={!prompt.trim() || notConnected}
+ disabled={!prompt.trim() || notConnected || editImageMissing}
+ title={editImageMissing ? 'This image-edit model needs a source image — upload one below first' : undefined}
className="flex items-center gap-2 px-4 py-2 bg-port-accent hover:bg-port-accent/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded-lg min-h-[40px]"
>
<Sparkles className="w-4 h-4" /> {generating ? 'Queue' : 'Generate'}
{isAsyncMode && batchCount > 1 && <span className="text-xs opacity-80">× {batchCount}</span>}
</button>
+ {editImageMissing && (
+ <span className="text-xs text-port-warning">Upload a source image to use this edit model</span>
+ )}
{isAsyncMode && (
<label className="flex items-center gap-1.5 text-xs text-gray-400" title="Batch size: number of renders to queue per submit">
<span className="select-none">×</span>
diff --git a/data.reference/media-models.json b/data.reference/media-models.json
index e2cbd075fc..312e5d4c83 100644
--- a/data.reference/media-models.json
+++ b/data.reference/media-models.json
@@ -191,7 +191,8 @@
"repo": "Qwen/Qwen-Image-Edit",
"pipelineClass": "QwenImageEditPipeline",
"steps": 30,
- "guidance": 4
+ "guidance": 4,
+ "editOnly": true
},
{
"id": "z-image-turbo-bf16",
diff --git a/server/lib/mediaModels.js b/server/lib/mediaModels.js
index 4b24cb2229..57f949f55c 100644
--- a/server/lib/mediaModels.js
+++ b/server/lib/mediaModels.js
@@ -216,6 +216,10 @@ const DEFAULT_REGISTRY = {
pipelineClass: 'QwenImageEditPipeline',
steps: 30,
guidance: 4.0,
+ // QwenImageEditPipeline requires a source `image` arg — a text-only
+ // submission crashes deep inside diffusers. `editOnly` lets the route
+ // reject (and the UI gate) a render with no init image up-front.
+ editOnly: true,
},
// z-image runner — Apache 2.0, ungated, reuses the FLUX.2 venv. Turbo
// distillation runs ~8 steps with CFG disabled (guidance 1.0).
@@ -355,12 +359,33 @@ const backfillCfgDisabled = (list) => {
});
};
+// IDs whose underlying pipeline REQUIRES a source `image` arg (Qwen-Image-Edit
+// loads QwenImageEditPipeline). A text-only render against one of these crashes
+// deep inside diffusers, so the route rejects (and the UI gates) it up-front.
+// Backfilled at load time — same pattern as cfgDisabled — so installs that
+// stored their `qwen-image-edit` entry before this flag existed pick it up
+// without a migration. Mirrored in data.reference/media-models.json.
+const EDIT_ONLY_IDS = new Set([
+ 'qwen-image-edit',
+]);
+
+const backfillEditOnly = (list) => {
+ if (!Array.isArray(list)) return list;
+ return list.map((entry) => {
+ if (!isPlainObject(entry) || typeof entry.id !== 'string') return entry;
+ if ('editOnly' in entry) return entry; // user override (true OR false) wins
+ if (!EDIT_ONLY_IDS.has(entry.id)) return entry;
+ return { ...entry, editOnly: true };
+ });
+};
+
export const isFlux2 = (model) => model?.runner === RUNNER_FAMILIES.FLUX2;
export const isZImage = (model) => model?.runner === RUNNER_FAMILIES.Z_IMAGE;
export const isErnie = (model) => model?.runner === RUNNER_FAMILIES.ERNIE;
export const isHiDream = (model) => model?.runner === RUNNER_FAMILIES.HIDREAM;
export const isQwen = (model) => model?.runner === RUNNER_FAMILIES.QWEN;
export const isCfgDisabled = (model) => model?.cfgDisabled === true;
+export const isEditOnly = (model) => model?.editOnly === true;
// Append models that are genuinely new in this release (not in
// _shippedDefaults) to the user's list, while respecting deletions the user
@@ -471,9 +496,9 @@ const normalizeRegistry = (parsed) => {
// (treat as fresh install — let the new entries land).
const shippedImage = isPlainObject(safe._shippedDefaults?.image) ? safe._shippedDefaults.image : null;
const isImageBootstrap = shippedImage === null;
- const upgradedImage = backfillCfgDisabled(
+ const upgradedImage = backfillEditOnly(backfillCfgDisabled(
upgradeImageEntries(arrayOrDefault(safe.image, DEFAULT_REGISTRY.image)),
- );
+ ));
// Image bootstrap deliberately uses userIds ONLY (not union with defaults).
// Image is getting `_shippedDefaults` for the first time in this release, so
// there's no prior history of deletions to preserve via the union trick the
diff --git a/server/lib/mediaModels.test.js b/server/lib/mediaModels.test.js
index 48d6c152f8..354a973db0 100644
--- a/server/lib/mediaModels.test.js
+++ b/server/lib/mediaModels.test.js
@@ -406,6 +406,51 @@ describe('mediaModels registry', () => {
expect(onDisk._shippedDefaults.image.list).toContain('z-image-turbo-bf16');
});
+ // editOnly — backfilled like cfgDisabled so the route/UI can reject a
+ // text-only render against a pipeline that requires a source image.
+
+ it('fresh install: qwen-image-edit ships with editOnly: true', async () => {
+ const { loadMediaModels, getImageModels, isEditOnly } = await import('./mediaModels.js');
+ loadMediaModels();
+ const qwenEdit = getImageModels().find((m) => m.id === 'qwen-image-edit');
+ expect(qwenEdit).toBeDefined();
+ expect(qwenEdit.editOnly).toBe(true);
+ expect(isEditOnly(qwenEdit)).toBe(true);
+ // The plain text-to-image qwen entry must NOT be flagged edit-only.
+ const qwen = getImageModels().find((m) => m.id === 'qwen-image');
+ expect(isEditOnly(qwen)).toBe(false);
+ });
+
+ it('backfills editOnly onto a pre-flag qwen-image-edit entry (no migration needed)', async () => {
+ // Simulate an install that stored qwen-image-edit before the editOnly flag
+ // existed — the entry lacks the field entirely.
+ writeFileSync(registryFile, JSON.stringify({
+ video: { macos: [], windows: [], defaultMacos: 'x', defaultWindows: 'x' },
+ image: [
+ { id: 'qwen-image-edit', name: 'Qwen-Image-Edit', runner: 'qwen', repo: 'Qwen/Qwen-Image-Edit', pipelineClass: 'QwenImageEditPipeline', steps: 30, guidance: 4 },
+ ],
+ textEncoders: [{ id: 't', label: 't', repo: 'r' }],
+ selectedTextEncoder: 't',
+ }));
+ const { getImageModels } = await import('./mediaModels.js');
+ const qwenEdit = getImageModels().find((m) => m.id === 'qwen-image-edit');
+ expect(qwenEdit.editOnly).toBe(true);
+ });
+
+ it('preserves an explicit editOnly: false user override', async () => {
+ writeFileSync(registryFile, JSON.stringify({
+ video: { macos: [], windows: [], defaultMacos: 'x', defaultWindows: 'x' },
+ image: [
+ { id: 'qwen-image-edit', name: 'Qwen-Image-Edit', runner: 'qwen', repo: 'Qwen/Qwen-Image-Edit', pipelineClass: 'QwenImageEditPipeline', steps: 30, guidance: 4, editOnly: false },
+ ],
+ textEncoders: [{ id: 't', label: 't', repo: 'r' }],
+ selectedTextEncoder: 't',
+ }));
+ const { getImageModels } = await import('./mediaModels.js');
+ const qwenEdit = getImageModels().find((m) => m.id === 'qwen-image-edit');
+ expect(qwenEdit.editOnly).toBe(false);
+ });
+
it('existing install without _shippedDefaults.image gains the new z-image entries on upgrade', async () => {
// Simulate a pre-z-image registry: only flux2 and Flux 1 entries, no
// _shippedDefaults.image at all.
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index 58c9ebe118..18bf81f55f 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -23,7 +23,7 @@ import { local, IMAGE_GEN_MODE, IMAGE_GEN_MODES, resolveImageCleaners } from '..
import { enqueueJob, attachSseClient as attachQueueSseClient, cancelJob, listJobs } from '../services/mediaJobQueue/index.js';
import { getSettings, updateSettingsWith } from '../services/settings.js';
import { getHfToken, getHfTokenInfo, HF_TOKEN_REGEX } from '../lib/hfToken.js';
-import { getImageModels, isFlux2, repoForModel, requiredReposForModel } from '../lib/mediaModels.js';
+import { getImageModels, isFlux2, isEditOnly, repoForModel, requiredReposForModel } from '../lib/mediaModels.js';
import { usesDiffusersRunner } from '../lib/runners.js';
import { inspectModelCache } from '../lib/hfCache.js';
import { startHfDownloadStream } from '../lib/sseDownload.js';
@@ -350,6 +350,17 @@ router.post('/generate', imageGenUploads, asyncHandler(async (req, res) => {
const selectedModel = allModels.find((m) => m.id === data.modelId)
?? allModels.find((m) => m.id === 'dev')
?? allModels[0];
+ // Edit-only models (Qwen-Image-Edit) load a pipeline that REQUIRES a
+ // source image. Reject a text-only submission up-front rather than
+ // enqueueing a job that crashes deep inside diffusers. `data.initImagePath`
+ // is already populated above from either an uploaded `initImage` or a
+ // gallery `initImageFile`.
+ if (isEditOnly(selectedModel) && !data.initImagePath) {
+ throw new ServerError(
+ `${selectedModel.name || selectedModel.id} is an image-edit model — it requires a source image. Upload an init image to use it.`,
+ { status: 400, code: 'IMAGE_GEN_EDIT_IMAGE_REQUIRED' },
+ );
+ }
if (selectedModel && !isFlux2(selectedModel) && !usesDiffusersRunner(selectedModel) && !py) {
throw new ServerError(
'Local image generation is not configured (settings.imageGen.local.pythonPath is missing).',
diff --git a/server/routes/imageGen.multipart.test.js b/server/routes/imageGen.multipart.test.js
index 3f49063f3e..3c704add06 100644
--- a/server/routes/imageGen.multipart.test.js
+++ b/server/routes/imageGen.multipart.test.js
@@ -218,6 +218,39 @@ describe('POST /api/image-gen/generate — multipart reference-image packing', (
expect(params.referenceImageStrengths).toEqual([1.0]);
});
+ // Edit-only models (Qwen-Image-Edit) require a source image. With an init
+ // image uploaded, the route stages it and enqueues normally — the editOnly
+ // gate only fires for text-only submissions.
+ it('edit-only model WITH an uploaded init image enqueues with initImagePath set', async () => {
+ const res = await postMultipart(app, '/api/image-gen/generate', [
+ { name: 'prompt', value: 'make the sky purple' },
+ { name: 'modelId', value: 'qwen-image-edit' },
+ { name: 'initImage', filename: 'src.png', contentType: 'image/png', value: PNG_FIXTURE },
+ ]);
+
+ expect(res.status).toBe(200);
+ expect(res.body.status).toBe('queued');
+ expect(enqueueJob).toHaveBeenCalledTimes(1);
+ const params = enqueueJob.mock.calls[0][0].params;
+ const { dir, name, ext } = parsePath(params.initImagePath);
+ expect(dir).toBe(imagesSandbox);
+ expect(name.startsWith('init-')).toBe(true);
+ expect(ext).toBe('.png');
+ });
+
+ // The editOnly gate must fire for a text-only submission to an edit-only
+ // model even over multipart — no job is enqueued.
+ it('edit-only model with NO init image returns 400 before enqueueing', async () => {
+ const res = await postMultipart(app, '/api/image-gen/generate', [
+ { name: 'prompt', value: 'make the sky purple' },
+ { name: 'modelId', value: 'qwen-image-edit' },
+ ]);
+
+ expect(res.status).toBe(400);
+ expect(res.body.code).toBe('IMAGE_GEN_EDIT_IMAGE_REQUIRED');
+ expect(enqueueJob).not.toHaveBeenCalled();
+ });
+
it('rejects refs uploaded for a non-FLUX.2 model before any file is copied', async () => {
const res = await postMultipart(app, '/api/image-gen/generate', [
{ name: 'prompt', value: 'wrong-model ref' },
diff --git a/server/routes/imageGen.test.js b/server/routes/imageGen.test.js
index d137c7ed38..ad026854b7 100644
--- a/server/routes/imageGen.test.js
+++ b/server/routes/imageGen.test.js
@@ -453,6 +453,22 @@ describe('Image Gen Routes', () => {
});
});
+ // Edit-only models (Qwen-Image-Edit) require a source image. A text-only
+ // submission must be rejected up-front (400) — enqueueing it would crash
+ // the runner deep inside the diffusers QwenImageEditPipeline.
+ it('local mode with an edit-only model and no init image returns 400 IMAGE_GEN_EDIT_IMAGE_REQUIRED', async () => {
+ getSettings.mockResolvedValueOnce({ imageGen: { mode: 'local' } }); // qwen uses the flux2 venv — no pythonPath needed
+
+ const response = await request(app)
+ .post('/api/image-gen/generate')
+ .send({ prompt: 'make the sky purple', modelId: 'qwen-image-edit' });
+
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('IMAGE_GEN_EDIT_IMAGE_REQUIRED');
+ expect(response.body.error).toMatch(/source image/i);
+ expect(mediaJobQueue.enqueueJob).not.toHaveBeenCalled();
+ });
+
// Codex with the toggle off rejects up-front rather than enqueueing.
it('codex mode with disabled toggle returns 400 CODEX_IMAGEGEN_DISABLED', async () => {
getSettings.mockResolvedValueOnce({