[GH-ISSUE #2289] [Issue]: strictRoleFormatting is gated to roleplay mode, producing malformed Anthropic and Google requests in conversation/game/visual_novel modes #1127

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

The refactor only enforces strict role formatting when chatMode is roleplay, but the default preset ships strictRoleFormatting true and the default chat mode is conversation. When a depth-injected system message lands between two same-role turns, the Anthropic and Google request builders emit adjacent same-role turns and the API rejects them.

Expected behavior

strictRoleFormatting should apply whenever the parameter is true regardless of chat mode (as on main), coercing mid-history system messages and forcing user/assistant alternation, so Anthropic/Google requests stay valid.

Actual behavior

In conversation/game/visual_novel modes the refactor takes the mergeAdjacentMessages branch, which only merges literally adjacent same-role messages and never coerces system to user. The Rust providers do not compensate (Anthropic hoists system and appends the rest with no consecutive-role merge; Google filters system with no merge), so author-note and lorebook depth injections can yield two adjacent same-role turns and a provider rejection ("roles must alternate").

Steps to reproduce

  1. Use the default preset (strictRoleFormatting: true) in the default conversation mode with an Anthropic or Google connection.
  2. Add an author's note or a depth-injected lorebook entry (system role) so a system message lands between same-role turns.
  3. Generate and observe the provider rejects the request for non-alternating roles.

Impact area

  • Chat mode
  • Game mode
  • React-free engine behavior, contracts, agents, or capability ports
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Regression notes

Worked on main. Main runs enforceStrictRoles whenever strictRoleFormatting is true with no mode condition (packages/server/src/services/prompt/assembler.ts:470-472,724-726), the default preset ships it true (db/default-preset.json:14), and the Anthropic provider also merges consecutive messages as a safety net (anthropic.provider.ts:42-43,267-284). The refactor gates it to chatMode === "roleplay" && !individualGroupTarget (src/engine/generation/prompt-assembly.ts:3099-3100), default mode is conversation (:2839), and mergeAdjacentMessages never coerces system to user (src/engine/generation-core/prompt/merger.ts:29-31). Rust builders do not merge consecutive roles (crates/llm/src/lib.rs:2116-2147 Anthropic, :2456-2483 Google). Conditional on a hoisted system sitting between same-role neighbors, which author notes (default depth 4) and lorebook depth entries make realistic.

Environment

  • Branch or commit: refactor @ 5ddb9840 (compared against main @ b4ab97f)
  • Run mode: Tauri desktop
  • OS + version: Windows 11
  • Node + pnpm versions: not relevant (static source comparison)
  • Rust version, if relevant: not relevant (static source comparison)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: see body

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2289 Originally assigned to: @Romuromylus on GitHub. ## Summary The refactor only enforces strict role formatting when chatMode is roleplay, but the default preset ships strictRoleFormatting true and the default chat mode is conversation. When a depth-injected system message lands between two same-role turns, the Anthropic and Google request builders emit adjacent same-role turns and the API rejects them. ## Expected behavior strictRoleFormatting should apply whenever the parameter is true regardless of chat mode (as on main), coercing mid-history system messages and forcing user/assistant alternation, so Anthropic/Google requests stay valid. ## Actual behavior In conversation/game/visual_novel modes the refactor takes the mergeAdjacentMessages branch, which only merges literally adjacent same-role messages and never coerces system to user. The Rust providers do not compensate (Anthropic hoists system and appends the rest with no consecutive-role merge; Google filters system with no merge), so author-note and lorebook depth injections can yield two adjacent same-role turns and a provider rejection ("roles must alternate"). ## Steps to reproduce 1. Use the default preset (strictRoleFormatting: true) in the default conversation mode with an Anthropic or Google connection. 2. Add an author's note or a depth-injected lorebook entry (system role) so a system message lands between same-role turns. 3. Generate and observe the provider rejects the request for non-alternating roles. ## Impact area - [x] Chat mode - [x] Game mode - [x] React-free engine behavior, contracts, agents, or capability ports - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Regression notes Worked on main. Main runs `enforceStrictRoles` whenever `strictRoleFormatting` is true with no mode condition (`packages/server/src/services/prompt/assembler.ts:470-472,724-726`), the default preset ships it true (`db/default-preset.json:14`), and the Anthropic provider also merges consecutive messages as a safety net (`anthropic.provider.ts:42-43,267-284`). The refactor gates it to `chatMode === "roleplay" && !individualGroupTarget` (`src/engine/generation/prompt-assembly.ts:3099-3100`), default mode is conversation (`:2839`), and `mergeAdjacentMessages` never coerces system to user (`src/engine/generation-core/prompt/merger.ts:29-31`). Rust builders do not merge consecutive roles (`crates/llm/src/lib.rs:2116-2147` Anthropic, `:2456-2483` Google). Conditional on a hoisted system sitting between same-role neighbors, which author notes (default depth 4) and lorebook depth entries make realistic. ## Environment - Branch or commit: refactor @ 5ddb9840 (compared against main @ b4ab97f) - Run mode: Tauri desktop - OS + version: Windows 11 - Node + pnpm versions: not relevant (static source comparison) - Rust version, if relevant: not relevant (static source comparison) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: see body ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:27:28 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2395, merged into refactor.

<!-- gh-comment-id:4637901392 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2395, merged into `refactor`.
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#1127
No description provided.