[GH-ISSUE #5058] Illustrator payload failure nanogpt image #2800

Closed
opened 2026-10-21 05:55:45 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ghost on GitHub (Aug 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5058

Originally assigned to: @SpicyMarinara on GitHub.

Bug: NanoGPT image generation broken — 413 with reference images, and silent response-parsing failure without reference images (regression)

Summary

NanoGPT image generation is broken in two ways, both regressions from a previously working state (was fine a couple updates ago):

  1. With reference images: 413 Request Entity Too Large (FUNCTION_PAYLOAD_TOO_LARGE) — base64 reference images are packed directly into the JSON body with no payload-size guard.
  2. Without reference images: Generation succeeds on NanoGPT's side (image appears in NanoGPT gallery) but Marinara shows a broken image icon with a wall of prompt text, and no image lands in Marinara's gallery. This indicates a response-parsing failure where the image is generated but Marinara cannot read the response.

Environment

  • Marinara Engine version: (Marinara Engine diagnostics
    Version: 2.4.3
    Build: 2.4.3+531e323032f4
    Commit: 531e323032
    OS: Android 17
    Browser / app shell: Mozilla/5.0 (Linux; Android 17; SM-F976U1 Build/CP2A.260605.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/150.0.7871.181 Safari/537.36 MarinaraEngine/Android
    GPU: Adreno (TM) 840
    Active connection: Z.Ai
    Connection provider: custom
    LLM model: glm-5.2
  • Connection type: NanoGPT (nanogpt)
  • Trigger: Illustrator agent image generation via retry route
  • Platform: Android / Termux
  • Connection model: Qwen Image

Error 1 — 413 with reference images

Log entry:

{"level":50,"time":1786793351468,"err":{"type":"Error","message":"NanoGPT image generation failed (413): Request Entity Too Large\n\nFUNCTION_PAYLOAD_TOO_LARGE\n\niad1::n8nxh-1786793350926-531501e1919f\n","stack":"Error: NanoGPT image generation failed (413): Request Entity Too Large\n\nFUNCTION_PAYLOAD_TOO_LARGE\n\niad1::n8nxh-1786793350926-531501e1919f\n\n    at generateNanoGPT (image-generation.js:984:11)\n    at async withConnectionAdmission (connection-admission.js:121:20)\n    at async generateImage (image-generation.js:187:27)\n    at async runMediaGenerationRequest (image-generation-queue.js:41:12)\n    at async generateIllustratorImageVariants (illustrator-image-variants.js:12:20)\n    at async applyRetryResultEffects (retry-agents-route.js:2364:34)\n    at async Object.<anonymous> (retry-agents-route.js:3141:7)"},"msg":"[retry-agents] Illustrator image generation failed"}

Root cause: generateNanoGPT() at packages/server/src/services/image/image-generation.ts:1322–1371 packs reference images as base64 data URLs directly into the JSON request body:

// Line 1336–1344
const references = nanoGPTReferenceImages(request);
if (references.length === 1) {
  body.imageDataUrl = imageDataUrlFromReference(references[0]!);
} else if (references.length > 1) {
  body.imageDataUrls = references.map(imageDataUrlFromReference);
}

The limit is 3 reference images (NANOGPT_REFERENCE_IMAGE_LIMIT = 3, line 528). Base64 encoding adds ~33% overhead, so multiple high-res references easily exceed the serverless function payload limit (~4.5 MB on Vercel-style deployments like NanoGPT's iad1 region). There is no client-side payload-size guard before sending.

Suggested fix: Add a payload-size estimate before sending. If the estimated payload exceeds a threshold (e.g., 4 MB), either downscale reference images, reduce the count, or fail with a descriptive error instead of letting the provider return a cryptic 413.

Error 2 — Broken image without reference images (the bigger issue)

Symptoms:

  • No reference images → generation succeeds on NanoGPT's side (confirmed: image is visible in NanoGPT's gallery)
  • Marinara shows a broken image icon with a wall of prompt text instead of the generated image
  • No image appears in Marinara's gallery
  • This was working a couple updates ago — it's a regression

Likely root cause: The NanoGPT response parser at lines 1365–1370 only handles two response shapes:

// Lines 1365–1370
const data = (await resp.json()) as { data?: Array<{ b64_json?: string; url?: string }> };
const result = data.data?.[0];
if (result?.b64_json) return { base64: result.b64_json, mimeType: "image/png", ext: "png" };
if (result?.url) return downloadImageUrl(result.url, request.privateImageResultOrigin, request.signal);

throw new Error("No image data in NanoGPT response");

If NanoGPT changed their API response format (e.g., returning a different field name, a nested structure, or a URL that fails the downloadImageUrl fetch/SSRF policy), the parser throws "No image data in NanoGPT response", the error is caught in the retry route, and an error event is sent to the client — which renders as the broken image + error text wall.

Notably, the OpenAI parser (lines 966–981) handles three fields (b64_json, image_base64, url) and provides a detailed error message listing the actual response fields. The NanoGPT parser handles only two (b64_json, url) and gives a bare error with no diagnostic info. This asymmetry suggests the NanoGPT parser was not updated to match newer response formats.

Suggested fixes:

  1. Log the raw NanoGPT response body when parsing fails, so the actual response shape can be inspected
  2. Handle additional response fields (e.g., image_base64, image_url, output, result)
  3. If downloadImageUrl is failing, log the specific failure reason (SSRF policy, network error, non-200 status)
  4. Verify that the response_format: "b64_json" parameter (line 1331) is still being honored by NanoGPT's endpoint
  5. Bring the NanoGPT parser up to parity with the OpenAI parser's error reporting (list actual fields)

Steps to reproduce

  1. Configure a NanoGPT image connection in Settings → Connections
  2. Enable the Illustrator agent for a chat
  3. Trigger image generation:
    • With reference images: 413 error in server logs
    • Without reference images: Broken image icon in chat; image exists in NanoGPT gallery but not Marinara's

Expected behavior

  • With refs: Image generates successfully (as it did before recent updates)
  • Without refs: Image generates, downloads/displays in chat, and appears in Marinara's gallery

Additional note — Illustrator agent connection ID mismatch

The Illustrator agent config has two different connection IDs:

  • Top-level connectionId: HiVmezWsvsi-46vhyhEUE
  • settings.imageConnectionId: OHeHzvMw0D_psYgAfxTTs

The retry route resolves the image connection from settings.imageConnectionId (line 499), not the top-level connectionId. If these point to different providers, it could cause confusion about which connection is actually used.

Originally created by @ghost on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5058 Originally assigned to: @SpicyMarinara on GitHub. ## Bug: NanoGPT image generation broken — 413 with reference images, and silent response-parsing failure without reference images (regression) ### Summary NanoGPT image generation is broken in two ways, both regressions from a previously working state (was fine a couple updates ago): 1. **With reference images**: `413 Request Entity Too Large` (`FUNCTION_PAYLOAD_TOO_LARGE`) — base64 reference images are packed directly into the JSON body with no payload-size guard. 2. **Without reference images**: Generation succeeds on NanoGPT's side (image appears in NanoGPT gallery) but Marinara shows a broken image icon with a wall of prompt text, and no image lands in Marinara's gallery. This indicates a response-parsing failure where the image is generated but Marinara cannot read the response. ### Environment - **Marinara Engine version**: *(Marinara Engine diagnostics Version: 2.4.3 Build: 2.4.3+531e323032f4 Commit: 531e323032f4 OS: Android 17 Browser / app shell: Mozilla/5.0 (Linux; Android 17; SM-F976U1 Build/CP2A.260605.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/150.0.7871.181 Safari/537.36 MarinaraEngine/Android GPU: Adreno (TM) 840 Active connection: Z.Ai Connection provider: custom LLM model: glm-5.2* - **Connection type**: NanoGPT (`nanogpt`) - **Trigger**: Illustrator agent image generation via retry route - **Platform**: Android / Termux - **Connection model**: *Qwen Image* ### Error 1 — 413 with reference images **Log entry:** ``` {"level":50,"time":1786793351468,"err":{"type":"Error","message":"NanoGPT image generation failed (413): Request Entity Too Large\n\nFUNCTION_PAYLOAD_TOO_LARGE\n\niad1::n8nxh-1786793350926-531501e1919f\n","stack":"Error: NanoGPT image generation failed (413): Request Entity Too Large\n\nFUNCTION_PAYLOAD_TOO_LARGE\n\niad1::n8nxh-1786793350926-531501e1919f\n\n at generateNanoGPT (image-generation.js:984:11)\n at async withConnectionAdmission (connection-admission.js:121:20)\n at async generateImage (image-generation.js:187:27)\n at async runMediaGenerationRequest (image-generation-queue.js:41:12)\n at async generateIllustratorImageVariants (illustrator-image-variants.js:12:20)\n at async applyRetryResultEffects (retry-agents-route.js:2364:34)\n at async Object.<anonymous> (retry-agents-route.js:3141:7)"},"msg":"[retry-agents] Illustrator image generation failed"} ``` **Root cause:** `generateNanoGPT()` at `packages/server/src/services/image/image-generation.ts:1322–1371` packs reference images as base64 data URLs directly into the JSON request body: ```typescript // Line 1336–1344 const references = nanoGPTReferenceImages(request); if (references.length === 1) { body.imageDataUrl = imageDataUrlFromReference(references[0]!); } else if (references.length > 1) { body.imageDataUrls = references.map(imageDataUrlFromReference); } ``` The limit is 3 reference images (`NANOGPT_REFERENCE_IMAGE_LIMIT = 3`, line 528). Base64 encoding adds ~33% overhead, so multiple high-res references easily exceed the serverless function payload limit (~4.5 MB on Vercel-style deployments like NanoGPT's `iad1` region). There is no client-side payload-size guard before sending. **Suggested fix:** Add a payload-size estimate before sending. If the estimated payload exceeds a threshold (e.g., 4 MB), either downscale reference images, reduce the count, or fail with a descriptive error instead of letting the provider return a cryptic 413. ### Error 2 — Broken image without reference images (the bigger issue) **Symptoms:** - No reference images → generation succeeds on NanoGPT's side (confirmed: image is visible in NanoGPT's gallery) - Marinara shows a broken image icon with a wall of prompt text instead of the generated image - No image appears in Marinara's gallery - This was working a couple updates ago — it's a regression **Likely root cause:** The NanoGPT response parser at lines 1365–1370 only handles two response shapes: ```typescript // Lines 1365–1370 const data = (await resp.json()) as { data?: Array<{ b64_json?: string; url?: string }> }; const result = data.data?.[0]; if (result?.b64_json) return { base64: result.b64_json, mimeType: "image/png", ext: "png" }; if (result?.url) return downloadImageUrl(result.url, request.privateImageResultOrigin, request.signal); throw new Error("No image data in NanoGPT response"); ``` If NanoGPT changed their API response format (e.g., returning a different field name, a nested structure, or a URL that fails the `downloadImageUrl` fetch/SSRF policy), the parser throws `"No image data in NanoGPT response"`, the error is caught in the retry route, and an error event is sent to the client — which renders as the broken image + error text wall. Notably, the OpenAI parser (lines 966–981) handles **three** fields (`b64_json`, `image_base64`, `url`) and provides a detailed error message listing the actual response fields. The NanoGPT parser handles only **two** (`b64_json`, `url`) and gives a bare error with no diagnostic info. This asymmetry suggests the NanoGPT parser was not updated to match newer response formats. **Suggested fixes:** 1. Log the raw NanoGPT response body when parsing fails, so the actual response shape can be inspected 2. Handle additional response fields (e.g., `image_base64`, `image_url`, `output`, `result`) 3. If `downloadImageUrl` is failing, log the specific failure reason (SSRF policy, network error, non-200 status) 4. Verify that the `response_format: "b64_json"` parameter (line 1331) is still being honored by NanoGPT's endpoint 5. Bring the NanoGPT parser up to parity with the OpenAI parser's error reporting (list actual fields) ### Steps to reproduce 1. Configure a NanoGPT image connection in Settings → Connections 2. Enable the Illustrator agent for a chat 3. Trigger image generation: - **With reference images**: 413 error in server logs - **Without reference images**: Broken image icon in chat; image exists in NanoGPT gallery but not Marinara's ### Expected behavior - With refs: Image generates successfully (as it did before recent updates) - Without refs: Image generates, downloads/displays in chat, and appears in Marinara's gallery ### Additional note — Illustrator agent connection ID mismatch The Illustrator agent config has two different connection IDs: - Top-level `connectionId`: `HiVmezWsvsi-46vhyhEUE` - `settings.imageConnectionId`: `OHeHzvMw0D_psYgAfxTTs` The retry route resolves the image connection from `settings.imageConnectionId` (line 499), not the top-level `connectionId`. If these point to different providers, it could cause confusion about which connection is actually used.
bsakaguchi 2026-10-21 05:55:45 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 15, 2026):

I’m taking this one. NanoGPT’s current official image endpoint supports URL responses with base64 fallback and caps image uploads at 4 MB, so I’ll keep the fix provider-specific: bound the JSON reference payload, prefer immediate signed-URL download, harden the fallback parser, and add an end-to-end provider regression.

<!-- gh-comment-id:5302597355 --> @SpicyMarinara commented on GitHub (Aug 15, 2026): I’m taking this one. NanoGPT’s current official image endpoint supports URL responses with base64 fallback and caps image uploads at 4 MB, so I’ll keep the fix provider-specific: bound the JSON reference payload, prefer immediate signed-URL download, harden the fallback parser, and add an end-to-end provider regression.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2800
No description provided.