mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2677] [Issue]: Assistant prefill mis-applied during impersonation and Google user-message regeneration (wrong voice / corrupted saved message) #1325
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1325
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2677
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The assistant prefill is appended/seeded without accounting for a following user-role message, so it is mis-applied in two cases: (1) impersonation — the prefill becomes the trailing assistant turn after the "write as {{user}}" instruction, making the model continue in the character's voice and leaking the prefill text into the saved user message; (2) Google user-message regeneration — the prefill is seeded into the saved swipe even though it is not the trailing turn, corrupting the regenerated user message. SillyTavern does not apply the assistant prefill during impersonation or user-message regeneration.
Expected behavior
Actual behavior
appendGenerationTailMessagespushes the assistant prefill and only early-returns on follow-up iterations — it never consultsoptions.impersonate, and in the Google-regeneration branch it pushes the prefill first and then the user rewrite instruction, yet still returnsassistantPrefillInjected: true.[…history, user:"write as {{user}}", assistant:<character prefill>]. The trailing assistant prefill makes the model extend the character's voice (recency-dominant), contradicting the impersonate instruction; the prefill is also prepended tofullResponseand persisted as the user's message.fullResponseand saved as the regenerated user swipe.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/routes/generate/generate-route-utils.ts:534-555—appendGenerationTailMessages: early-returns only onfollowUpIteration !== 0(line 535); pushes the prefill (line ~547); in the Google branch pushesregenerateUserMessageafter the prefill (line ~551); returnsassistantPrefillInjected: trueregardless of trailing position.packages/server/src/routes/generate.routes.ts:5259pushes the{role:"user", content: impersonateInstruction}(DEFAULT_IMPERSONATE_PROMPT,packages/shared/src/constants/impersonate.ts) then calls the tail helper (:5262).fullResponseis seeded from the prefill (:5694) and saved withrole: input.impersonate ? "user" : "assistant"(~:6402).assistantPrefillis set from preset/params (lines 1975/3275) and never cleared for impersonate.fullResponseseeding at:5694is gated only onassistantPrefillInjected(true here), and the swipe is saved viaaddSwipe(:6396). The prefill-dedup at ~:6147-6157only collapses an exact double-echo, not a non-trailing prefill.Steps to reproduce
Impersonate: With a preset/connection/chat
assistantPrefillset (e.g.\n\n{{char}}: *she leans in*) on an Anthropic connection, click Impersonate. The impersonated "user" message comes back in the character's voice / begins with the prefill text, and the saved user message starts with the prefill.Google regen: On a Google/Gemini connection with a non-empty
assistantPrefill, regenerate one of your own user-authored messages as a swipe. The regenerated user swipe text starts with the assistant prefill string.Suggested fix
In
appendGenerationTailMessages, skip the assistant-prefill push whenoptions.impersonateis true (it is already passed in), or clearassistantPrefillon the impersonate branch (generate.routes.ts:5252) before the tail call. For the Google-regeneration case, have the helper report whether the prefill actually ended up trailing, and gate thefullResponseseeding (:5694) on that (e.g. only seed when!googleUserRegenerationInjected && !impersonate) so a non-continued prefill is never seeded or persisted. Matches SillyTavern, which omits the prefill during impersonation and user-message regeneration.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of the prompt-assembly / prefill path. Both cases share one root cause (the tail helper injects/seeds the prefill without accounting for a following user-role message). Related to the prefill trailing-whitespace fix in #2673 / #2674 and the Claude-subscription prefill issue filed separately.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 21, 2026):
Clarification on the code trace (verified against
b826f8f4and the current fix/anthropic-prefill-trailing-whitespace tree):The "Actual behavior" wording "it never consults options.impersonate" is imprecise. The helper DOES reference options.impersonate at generate-route-utils.ts:538-539 (
shouldAppendGoogleUserRegeneration = !options.impersonate && options.isGoogleProvider && !!options.regenerateUserMessage). The precise defect is that the prefill push itself (generate-route-utils.ts:547) is unconditional and ignores impersonate, and the fullResponse seeding (generate.routes.ts:5694) is gated only on assistantPrefillInjected.The suggested fix is correct as written and needs no new helper return value — note for fixers that the helper already returns googleUserRegenerationInjected, which is exactly the "prefill is non-trailing" signal, and the issue's own example gate already uses it. Minimal fix: (a) Impersonate — skip the prefill push when options.impersonate is true (or clear assistantPrefill before the tail call at generate.routes.ts:5252); this makes assistantPrefillInjected false and automatically prevents both the 5694 seeding and the 6404 save. (b) Google regen — gate the seeding at generate.routes.ts:5694 on the existing return value, e.g.
if (tailMessages.assistantPrefillInjected && !tailMessages.googleUserRegenerationInjected && assistantPrefill). The&& !impersonatein the issue's example is harmless but redundant once (a) is in place.Confirmed unaffected by #2673/#2679: #2673 only added .trimEnd() to the prefill push (generate-route-utils.ts + dry-run-route.ts) and #2679 only changed anthropic.provider.ts; git diff b826f8f4..HEAD shows no prefill changes in generate.routes.ts. The push/seed/save sites are unchanged and the bug is still present.
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on the issue-sweep branch. The tail helper now skips assistant prefill injection during impersonation, dry-run mirrors that behavior, and the stream/save prefill seed only runs when the prefill remains the trailing assistant message, not when Gemini user-message regeneration adds a final user rewrite instruction after it. Final repo checks will run after the sweep.