[GH-ISSUE #2759] [Issue]: Image-gen prompt/output correctness nits — orientation ignored, MIME mislabel, negatives, wrong-face reference #1398

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

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2759

Originally assigned to: @SpicyMarinara on GitHub.

Summary

A set of lower-impact image-generation prompt/output correctness issues.

Sub-bug 1: aspectRatio ignored (#59)

  • How it breaks: The illustrator agent is instructed (and spends tokens) to emit aspectRatio, but the in-chat illustration path always uses the fixed imageSettings.illustration.width/height and never reads illData.aspectRatio (grep: read nowhere). A 'portrait' scene renders at the global landscape resolution.

Sub-bug 2: Wrong-face reference (#54)

  • How it breaks: buildNameAliases adds every >=4-char name token as a standalone alias; the prompt-text pass attaches that character's reference image whenever the alias word-boundary-matches anywhere in the entire assistant turn. A character named with a dictionary word (Rose, Hunter, Grace) whose word appears for unrelated reasons gets their face attached as a likeness reference. (Gated behind useAvatarReferences/includeCharacterAppearance.)

Sub-bug 3: MIME mislabel (#22)

  • How it breaks: detectImageMimeType returns 'image/png' as an unconditional default, making the declared/content-type fallbacks dead code; on the OpenRouter raw-bytes path an AVIF/BMP image is saved/served as .png/image/png.

Sub-bug 4: Negative tag dup/separator (#57)

  • How it breaks: Natural-mode profiles don't split comma tag lists, so each negative source collapses to one fragment; cross-source duplicates aren't deduped and sources are joined with '. ' instead of ', '. Wasted negative-prompt tokens.

Sub-bug 5: Prefix tag dup (#58)

  • How it breaks: hard-prefix and body fragments are deduped with separate seen-sets, so a user promptPrefix tag that also appears in profile/positive tags is duplicated in the final prompt.
  • How it breaks: saveImageToDisk does join(GALLERY_DIR, chatId) + writeFileSync with no assertInsideDir and no temp-file+rename. chatId is validated upstream (low traversal risk), but the function is unguarded and the gallery DB row can reference a truncated file on crash.

Suggested Fix

  • Consume illData.aspectRatio to pick width/height (or remove it from the manifest/schema to stop wasting tokens).
  • For the prompt-text reference scan, require the full normalized name (not a single short token), or restrict single-token matching to explicit requestedNames; scope the scan to the scene prompt.
  • Have detectImageMimeType return null when no signature matches so fallbacks run, or prefer the response content-type.
  • Split negatives on commas regardless of mode, dedupe per-tag, join with ', '.
  • Dedupe [...hardPrefix, ...positiveFragments] with a single shared seen-set.
  • Add assertInsideDir(GALLERY_DIR, dir) and write to a temp file then renameSync.

Verification checklist (all manual)

  • Verify a 'portrait' illustrator scene renders at portrait dimensions (or aspectRatio removed from schema)
  • Verify a dictionary-word-named character is not attached as a reference for unrelated mentions
  • Verify AVIF/non-png provider output is labeled with the correct MIME/extension
  • Verify negative prompts have no duplicate tags and use a comma separator
  • Verify a promptPrefix tag overlapping profile tags is not duplicated
  • Verify gallery writes are atomic and path-validated
  • Run pnpm check

Affected files

  • packages/shared/src/features/agents/illustrator/manifest.ts
  • packages/server/src/routes/generate/illustrator-references.ts
  • packages/server/src/services/image/image-generation.ts
  • packages/shared/src/utils/image-prompt-compiler.ts

Audit provenance

Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged staging tree. Severity: LOW.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2759 Originally assigned to: @SpicyMarinara on GitHub. ## Summary A set of lower-impact image-generation prompt/output correctness issues. ## Sub-bug 1: aspectRatio ignored (#59) - **How it breaks:** The illustrator agent is instructed (and spends tokens) to emit `aspectRatio`, but the in-chat illustration path always uses the fixed `imageSettings.illustration.width/height` and never reads `illData.aspectRatio` (grep: read nowhere). A 'portrait' scene renders at the global landscape resolution. ## Sub-bug 2: Wrong-face reference (#54) - **How it breaks:** `buildNameAliases` adds every >=4-char name token as a standalone alias; the prompt-text pass attaches that character's reference image whenever the alias word-boundary-matches anywhere in the entire assistant turn. A character named with a dictionary word (Rose, Hunter, Grace) whose word appears for unrelated reasons gets their face attached as a likeness reference. (Gated behind useAvatarReferences/includeCharacterAppearance.) ## Sub-bug 3: MIME mislabel (#22) - **How it breaks:** `detectImageMimeType` returns 'image/png' as an unconditional default, making the declared/content-type fallbacks dead code; on the OpenRouter raw-bytes path an AVIF/BMP image is saved/served as .png/image/png. ## Sub-bug 4: Negative tag dup/separator (#57) - **How it breaks:** Natural-mode profiles don't split comma tag lists, so each negative source collapses to one fragment; cross-source duplicates aren't deduped and sources are joined with '. ' instead of ', '. Wasted negative-prompt tokens. ## Sub-bug 5: Prefix tag dup (#58) - **How it breaks:** hard-prefix and body fragments are deduped with separate seen-sets, so a user promptPrefix tag that also appears in profile/positive tags is duplicated in the final prompt. ## Sub-bug 6: Gallery write path/atomicity (#20/#21) - **How it breaks:** `saveImageToDisk` does `join(GALLERY_DIR, chatId)` + `writeFileSync` with no `assertInsideDir` and no temp-file+rename. chatId is validated upstream (low traversal risk), but the function is unguarded and the gallery DB row can reference a truncated file on crash. ## Suggested Fix - Consume `illData.aspectRatio` to pick width/height (or remove it from the manifest/schema to stop wasting tokens). - For the prompt-text reference scan, require the full normalized name (not a single short token), or restrict single-token matching to explicit requestedNames; scope the scan to the scene prompt. - Have `detectImageMimeType` return null when no signature matches so fallbacks run, or prefer the response content-type. - Split negatives on commas regardless of mode, dedupe per-tag, join with ', '. - Dedupe `[...hardPrefix, ...positiveFragments]` with a single shared seen-set. - Add `assertInsideDir(GALLERY_DIR, dir)` and write to a temp file then renameSync. ## Verification checklist (all manual) - [ ] Verify a 'portrait' illustrator scene renders at portrait dimensions (or aspectRatio removed from schema) - [ ] Verify a dictionary-word-named character is not attached as a reference for unrelated mentions - [ ] Verify AVIF/non-png provider output is labeled with the correct MIME/extension - [ ] Verify negative prompts have no duplicate tags and use a comma separator - [ ] Verify a promptPrefix tag overlapping profile tags is not duplicated - [ ] Verify gallery writes are atomic and path-validated - [ ] Run `pnpm check` --- ### Affected files - `packages/shared/src/features/agents/illustrator/manifest.ts` - `packages/server/src/routes/generate/illustrator-references.ts` - `packages/server/src/services/image/image-generation.ts` - `packages/shared/src/utils/image-prompt-compiler.ts` ### Audit provenance Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged `staging` tree. Severity: **LOW**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed on PR #2747. Fixed Illustrator aspectRatio sizing, tightened character reference matching so prompt-text scans use full-name aliases, made generated-image MIME detection nullable with AVIF/BMP support and explicit fallbacks, made gallery image writes path-contained and atomic, and cleaned image prompt compiler negative/prefix dedupe behavior. Validation so far: git diff --check. Full pnpm checks are intentionally deferred until the issue sweep is complete.

<!-- gh-comment-id:4763345595 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on PR #2747. Fixed Illustrator aspectRatio sizing, tightened character reference matching so prompt-text scans use full-name aliases, made generated-image MIME detection nullable with AVIF/BMP support and explicit fallbacks, made gallery image writes path-contained and atomic, and cleaned image prompt compiler negative/prefix dedupe behavior. Validation so far: git diff --check. Full pnpm checks are intentionally deferred until the issue sweep is complete.
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#1398
No description provided.