[PR #3221] [MERGED] feat: Reactions command toggle + fix group reaction attribution (#3219, #3220) #5846

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

📋 Pull Request Information

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

Base: staging ← Head: fix/react-toggle-and-group-attribution


📝 Commits (5)

  • e3b8c04 feat: Reactions per-command toggle + fix group react attribution to first character (#3219, #3220)
  • 254ef44 fix: gate group react placement guidance to merged mode; chat members outrank persona-name react targets
  • 70b072b feat: tell merged group replies that multiple characters may react in one reply
  • 41f4a48 fix: reaction sweep hardening (linear timestamp strip, fewer store scans per react, timestamp-proof attribution, junk-tag rejection, lazy picker, phantom-box guard)
  • f57b3fe Merge remote-tracking branch 'origin/staging' into fix/react-toggle-and-group-attribution

📊 Changes

9 files changed (+215 additions, -92 deletions)

View changed files

📝 CHANGELOG.md (+8 -1)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+5 -0)
📝 packages/client/src/components/chat/ChatSetupWizard.tsx (+1 -0)
📝 packages/client/src/components/chat/ConversationMessageGrouped.tsx (+4 -0)
📝 packages/client/src/components/chat/ReactionAddButton.tsx (+59 -38)
📝 packages/server/src/routes/generate.routes.ts (+79 -38)
📝 packages/server/src/services/conversation/character-commands.ts (+52 -13)
📝 packages/shared/src/types/chat.ts (+1 -0)
📝 packages/shared/src/utils/speaker-segments.ts (+6 -2)

📄 Description

Fixes #3219, fixes #3220

Summary

Two follow-ups from maintainer playtesting of the reaction feature (#3211):

  1. Reactions toggle (#3219): character emoji reactions get their own card in the per-command Commands grid (Chat Settings and the chat setup wizard), wired like Selfies/Music/etc. — when off, the react instruction stays out of the prompt and [react:] tags are filtered by the command pipeline. Default on.
  2. Group attribution fix (#3220): character reactions in group chats were always credited to the first character in the chat. Real replies showed why: models emit the [react:] tag as the first line of the whole merged reply, above any character's Name: section, and that leading region fell back to the generation-primary (first) character.

Why

While playtesting, reactions silently didn't work until the master Commands toggle was found (nothing indicates reactions depend on it), and once they worked, every chip's tooltip read "reacted by " regardless of who was reacting in the story. Inspecting extra.conversationCommandContent of the actual replies confirmed the tag-above-first-section placement in 3 out of 3 reacting replies.

What changed

Layer Change
packages/shared/src/types/chat.ts "react" added to CONVERSATION_COMMAND_KEYS.
packages/server/src/routes/generate.routes.ts React instruction gated on the new per-command toggle; merged group chats (not individual-order mode, which forbids name prefixes) get added guidance instructing models to write the tag inside the reacting character's own section (never above the first name line) and stating explicitly that multiple characters may each react in the same reply (playtesting showed models emitting exactly one tag per merged reply, 5/5); a react targeting the persona name or "User" resolves to the user's latest message when no chat member shares the name (members take precedence); getConversationCommandKey maps react so the existing command filter enforces the toggle.
packages/server/src/services/conversation/character-commands.ts parseCharacterCommandsBySpeaker: the leading region (text above the first recognized Name: prefix) now attributes to the speaker of the first named section — the turn the header visually opens — instead of the generation-primary character. No named sections → unchanged fallback. Affects all commands parked above the first section, not just reacts.
packages/client/src/components/chat/ChatSettingsDrawer.tsx + ChatSetupWizard.tsx "Reactions" toggle card ("Let characters react to messages with emoji badges."), placed with the other command cards.

Verified by executing the real parser: a header-placed tag now attributes to the first section's speaker, an in-section tag to that section's speaker, and a sectionless reply falls back exactly as before.

Sweep hardening (adversarial regression/perf review of #3211 + this branch)

A multi-agent sweep (hunting the #3104/#3164 lag classes specifically) confirmed and fixed five more issues here:

  • Quadratic stripLeadingMessageTimestamps on whitespace runs (measured 1.1s/call at 40KB of newlines, called per reacted history message per generation) — the leading whitespace class is now same-line-only: 100KB drops from ~6.9s to 0.68ms, output byte-identical on real timestamp shapes. Both new call sites also cap content size BEFORE stripping.
  • Redundant store scans per [react:] command (each get/update is a full-table scan in the file-native store; 5 reacts on a 30k-message install measured ~2s of event-loop blocking): the chat-member build is now cached per request, the resolved target message is reused instead of re-fetched, and the swipe mirror skips the active swipe updateMessageExtra already writes.
  • Attribution vs leaked timestamps: parseCharacterCommandsBySpeaker now segments the timestamp-stripped shape (matching the client display and the react resolver), so [12:01] Alice: hey [react: …] credits Alice, not the next character. Verified by execution.
  • Junk react tags: quote-bearing bodies ([react: she said "hi"]) no longer mint literal-text chips — they're rejected and left visible like the old grammar; emoji = "😂" (spaces around =) now parses as intended.
  • Phantom themed box: whitespace-only narration segments no longer render an empty [data-card-css] wrapper; and per-segment ReactionAddButtons now mount their picker + custom-emoji query subscription only while open (they render once per speaker segment across the transcript).

The sweep's remaining HIGH finding — the whole transcript re-rendering every streaming frame because useConversationCustomEmojis/Stickers return fresh Maps per render — predates these PRs (it's the #3164 disease on another prop) and is filed + fixed separately: #3223 / PR #3224.

Known limitations

  • A tag above the first section is inherently ambiguous — the model doesn't say who meant it. Attributing it to the section it opens is deterministic and positionally coherent, but the real cure is the new instruction pushing models to place tags inside their own sections; the fallback only covers non-compliant replies.
  • The leading-region attribution change applies to every command type (e.g. a [selfie] above the first section), for consistency — flagging in case a different fallback is preferred there.

Test plan (manual verification needed)

  • Chat Settings → Commands: a "Reactions" card appears in the grid (and in the setup wizard's command step); light + dark mode, mobile width.
  • With Reactions off: characters stop reacting, no raw [react:] text leaks into visible messages, and Peek Prompt no longer contains the react instruction.
  • With Reactions on in a group chat: when characters react, hover the chips — the "reacted by" tooltip credits different characters over time, not always the first one. (Verified in live playtest against stored data — Floyd/Jade/Aurey all credited across one session; see verification report comment.)
  • Peek Prompt in a group chat shows the new placement sentence ("write the tag inside that character's own section..."); in a manual/individual-order group chat it does NOT appear.
  • Over a longer group session, replies sometimes carry reactions from more than one character (the multi-react guidance) — verified in raw output (extra.conversationCommandContent) or via chips from different reactors on the same turn. (Verified: single replies carried 2–3 tags; chips from three characters on one message; see verification report comment.)
  • Ask a character to react to your message: the chip lands on your latest message (models targeting to "User"/persona name now resolve explicitly). (Verified in live playtest — models emit to "User" routinely and chips landed on the user's message; the collision-precedence edge is code-traced only.)

Docs touched

  • CHANGELOG.md (Unreleased → Added + Fixed).

Summary by CodeRabbit

  • New Features

    • Added support for character reactions in Conversation mode, including a new Reactions command toggle in settings and setup.
  • Bug Fixes

    • Improved reaction targeting in group chats so reactions are attributed to the correct character.
    • Prevented empty message segments from rendering as visible placeholders.
    • Fixed reaction parsing to ignore malformed emoji inputs and leave invalid text unchanged.
    • Improved reaction performance and responsiveness by reducing unnecessary work during message processing.

🔄 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/3221 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/4/2026 **Status:** ✅ Merged **Merged:** 7/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/react-toggle-and-group-attribution` --- ### 📝 Commits (5) - [`e3b8c04`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e3b8c0431478bf8ed60af5624d3f02de98903e25) feat: Reactions per-command toggle + fix group react attribution to first character (#3219, #3220) - [`254ef44`](https://github.com/Pasta-Devs/Marinara-Engine/commit/254ef44c0b9a8f4783028ad3f46616ce9cc5aa82) fix: gate group react placement guidance to merged mode; chat members outrank persona-name react targets - [`70b072b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/70b072b547dd7cc679f5b6571cd0392b65c44075) feat: tell merged group replies that multiple characters may react in one reply - [`41f4a48`](https://github.com/Pasta-Devs/Marinara-Engine/commit/41f4a482d607f6be743361c7ccbe99ee9b465824) fix: reaction sweep hardening (linear timestamp strip, fewer store scans per react, timestamp-proof attribution, junk-tag rejection, lazy picker, phantom-box guard) - [`f57b3fe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f57b3fe250e475659b171ebe0c263add0e6c45d6) Merge remote-tracking branch 'origin/staging' into fix/react-toggle-and-group-attribution ### 📊 Changes **9 files changed** (+215 additions, -92 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+8 -1) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+5 -0) 📝 `packages/client/src/components/chat/ChatSetupWizard.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ConversationMessageGrouped.tsx` (+4 -0) 📝 `packages/client/src/components/chat/ReactionAddButton.tsx` (+59 -38) 📝 `packages/server/src/routes/generate.routes.ts` (+79 -38) 📝 `packages/server/src/services/conversation/character-commands.ts` (+52 -13) 📝 `packages/shared/src/types/chat.ts` (+1 -0) 📝 `packages/shared/src/utils/speaker-segments.ts` (+6 -2) </details> ### 📄 Description Fixes #3219, fixes #3220 ## Summary Two follow-ups from maintainer playtesting of the reaction feature (#3211): 1. **Reactions toggle (#3219)**: character emoji reactions get their own card in the per-command Commands grid (Chat Settings and the chat setup wizard), wired like Selfies/Music/etc. — when off, the react instruction stays out of the prompt and `[react:]` tags are filtered by the command pipeline. Default on. 2. **Group attribution fix (#3220)**: character reactions in group chats were always credited to the first character in the chat. Real replies showed why: models emit the `[react:]` tag as the first line of the whole merged reply, above any character's `Name:` section, and that leading region fell back to the generation-primary (first) character. ## Why While playtesting, reactions silently didn't work until the master Commands toggle was found (nothing indicates reactions depend on it), and once they worked, every chip's tooltip read "reacted by <first character>" regardless of who was reacting in the story. Inspecting `extra.conversationCommandContent` of the actual replies confirmed the tag-above-first-section placement in 3 out of 3 reacting replies. ## What changed | Layer | Change | |---|---| | `packages/shared/src/types/chat.ts` | `"react"` added to `CONVERSATION_COMMAND_KEYS`. | | `packages/server/src/routes/generate.routes.ts` | React instruction gated on the new per-command toggle; merged group chats (not individual-order mode, which forbids name prefixes) get added guidance instructing models to write the tag **inside the reacting character's own section** (never above the first name line) and stating explicitly that **multiple characters may each react in the same reply** (playtesting showed models emitting exactly one tag per merged reply, 5/5); a react targeting the persona name or "User" resolves to the user's latest message when no chat member shares the name (members take precedence); `getConversationCommandKey` maps `react` so the existing command filter enforces the toggle. | | `packages/server/src/services/conversation/character-commands.ts` | `parseCharacterCommandsBySpeaker`: the leading region (text above the first recognized `Name:` prefix) now attributes to the speaker of the first named section — the turn the header visually opens — instead of the generation-primary character. No named sections → unchanged fallback. Affects all commands parked above the first section, not just reacts. | | `packages/client/src/components/chat/ChatSettingsDrawer.tsx` + `ChatSetupWizard.tsx` | "Reactions" toggle card ("Let characters react to messages with emoji badges."), placed with the other command cards. | Verified by executing the real parser: a header-placed tag now attributes to the first section's speaker, an in-section tag to that section's speaker, and a sectionless reply falls back exactly as before. ## Sweep hardening (adversarial regression/perf review of #3211 + this branch) A multi-agent sweep (hunting the #3104/#3164 lag classes specifically) confirmed and fixed five more issues here: - **Quadratic `stripLeadingMessageTimestamps`** on whitespace runs (measured 1.1s/call at 40KB of newlines, called per reacted history message per generation) — the leading whitespace class is now same-line-only: 100KB drops from ~6.9s to 0.68ms, output byte-identical on real timestamp shapes. Both new call sites also cap content size BEFORE stripping. - **Redundant store scans per `[react:]` command** (each get/update is a full-table scan in the file-native store; 5 reacts on a 30k-message install measured ~2s of event-loop blocking): the chat-member build is now cached per request, the resolved target message is reused instead of re-fetched, and the swipe mirror skips the active swipe `updateMessageExtra` already writes. - **Attribution vs leaked timestamps**: `parseCharacterCommandsBySpeaker` now segments the timestamp-stripped shape (matching the client display and the react resolver), so `[12:01] Alice: hey [react: …]` credits Alice, not the next character. Verified by execution. - **Junk react tags**: quote-bearing bodies (`[react: she said "hi"]`) no longer mint literal-text chips — they're rejected and left visible like the old grammar; `emoji = "😂"` (spaces around `=`) now parses as intended. - **Phantom themed box**: whitespace-only narration segments no longer render an empty `[data-card-css]` wrapper; and per-segment `ReactionAddButton`s now mount their picker + custom-emoji query subscription only while open (they render once per speaker segment across the transcript). The sweep's remaining HIGH finding — the whole transcript re-rendering every streaming frame because `useConversationCustomEmojis/Stickers` return fresh Maps per render — **predates these PRs** (it's the #3164 disease on another prop) and is filed + fixed separately: #3223 / PR #3224. ## Known limitations - A tag above the first section is inherently ambiguous — the model doesn't say who meant it. Attributing it to the section it opens is deterministic and positionally coherent, but the real cure is the new instruction pushing models to place tags inside their own sections; the fallback only covers non-compliant replies. - The leading-region attribution change applies to every command type (e.g. a `[selfie]` above the first section), for consistency — flagging in case a different fallback is preferred there. ## Test plan (manual verification needed) - [ ] Chat Settings → Commands: a "Reactions" card appears in the grid (and in the setup wizard's command step); light + dark mode, mobile width. - [ ] With Reactions off: characters stop reacting, no raw `[react:]` text leaks into visible messages, and Peek Prompt no longer contains the react instruction. - [x] With Reactions on in a group chat: when characters react, hover the chips — the "reacted by" tooltip credits different characters over time, not always the first one. *(Verified in live playtest against stored data — Floyd/Jade/Aurey all credited across one session; see verification report comment.)* - [ ] Peek Prompt in a group chat shows the new placement sentence ("write the tag inside that character's own section..."); in a manual/individual-order group chat it does NOT appear. - [x] Over a longer group session, replies sometimes carry reactions from more than one character (the multi-react guidance) — verified in raw output (`extra.conversationCommandContent`) or via chips from different reactors on the same turn. *(Verified: single replies carried 2–3 tags; chips from three characters on one message; see verification report comment.)* - [x] Ask a character to react to your message: the chip lands on your latest message (models targeting `to "User"`/persona name now resolve explicitly). *(Verified in live playtest — models emit `to "User"` routinely and chips landed on the user's message; the collision-precedence edge is code-traced only.)* ## Docs touched - `CHANGELOG.md` (Unreleased → Added + Fixed). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for character reactions in Conversation mode, including a new Reactions command toggle in settings and setup. * **Bug Fixes** * Improved reaction targeting in group chats so reactions are attributed to the correct character. * Prevented empty message segments from rendering as visible placeholders. * Fixed reaction parsing to ignore malformed emoji inputs and leave invalid text unchanged. * Improved reaction performance and responsiveness by reducing unnecessary work during message processing. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:20:08 +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#5846
No description provided.