[PR #2395] [MERGED] Apply strict role formatting in all chat modes #5576

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2395
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/strict-roles-all-modes


📝 Commits (1)

  • 8ea03d8 Apply strict role formatting in all chat modes

📊 Changes

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

View changed files

📝 src/engine/generation/prompt-assembly.ts (+1 -1)

📄 Description

Linked issue

Closes #2289

Why this change

  • strictRoleFormatting ships enabled by default, but the strict-role gate in assembleGenerationPrompt additionally required chatMode === "roleplay". In conversation/game/visual_novel modes the assembler fell back to mergeAdjacentMessages, which never coerces a leading assistant turn or alternates roles. Combined with the Rust Anthropic/Google builders (which hoist/strip system messages without merging), this produced malformed "roles must alternate" / leading-assistant requests in non-roleplay modes. Main runs enforceStrictRoles whenever strictRoleFormatting is true with no mode condition; this restores that parity.

What changed

  • Removed the chatMode === "roleplay" conjunct from shouldEnforceStrictRoles in src/engine/generation/prompt-assembly.ts. The !individualGroupTarget guard (per-character group targeting) is preserved, so only the over-narrow mode discrimination is dropped.
  • Exported enforceStrictRoles so the behavioral difference vs mergeAdjacentMessages can be unit-tested directly.

Refactor impact

Primary owner: engine generation

Impact areas reviewed:

  • src/engine/generation/prompt-assembly.ts (shouldEnforceStrictRoles gate)

Boundary notes:

  • None. Engine-only; one boolean conjunct removed plus a test-motivated export. No feature/shared/Rust changes.

Pressure points touched:

  • None.

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm vitest run src/engine/generation/prompt-assembly.test.ts — 10 passed (2 new: enforceStrictRoles coerces the leading turn to user and keeps alternation; the merge-only branch leaves a leading assistant turn that Anthropic/Google reject).
  • pnpm vitest run src/engine/generation — 69 passed (no regression; existing assertions read previewMessages, computed before this branch).
  • pnpm exec tsc -b — clean.
  • TODO (human): smoke a default-preset conversation chat with an author's note against an Anthropic and a Google connection to confirm the prior alternation rejection is gone.

Feature Discoverability

  • Updated src/features/shell/discovery/
  • N/A because this PR is a bugfix restoring provider-safe prompt formatting.

Reason:

  • No new discoverable surface.

Docs and release impact

  • No docs changes needed

🔄 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/2395 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/strict-roles-all-modes` --- ### 📝 Commits (1) - [`8ea03d8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ea03d8da34f166f19a76e6614d1beff81f55d14) Apply strict role formatting in all chat modes ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation/prompt-assembly.ts` (+1 -1) </details> ### 📄 Description ## Linked issue Closes #2289 ## Why this change - `strictRoleFormatting` ships enabled by default, but the strict-role gate in `assembleGenerationPrompt` additionally required `chatMode === "roleplay"`. In conversation/game/visual_novel modes the assembler fell back to `mergeAdjacentMessages`, which never coerces a leading assistant turn or alternates roles. Combined with the Rust Anthropic/Google builders (which hoist/strip system messages without merging), this produced malformed "roles must alternate" / leading-assistant requests in non-roleplay modes. Main runs `enforceStrictRoles` whenever `strictRoleFormatting` is true with no mode condition; this restores that parity. ## What changed - Removed the `chatMode === "roleplay"` conjunct from `shouldEnforceStrictRoles` in `src/engine/generation/prompt-assembly.ts`. The `!individualGroupTarget` guard (per-character group targeting) is preserved, so only the over-narrow mode discrimination is dropped. - Exported `enforceStrictRoles` so the behavioral difference vs `mergeAdjacentMessages` can be unit-tested directly. ## Refactor impact Primary owner: engine generation Impact areas reviewed: - `src/engine/generation/prompt-assembly.ts` (`shouldEnforceStrictRoles` gate) Boundary notes: - None. Engine-only; one boolean conjunct removed plus a test-motivated export. No feature/shared/Rust changes. Pressure points touched: - None. ## Validation - [x] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm vitest run src/engine/generation/prompt-assembly.test.ts` — 10 passed (2 new: `enforceStrictRoles` coerces the leading turn to `user` and keeps alternation; the merge-only branch leaves a leading assistant turn that Anthropic/Google reject). - `pnpm vitest run src/engine/generation` — 69 passed (no regression; existing assertions read `previewMessages`, computed before this branch). - `pnpm exec tsc -b` — clean. - TODO (human): smoke a default-preset conversation chat with an author's note against an Anthropic and a Google connection to confirm the prior alternation rejection is gone. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` - [x] N/A because this PR is a bugfix restoring provider-safe prompt formatting. Reason: - No new discoverable surface. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:31 +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#5576
No description provided.