mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3108] [Issue]: In XML wrap format, user-typed < and > are escaped to </> before the model sees them (breaks blockquotes, wastes tokens) #1667
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#1667
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 30, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3108
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When the prompt wrap format is set to XML, any
<,>, and&you typed yourself — in a message, a lorebook entry, a character field, a summary, etc. — is converted to HTML entities (<,>,&) before the model sees it. So a lorebook heading<Setting>is sent as<Setting>, and a markdown blockquote> ...is sent as> .... Marinara's own structural tags (<lorebook_all>,<last_message>, …) are not escaped, which is why those look fine while your typed text doesn't.This has two real costs the reporting user called out:
>/<Setting>rather than>/<Setting>. (Confirmed live: a user asked the model to echo their message back verbatim and the reply contained>, so the model genuinely received the entity, not the character.) Markdown blockquotes (>), a staple of roleplay formatting, are broken this way on every turn.>/<tokenize to several tokens each versus one for>/<, so heavy<...>/blockquote users pay an ongoing token tax.The biggest single offender is
>: XML does not require>to be escaped in text content at all (only<and&are mandatory;>only needs escaping inside the literal]]>sequence). So escaping every>is unnecessary and it's the part that breaks the very common markdown blockquote.How to reproduce (try it yourself)
<lorebook_all>,<last_message>style tags).<Setting>, or send a chat message that starts with a markdown blockquote, e.g.> hello.You'll see: the typed
<Setting>appears as<Setting>, and the>appears as>— and an echo test shows the model received>, not>.Expected: your
</>reach the model as the characters you typed (at minimum>should never be escaped), so blockquotes work and no extra tokens are spent. Marinara's own wrapper tags stay literal as today.(Workaround for now: set the preset's wrap format to Markdown or None — those paths don't XML-escape.)
Where it is
packages/server/src/services/prompt/prompt-escaping.ts—escapeXmlText(line 4) does.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");sanitizePromptLeaf(11-15) applies it to every leaf whenwrapFormat === "xml". It's called for essentially all user-authored leaf content during assembly: messages viaservices/prompt/macro-context.ts:411, lorebook / world-info viaservices/prompt/marker-expander.ts:356/366/368, character fields viaservices/generation/character-prompt-context.ts:120/206, summaries viaservices/prompt/assembler.ts:775, plus memory/scene contexts that callescapeXmlTextdirectly.What's happening
In XML wrap mode the assembler escapes leaf content so a user's literal text can't break the well-formedness of the XML wrapper (and can't inject a closing tag). That intent is reasonable for
<and&, but: (a)>is swept in even though XML never requires it, which is what breaks markdown blockquotes; and (b) the escaped result is what the model literally reads, so even the</&escaping shows up as visible entities and extra tokens.Suggested fix
>inescapeXmlText— drop the.replace(/>/g, ">"). This immediately fixes markdown blockquotes and removes the most common token waste, with no loss of well-formedness (a bare>is valid XML text). If you want to be fully strict, escape only the literal]]>sequence instead.</&for leaf content, or make it less aggressive: escaping<is a deliberate anti-injection / well-formedness measure, but its side effect is that the model reads<...>for any legitimately-typed<tag>(the<Setting>case) and pays extra tokens. Options: only escape<when it actually forms a sequence that could be mistaken for one of the framework's own wrapper tags; make XML-escaping opt-in; or document the tradeoff so users know to pick Markdown/None when they rely on literal angle brackets.AI-investigated against v2.0.6 from the user's report (Peek Prompt + a model echo-back test). The repro is the user's; the code location is from a code read — please confirm before fixing.
@SpicyMarinara commented on GitHub (Jun 30, 2026):
Addressed in draft PR #3109. The fix keeps user-authored
>literal in XML-wrapped prompt leaves so blockquotes reach the model as typed, while<and&remain escaped for prompt-boundary safety; prompt regression coverage was added.