[PR #7510] [MERGED] fix(agents): rewrite only the last group reply's own text #7767

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7510
Author: @SpicyMarinara
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/group-rewrite-last-reply-only


📝 Commits (2)

  • 30199ca fix(agents): rewrite only the last group reply's own text (#7509)
  • ed52442 fix(agents): build the rewrite agents' result summary once, before the part loop

📊 Changes

2 files changed (+43 additions, -10 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+9 -9)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+34 -1)

📄 Description

Closes #7509

Why

Take a group chat where characters reply one by one, with Prose Guardian, Continuity or the HTML agent on. When several characters replied in one turn, the last character's message ended up holding every reply from that turn, rewritten together. The earlier characters' replies then showed twice: once in their own messages and again inside the last character's message. This happened with "hold for rewrite" on or off, whenever the last reply was not split at scene breaks. It is an older bug: staging before #7497 (3066f0c72) does the same.

The cause: the rewrite step was given the whole turn (all replies joined) and saved the result into the last responder's message.

What changed

  • packages/server/src/routes/generate.routes.ts: when the last reply is not split, the rewrite agents now get that reply's own text, or the whole continued message for Continue, instead of the turn's joined replies. Single replies, merged groups and Game still have one reply per message, so they get the same text as before. The split case from #7507 is unchanged.
  • scripts/regressions/advanced-memory-post-generation.regression.ts: new case with two individual responders and a last reply that is not split. It runs with hold on, hold off, and hold on with a failing rewrite. It checks that the rewrite agent sees only the last reply, that the earlier reply stays as written, and that the text_rewrite event (the rewrite, or the released held text) carries only the last reply. The fixture gained a small mainReplyFor hook so each responder answers with its own name. Without the fix, the case fails on current staging: the rewrite source is REPLY_FROM_Dottore.\n\nREPLY_FROM_Cyno. instead of REPLY_FROM_Cyno.

Validation

  • pnpm check: passed locally (exit 0)
  • node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed locally
  • node ./scripts/run-regressions.mjs --filter roleplay: 14/14 passed locally
  • node ./scripts/run-regressions.mjs --filter regeneration-context: 2/2 passed locally
  • New regression case fails without the fix: confirmed locally (assertion "group, held: only the last reply is rewritten")
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit <merge-base>): 1 minor finding, dismissed. It asked for this case in every chat mode and group mode. The changed line only matters when a turn produces several replies, which only happens in the shared individual-responder loop that Conversation and Roleplay both use. Merged groups, single replies and Game write one entry to allResponses, so allResponses.at(-1) is the same text as the old join.

Manual verification needed

  • Manually verify in the browser: in a Roleplay group chat with individual replies and Prose Guardian on, send a message so two characters reply. The second character's message should contain only its own (rewritten) reply, with hold for rewrite on and off.
  • Manually verify the same in a Conversation group chat with individual replies.
  • Manually verify that a one-character chat and a merged group chat still get their whole reply rewritten as before.
  • Manually verify that Continue on a message with Prose Guardian on still rewrites the whole continued message.

Summary by CodeRabbit

  • Bug Fixes
    • Text rewrites now apply only to the latest responder’s reply, rather than combining earlier replies. If a rewrite is held or fails, the latest responder’s original text is preserved.
  • Tests
    • Added coverage for group-chat rewrites, including held and failed rewrites.

🔄 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/7510 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/group-rewrite-last-reply-only` --- ### 📝 Commits (2) - [`30199ca`](https://github.com/Pasta-Devs/Marinara-Engine/commit/30199ca2aa3d935b7e2a17397def3fce7bc388a7) fix(agents): rewrite only the last group reply's own text (#7509) - [`ed52442`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ed5244280d4b66bd7f35980af8ed8734fe1d0ea4) fix(agents): build the rewrite agents' result summary once, before the part loop ### 📊 Changes **2 files changed** (+43 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+9 -9) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+34 -1) </details> ### 📄 Description Closes #7509 ## Why Take a group chat where characters reply one by one, with Prose Guardian, Continuity or the HTML agent on. When several characters replied in one turn, the last character's message ended up holding **every** reply from that turn, rewritten together. The earlier characters' replies then showed twice: once in their own messages and again inside the last character's message. This happened with "hold for rewrite" on or off, whenever the last reply was not split at scene breaks. It is an older bug: `staging` before #7497 (`3066f0c72`) does the same. The cause: the rewrite step was given the whole turn (all replies joined) and saved the result into the last responder's message. ## What changed - `packages/server/src/routes/generate.routes.ts`: when the last reply is not split, the rewrite agents now get that reply's own text, or the whole continued message for Continue, instead of the turn's joined replies. Single replies, merged groups and Game still have one reply per message, so they get the same text as before. The split case from #7507 is unchanged. - `scripts/regressions/advanced-memory-post-generation.regression.ts`: new case with two individual responders and a last reply that is not split. It runs with hold on, hold off, and hold on with a failing rewrite. It checks that the rewrite agent sees only the last reply, that the earlier reply stays as written, and that the `text_rewrite` event (the rewrite, or the released held text) carries only the last reply. The fixture gained a small `mainReplyFor` hook so each responder answers with its own name. Without the fix, the case fails on current `staging`: the rewrite source is `REPLY_FROM_Dottore.\n\nREPLY_FROM_Cyno.` instead of `REPLY_FROM_Cyno.` ## Validation - [ ] `pnpm check`: passed locally (exit 0) - [ ] `node ./scripts/run-regressions.mjs --filter advanced-memory`: 16/16 passed locally - [ ] `node ./scripts/run-regressions.mjs --filter roleplay`: 14/14 passed locally - [ ] `node ./scripts/run-regressions.mjs --filter regeneration-context`: 2/2 passed locally - [ ] New regression case fails without the fix: confirmed locally (assertion "group, held: only the last reply is rewritten") - [ ] Local CodeRabbit (`coderabbit review --agent --committed --base-commit <merge-base>`): 1 minor finding, dismissed. It asked for this case in every chat mode and group mode. The changed line only matters when a turn produces several replies, which only happens in the shared individual-responder loop that Conversation and Roleplay both use. Merged groups, single replies and Game write one entry to `allResponses`, so `allResponses.at(-1)` is the same text as the old join. ## Manual verification needed - [ ] Manually verify in the browser: in a Roleplay group chat with individual replies and Prose Guardian on, send a message so two characters reply. The second character's message should contain only its own (rewritten) reply, with hold for rewrite on and off. - [ ] Manually verify the same in a Conversation group chat with individual replies. - [ ] Manually verify that a one-character chat and a merged group chat still get their whole reply rewritten as before. - [ ] Manually verify that Continue on a message with Prose Guardian on still rewrites the whole continued message. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Text rewrites now apply only to the latest responder’s reply, rather than combining earlier replies. If a rewrite is held or fails, the latest responder’s original text is preserved. * **Tests** * Added coverage for group-chat rewrites, including held and failed rewrites. <!-- 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-24 04:07:18 +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#7767
No description provided.