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

address review (self): i2i paths drop modelId, codex empty-prompt gate, hardening

[._.]/ Adam Eivy29705e5cd9ec
diff --git a/client/src/hooks/useMediaPreviewActions.js b/client/src/hooks/useMediaPreviewActions.js
index 1ea35418ad..66b39fb3f2 100644
--- a/client/src/hooks/useMediaPreviewActions.js
+++ b/client/src/hooks/useMediaPreviewActions.js
@@ -5,10 +5,12 @@ import { cleanGalleryImage, extractLastFrame } from '../services/apiImageVideo';
import { VIDEO_TILING_ENUM_SET } from '../lib/videoTilingOptions';
// Common image render-setting params shared by the image branch of Remix and by
-// Send-to-image-to-image — both open /media/image with the same fields prefilled
-// and differ only in their discriminator param (`remix` vs `initImageFile`).
-// `(no prompt)` is the metadata-sidecar placeholder for items that lost their
-// prompt — skip it so the next render doesn't start with that literal.
+// Send-to-image-to-image — both open /media/image with these fields prefilled.
+// The callers diverge after: Remix adds `remix`, while Send-to-i2i adds
+// `initImageFile` AND drops `modelId` (i2i may auto-switch backends, so the
+// source's model must not poison the target form). `(no prompt)` is the
+// metadata-sidecar placeholder for items that lost their prompt — skip it so the
+// next render doesn't start with that literal.
function buildImageGenParams(item) {
const params = new URLSearchParams();
if (item.prompt && item.prompt !== '(no prompt)') params.set('prompt', item.prompt);
diff --git a/client/src/lib/imageGenBackends.test.js b/client/src/lib/imageGenBackends.test.js
new file mode 100644
index 0000000000..23a5b6e5ce
--- /dev/null
+++ b/client/src/lib/imageGenBackends.test.js
@@ -0,0 +1,53 @@
+import { describe, it, expect } from 'vitest';
+import {
+ IMAGE_GEN_MODE,
+ I2I_CAPABLE_MODES,
+ isI2iCapableMode,
+ pickI2iMode,
+ deriveAvailableBackends,
+} from './imageGenBackends';
+
+describe('I2I_CAPABLE_MODES / isI2iCapableMode', () => {
+ it('treats local and codex as i2i-capable, external as not', () => {
+ expect(I2I_CAPABLE_MODES).toEqual([IMAGE_GEN_MODE.LOCAL, IMAGE_GEN_MODE.CODEX]);
+ expect(isI2iCapableMode(IMAGE_GEN_MODE.LOCAL)).toBe(true);
+ expect(isI2iCapableMode(IMAGE_GEN_MODE.CODEX)).toBe(true);
+ expect(isI2iCapableMode(IMAGE_GEN_MODE.EXTERNAL)).toBe(false);
+ expect(isI2iCapableMode(undefined)).toBe(false);
+ });
+});
+
+describe('pickI2iMode', () => {
+ const backend = (id) => ({ id });
+
+ it('prefers local when both local and codex are available', () => {
+ expect(pickI2iMode([backend('external'), backend('codex'), backend('local')]))
+ .toBe(IMAGE_GEN_MODE.LOCAL);
+ });
+
+ it('falls back to codex when local is absent', () => {
+ expect(pickI2iMode([backend('external'), backend('codex')])).toBe(IMAGE_GEN_MODE.CODEX);
+ });
+
+ it('returns null when neither i2i backend is installed', () => {
+ expect(pickI2iMode([backend('external')])).toBeNull();
+ expect(pickI2iMode([])).toBeNull();
+ });
+});
+
+describe('deriveAvailableBackends', () => {
+ it('includes only configured backends and respects excludeExternal', () => {
+ const settings = {
+ imageGen: {
+ local: { pythonPath: '/usr/bin/python3' },
+ codex: { enabled: true },
+ external: { sdapiUrl: 'http://localhost:7860' },
+ },
+ };
+ expect(deriveAvailableBackends(settings).map((b) => b.id))
+ .toEqual([IMAGE_GEN_MODE.LOCAL, IMAGE_GEN_MODE.CODEX, IMAGE_GEN_MODE.EXTERNAL]);
+ expect(deriveAvailableBackends(settings, { excludeExternal: true }).map((b) => b.id))
+ .toEqual([IMAGE_GEN_MODE.LOCAL, IMAGE_GEN_MODE.CODEX]);
+ expect(deriveAvailableBackends(undefined)).toEqual([]);
+ });
+});
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index 37c0d7e369..68e455619d 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -402,8 +402,10 @@ export default function ImageGen() {
if (i2iCapable) { wantI2iModeRef.current = false; return; }
if (!availableBackends.length) return; // wait for load
const mode = pickI2iMode(availableBackends);
- if (mode) switchMode(mode);
- wantI2iModeRef.current = false;
+ // Only clear the pending flag once we actually switch — if no i2i backend
+ // exists at first load, leave it set so a later install (Settings drawer
+ // close → reloadBackends) still flips us over.
+ if (mode) { switchMode(mode); wantI2iModeRef.current = false; }
}, [availableBackends, i2iCapable, switchMode]);
// ?lora=<filename> preselects a LoRA when the user clicks "Test" on the
@@ -505,7 +507,7 @@ export default function ImageGen() {
// — gallery PNGs are already baked correct.
const handlePickGalleryInitImage = (item) => {
if (!item?.filename) return;
- if (item.raw) handleRemix(item.raw);
+ if (item.raw) handleRemix(item.raw, { applyModel: false });
revokeIfBlob(initImage.previewUrl);
setInitImage({ source: 'gallery', file: null, name: item.filename, previewUrl: item.previewUrl || `/data/images/${item.filename}` });
};
@@ -541,7 +543,7 @@ export default function ImageGen() {
// upload path — the server has no gallery-basename field for references (unlike
// the init image). Gallery PNGs are already EXIF-correct, so no re-encode.
const galleryImageToFile = async (filename) => {
- const res = await fetch(`/data/images/${filename}`);
+ const res = await fetch(`/data/images/${encodeURIComponent(filename)}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const blob = await res.blob();
return new File([blob], filename, { type: blob.type || 'image/png' });
@@ -604,6 +606,11 @@ export default function ImageGen() {
// 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;
+ // Codex text-to-image (no init image) still needs a prompt — mirror the server
+ // rule (codex.js requires a prompt only when there's no init image) so the user
+ // sees a disabled button + hint instead of a failed job toast. Local runs
+ // unconditionally and external (A1111) accepts an empty prompt, so neither gates.
+ const codexNeedsPrompt = isCodexMode && initImage.source == null && !prompt.trim();
// mflux is the default runner for entries with no explicit `runner` field.
// LoraPicker filters compatible weights itself; we pass the family (for the
// "install one matching X" copy) and the fine-grained compat key (which
@@ -830,8 +837,8 @@ export default function ImageGen() {
// Empty prompt is allowed (e.g. i2i / unconditional generation). The disabled
// submit button blocks clicks, but an Enter keypress in a number input still
// fires onSubmit — gate here too so an edit-only model without a source image
- // hits the inline hint, not a server 400 toast.
- if (editImageMissing) return;
+ // (or codex text-to-image with no prompt) hits the inline hint, not a 400 toast.
+ if (editImageMissing || codexNeedsPrompt) return;
const batchN = isAsyncMode ? Math.max(1, batchCount) : 1;
if (generating) return queueAdditional(batchN);
setGenerating(true);
@@ -958,7 +965,12 @@ export default function ImageGen() {
navigate(`/media/video?${params}`);
};
- const handleRemix = (img) => {
+ // applyModel=false skips restoring the source's modelId — used by the i2i
+ // paths, which are image-driven: switching to the source's model can flip the
+ // active family (e.g. away from FLUX.2), silently unmounting the reference
+ // picker and dropping staged reference slots. Mirrors the cross-page
+ // handleSendToImage, which drops modelId from the nav params for the same reason.
+ const handleRemix = (img, { applyModel = true } = {}) => {
// Preset was already folded into the recorded prompt at submit time;
// clear the picker so the user sees what actually produced the image.
setStylePreset(null);
@@ -970,7 +982,7 @@ export default function ImageGen() {
if (img.quantize) setQuantize(String(img.quantize));
if (img.width) setWidth(img.width);
if (img.height) setHeight(img.height);
- if (img.modelId && models.some((m) => m.id === img.modelId)) setModelId(img.modelId);
+ if (applyModel && img.modelId && models.some((m) => m.id === img.modelId)) setModelId(img.modelId);
// Restore LoRAs from the new `loraFilenames` field; fall back to the
// legacy `loraPaths` (absolute server paths) for older sidecar metadata
@@ -990,9 +1002,10 @@ export default function ImageGen() {
// The i2i init image only applies on an i2i-capable backend (local or codex).
// Switch to one now if installed; otherwise flag the deferred effect to retry
- // once availableBackends resolves. Shared by the in-page send-to-i2i handler
- // and the ?initImageFile URL effect. No-op when already on local/codex, so an
- // explicit codex user stays on codex.
+ // once availableBackends resolves. Called by the in-page send-to-i2i handler;
+ // the cross-page ?initImageFile path instead sets wantI2iModeRef directly and
+ // lets the deferred effect do the switch. No-op when already on local/codex, so
+ // an explicit codex user stays on codex.
const ensureI2iCapableMode = useCallback(() => {
if (i2iCapable) return;
const mode = pickI2iMode(availableBackends);
@@ -1004,7 +1017,7 @@ export default function ImageGen() {
// image as the i2i source on an i2i-capable backend.
const handleSendToImage = (img) => {
if (!img?.filename) return;
- handleRemix(img);
+ handleRemix(img, { applyModel: false });
ensureI2iCapableMode();
revokeIfBlob(initImage.previewUrl);
setInitImage({ source: 'gallery', file: null, name: img.filename, previewUrl: `/data/images/${img.filename}` });
@@ -1197,8 +1210,8 @@ export default function ImageGen() {
<div className="flex items-center gap-2 pt-1 flex-wrap">
<button
type="submit"
- disabled={notConnected || editImageMissing}
- title={editImageMissing ? 'This image-edit model needs a source image — upload one below first' : undefined}
+ disabled={notConnected || editImageMissing || codexNeedsPrompt}
+ title={editImageMissing ? 'This image-edit model needs a source image — upload one below first' : codexNeedsPrompt ? 'Codex text-to-image needs a prompt — add one, or attach a source image to edit' : 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'}
@@ -1207,6 +1220,9 @@ export default function ImageGen() {
{editImageMissing && (
<span className="text-xs text-port-warning">Upload a source image to use this edit model</span>
)}
+ {codexNeedsPrompt && (
+ <span className="text-xs text-port-warning">Codex needs a prompt, or attach a source image to edit</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/server/services/imageGen/codex.js b/server/services/imageGen/codex.js
index 23e7194411..f028c59027 100644
--- a/server/services/imageGen/codex.js
+++ b/server/services/imageGen/codex.js
@@ -139,7 +139,7 @@ const describeFidelity = (strength) => {
// `initImageStrength` is mapped to a fidelity phrase via describeFidelity —
// codex CLI exposes no numeric denoise knob.
export async function generateImage({
- codexPath, model, prompt, width, height, negativePrompt,
+ codexPath, model, prompt = '', width, height, negativePrompt,
initImagePath, initImageStrength,
jobId: providedJobId = null,
cleanC2PA = false,
diff --git a/server/services/imageGen/local.js b/server/services/imageGen/local.js
index c79da5526d..277258c355 100644
--- a/server/services/imageGen/local.js
+++ b/server/services/imageGen/local.js
@@ -404,7 +404,7 @@ export function buildSidecarMeta({
};
}
-export async function generateImage({ pythonPath, prompt, negativePrompt = '', modelId = 'dev', width = 1024, height = 1024, steps, guidance, seed, quantize = '8', loraFilenames = [], loraPaths = [], loraScales = [], initImagePath = null, initImageStrength = null, referenceImagePaths = [], referenceImageStrengths = [], jobId: providedJobId = null, cleanC2PA = false, denoise = false, regenOf = null, upscaleTo = null }) {
+export async function generateImage({ pythonPath, prompt = '', negativePrompt = '', modelId = 'dev', width = 1024, height = 1024, steps, guidance, seed, quantize = '8', loraFilenames = [], loraPaths = [], loraScales = [], initImagePath = null, initImageStrength = null, referenceImagePaths = [], referenceImageStrengths = [], jobId: providedJobId = null, cleanC2PA = false, denoise = false, regenOf = null, upscaleTo = null }) {
// Empty prompt is allowed: img2img / edit / unconditional renders are driven
// by the init image (or run unconditionally), so text isn't required. The
// mflux/diffusers runners accept an empty `--prompt` — the regen pass (#912)