[PR #1315] [CLOSED] Fix preset role history preservation #5031

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1315
Author: @cha1latte
Created: 5/26/2026
Status: ❌ Closed

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


📝 Commits (7)

  • 290abb0 Fix preset role history preservation
  • dabd112 Fix refactor roleplay panel avatar height
  • 84aaafa Fix roleplay streaming and agent activation
  • 676950b Merge pull request #1317 from cha1latte/fix/issue-1272-roleplay-avatar-height-refactor
  • a38698a Fix import rollback test fixtures (#1321)
  • df0da56 Fix preset role history preservation
  • c975285 Merge remote issue 1273 branch after refactor update

📊 Changes

12 files changed (+213 additions, -26 deletions)

View changed files

➕ pr-evidence/issue-1272-refactor/after.png (+0 -0)
➕ pr-evidence/issue-1272-refactor/before.png (+0 -0)
📝 src-tauri/src/commands/storage/imports/bulk_imports.rs (+10 -10)
📝 src-tauri/src/commands/storage/imports/service_tests.rs (+6 -6)
📝 src/engine/generation/agent-runner.test.ts (+47 -0)
📝 src/engine/generation/agent-runner.ts (+1 -0)
📝 src/engine/generation/prompt-assembly.test.ts (+50 -0)
📝 src/engine/generation/prompt-assembly.ts (+2 -2)
📝 src/features/modes/roleplay/components/ChatRoleplaySurface.tsx (+5 -3)
📝 src/features/modes/roleplay/components/RoleplayModeRoute.tsx (+4 -2)
📝 src/features/modes/shared/chat-ui/components/ChatMessage.tsx (+1 -1)
📝 src/features/runtime/generation/hooks/use-generate.ts (+87 -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.

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.

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 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/1315 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/26/2026 **Status:** ❌ Closed **Base:** `refactor` ← **Head:** `fix/issue-1273-preset-roles` --- ### 📝 Commits (7) - [`290abb0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/290abb006fc069360e5cfb689408197d5d9b6083) Fix preset role history preservation - [`dabd112`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dabd11250dbde146e385969bae882b8782242e4f) Fix refactor roleplay panel avatar height - [`84aaafa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/84aaafa7ea0b1916c2df8cc1460f055504b299b0) Fix roleplay streaming and agent activation - [`676950b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/676950b0b5d44d2bdf3e97b6694ac81bb7e125fe) Merge pull request #1317 from cha1latte/fix/issue-1272-roleplay-avatar-height-refactor - [`a38698a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a38698af5c3c8032db86ab1f924766ce38915e1b) Fix import rollback test fixtures (#1321) - [`df0da56`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df0da56e8e4663fbce2cebedba83ca46295aa2ca) Fix preset role history preservation - [`c975285`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c9752852c996a3e573b28140df283ff711ee8eb3) Merge remote issue 1273 branch after refactor update ### 📊 Changes **12 files changed** (+213 additions, -26 deletions) <details> <summary>View changed files</summary> ➕ `pr-evidence/issue-1272-refactor/after.png` (+0 -0) ➕ `pr-evidence/issue-1272-refactor/before.png` (+0 -0) 📝 `src-tauri/src/commands/storage/imports/bulk_imports.rs` (+10 -10) 📝 `src-tauri/src/commands/storage/imports/service_tests.rs` (+6 -6) 📝 `src/engine/generation/agent-runner.test.ts` (+47 -0) 📝 `src/engine/generation/agent-runner.ts` (+1 -0) 📝 `src/engine/generation/prompt-assembly.test.ts` (+50 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+2 -2) 📝 `src/features/modes/roleplay/components/ChatRoleplaySurface.tsx` (+5 -3) 📝 `src/features/modes/roleplay/components/RoleplayModeRoute.tsx` (+4 -2) 📝 `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` (+1 -1) 📝 `src/features/runtime/generation/hooks/use-generate.ts` (+87 -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. ## 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. 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` 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:38 +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#5031
No description provided.