[PR #78] [MERGED] fix: preserve per-message persona identity across persona switches #4447

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/78
Author: @LukaTheHero
Created: 4/9/2026
Status: ✅ Merged
Merged: 4/9/2026
Merged by: @LukaTheHero

Base: main ← Head: fix/chat-multi-persona-support


📝 Commits (1)

  • a83612f fix: preserve per-message persona identity across persona switches

📊 Changes

7 files changed (+113 additions, -12 deletions)

View changed files

📝 packages/client/src/components/chat/ChatArea.tsx (+10 -1)
📝 packages/client/src/components/chat/ChatMessage.tsx (+17 -3)
📝 packages/client/src/components/chat/ConversationMessage.tsx (+13 -7)
📝 packages/client/src/components/chat/ConversationView.tsx (+12 -0)
📝 packages/client/src/hooks/use-generate.ts (+32 -1)
📝 packages/server/src/routes/generate.routes.ts (+20 -0)
📝 packages/shared/src/types/chat.ts (+9 -0)

📄 Description

Problem

When chatting as one persona and then switching to another mid-conversation, all previous user messages retroactively changed their profile picture and name to the new persona. This made multi-persona conversations confusing — you couldn't tell which persona sent which message.

Root Cause

Persona info (name, avatar, colors) was resolved once from the currently active persona and applied identically to all user messages. Messages had no memory of which persona was active when they were sent.

Solution

Store a personaSnapshot in each user message's extra JSON field at creation time. This snapshot captures the persona's ID, name, avatar URL, and color settings. Rendering now reads from this snapshot first, preserving the original persona's identity on every message.

Changes across 3 packages (7 files):

Shared types (packages/shared/src/types/chat.ts)

  • Added optional personaSnapshot field to MessageExtra interface

Server (packages/server/src/routes/generate.routes.ts)

  • After creating a user message during generation, look up the active persona and store a snapshot in the message's extra via updateMessageExtra

Client (packages/client/)

  • use-generate.ts — Include persona snapshot in the optimistic message (read from React Query cache) so it renders correctly immediately
  • ConversationMessage.tsx — Read extra.personaSnapshot for user messages; fall back to personaInfo prop for older messages
  • ChatMessage.tsx — Same snapshot-first logic for roleplay mode rendering
  • ConversationView.tsx — Break Discord-style message grouping when persona changes between consecutive user messages (always show avatar + name for the new persona)
  • ChatArea.tsx — Break roleplay-mode grouping on persona change

Backward compatibility

  • Existing messages without personaSnapshot gracefully fall back to showing the current active persona (old behavior)
  • No database migration required — uses the existing extra JSON field
  • Build passes cleanly (pnpm check — 0 errors)

🔄 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/78 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 4/9/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `fix/chat-multi-persona-support` --- ### 📝 Commits (1) - [`a83612f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a83612f4cb40b01ca983e4352147dc0a5357a31a) fix: preserve per-message persona identity across persona switches ### 📊 Changes **7 files changed** (+113 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatArea.tsx` (+10 -1) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+17 -3) 📝 `packages/client/src/components/chat/ConversationMessage.tsx` (+13 -7) 📝 `packages/client/src/components/chat/ConversationView.tsx` (+12 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+32 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+20 -0) 📝 `packages/shared/src/types/chat.ts` (+9 -0) </details> ### 📄 Description ## Problem When chatting as one persona and then switching to another mid-conversation, all previous user messages retroactively changed their profile picture and name to the new persona. This made multi-persona conversations confusing — you couldn't tell which persona sent which message. ## Root Cause Persona info (name, avatar, colors) was resolved **once** from the currently active persona and applied identically to **all** user messages. Messages had no memory of which persona was active when they were sent. ## Solution Store a `personaSnapshot` in each user message's `extra` JSON field at creation time. This snapshot captures the persona's ID, name, avatar URL, and color settings. Rendering now reads from this snapshot first, preserving the original persona's identity on every message. ### Changes across 3 packages (7 files): **Shared types** (`packages/shared/src/types/chat.ts`) - Added optional `personaSnapshot` field to `MessageExtra` interface **Server** (`packages/server/src/routes/generate.routes.ts`) - After creating a user message during generation, look up the active persona and store a snapshot in the message's `extra` via `updateMessageExtra` **Client** (`packages/client/`) - **`use-generate.ts`** — Include persona snapshot in the optimistic message (read from React Query cache) so it renders correctly immediately - **`ConversationMessage.tsx`** — Read `extra.personaSnapshot` for user messages; fall back to `personaInfo` prop for older messages - **`ChatMessage.tsx`** — Same snapshot-first logic for roleplay mode rendering - **`ConversationView.tsx`** — Break Discord-style message grouping when persona changes between consecutive user messages (always show avatar + name for the new persona) - **`ChatArea.tsx`** — Break roleplay-mode grouping on persona change ### Backward compatibility - Existing messages without `personaSnapshot` gracefully fall back to showing the current active persona (old behavior) - No database migration required — uses the existing `extra` JSON field - Build passes cleanly (`pnpm check` — 0 errors) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:07:40 +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#4447
No description provided.