mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #3765] [MERGED] fix(prompt): pass prompt leaf content to the model verbatim (stop escaping angle brackets) #6092
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#6092
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3765
Author: @kolacheee
Created: 7/18/2026
Status: ✅ Merged
Merged: 7/18/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/prompt-leaf-verbatim-tags📝 Commits (3)
b926026fix(prompt): stop escaping angle brackets in prompt leaf content7510d36fix(prompt): harden verbatim prompt-leaf contract against re-escaping0ac038eMerge branch 'staging' into fix/prompt-leaf-verbatim-tags📊 Changes
6 files changed (+194 additions, -53 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
CONTRIBUTING.md(+12 -0)📝
packages/server/src/services/generation/scene-context-runtime.ts(+7 -7)📝
packages/server/src/services/prompt/prompt-escaping.ts(+67 -8)📝
scripts/regressions/open-issues.regression.ts(+2 -2)📝
scripts/regressions/prompt.regression.ts(+105 -36)📄 Description
Linked issue
Closes #3766
What this does
Prompt leaf content — character card fields, persona, lorebook entries, memories, scene text, and example dialogue — now reaches the model verbatim. Angle-bracket and HTML-style tags (
<thinking>,<scenario>,<div style="...">) are passed through exactly as authored instead of arriving at the model as<thinking>.This fixes a recurring user-visible bug:
<test>typed in a persona or card showed up as<test>in Peek Prompt / the assembled prompt, roleplay HTML formatting broke, the editor displayed raw<, and tokens were wasted on entities.The change itself is one line of behavior (the XML leaf path stops HTML-escaping). The bulk of this PR is hardening so it stops getting silently re-broken.
Why this regression keeps happening
Leaf-content escaping has flip-flopped across many versions. The reason it keeps coming back is that the guard was never actually deleted before this branch — every prior "fix" only carved out an exception rather than removing the escaping:
&,<,>;>, a later one re-added>, another dropped it again;<START>example-dialogue carve-outs were added (#3441, #3623);<font…>before rendering (#3206) so the escaping merely looked harmless while the model still received the mangled<.The
<escaping survived all of that. Because the underlying injection-guard framing was never removed, three renewable sources kept regenerating the belief that escaping is correct and kept re-attracting it:escapeXmlTextreads as "an XML escaper," so making its body escape again looks like a bug fix, not a regression. (There is even a second, unrelated localescapeXmlTextinknowledge-router.tsthat legitimately does escape — an identical name with opposite behavior.)</&escaping deliberate "prompt-boundary safety" (#3108) and "Hardened prompt assembly … by escaping untrusted character/persona card text," with no countervailing entry. Release notes are the first thing a contributor reads, and they argued for escaping.CONTRIBUTING.mdnever mentioned this; the only rationale lived in a file header a re-escape PR's author might never open.This PR is the first true removal, and it closes all three sources (see Hardening below).
Why verbatim is the correct final state
Threat model. Marinara Engine is local, single-user roleplay. The person who authors or imports a card is the same person the card would "attack." The worst realistic outcome of an unescaped
<system>-looking tag is the model role-playing something odd — which the user sees immediately in their own chat and fixes by editing their own card. That is a rare, self-inflicted, self-correcting annoyance, not a security boundary. Escaping traded that non-threat for a constant, real harm: the very common, legitimate use of angle-bracket/HTML tags in cards and lorebooks arrived mangled.The model is not an XML parser. Escaping treated the LLM as if a stray
<could "break out" of a structural element the way it would in a real XML document. An LLM reads tokens; there is no parser to break out of. Turning<into<closes no injection surface — it only corrupts text.Structure is not at risk. The framework's own section wrappers (
<description>…</description>,<last_message>…, etc.) are emitted bywrapContentaround leaf content, from fixed section names, independent of what the content contains. Verbatim leaf content therefore cannot alter the structural tags — it only changes what sits inside them, as intended.Honest residual limitation. Verbatim does mean a self-authored/imported card can paste a convincing framework-style closing tag plus fake instructions into context. In a local single-user tool that is self-inflicted and self-fixable, and it is no stronger than writing those instructions in plain prose (which the model reads either way). If a future multi-tenant or shared-marketplace deployment ever changes the threat model, the right response is a validation/consent step at the import boundary, not silent per-token escaping of everyone's content at prompt-assembly time.
What deliberately stays escaped (out of scope)
The agent value/attribute escapers are unchanged and must stay:
escapeXml/escapeXmlAttributeinagent-executor.ts, the local escaper inknowledge-router.ts, and the storyboard/attachment escapers escape dynamic values into XML attributes and into strict, machine-parsed agent documents (world-state, entry catalogs,<turn_sections>,<attached_file name="…">). Those are parsed downstream, where a stray"or<genuinely breaks an attribute or element.Note that
agent-executor.tsalso escapes some of the same card fields into element content of that parsed document. That is a different consumer with different rules — it is explicitly not a consistency argument for re-escaping the main prompt path (the SCOPE comment now says so).Hardening (so this stops recurring)
escapeXmlText→passThroughLeaf(+ its callers inscene-context-runtime.tsand the regression). A function named "escapeXmlText" whose body isreturn valueinvites the one-line "obviously it should escape" change.<test>+ inline HTML through the real assembly path and asserts they arrive verbatim with no</&/>anywhere. The prior lock test only proved the leaf helper is identity, not the whole path.Validation
pnpm check(TypeScript + ESLint + build): passes.pnpm regression:prompt: passes for all prompt-escaping tests, including the new canary and the renamed verbatim tests. (One unrelated, pre-existing failure exists on this tree — the "Professor Mari … public reference … Prose Guardian" agent-catalog completeness check — and reproduces without any change in this PR.)pnpm --filter @marinara-engine/server exec tsx ../../scripts/regressions/open-issues.regression.ts: passes.Manual verification (please confirm)
<test>shows<test>verbatim (not<test>).<thinking>or inline HTML reaches the model and renders as authored (roleplay HTML no longer breaks).<START>separators still work, including cards imported with the marker already entity-encoded.Notes
stagingper the contributor workflow.stagingrather than the default branch, theFixeskeyword won't auto-close #3766 on merge — thein-pr→fixed-in-staginglabel flow covers closure when staging merges to main.Summary by CodeRabbit
<thinking>and<scenario>is no longer converted into escaped entities like<...>.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.