[PR #539] [MERGED] Preserve roleplay prompt boundaries for providers #4661

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/539
Author: @cha1latte
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @cha1latte

Base: main ← Head: fix/issue-520-roleplay-message-roles


📝 Commits (1)

  • 99e9f5a Preserve prompt boundaries in roleplay requests

📊 Changes

4 files changed (+60 additions, -5 deletions)

View changed files

📝 packages/server/src/services/lorebook/prompt-injector.ts (+2 -0)
📝 packages/server/src/services/prompt/assembler.ts (+6 -4)
📝 packages/server/src/services/prompt/merger.ts (+7 -1)
➕ packages/server/test/prompt-message-boundaries.test.ts (+45 -0)

📄 Description

Linked issue

Closes #520

Why this change

  • Roleplay prompts sent through OpenAI-compatible providers could merge post-history prompt instructions, like <output_format>, into the final user/history message. In llama.cpp request logs this made the payload look like one giant user message containing chat history plus formatting instructions instead of keeping those prompt sections separate from chat turns.

What changed

  • Preserve contextKind on assembled prompt sections so prompt blocks stay distinguishable from chat history.
  • Mark depth-injected lorebook messages as injection context.
  • Update adjacent-message merging so same-role messages only merge across compatible context buckets.
  • Add a focused regression test for the reported prompt-boundary collapse and a guard that same-context merging still works.

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

  • Before proof: copied the regression test into a detached upstream/main worktree and ran pnpm --filter @marinara-engine/server exec tsx --test test/prompt-message-boundaries.test.ts; it failed because <output_format> merged into the final <last_message> user turn and lost contextKind.
  • After proof: ran pnpm --filter @marinara-engine/server exec tsx --test test/prompt-message-boundaries.test.ts; both tests passed.
  • Edge case covered: same-role messages from the same context bucket still merge, so normal prompt compaction behavior is preserved.
  • Baseline: pnpm check passed.

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)

N/A - server prompt/request-shaping fix with command proof 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/539 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/7/2026 **Status:** ✅ Merged **Merged:** 5/7/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `main` ← **Head:** `fix/issue-520-roleplay-message-roles` --- ### 📝 Commits (1) - [`99e9f5a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/99e9f5a80bb88cac501a67b4051b02ea23e7cc66) Preserve prompt boundaries in roleplay requests ### 📊 Changes **4 files changed** (+60 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/lorebook/prompt-injector.ts` (+2 -0) 📝 `packages/server/src/services/prompt/assembler.ts` (+6 -4) 📝 `packages/server/src/services/prompt/merger.ts` (+7 -1) ➕ `packages/server/test/prompt-message-boundaries.test.ts` (+45 -0) </details> ### 📄 Description ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #520 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - Roleplay prompts sent through OpenAI-compatible providers could merge post-history prompt instructions, like `<output_format>`, into the final user/history message. In llama.cpp request logs this made the payload look like one giant user message containing chat history plus formatting instructions instead of keeping those prompt sections separate from chat turns. ## What changed <!-- List the key changes in this PR --> - Preserve `contextKind` on assembled prompt sections so prompt blocks stay distinguishable from chat history. - Mark depth-injected lorebook messages as injection context. - Update adjacent-message merging so same-role messages only merge across compatible context buckets. - Add a focused regression test for the reported prompt-boundary collapse and a guard that same-context merging still works. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [x] 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 <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ?? If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - Before proof: copied the regression test into a detached `upstream/main` worktree and ran `pnpm --filter @marinara-engine/server exec tsx --test test/prompt-message-boundaries.test.ts`; it failed because `<output_format>` merged into the final `<last_message>` user turn and lost `contextKind`. - After proof: ran `pnpm --filter @marinara-engine/server exec tsx --test test/prompt-message-boundaries.test.ts`; both tests passed. - Edge case covered: same-role messages from the same context bucket still merge, so normal prompt compaction behavior is preserved. - Baseline: `pnpm check` passed. ## 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) N/A - server prompt/request-shaping fix with command proof above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:09:35 +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#4661
No description provided.