[PR #1322] [MERGED] Fix preset role history preservation #5040

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-1273-preset-roles-clean


📝 Commits (1)

  • f7c1dce Fix preset role history preservation

📊 Changes

2 files changed (+52 additions, -2 deletions)

View changed files

📝 src/engine/generation/prompt-assembly.test.ts (+50 -0)
📝 src/engine/generation/prompt-assembly.ts (+2 -2)

📄 Description

Linked issue

Closes #1273

Why this change

  • Applying a prompt preset in roleplay could cause strict role formatting to rewrite real chat history turns into the alternating slot, which made an assistant greeting/user reply sequence become user/assistant instead of assistant/user.
  • This is a clean replacement for #1315 after that PR's GitHub diff became polluted while avoiding a force-push.

What changed

  • Preserve the actual effective role when strict role formatting encounters a non-mergable role mismatch, instead of rewriting that message to the expected alternating role.
  • Added regression coverage for preset chat history beginning with an assistant greeting, plus the no-preset fallback path.

Refactor impact

Primary owner:

engine generation

Impact areas reviewed:

  • assembleGenerationPrompt strict role formatting
  • prompt preset chat_history marker insertion
  • roleplay fallback prompt assembly

Boundary notes:

  • Stays inside React-free engine generation code.
  • No prompt wording, preset content, UI, storage, schema, dependency, provider, or Rust behavior changes.
  • GitHub PR diff was checked to include only the two prompt assembly files.

Pressure points touched:

  • src/engine/generation/prompt-assembly.ts

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Codex-run machine proof:

  • Reproduced before fix with a Vitest regression row: assistant greeting followed by user reply was collapsed into one user history message.
  • pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts --reporter=json --outputFile=scratch/issue-1273-vitest-clean.json passed after the fix: 8 tests.
  • pnpm check passed locally: architecture, frontend typecheck, Rust cargo check, docs.
  • node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json passed.
  • Bunny review passed before opening: focused diff, direct regression proof, no scope expansion.

Manual verification notes

  • No manual verification required for the core claim; this is covered by engine-level regression tests and pnpm check.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

No docs or release metadata changes needed; this is a narrow engine bugfix.

UI evidence

N/A - no visible UI surface changed. The affected behavior is generated provider message role assembly.


🔄 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/1322 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/26/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-1273-preset-roles-clean` --- ### 📝 Commits (1) - [`f7c1dce`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7c1dcea52e045718f97b35c9b0ac140320e96e1) Fix preset role history preservation ### 📊 Changes **2 files changed** (+52 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation/prompt-assembly.test.ts` (+50 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+2 -2) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #1273 ## Why this change - Applying a prompt preset in roleplay could cause strict role formatting to rewrite real chat history turns into the alternating slot, which made an assistant greeting/user reply sequence become user/assistant instead of assistant/user. - This is a clean replacement for #1315 after that PR's GitHub diff became polluted while avoiding a force-push. ## What changed - Preserve the actual effective role when strict role formatting encounters a non-mergable role mismatch, instead of rewriting that message to the expected alternating role. - Added regression coverage for preset chat history beginning with an assistant greeting, plus the no-preset fallback path. ## Refactor impact Primary owner: engine generation Impact areas reviewed: - `assembleGenerationPrompt` strict role formatting - prompt preset `chat_history` marker insertion - roleplay fallback prompt assembly Boundary notes: - Stays inside React-free engine generation code. - No prompt wording, preset content, UI, storage, schema, dependency, provider, or Rust behavior changes. - GitHub PR diff was checked to include only the two prompt assembly files. Pressure points touched: - `src/engine/generation/prompt-assembly.ts` ## Validation - [ ] `pnpm check` passes locally - [ ] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [ ] `pnpm check:architecture` passes locally - [ ] `pnpm check:docs` passes locally - [ ] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant Codex-run machine proof: - Reproduced before fix with a Vitest regression row: assistant greeting followed by user reply was collapsed into one `user` history message. - `pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts --reporter=json --outputFile=scratch/issue-1273-vitest-clean.json` passed after the fix: 8 tests. - `pnpm check` passed locally: architecture, frontend typecheck, Rust cargo check, docs. - `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` passed. - Bunny review passed before opening: focused diff, direct regression proof, no scope expansion. ### Manual verification notes - No manual verification required for the core claim; this is covered by engine-level regression tests and `pnpm check`. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims No docs or release metadata changes needed; this is a narrow engine bugfix. ## UI evidence N/A - no visible UI surface changed. The affected behavior is generated provider message role assembly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:42 +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#5040
No description provided.