[PR #354] [MERGED] fix(agents): load available sprites and validate expressions in retry-agents path #4576

Closed
opened 2026-10-22 04:08:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/354
Author: @Lochalan
Created: 5/2/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @SpicyMarinara

Base: main ← Head: fix/retry-agents-expression-validation


📝 Commits (1)

  • 6517608 fix(agents): load available sprites and validate expressions in retry-agents path

📊 Changes

1 file changed (+134 additions, -0 deletions)

View changed files

📝 packages/server/src/routes/generate/retry-agents-route.ts (+134 -0)

📄 Description

Linked issue

Closes #353

Why this change

When manually re-running the Expression Engine via the retry button, the agent hallucinates expression names that don't exist as sprite files (e.g. "intense_focus", "intrigued"). The sprite silently fails to update. This is because retry-agents-route.ts never loads available sprites into the agent context, has no validation, and sends unvalidated results to the client before any checks run.

What changed

Three fixes in packages/server/src/routes/generate/retry-agents-route.ts:

  • buildRetryAgentContext() now loads _availableSprites (and _availableBackgrounds) from the filesystem when the expression/background agent is being retried, matching the logic in generate.routes.ts
  • Expression results are validated against available sprite files before the SSE agent_result event is sent to the client (case-insensitive matching with substring fallback)
  • applyRetryResultEffects() now has a sprite_change handler that persists validated expressions to message and swipe extra

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

Manual verification notes

  • Ran pnpm check — passes with 0 errors (1 pre-existing warning in GameNarration.tsx, unrelated)
  • Started the app with pnpm dev:server, opened a roleplay chat with a character that has sprite files
  • Clicked the "Agents & Actions" button → "Re-run trackers" multiple times
  • Before fix: agent returned non-existent expressions like "intense_focus", sprite did not change
  • After fix: agent returns only valid expressions matching actual sprite filenames, sprite updates correctly on each re-run
  • Did not test Docker as I run from source

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Before

image

After

Screenshot 2026-05-02 202757

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation and normalization of sprite expression changes during retries for consistent results.
    • Better resolution of character identifiers with case-insensitive and sanitized matching for accurate sprite updates.
    • Persisted validated sprite expressions so choices remain consistent across messages and swipe views.
    • Filtered out unknown characters and malformed expressions to prevent incorrect sprite changes.
    • Ensured available sprites and backgrounds are loaded during retries so relevant options display correctly.

🔄 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/354 **Author:** [@Lochalan](https://github.com/Lochalan) **Created:** 5/2/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `fix/retry-agents-expression-validation` --- ### 📝 Commits (1) - [`6517608`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6517608c1e57a8f258f182cdcbf55fe0b3081417) fix(agents): load available sprites and validate expressions in retry-agents path ### 📊 Changes **1 file changed** (+134 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+134 -0) </details> ### 📄 Description ## Linked issue Closes #353 ## Why this change When manually re-running the Expression Engine via the retry button, the agent hallucinates expression names that don't exist as sprite files (e.g. "intense_focus", "intrigued"). The sprite silently fails to update. This is because `retry-agents-route.ts` never loads available sprites into the agent context, has no validation, and sends unvalidated results to the client before any checks run. ## What changed Three fixes in `packages/server/src/routes/generate/retry-agents-route.ts`: - `buildRetryAgentContext()` now loads `_availableSprites` (and `_availableBackgrounds`) from the filesystem when the expression/background agent is being retried, matching the logic in `generate.routes.ts` - Expression results are validated against available sprite files **before** the SSE `agent_result` event is sent to the client (case-insensitive matching with substring fallback) - `applyRetryResultEffects()` now has a `sprite_change` handler that persists validated expressions to message and swipe extra ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Ran `pnpm check` — passes with 0 errors (1 pre-existing warning in GameNarration.tsx, unrelated) - Started the app with `pnpm dev:server`, opened a roleplay chat with a character that has sprite files - Clicked the "Agents & Actions" button → "Re-run trackers" multiple times - Before fix: agent returned non-existent expressions like "intense_focus", sprite did not change - After fix: agent returns only valid expressions matching actual sprite filenames, sprite updates correctly on each re-run - Did not test Docker as I run from source ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) ### Before <img width="462" height="203" alt="image" src="https://github.com/user-attachments/assets/7032e287-2d5c-47da-843e-def71509f382" /> ### After <img width="455" height="153" alt="Screenshot 2026-05-02 202757" src="https://github.com/user-attachments/assets/58916bfe-6367-4c19-972f-a228481036b2" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved validation and normalization of sprite expression changes during retries for consistent results. * Better resolution of character identifiers with case-insensitive and sanitized matching for accurate sprite updates. * Persisted validated sprite expressions so choices remain consistent across messages and swipe views. * Filtered out unknown characters and malformed expressions to prevent incorrect sprite changes. * Ensured available sprites and backgrounds are loaded during retries so relevant options display correctly. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:52 +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#4576
No description provided.