mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3377] [Issue]: Persona/character card info is duplicated in the prompt when a description starts with a macro (conversation / preset-less modes) #1825
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#1825
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 (Jul 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3377
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
Persona (and character) card info can be injected into the system prompt twice — once from your own prompt/macro, and once from an automatic "identity fallback" that fails to notice the info is already there. You get a duplicated description/personality block.
The report is right that this happens, but two of its details don't hold up in the code, so here's the corrected version:
The everyday trigger: personas very commonly start their description with
{{user}}(or{{char}}), which is exactly what defeats the duplicate-detection.How to reproduce (try it yourself)
{{user}} is a rival journalist who ….{{persona}}, or just{{personaDescription}}) into your system/prompt text.You'll see: the persona description appears twice — once where your macro resolved it, and once in an auto-injected system block.
Expected: exactly once.
Control that proves the cause: change the description to plain text with no leading macro → it appears once. (The same duplication reproduces for a character whose description starts with a macro.)
Where it is
packages/server/src/services/generation/character-prompt-context.ts—injectIdentityFallbackMessages(133-217) re-injects card info unlesshasProfileBlock(123-130) says it's already present. The character gate is line 151 and the persona gate line 188 — identical logic.hasProfileBlock's only mode-independent check compares the unresolved description (args.personaDescription, macros intact) against the resolved prompt text:so a macro in the description's first line makes the two strings differ and the check misses. The other checks —
<xmlTag>(127),<name>(128),# name(129) — only match when the info was wrapped with the entity name, but inline text macros never emit a name wrapper andwrapFormat="none"emits none. Detection returns false and the block is spliced in a second time (persona 213-216, character 182-185).This fallback runs (so the bug is reachable) only where
shouldInjectIdentityFallbackreturns true (packages/server/src/routes/generate/generate-route-utils.ts:1160-1169: game → never, conversation → always, other modes → only when no preset). A parallel copy of the gate lives inpackages/server/src/routes/chats.routes.ts(~2393-2415).What's happening
The fallback decides "is this identity already in the prompt?" by fuzzy, after-the-fact text matching — comparing an unresolved description against resolved prompt text. When the description leads with a macro (or was surfaced without a name wrapper), the match fails and the card info is added again.
Suggested fix
Make detection macro-aware — but do it carefully so it doesn't reintroduce the macro-resolution cost problem from PR #3118 (see the note below). Two options, preferred first:
chat_summary(assembler.ts:362 / 380-387 / 524). In conversation mode (no marker pipeline) this can be a check for the persona/char macro token in the pre-resolution prompt text — still no macro resolution. This is the most robust and the least risky performance-wise.args.resolvePromptMacros(personaDescription)for persona; the loop'sresolveCharacterMacros(character.description)for characters — note the character check at line 151 must move to aftercharacterMacroContextis built at 153-166) and reuse that same resolved string for both thehasProfileBlockdetection and the injected block (persona line 192, character 170). Do not resolve twice, and do not touchresolveMacrosinpackages/sharedor any client display path.Apply the same fix to the parallel gate in
chats.routes.ts(~2393-2415), and extendscripts/regressions/prompt.regression.ts(it already imports this fallback and guards the #3118 lazy-persona behavior) with: a macro-leading description → identity appears exactly once; a plain description → unchanged; and byte-identical macro output preserved.Performance & regression note (re: PR #3118)
#3118 fixed a super-linear freeze caused by
resolveMacroseagerly rebuilding persona text per message on every display render (client-side,ChatMessage/ConversationMessage/GameNarration). This fix is not on that surface:injectIdentityFallbackMessagesruns server-side, once per generation during prompt assembly (generate.routes.ts:2177), so at most it adds one description-resolve per identity per generation — negligible next to generation itself, and post-#3118 a single resolve is ~1 ms even for a pathological self-referential persona. The guardrails to keep it that way: (1) resolve at most once and reuse (or use the deterministic flag and resolve nothing extra); (2) use the resolver the block path already uses, so deferred-character-macro (deferCharacterMacros) and budget-cap semantics are unchanged and macro output stays byte-identical; (3) make no change topackages/shared/src/utils/macro-engine.tsor any per-render display path, so #3118's early-out and lazy-persona optimizations are untouched.AI-investigated against the current tree (v2.0.9); the fallback gate,
hasProfileBlock,shouldInjectIdentityFallback, the persona/character symmetry, the server-once-per-generation call site, and the existing regression harness all read and confirmed. The original report's two inaccuracies (persona-only; marker-triggered) are corrected above. Please verify before fixing.@SpicyMarinara commented on GitHub (Jul 8, 2026):
Addressed in #3388 and merged to staging.