mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5541] [MERGED] Make sidecar JSON agents robust to inline thinking and Gemma delimiters #6806
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#6806
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5541
Author: @kolacheee
Created: 8/25/2026
Status: ✅ Merged
Merged: 8/25/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/5537-sidecar-agent-json📝 Commits (1)
2243d54fix(agents): make sidecar JSON agents robust to inline thinking and Gemma delimiters📊 Changes
4 files changed (+128 additions, -1 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/services/agents/agent-executor.ts(+53 -0)📝
packages/server/src/services/llm/textual-tool-call-parser.ts(+3 -1)📝
scripts/regressions/agent-runtime.regression.ts(+71 -0)📄 Description
Linked issue
Closes #5537
Why this change
Every JSON-returning agent on the built-in Local Model fails with "Agent returned invalid JSON…" since the Aug 19 staging update (#5247): JSON agents now send
reasoningEffort: "none", which the sidecar translates toreasoning_format: "none"+chat_template_kwargs.enable_thinking: false.reasoning_format: "none"makes llama.cpp leave any thinking inline incontent— and the agent path asks for JSON by prompt alone, with noresponse_format/grammar anywhere, so a thinking preamble poisons the fence/brace extraction identically on the first call, the strict retry, and the batch fallback. Full analysis in #5537. (Ironically #5247 was itself a Gemma JSON fix; it fixed the empty-content mode and exposed this one.)What changed
Three layers, from prevention to tolerance, all in
packages/server:1. Sidecar JSON agents are now grammar-constrained.
executeAgent, the tool loop's final round, andexecuteAgentBatchattachresponseFormat: { type: "json_object" }when the model is the local sidecar and the agent's result must parse as JSON. llama.cpp then constrains generation itself — the parse cannot be poisoned regardless of what the template does with thinking. Scoping decisions:model === LOCAL_SIDECAR_MODEL): it's the runtime we ship and the one guaranteed to support the parameter; remote providers keep their existing prompt-only behavior. The MLX backend already stripsresponseFormatinLocalSidecarProvider, so both sidecar backends are safe.toolsare excluded and the final no-tools round carries the format instead (commented in code).responseFormatswitchesLocalSidecarProviderto greedy sampling (temp 0 / topP 1) — the desired decoding for machine-readable output, but it does override an agent's configured temperature on the sidecar.2.
extractJsonstrips leading thinking blocks before the fence match. Uses the existingextractLeadingThinkingBlocksfrom@marinara-engine/shared(covers<think>,<thinking>,<thought>, bracketed variants). Ordering matters: a fenced draft inside the thinking region would otherwise win the fence regex. One change covers every extraction site — first call, retry, tool loop, beholder lanes, batch container, and batch per-agent fallback.3. Gemma 4
<|"|>delimiters are normalized in the agent JSON path.normalizeGemma4Delimitersis now exported from the textual tool-call parser (previously module-private) and applied inextractJson, so the agent path tolerates the same model quirk the tool-call path already handles.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Automated, from this branch:
pnpm lintpasses (tsc on shared+server, ESLint on client).node ./scripts/run-regressions.mjs --filter scripts/regressions/agent-runtime.regression.tspasses, including seven new assertions: thinking-prefixed JSON parses without a retry; a fenced draft inside a thinking block loses to the real payload; Gemma<|"|>delimiters parse; sidecar JSON agents requestjson_object; non-sidecar agents and text-result agents on the sidecar do not.--end-of-line auto; repo-wideformat:checkfails pre-existing on CRLF Windows checkouts).Needs a human with the local model downloaded (I could not run the sidecar binary in this environment):
LOG_LEVEL=debugto confirm requests carryresponse_format: {"type":"json_object"}and responses parse on the first call.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG entry under
[Unreleased] → Fixed. No user-facing docs describe the agent JSON pipeline; nodocs-i18nimpact.Summary by CodeRabbit
Bug Fixes
Documentation
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.