[PR #7516] [MERGED] fix(tracker): keep the outfit in Character Tracker portraits #7770

Closed
opened 2026-10-24 04:07:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7516
Author: @SpicyMarinara
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/7419-tracker-portrait-outfit


📝 Commits (5)

  • c6e72cc fix(tracker): keep the outfit in Character Tracker portraits
  • e5b85df docs(tracker): describe outfit portraits and the new portrait buttons
  • 37ff042 fix(tracker): accept long looks and outfits in the portrait route
  • c8af159 fix(tracker): keep every outfit sentence and protect uploads during portrait generation
  • c22a0fa fix(tracker): keep provider error text out of the portrait route response

📊 Changes

16 files changed (+505 additions, -64 deletions)

View changed files

📝 docs/agents/built-in-agents.md (+1 -1)
📝 docs/roleplay/hud-and-trackers.md (+2 -0)
📝 packages/client/src/components/agents/AgentEditor.tsx (+18 -0)
📝 packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx (+3 -0)
📝 packages/client/src/features/tracker-panel/components/TrackerWindowCharacters.tsx (+5 -0)
📝 packages/client/src/features/tracker-panel/components/character-card/FeaturedCharacterPortrait.tsx (+34 -0)
📝 packages/client/src/features/tracker-panel/components/character-card/FeaturedCharacterTrackerCard.tsx (+3 -0)
📝 packages/client/src/features/tracker-panel/components/controls/TrackerPortraitStage.tsx (+38 -0)
📝 packages/client/src/features/tracker-panel/components/sections/CharacterTrackerPanel.tsx (+5 -0)
📝 packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts (+56 -10)
📝 packages/client/src/localization/locales/en.json (+5 -0)
📝 packages/server/src/routes/avatars.routes.ts (+54 -0)
📝 packages/server/src/routes/generate.routes.ts (+11 -51)
➕ packages/server/src/services/image/tracker-portrait.ts (+147 -0)
📝 packages/shared/src/utils/image-prompt-compiler.ts (+2 -1)
📝 scripts/regressions/image-appearance-game.regression.ts (+121 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7419

Why this change

  • Character Tracker portraits came out nude or in the wrong clothes. The tracker did put the outfit in the prompt, as a wearing … clause, but the portrait prompt compiler drops that clause for the Off, Auto, anime, Danbooru, cinematic, digital-painting and painterly style profiles. Only the coat-and-boots words it recognises survived, and an outfit like "a simple red tunic" vanished entirely, so the image model saw only the look.
  • There was no way to redo a portrait except uploading your own image.

What changed

  • Nothing stops working. Portraits from the look alone are unchanged; existing portraits are not touched.
  • Automatic NPC portraits now include the tracked outfit for every style profile. The outfit goes on its own Outfit: line, and the shared prompt compiler now keeps Outfit: items the same way it keeps Appearance: items. A user who writes Outfit: in a prompt the compiler shortens also keeps it now. An outfit written as several sentences ("Barefoot. Loose linen trousers and a sleeveless grey vest.") is joined into one line, so every part of it survives, not just the first sentence.
  • An outfit or look that the model wrote as something other than text (for example a list) is left out of the portrait instead of crashing the large card or skipping the automatic portrait.
  • New Character Tracker setting Include the outfit in portraits, under Auto-generate NPC avatars, on by default. Turning it off draws automatic portraits from the look alone.
  • A character's large tracker card gets two portrait buttons when the Character Tracker has an image connection: the eye makes a new portrait from the Look, the shirt from the Look and Outfit (shown only when there is an outfit). They use the same image connection, style and size as automatic portraits. The old portrait stays until the new one arrives and stays if it fails; a failure shows a toast. Characters shown with their card's avatar or an expression sprite don't get the buttons, same as the upload button.
  • New route POST /api/avatars/npc/:chatId/generate behind those buttons. In debug mode (or with DEBUG_AGENTS), it logs the final portrait prompt and negative prompt, for automatic portraits too.
  • When making a portrait fails, the toast says "Portrait generation failed. The server log has the details." The image service's own error text stays in the server log, because it can carry upstream response data or local paths.
  • Only one portrait per character is made at a time. A second click while one is still being made (for example after the card was closed and reopened) gets a "Couldn't make a new portrait." toast instead of a second paid image. If you upload your own portrait while a new one is being made, your upload is kept and the new one is not saved.
  • Automatic and manual portraits share one helper, services/image/tracker-portrait.ts, which replaces the inline generation in generate.routes.ts.
  • Docs: Character Tracker settings in docs/agents/built-in-agents.md and the portrait buttons in docs/roleplay/hud-and-trackers.md. Translations: #7517.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent, with results:

  • node ./scripts/run-regressions.mjs --filter scripts/regressions/image-appearance-game.regression.ts: passed. The new #7419 block checks Look vs Look + Outfit vs missing, blank or non-text outfit prompt assembly, that a one-phrase and a multi-sentence outfit both survive compilation in every built-in style profile, and the route: 400 without a tracker image connection, the outfit reaching the image service only for Look + Outfit, the old portrait file kept when the image service fails (and the service's own error text kept out of the response), a second request for the same character refused with 409 while the first is held open (it never reaches the image service), and an upload made during generation kept on disk (the late generation answers 409). With the compiler change reverted, it fails at off: the outfit reaches the image prompt. On the pre-review head it failed at the non-text outfit (replace is not a function), then at off: and the next one (multi-sentence outfit), then at the 409 check (200: a second paid image); with only the upload guard disabled it fails at the late request (200: the upload overwritten).
  • Debug logging probe (scratch script, not committed) at LOG_LEVEL=warn: with debugMode: true the server prints [debug/character-tracker/portrait] prompt: with the outfit in it and the negative prompt; with debugMode: false it prints nothing.
  • Regression filters prompt.regression.ts, tracker, image, avatar, portrait, illustrator, open-issues, agent-activation, spatial-context, localization: all passed (before review fixes). After the review fixes (c22a0fa35): image-appearance-game (1/1), agent-activation (2/2), spatial-context (1/1) and open-issues (1/1) passed again.
  • pnpm lint (server and client tsc, client ESLint): passed, with one existing warning in HomeProfessorMariChat.tsx.
  • pnpm localization:check: passed. Prettier on the changed files: clean.
  • pnpm check (locales, format, lint, e2e and token-estimation types, build): passed on the final code (c22a0fa35), after the review fixes; the only lint output is the existing HomeProfessorMariChat.tsx warning. pnpm localization:check: passed.
  • Local CodeRabbit (coderabbit review --agent --committed): 2 findings, both declined with reasons:
    • "Saved .png may hold JPEG/WebP bytes": the NPC avatar route serves any recognised raster by its detected format (validateImageAssetBuffer in media-file-security.ts exists for exactly this), and the .png name is the existing contract that the on-disk lookups in generate.routes.ts and chats.routes.ts rely on. The automatic path always wrote this way; this PR only moved it.
    • "Two characters with the same name share one portrait file": NPC portraits are keyed by name per chat everywhere (the upload route, automatic portraits, and the name lookups above). Per-character files would break those lookups, and that change is outside this issue.
  • Local CodeRabbit after the review fixes: 6 findings, 1 fixed and 5 declined with reasons:
    • "Write the portrait atomically" (twice): the old automatic code and the upload route write the file the same direct way; this PR's guarantee is that a failed image request keeps the old file, which the regression proves. Not a regression, and out of scope.
    • "A synchronous throw leaves the button stuck": generateAvatar is an async function, so it always returns a promise and .finally always runs.
    • "Shorten the docs paragraph and add translations": the sentences are already short, and the [docs-i18n] follow-up is #7517.
    • "Return a generic error instead of err.message": fixed in c22a0fa35 after the GitHub CodeRabbit review raised it too (CWE-209). Only the two conflict messages are sent as-is; the regression asserts the provider's text stays out of the 502 body.
    • "Guard the route with requirePrivilegedAccess": the global host, IP allowlist, Basic Auth and CSRF hooks already cover every API route. The privileged gate is for admin features (backups, imports, packages, updates); the peer image and chat generation routes don't use it, and adding it would break the buttons for LAN users without an admin secret.

Manual verification notes

  • Manually verify in a browser: in Agents → Character Tracker, turn on Auto-generate NPC avatars, pick an image connection, and check that Include the outfit in portraits shows under it, switched on. Save, reopen the agent, and check the switch kept its state, both on and off.
  • Manually verify: in a Roleplay chat with the Character Tracker on, introduce an NPC with a look and an outfit. Check that the automatic portrait wears the outfit (with debug mode on, the server log shows the final image prompt with the outfit in it). Turn the switch off and check that a new NPC's portrait prompt has no outfit.
  • Manually verify in the Tracker Panel: feature a tracked NPC's card, hover the portrait, and check the eye and shirt buttons at the top right. Click each one and check that a spinner shows, the portrait changes when the image arrives, and the new image shows straight away rather than a cached copy.
  • Manually verify: clear the NPC's Outfit and check that only the eye button remains.
  • Manually verify: break the image connection (wrong URL or key), click a button, and check that a "Couldn't make a new portrait." toast appears and the old portrait stays.
  • Manually verify: with a slow image connection, click the shirt button, switch the card to compact and back, and click it again. Check that the second click shows a "Couldn't make a new portrait." toast saying one is already being made, and that only one image is requested.
  • Manually verify: with a slow image connection, click the shirt button, then upload your own PNG for the same character before the new image arrives. Check that your upload stays after a hard reload.
  • Manually verify: turn on debug mode, click a portrait button, and check that the server log shows the final portrait prompt (with the outfit for the shirt button) and the negative prompt.
  • Manually verify: give an NPC an outfit of several sentences (for example "Barefoot. Loose linen trousers and a sleeveless grey vest.") in the Off or anime style and check that the portrait shows the trousers and vest.
  • Manually verify: a character with a card avatar or an expression sprite shows no portrait buttons; the Character Tracker without an image connection shows none either.
  • Manually verify the same buttons in the Trackers window on a computer, and on a phone (touch shows the buttons without hover), in light and dark mode.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs changed: docs/agents/built-in-agents.md, docs/roleplay/hud-and-trackers.md. Translation follow-up: #7517.

UI evidence (if applicable)

None captured by the agent; see the manual verification steps above.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7516 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/7419-tracker-portrait-outfit` --- ### 📝 Commits (5) - [`c6e72cc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c6e72cc224b3f6f079fca4d8ffab9540ae9a4517) fix(tracker): keep the outfit in Character Tracker portraits - [`e5b85df`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e5b85df662c8c6fd335d15d01823eb88f8c8d256) docs(tracker): describe outfit portraits and the new portrait buttons - [`37ff042`](https://github.com/Pasta-Devs/Marinara-Engine/commit/37ff042cd4e7bd0f964810681d06c4856b5fddb0) fix(tracker): accept long looks and outfits in the portrait route - [`c8af159`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c8af159b4d7928fceae40787c9f51a091deabc4f) fix(tracker): keep every outfit sentence and protect uploads during portrait generation - [`c22a0fa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c22a0fa35c016b92afc472cfc9e785827775d27e) fix(tracker): keep provider error text out of the portrait route response ### 📊 Changes **16 files changed** (+505 additions, -64 deletions) <details> <summary>View changed files</summary> 📝 `docs/agents/built-in-agents.md` (+1 -1) 📝 `docs/roleplay/hud-and-trackers.md` (+2 -0) 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+18 -0) 📝 `packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx` (+3 -0) 📝 `packages/client/src/features/tracker-panel/components/TrackerWindowCharacters.tsx` (+5 -0) 📝 `packages/client/src/features/tracker-panel/components/character-card/FeaturedCharacterPortrait.tsx` (+34 -0) 📝 `packages/client/src/features/tracker-panel/components/character-card/FeaturedCharacterTrackerCard.tsx` (+3 -0) 📝 `packages/client/src/features/tracker-panel/components/controls/TrackerPortraitStage.tsx` (+38 -0) 📝 `packages/client/src/features/tracker-panel/components/sections/CharacterTrackerPanel.tsx` (+5 -0) 📝 `packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts` (+56 -10) 📝 `packages/client/src/localization/locales/en.json` (+5 -0) 📝 `packages/server/src/routes/avatars.routes.ts` (+54 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+11 -51) ➕ `packages/server/src/services/image/tracker-portrait.ts` (+147 -0) 📝 `packages/shared/src/utils/image-prompt-compiler.ts` (+2 -1) 📝 `scripts/regressions/image-appearance-game.regression.ts` (+121 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7419 ## Why this change - Character Tracker portraits came out nude or in the wrong clothes. The tracker did put the outfit in the prompt, as a `wearing …` clause, but the portrait prompt compiler drops that clause for the **Off**, **Auto**, anime, Danbooru, cinematic, digital-painting and painterly style profiles. Only the coat-and-boots words it recognises survived, and an outfit like "a simple red tunic" vanished entirely, so the image model saw only the look. - There was no way to redo a portrait except uploading your own image. ## What changed - **Nothing stops working.** Portraits from the look alone are unchanged; existing portraits are not touched. - Automatic NPC portraits now include the tracked outfit for every style profile. The outfit goes on its own `Outfit:` line, and the shared prompt compiler now keeps `Outfit:` items the same way it keeps `Appearance:` items. A user who writes `Outfit:` in a prompt the compiler shortens also keeps it now. An outfit written as several sentences ("Barefoot. Loose linen trousers and a sleeveless grey vest.") is joined into one line, so every part of it survives, not just the first sentence. - An outfit or look that the model wrote as something other than text (for example a list) is left out of the portrait instead of crashing the large card or skipping the automatic portrait. - New Character Tracker setting **Include the outfit in portraits**, under **Auto-generate NPC avatars**, on by default. Turning it off draws automatic portraits from the look alone. - A character's large tracker card gets two portrait buttons when the Character Tracker has an image connection: the eye makes a new portrait from the **Look**, the shirt from the **Look** and **Outfit** (shown only when there is an outfit). They use the same image connection, style and size as automatic portraits. The old portrait stays until the new one arrives and stays if it fails; a failure shows a toast. Characters shown with their card's avatar or an expression sprite don't get the buttons, same as the upload button. - New route `POST /api/avatars/npc/:chatId/generate` behind those buttons. In debug mode (or with `DEBUG_AGENTS`), it logs the final portrait prompt and negative prompt, for automatic portraits too. - When making a portrait fails, the toast says "Portrait generation failed. The server log has the details." The image service's own error text stays in the server log, because it can carry upstream response data or local paths. - Only one portrait per character is made at a time. A second click while one is still being made (for example after the card was closed and reopened) gets a "Couldn't make a new portrait." toast instead of a second paid image. If you upload your own portrait while a new one is being made, your upload is kept and the new one is not saved. - Automatic and manual portraits share one helper, `services/image/tracker-portrait.ts`, which replaces the inline generation in `generate.routes.ts`. - Docs: Character Tracker settings in `docs/agents/built-in-agents.md` and the portrait buttons in `docs/roleplay/hud-and-trackers.md`. Translations: #7517. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent, with results: - `node ./scripts/run-regressions.mjs --filter scripts/regressions/image-appearance-game.regression.ts`: passed. The new #7419 block checks Look vs Look + Outfit vs missing, blank or non-text outfit prompt assembly, that a one-phrase and a multi-sentence outfit both survive compilation in every built-in style profile, and the route: 400 without a tracker image connection, the outfit reaching the image service only for Look + Outfit, the old portrait file kept when the image service fails (and the service's own error text kept out of the response), a second request for the same character refused with 409 while the first is held open (it never reaches the image service), and an upload made during generation kept on disk (the late generation answers 409). With the compiler change reverted, it fails at `off: the outfit reaches the image prompt`. On the pre-review head it failed at the non-text outfit (`replace is not a function`), then at `off: and the next one` (multi-sentence outfit), then at the 409 check (200: a second paid image); with only the upload guard disabled it fails at the late request (200: the upload overwritten). - Debug logging probe (scratch script, not committed) at `LOG_LEVEL=warn`: with `debugMode: true` the server prints `[debug/character-tracker/portrait] prompt:` with the outfit in it and the negative prompt; with `debugMode: false` it prints nothing. - Regression filters `prompt.regression.ts`, `tracker`, `image`, `avatar`, `portrait`, `illustrator`, `open-issues`, `agent-activation`, `spatial-context`, `localization`: all passed (before review fixes). After the review fixes (c22a0fa35): `image-appearance-game` (1/1), `agent-activation` (2/2), `spatial-context` (1/1) and `open-issues` (1/1) passed again. - `pnpm lint` (server and client tsc, client ESLint): passed, with one existing warning in `HomeProfessorMariChat.tsx`. - `pnpm localization:check`: passed. Prettier on the changed files: clean. - `pnpm check` (locales, format, lint, e2e and token-estimation types, build): passed on the final code (c22a0fa35), after the review fixes; the only lint output is the existing `HomeProfessorMariChat.tsx` warning. `pnpm localization:check`: passed. - Local CodeRabbit (`coderabbit review --agent --committed`): 2 findings, both declined with reasons: - "Saved `.png` may hold JPEG/WebP bytes": the NPC avatar route serves any recognised raster by its detected format (`validateImageAssetBuffer` in `media-file-security.ts` exists for exactly this), and the `.png` name is the existing contract that the on-disk lookups in `generate.routes.ts` and `chats.routes.ts` rely on. The automatic path always wrote this way; this PR only moved it. - "Two characters with the same name share one portrait file": NPC portraits are keyed by name per chat everywhere (the upload route, automatic portraits, and the name lookups above). Per-character files would break those lookups, and that change is outside this issue. - Local CodeRabbit after the review fixes: 6 findings, 1 fixed and 5 declined with reasons: - "Write the portrait atomically" (twice): the old automatic code and the upload route write the file the same direct way; this PR's guarantee is that a failed image request keeps the old file, which the regression proves. Not a regression, and out of scope. - "A synchronous throw leaves the button stuck": `generateAvatar` is an `async` function, so it always returns a promise and `.finally` always runs. - "Shorten the docs paragraph and add translations": the sentences are already short, and the `[docs-i18n]` follow-up is #7517. - "Return a generic error instead of `err.message`": fixed in c22a0fa35 after the GitHub CodeRabbit review raised it too (CWE-209). Only the two conflict messages are sent as-is; the regression asserts the provider's text stays out of the 502 body. - "Guard the route with `requirePrivilegedAccess`": the global host, IP allowlist, Basic Auth and CSRF hooks already cover every API route. The privileged gate is for admin features (backups, imports, packages, updates); the peer image and chat generation routes don't use it, and adding it would break the buttons for LAN users without an admin secret. ### Manual verification notes - Manually verify in a browser: in **Agents → Character Tracker**, turn on **Auto-generate NPC avatars**, pick an image connection, and check that **Include the outfit in portraits** shows under it, switched on. Save, reopen the agent, and check the switch kept its state, both on and off. - Manually verify: in a Roleplay chat with the Character Tracker on, introduce an NPC with a look and an outfit. Check that the automatic portrait wears the outfit (with debug mode on, the server log shows the final image prompt with the outfit in it). Turn the switch off and check that a new NPC's portrait prompt has no outfit. - Manually verify in the Tracker Panel: feature a tracked NPC's card, hover the portrait, and check the eye and shirt buttons at the top right. Click each one and check that a spinner shows, the portrait changes when the image arrives, and the new image shows straight away rather than a cached copy. - Manually verify: clear the NPC's **Outfit** and check that only the eye button remains. - Manually verify: break the image connection (wrong URL or key), click a button, and check that a "Couldn't make a new portrait." toast appears and the old portrait stays. - Manually verify: with a slow image connection, click the shirt button, switch the card to compact and back, and click it again. Check that the second click shows a "Couldn't make a new portrait." toast saying one is already being made, and that only one image is requested. - Manually verify: with a slow image connection, click the shirt button, then upload your own PNG for the same character before the new image arrives. Check that your upload stays after a hard reload. - Manually verify: turn on debug mode, click a portrait button, and check that the server log shows the final portrait prompt (with the outfit for the shirt button) and the negative prompt. - Manually verify: give an NPC an outfit of several sentences (for example "Barefoot. Loose linen trousers and a sleeveless grey vest.") in the Off or anime style and check that the portrait shows the trousers and vest. - Manually verify: a character with a card avatar or an expression sprite shows no portrait buttons; the Character Tracker without an image connection shows none either. - Manually verify the same buttons in the Trackers window on a computer, and on a phone (touch shows the buttons without hover), in light and dark mode. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs changed: `docs/agents/built-in-agents.md`, `docs/roleplay/hud-and-trackers.md`. Translation follow-up: #7517. ## UI evidence (if applicable) None captured by the agent; see the manual verification steps above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:21 +07:00
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#7770
No description provided.