mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2686] [Issue]: Agent batch prompt & response-parsing XML integrity (unescaped name/type/macros + parseBatchResponse truncation/bare-tag hijack) #1329
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#1329
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 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2686
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The batched-agent prompt and its response parser have several XML-integrity weaknesses that corrupt the agent→output half of the pipeline: agent
name/type(and{{macro}}settings values) are interpolated unescaped into the batch prompt's XML, andparseBatchResponseuses regexes that can truncate the last agent block or hijack an unrelated nested tag — mis-assigning, dropping, or corrupting agent outputs.Expected behavior
A custom agent's name/type/settings should never be able to break the batch prompt structure, and the parser should assign each
<result>block to exactly the right agent without grabbing nested/unrelated tags.Actual behavior
buildBatchSystemPromptinsertsconfig.typeandconfig.nameinto XML attributes unescaped (<agent_task id="${config.type}" name="${config.name}">,<result agent="${config.type}">). A name/type containing",<,>, or a literal</agents>/</result>breaks the block structure and desyncsparseBatchResponse's regexes.renderAgentSettingsMacrossubstitutes settings{{key}}values unescaped into the<agents>block, so a settings value containing</agents>/<result agent="...">can close the block early or forge a result block.parseBatchResponse: the lazy[\s\S]*?match can truncate the last agent's block on a</result>inside JSON when trailing text follows; the bare-tag fallback<type>...</type>(pattern 5) matches the first same-named tag anywhere — including a tag nested inside another agent's body — and reports it as a successful result instead of failing/retrying.nameToXmlTag(feedback injection) lowercases + strips non-[a-z0-9_-], so two distinct agent names can slug to the same tag, producing duplicate/ambiguous<tag>blocks in the injected feedback.How it breaks the pipeline
Code trace (staging @
b826f8f4) —packages/server/src/services/agents/agent-executor.ts:buildBatchSystemPrompt~:821(id/name),~:843(<result agent>).escapeXmlAttributeexists (:1329) but is used only formessage_id.renderAgentSettingsMacros:109-113→ injected into<agents>at~:822/:1064.parseBatchResponse:860-930; lazy patterns:882-891; bare-tag pattern 5 at:894; assignment:902-926. Customtypeis free-form (agent.schema.ts:44z.string().min(1)).nameToXmlTagcollision:runtime-agent-sections.ts:33-37/packages/shared/src/utils/xml-wrapper.ts:9-16.Steps to reproduce
Combat "Pro"(contains a quote), enable it in a batch → thename="Combat "Pro""attribute breaks the<agent_task>element and can desync parsing.typep(via the REST API/import — the editor auto-slugs type, so this needs the raw path) batched with a narrator/expression agent that emits<p>...</p>; when the model omits thepagent's<result>block, pattern 5 assigns the narrator's<p>Once upon a time.</p>body to thepagent as success (no retry).Mood TrackerandMood-Trackerboth slug tomood-tracker→ duplicate feedback blocks.Suggested fix
config.type/config.namewithescapeXmlAttributeinbuildBatchSystemPrompt, andescapeXmlthe rendered macro values inrenderAgentSettingsMacros.parseBatchResponse: first extract all<result agent=...>blocks and remove their spans before running the bare-tag/underscore fallbacks against the residual; drop or denylist-gate pattern 5 (reserved HTML tags + length/whitespace sanity), and/or anchor the bare tag to top level. Reject/normalize customtypevalues that collide with HTML tags or other agents' types at creation.nameToXmlTagcollisions (append an index / includeagentTypeas an attribute).Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of the agent subsystem. The unescaped-name path affects any custom agent with special characters in its name; the bare-tag hijack mainly affects raw-API/imported short
typevalues. Part of a set of agent-pipeline issues filed together.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on the issue-sweep branch. Batched agent prompts now escape agent id/name attributes and XML-escape settings macro values inside the batched XML prompt. Batch response parsing now extracts explicit spans first, decodes escaped agent attrs, removes those spans before legacy fallback parsing, and drops the unsafe bare fallback so nested/unrelated tags cannot satisfy another agent. Runtime agent XML injection tags are now unique when names slug to the same tag. Final repo checks will run after the sweep.