[GH-ISSUE #2997] [Issue]: Retry wrap-format reads the preset wrapFormat for conversation/game modes, but the original generation always uses xml there #1571

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The retry route resolves the agent-context wrap format from the active prompt preset for ALL chat modes. But the main generate route only applies the preset's wrapFormat for roleplay/visual_novel — for conversation and game modes it stays at the hardcoded "xml" default. So for a conversation- or game-mode chat whose active preset declares wrapFormat "markdown" or "none", the retry route hands agents a DIFFERENT wrap format than the original generation did. The Secret Plot State agent-context block is wrapped as markdown/plain on retry but was XML at generation, changing the exact prompt the agent model sees.

How to reproduce (try it yourself)

  1. Create a conversation-mode (or game-mode) chat and set chat.promptPresetId to a preset whose wrapFormat is "markdown" or "none".
  2. Generate a message — agentContext.wrapFormat is "xml" because the main route does not consult the preset wrapFormat for these modes.
  3. Retry agents via POST /retry-agents (with a populated secret-plot state to make the difference observable).

You'll see: the agent context Secret Plot State block is wrapped per the preset (markdown/none) on retry instead of xml.
Expected: retry uses the same "xml" wrap format the original generation used for conversation/game chats.

Where it is
packages/server/src/routes/generate/retry-agents-route.ts:346-362 (resolveRetryAgentWrapFormat) vs packages/server/src/routes/generate.routes.ts:1879 (xml default) + :2170-2172 (gated preset application). Consumed at packages/server/src/services/agents/agent-executor.ts:2124-2131.

What's happening
resolveRetryAgentWrapFormat applies the preset wrapFormat unconditionally, not mirroring the main route's chatMode !== "conversation" && chatMode !== "game" gate that keeps conversation/game on the "xml" default.

Suggested fix
Add an early guard at the top of resolveRetryAgentWrapFormat, before building candidates:

  if (args.chatMode === "conversation" || args.chatMode === "game") {
    return "xml";
  }

Leave the existing candidate loop and final return "xml" unchanged for roleplay/visual_novel. ChatMode has exactly four values, so gating on these two fully and exclusively matches the original-generation behavior; roleplay/visual_novel keep resolving the preset wrapFormat as the main route also does for them.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2997 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The retry route resolves the agent-context wrap format from the active prompt preset for ALL chat modes. But the main generate route only applies the preset's wrapFormat for roleplay/visual_novel — for conversation and game modes it stays at the hardcoded "xml" default. So for a conversation- or game-mode chat whose active preset declares wrapFormat "markdown" or "none", the retry route hands agents a DIFFERENT wrap format than the original generation did. The Secret Plot State agent-context block is wrapped as markdown/plain on retry but was XML at generation, changing the exact prompt the agent model sees. **How to reproduce (try it yourself)** 1. Create a conversation-mode (or game-mode) chat and set chat.promptPresetId to a preset whose wrapFormat is "markdown" or "none". 2. Generate a message — agentContext.wrapFormat is "xml" because the main route does not consult the preset wrapFormat for these modes. 3. Retry agents via POST /retry-agents (with a populated secret-plot state to make the difference observable). You'll see: the agent context Secret Plot State block is wrapped per the preset (markdown/none) on retry instead of xml. Expected: retry uses the same "xml" wrap format the original generation used for conversation/game chats. **Where it is** `packages/server/src/routes/generate/retry-agents-route.ts:346-362` (`resolveRetryAgentWrapFormat`) vs `packages/server/src/routes/generate.routes.ts:1879` (xml default) + `:2170-2172` (gated preset application). Consumed at `packages/server/src/services/agents/agent-executor.ts:2124-2131`. **What's happening** `resolveRetryAgentWrapFormat` applies the preset wrapFormat unconditionally, not mirroring the main route's `chatMode !== "conversation" && chatMode !== "game"` gate that keeps conversation/game on the "xml" default. **Suggested fix** Add an early guard at the top of `resolveRetryAgentWrapFormat`, before building candidates: ```ts if (args.chatMode === "conversation" || args.chatMode === "game") { return "xml"; } ``` Leave the existing candidate loop and final `return "xml"` unchanged for roleplay/visual_novel. ChatMode has exactly four values, so gating on these two fully and exclusively matches the original-generation behavior; roleplay/visual_novel keep resolving the preset wrapFormat as the main route also does for them. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832282692 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1571
No description provided.