mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2986] [Issue]: Batch result mis-attribution: an embedded <result agent="X"> tag inside another agent's output hijacks agent X's slot and drops the author's output #1562
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#1562
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 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2986
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When agents are batched, the parser scans the whole batch response for
<result agent="...">openers and treats every match as a real block — including a<result agent="...">that appears literally inside another agent's content. Models readily emit such nested tags because the batch system prompt shows them the<result agent="...">template. Because the embedded fragment appears textually first and dedup keeps the first occurrence per agent type, the embedded fragment WINS the victim agent's slot and the victim's real, later block is discarded; the agent that authored the prose is dropped entirely and forced into individual retry. For a text/context-injection victim (e.g. knowledge-retrieval, director) the garbage fragment passes straight through and is injected into the main prompt with no safety net.How to reproduce (try it yourself)
You'll see: knowledge-retrieval is assigned
"FAKE INJECTED LORE</result> next\"}"(the embedded fragment), its real block is silently dropped, and world-state resolves to undefined and is forced into individual retry.Expected: knowledge-retrieval gets its real block and world-state parses correctly; the embedded tag stays inert as part of world-state's content.
Where it is
packages/server/src/services/agents/agent-executor.ts:1002-1005(first-wins dedup inparseBatchResponse) and:1048-1080(extractResultBlocks— the open-tag scan that never skips openers falling inside an already-consumed block's span). Text-victim passthrough at:2258-2270(parseAgentResponse).What's happening
extractResultBlocksuses/<result\b([^>]*)>/gito collect ALL openers and, for each, selects the last</result>before the next opener's index. It does not distinguish a real top-level opener from a<result agent="...">string inside another block's content. Combined with first-occurrence-wins dedup, an embedded/echoed tag textually preceding the legitimate block hijacks that agent's slot, and the outer block (whose close is cut short by the embedded opener) is dropped.Suggested fix
Rewrite
extractResultBlocksto be depth-aware while preserving the original "last close before the next sibling opener" tolerance for stray</result>in content. Tokenize all openers and closers once, then match each block with a depth counter so a nested/echoed<result agent="...">inside another agent's content is absorbed as content instead of treated as a real opener. Replace lines 1048-1080:Regression avoided: the naive suggested fix ("skip openers inside an already-consumed span") does NOT trigger here because the victim outer block is never consumed in the first place — output is byte-identical to the buggy original. Switching to "first
</result>after opener" or pure bracket-depth matching each breaks the stray-</result>-in-content tolerance the original logic was written for. This depth-aware version keeps that tolerance (verified parity on happy path, stray-close, missing-close, empty input, multi-agent JSON, etc.) and diverges only on the exact nested-tag bug. TheExtractedResultBlockshape is unchanged and no external caller depends on this function.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3004.