[GH-ISSUE #3046] [Issue]: In-turn group responses are appended without the speaker-name prefix, breaking 'Name Prefix History' for later responders in the same turn #1616

Closed
opened 2026-10-21 05:40:48 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3046

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
With the "Name Prefix History" option on for a sequential, individual-mode group chat, prior committed history turns are correctly prefixed with Name: so that individual-mode scoping (which collapses every non-target speaker into anonymous role:"user" blocks) still lets the model tell who said what. But each character's freshly generated response in the SAME server turn is appended to the running context WITHOUT a Name: prefix. The next responding character therefore sees this turn's earlier responses as anonymous, un-attributed user text — exactly the lines most relevant to its reply — defeating the feature for the in-turn responses.

How to reproduce (try it yourself)

  1. Create a roleplay (or visual_novel) GROUP chat with 2+ active characters (e.g. Alice and Bob).
  2. In chat settings set Group Chat Mode = Individual, Response Order = Sequential, and enable "Name Prefix History".
  3. Send a user message that prompts both characters to respond (server generates Alice then Bob).
  4. Inspect the prompt sent for Bob's generation (debug log / dry-run-equivalent).

You'll see: Bob's prompt contains committed history with Alice: / Bob: / persona prefixes, but Alice's just-generated response (this turn) is merged into the user block with NO Alice: prefix, so Bob can't attribute the immediately-prior line.
Expected: Alice's in-turn response carries the same Alice: prefix the committed history uses.

Where it is

  • packages/server/src/routes/generate.routes.ts:7263-7268 — pushes the response into runningMessages as a bare assistant message (characterId set, no Name: prefix).
  • packages/server/src/routes/generate.routes.ts:6851-6856 — explicitly STRIPS any leading Name: the model emitted, guaranteeing the fed-back line carries no marker.
  • packages/server/src/services/generation/prompt-message-scope.ts:253-256 — flips the non-target assistant history message to role:"user" without adding a prefix; mergeProviderAdjacentMessages (generate.routes.ts:6153-6180) then concatenates it with \n\n.
  • Prefix applied exactly once, to committed history: generate.routes.ts:2078-2088; feature gating at 1984-1989.

What's happening
prefixGroupIndividualHistorySpeakers runs a single time on the committed history at iteration 0. The individual-mode loop appends each character's response as a raw, unprefixed assistant message and never re-applies the speaker prefix before that message is scoped/role-flipped/merged for subsequent characters — and the response's own leading name was already stripped — so the fed-back line is guaranteed to be unattributed.

Suggested fix
Prefix each in-turn response with the speaker name before pushing it into runningMessages, gated on the same shouldPrefixGroupHistorySpeakers flag used for committed history. At generate.routes.ts:7263-7268:

const inTurnMessage = {
  role: "assistant" as const,
  content: genResult.response,
  contextKind: "history" as const,
  characterId: charId,
};
if (shouldPrefixGroupHistorySpeakers) {
  const characterNamesById = await getGroupHistoryCharacterNamesById();
  const [prefixed] = prefixGroupIndividualHistorySpeakers([inTurnMessage], { personaName, characterNamesById });
  runningMessages.push(prefixed ?? inTurnMessage);
} else {
  runningMessages.push(inTurnMessage);
}

Reusing prefixGroupIndividualHistorySpeakers (rather than the non-exported prefixSpeakerName) shares the exact name-resolution map and idempotency guard already used for committed history. Regression notes: the change is gated to individual-mode, 2+ characters, non-conversation/game with the option on, so single-character/merged/conversation/game flows are untouched. The pushed message is prompt-only context for the next character — the saved/displayed message uses genResult.response independently, so no Name: leaks into stored or rendered text. prefixSpeakerName checks for an existing ^Name: case-insensitively, so there is no double-prefix risk.

v2.0.7 note: generate.routes.ts was reworked in origin/staging; this bug PERSISTS there — the in-turn response is still pushed unprefixed at staging lines ~7373-7378 (vs main 7263-7268), and prefixGroupIndividualHistorySpeakers is still applied only to committed history. Apply the prefix at that push.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3046 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** With the "Name Prefix History" option on for a sequential, individual-mode group chat, prior committed history turns are correctly prefixed with `Name:` so that individual-mode scoping (which collapses every non-target speaker into anonymous `role:"user"` blocks) still lets the model tell who said what. But each character's freshly generated response in the SAME server turn is appended to the running context WITHOUT a `Name:` prefix. The next responding character therefore sees this turn's earlier responses as anonymous, un-attributed user text — exactly the lines most relevant to its reply — defeating the feature for the in-turn responses. **How to reproduce (try it yourself)** 1. Create a roleplay (or visual_novel) GROUP chat with 2+ active characters (e.g. Alice and Bob). 2. In chat settings set Group Chat Mode = Individual, Response Order = Sequential, and enable "Name Prefix History". 3. Send a user message that prompts both characters to respond (server generates Alice then Bob). 4. Inspect the prompt sent for Bob's generation (debug log / dry-run-equivalent). You'll see: Bob's prompt contains committed history with `Alice:` / `Bob:` / persona prefixes, but Alice's just-generated response (this turn) is merged into the user block with NO `Alice:` prefix, so Bob can't attribute the immediately-prior line. Expected: Alice's in-turn response carries the same `Alice:` prefix the committed history uses. **Where it is** - `packages/server/src/routes/generate.routes.ts:7263-7268` — pushes the response into `runningMessages` as a bare assistant message (characterId set, no `Name:` prefix). - `packages/server/src/routes/generate.routes.ts:6851-6856` — explicitly STRIPS any leading `Name:` the model emitted, guaranteeing the fed-back line carries no marker. - `packages/server/src/services/generation/prompt-message-scope.ts:253-256` — flips the non-target assistant history message to `role:"user"` without adding a prefix; `mergeProviderAdjacentMessages` (generate.routes.ts:6153-6180) then concatenates it with `\n\n`. - Prefix applied exactly once, to committed history: `generate.routes.ts:2078-2088`; feature gating at `1984-1989`. **What's happening** `prefixGroupIndividualHistorySpeakers` runs a single time on the committed history at iteration 0. The individual-mode loop appends each character's response as a raw, unprefixed assistant message and never re-applies the speaker prefix before that message is scoped/role-flipped/merged for subsequent characters — and the response's own leading name was already stripped — so the fed-back line is guaranteed to be unattributed. **Suggested fix** Prefix each in-turn response with the speaker name before pushing it into `runningMessages`, gated on the same `shouldPrefixGroupHistorySpeakers` flag used for committed history. At generate.routes.ts:7263-7268: ```ts const inTurnMessage = { role: "assistant" as const, content: genResult.response, contextKind: "history" as const, characterId: charId, }; if (shouldPrefixGroupHistorySpeakers) { const characterNamesById = await getGroupHistoryCharacterNamesById(); const [prefixed] = prefixGroupIndividualHistorySpeakers([inTurnMessage], { personaName, characterNamesById }); runningMessages.push(prefixed ?? inTurnMessage); } else { runningMessages.push(inTurnMessage); } ``` Reusing `prefixGroupIndividualHistorySpeakers` (rather than the non-exported `prefixSpeakerName`) shares the exact name-resolution map and idempotency guard already used for committed history. Regression notes: the change is gated to individual-mode, 2+ characters, non-conversation/game with the option on, so single-character/merged/conversation/game flows are untouched. The pushed message is prompt-only context for the next character — the saved/displayed message uses `genResult.response` independently, so no `Name:` leaks into stored or rendered text. `prefixSpeakerName` checks for an existing `^Name:` case-insensitively, so there is no double-prefix risk. *v2.0.7 note: `generate.routes.ts` was reworked in `origin/staging`; this bug PERSISTS there — the in-turn response is still pushed unprefixed at staging lines ~7373-7378 (vs main 7263-7268), and `prefixGroupIndividualHistorySpeakers` is still applied only to committed history. Apply the prefix at that push.* --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834989829 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835089777 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1616
No description provided.