[GH-ISSUE #2941] [Issue]: Text inserted by {{agent::TYPE}} is re-run as macros (can set variables or trigger the dice freeze) #1518

Closed
opened 2026-10-21 05:37:52 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2941

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

Text pulled into the prompt by {{agent::TYPE}} (an agent's or tracker's cached output) is then treated as macros and executed. So if an agent/tracker ever produces text that contains {{…}} — which the model can do on its own — those macros run: they can silently set variables, or trigger the runaway dice loop and freeze the app.

How to reproduce (try it yourself)

  1. Enable an agent/tracker whose output you reference somewhere with {{agent::TYPE}} (e.g. in a preset or character field).
  2. Get that agent's output to contain a macro. The clean demo: temporarily make the agent/tracker emit the literal text {{roll:999999999d6}} (or {{setvar::pwned::1}}).
  3. Send a turn that builds the prompt.

You'll see: with {{roll:999999999d6}} the request freezes (the dice loop runs); with {{setvar::pwned::1}} the variable pwned is now set even though no card/preset asked for it.
Expected: an agent's text output should be inserted as plain text, not re-interpreted as macros.

Where it is

packages/shared/src/utils/macro-engine.ts — resolveMacros substitutes {{agent::TYPE}} at lines 892–894, but the variable, random, and dice handlers (907–961) run after that on the same string, so anything the agent inserted is now eligible for macro processing.

What's happening

resolveMacros is one single pass: substituted values are not marked "already resolved," so untrusted text inserted mid-pass (agent output here) is processed by the remaining macro stages. This is the same shape as macros leaking from character cards/lorebooks generally, but {{agent::TYPE}} makes it reachable from model-generated text.

Suggested fix

Insert {{agent::TYPE}} output as inert text — either resolve it in a final pass after all other macros, or escape/neutralize any {{ }} in agent output before substituting it. More broadly, substituted values from untrusted sources should not be re-fed into the macro engine.


Found by a code review of v2.0.6. The mechanism is certain; the trigger depends on the agent output containing a macro — please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2941 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Text pulled into the prompt by `{{agent::TYPE}}` (an agent's or tracker's cached output) is then treated as macros and executed. So if an agent/tracker ever produces text that contains `{{…}}` — which the model can do on its own — those macros run: they can silently set variables, or trigger the runaway dice loop and freeze the app. **How to reproduce (try it yourself)** 1. Enable an agent/tracker whose output you reference somewhere with `{{agent::TYPE}}` (e.g. in a preset or character field). 2. Get that agent's output to contain a macro. The clean demo: temporarily make the agent/tracker emit the literal text `{{roll:999999999d6}}` (or `{{setvar::pwned::1}}`). 3. Send a turn that builds the prompt. **You'll see:** with `{{roll:999999999d6}}` the request freezes (the dice loop runs); with `{{setvar::pwned::1}}` the variable `pwned` is now set even though no card/preset asked for it. **Expected:** an agent's text output should be inserted as plain text, not re-interpreted as macros. **Where it is** `packages/shared/src/utils/macro-engine.ts` — `resolveMacros` substitutes `{{agent::TYPE}}` at lines 892–894, but the variable, random, and dice handlers (907–961) run *after* that on the same string, so anything the agent inserted is now eligible for macro processing. **What's happening** `resolveMacros` is one single pass: substituted values are not marked "already resolved," so untrusted text inserted mid-pass (agent output here) is processed by the remaining macro stages. This is the same shape as macros leaking from character cards/lorebooks generally, but `{{agent::TYPE}}` makes it reachable from model-generated text. **Suggested fix** Insert `{{agent::TYPE}}` output as inert text — either resolve it in a final pass after all other macros, or escape/neutralize any `{{` `}}` in agent output before substituting it. More broadly, substituted values from untrusted sources should not be re-fed into the macro engine. --- *Found by a code review of v2.0.6. The mechanism is certain; the trigger depends on the agent output containing a macro — please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Fixed on staging: {{agent::TYPE}} output is now substituted after executable macro passes, so agent/tracker text is inserted inertly instead of re-running dice/variable macros.

<!-- gh-comment-id:4827784293 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed on staging: `{{agent::TYPE}}` output is now substituted after executable macro passes, so agent/tracker text is inserted inertly instead of re-running dice/variable macros.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1518
No description provided.