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 single-LoRA image-gen submit failing validation over multipart

[._.]/ Adam Eivy9d3f80b95a23
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 44875f302c..3e78b240ec 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -18,6 +18,7 @@
## Fixed
+- **Single LoRA + init/reference image no longer fails validation** — submitting a local FLUX render with exactly one LoRA selected *and* an init or reference image attached used to 400 with "expected array, received string." The multipart path sends one LoRA as a bare repeated field (the parser only builds an array for two or more), and the route never wrapped it before Zod validation. Single-LoRA submissions over multipart now coerce correctly (matching the existing reference-strengths handling). Two-or-more LoRAs and the JSON path were always fine. (`server/routes/imageGen.js`)
- **Workspace-root validation on git/scaffold routes** — git operations and app scaffolding refuse paths outside allowed workspace roots; file staging uses literal pathspecs (no git glob expansion); `env` removed from the shell command allowlist so process secrets can't land in persisted job output.
- **Route validation + linkable tabs** — jira, loops, CoS, digital-twin, automation-schedule, and history inputs are now Zod-validated; Prompt Manager and Messages triage tabs live in the URL (deep-linkable); previously-swallowed client errors are logged.
- **Helper consolidation** — filename sanitization and MIME maps unified in fileUtils (was 3 copies); GSD/app document saves use atomic writes; client components use the canonical formatters and shared command API instead of local re-implementations.
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index 3c43277bce..2beda4f323 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -134,6 +134,17 @@ function coerceFormFields(body) {
const raw = Array.isArray(body.referenceStrengths) ? body.referenceStrengths : [body.referenceStrengths];
body.referenceStrengths = raw.map((v) => (typeof v === 'string' && v !== '' ? Number(v) : v));
}
+ // LoRA fields are repeated multipart keys (one per selected LoRA). A SINGLE
+ // selected LoRA arrives as a bare string, not a one-element array — wrap it
+ // so Zod's `z.array(...)` accepts it. `loraScales` numbers also arrive as
+ // strings, so coerce element-wise like referenceStrengths above.
+ for (const f of ['loraFilenames', 'loraPaths']) {
+ if (body[f] != null && !Array.isArray(body[f])) body[f] = [body[f]];
+ }
+ if (body.loraScales != null) {
+ const raw = Array.isArray(body.loraScales) ? body.loraScales : [body.loraScales];
+ body.loraScales = raw.map((v) => (typeof v === 'string' && v !== '' ? Number(v) : v));
+ }
// Multipart sends checkbox values as 'true' / 'false' strings; coerce to
// bool so Zod's `z.boolean()` accepts them.
for (const f of ['cleanC2PA', 'denoise', 'autoClean']) {
diff --git a/server/routes/imageGen.multipart.test.js b/server/routes/imageGen.multipart.test.js
index 3c704add06..78f6e6fd16 100644
--- a/server/routes/imageGen.multipart.test.js
+++ b/server/routes/imageGen.multipart.test.js
@@ -251,6 +251,28 @@ describe('POST /api/image-gen/generate — multipart reference-image packing', (
expect(enqueueJob).not.toHaveBeenCalled();
});
+ // Regression: a SINGLE selected LoRA arrives over multipart as a bare
+ // string (multer only builds an array for 2+ repeated keys). coerceFormFields
+ // must wrap it so Zod's `z.array(...)` accepts it — otherwise the request
+ // 400s with "expected array, received string" + a bogus "<=8 characters"
+ // (the .max(8) LoRA-count applied to the string's length).
+ it('accepts a single LoRA (bare-string multipart fields) alongside an init image', async () => {
+ const res = await postMultipart(app, '/api/image-gen/generate', [
+ { name: 'prompt', value: 'single lora i2i' },
+ { name: 'modelId', value: 'dev' },
+ { name: 'loraFilenames', value: 'Hyperdetailed Colored Pencil.safetensors' },
+ { name: 'loraScales', value: '0.9' },
+ { 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;
+ // The single scale coerced from string to number, not left as '0.9'.
+ expect(params.loraScales).toEqual([0.9]);
+ });
+
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' },