mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3008] [Issue]: A JSON array of tool calls wrapped in a <tool_call> tag is silently dropped by the textual parser #1580
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#1580
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/3008
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When a non-native-function-calling model emits multiple tool calls as a JSON ARRAY inside a single tool-call tag, e.g.
<tool_call>[{"name":"roll_dice","arguments":{}},{"name":"get_weather","arguments":{}}]</tool_call>, every call is silently discarded and the turn produces zero tool calls. The tagged-snippet path only ever produces a single payload object per snippet; it has no array branch.snippetToPayload()runsparseJsonishObject()on the snippet, which returns null for arrays; thename{...}regex does not match[...]; and the mari-command fallback also returns null. So the snippet yields null and all calls are lost. The top-level-array recovery branch does not help because the content begins with<, not[.How to reproduce (try it yourself)
tool_callsin the response and at least one tool enabled.<tool_call>[{"name":"roll_dice","arguments":{}},{"name":"get_weather","arguments":{}}]</tool_call>.You'll see:
parseTextualToolCalls(content, options.tools)returns[](0 tool calls); the agent does nothing and the raw tagged text is dropped. Confirmed by line-by-line reproduction of the parser (count 0); the same<|tool_call|>variant is also affected (count 0). Control cases work: a single object in a tag → count 1; a bare top-level array → count 2.Expected: both tool calls in the array are parsed and executed.
Where it is
packages/server/src/services/llm/textual-tool-call-parser.ts:snippetToPayloadat lines 111-134 (single-object only), consumed in the loop at lines 217-225 ofparseTextualToolCalls. Reachable frompackages/server/src/services/llm/providers/openai.provider.ts:1259(non-streaming) and:1427(streaming).What's happening
snippetToPayloadhandles only a single object payload or a singlename{...}command; it never destructures a top-level JSON array of tool calls. The array-recovery branch inparseTextualToolCallsis gated ontrimmed.startsWith('['), so an array nested inside a tag never reaches it.Suggested fix
Handle the array-in-tag case in the consumer loop of
parseTextualToolCalls(mirroring the existing top-level-array branch), so an array of tool calls inside a tag is expanded instead of dropped. Replace the loop at lines 217-225:The array check runs before
snippetToPayload(which returns null for arrays); elements go straight throughtoolCallFromRawsoknownTools/bash gating and the existingallowAnonymousJsonPayloadsemantics are preserved (anonymous array elements are not turned intomari_dbcalls, matching the top-level-array branch); invalid JSON or non-array snippets fall through to the unchanged single-payload path.Regression avoided: implementing this in the consumer loop (rather than making
snippetToPayloademit multiple payloads) fits the existing one-snippet→one-call wiring; otherwise all-but-one element would still be dropped. Per-element ids usecalls.lengthandtoolCallIdappends a random suffix, so ids stay unique.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 #3018.