mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2939] [Issue]: {{#if}} blocks leak their raw tag text (e.g. {{else if}}) into the model's prompt and pick the wrong branch #1515
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#1515
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 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2939
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
{{#if …}}conditional blocks can leak their own raw tag text (like{{else if …}}) straight into the prompt that gets sent to the model, and pick the wrong branch. So the model literally sees{{else if x}}in its context, and the character behaves oddly.How to reproduce (try it yourself)
Case 1 —
{{else if}}leaks. Put this in a character's Description or a lorebook entry:You'll see (in the prompt):
It is one{{else if 2==2}}It is two— the{{else if 2==2}}tag is left in verbatim.Expected: just
It is one.Case 2 — a macro inside the condition breaks it. First set a variable, then:
You'll see: the block doesn't resolve correctly — leftover text like
== "Bob"}}Hi Bobleaks through.Expected:
Hi Bob.(Also affected: a second
{{else}}in one block, and a stray/literal{{#if}}with no condition, both desync the parser and leak text.)Where it is
packages/shared/src/utils/macro-engine.ts—findConditionalStart(line 562) andfindConditionalEnd(571), used byresolveConditionalBlocks(600).What's happening
The conditional parser uses plain regexes that stop at the first
}}rather than the matching one, and it only knows three tags:{{#if}},{{else}},{{/if}}.{{else if}}, so that tag is treated as ordinary text and leaks.{{#if {{getvar::x}} == …}}— the condition regex[\s\S]*?stops at the inner macro's}}, so the condition is read as{{getvar::xand the rest spills out.{{#if}}(no condition) isn't recognized as a start but is counted by the end-scanner, throwing off the open/close depth count.Suggested fix
Make the conditional parser brace-aware (reuse the existing balanced-brace matcher
findBalancedMacroEndthat the rest of the engine already uses), resolve any macros inside the condition before matching the closing tag, and add support for{{else if …}}chains. At minimum, recognize and strip{{else if}}so it can never leak.Found by a code review of v2.0.6; please verify the reproductions before fixing.
@SpicyMarinara commented on GitHub (Jun 28, 2026):
Fixed on staging: conditional parsing is now brace-aware, supports else-if chains, resolves macros inside condition expressions, and avoids leaking raw conditional tags into the prompt. Added prompt regression coverage for else-if and nested getvar conditions. Validation: pnpm regression:prompt; pnpm check.