[GH-ISSUE #5537] Agents on the local sidecar all fail with "invalid JSON" since JSON agents force reasoning off #3076

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

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

Originally assigned to: @kolacheee on GitHub.

From a user report (staging, auto-updating install, the pre-linked default Gemma local model): after moving their agents back onto the local sidecar, every agent fails with

Agent returned invalid JSON instead of the requested … format. Check this agent's model/connection settings and try again.

The same model ran these agents fine days earlier. The user suspects their koboldcpp-and-back connection switching broke something, but the switching is almost certainly innocent — nothing from a koboldcpp leg can survive into a sidecar request (the agent editor rewrites the settings blob wholesale, and no model/template field carries over). What actually changed in that window is staging itself.

What changed

PR #5247 (46e7edf47, merged Aug 19) makes every JSON-result agent send reasoningEffort: "none" (packages/server/src/services/agents/agent-executor.ts:3251). For the local sidecar specifically, the provider translates that into two request-body fields that sidecar agent calls never carried before (packages/server/src/services/llm/providers/openai.provider.ts:866-867):

body.reasoning_format = "none";
body.chat_template_kwargs = { ...templateOptions, enable_thinking: false };

reasoning_format: "none" tells llama.cpp to leave any thinking inline in content instead of splitting it into reasoning_content. If the shipped Gemma template does not honor enable_thinking: false, every agent response now arrives as a thinking preamble glued in front of the JSON.

The agent path has no structural defense against that: agents ask for JSON by prompt only — no response_format, no json_schema, no grammar anywhere in the agent executor (grep it: zero hits) — and then run fence/brace extraction over content. A thinking preamble poisons that extraction identically on the first call, on the strict-JSON retry (agent-executor.ts:870), and on the per-agent batch fallback (:1651), which is why the user sees every agent fail the same way at once.

The irony is that #5247 was itself a Gemma JSON fix — its commit message documents Gemma-4 12B burning the whole completion budget on thinking and returning empty content. It fixed that failure mode for connections that honor the flags, and plausibly created this one for the sidecar.

There is also no escape hatch on this path: a connection can defeat the override via enabledParameters.reasoningEffort === false (agent-executor.ts:3249), but the explicit-sidecar resolution pins enabledParameters = { temperature: true } (packages/server/src/services/generation/agent-resolution.ts:363-375), so sidecar users cannot opt out.

Confirming it

One debug log settles the mechanism. With LOG_LEVEL=debug in .env, trigger any agent and read the raw response the executor logs (agent-executor.ts:855):

  • thinking text / <think> tags in front of the JSON → this regression;
  • consistently empty content → the original #5247 symptom still occurring on the sidecar despite the flags.

Either way the sidecar agent path is broken for the default model, only the fix differs.

Try it yourself

  1. On current staging, download the default local model.
  2. Open any JSON-returning agent (a tracker is easiest) and set its connection to Local Model (sidecar) in the agent editor.
  3. Run a chat turn that triggers it → "Agent returned invalid JSON…".

Fix directions

  1. Give the agent path real structure. Pass a json_schema response format for llama.cpp/sidecar connections in executeAgent / executeAgentBatch — the plumbing already exists and the game-scene generation path already uses it; the sidecar provider already handles responseFormat. This fixes the whole class regardless of what the template does with thinking.
  2. And/or gate the override. Only send reasoning_format: "none" + enable_thinking: false on the local sidecar when the loaded template is known to honor it — or strip inline <think>…</think> blocks before JSON extraction so the flags can't make things worse.
  3. Related, smaller: Gemma-4's <|"|> string-delimiter quirk is normalized in the textual tool-call parser (normalizeGemma4Delimiters) but never in the agent JSON extraction path — worth unifying while in there.
Originally created by @kolacheee on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5537 Originally assigned to: @kolacheee on GitHub. From a user report (staging, auto-updating install, the pre-linked default Gemma local model): after moving their agents back onto the local sidecar, **every** agent fails with > Agent returned invalid JSON instead of the requested … format. Check this agent's model/connection settings and try again. The same model ran these agents fine days earlier. The user suspects their koboldcpp-and-back connection switching broke something, but the switching is almost certainly innocent — nothing from a koboldcpp leg can survive into a sidecar request (the agent editor rewrites the settings blob wholesale, and no model/template field carries over). What actually changed in that window is staging itself. ## What changed PR #5247 (`46e7edf47`, merged Aug 19) makes every JSON-result agent send `reasoningEffort: "none"` (`packages/server/src/services/agents/agent-executor.ts:3251`). For the local sidecar specifically, the provider translates that into two request-body fields that sidecar agent calls never carried before (`packages/server/src/services/llm/providers/openai.provider.ts:866-867`): ```ts body.reasoning_format = "none"; body.chat_template_kwargs = { ...templateOptions, enable_thinking: false }; ``` `reasoning_format: "none"` tells llama.cpp to leave any thinking **inline in `content`** instead of splitting it into `reasoning_content`. If the shipped Gemma template does not honor `enable_thinking: false`, every agent response now arrives as a thinking preamble glued in front of the JSON. The agent path has no structural defense against that: agents ask for JSON **by prompt only** — no `response_format`, no `json_schema`, no grammar anywhere in the agent executor (grep it: zero hits) — and then run fence/brace extraction over `content`. A thinking preamble poisons that extraction identically on the first call, on the strict-JSON retry (`agent-executor.ts:870`), and on the per-agent batch fallback (`:1651`), which is why the user sees every agent fail the same way at once. The irony is that #5247 was itself a Gemma JSON fix — its commit message documents Gemma-4 12B burning the whole completion budget on thinking and returning empty content. It fixed that failure mode for connections that honor the flags, and plausibly created this one for the sidecar. There is also no escape hatch on this path: a connection can defeat the override via `enabledParameters.reasoningEffort === false` (`agent-executor.ts:3249`), but the explicit-sidecar resolution pins `enabledParameters = { temperature: true }` (`packages/server/src/services/generation/agent-resolution.ts:363-375`), so sidecar users cannot opt out. ## Confirming it One debug log settles the mechanism. With `LOG_LEVEL=debug` in `.env`, trigger any agent and read the raw response the executor logs (`agent-executor.ts:855`): - thinking text / `<think>` tags in front of the JSON → this regression; - consistently **empty** content → the original #5247 symptom still occurring on the sidecar despite the flags. Either way the sidecar agent path is broken for the default model, only the fix differs. ## Try it yourself 1. On current staging, download the default local model. 2. Open any JSON-returning agent (a tracker is easiest) and set its connection to **Local Model (sidecar)** in the agent editor. 3. Run a chat turn that triggers it → "Agent returned invalid JSON…". ## Fix directions 1. **Give the agent path real structure.** Pass a `json_schema` response format for llama.cpp/sidecar connections in `executeAgent` / `executeAgentBatch` — the plumbing already exists and the game-scene generation path already uses it; the sidecar provider already handles `responseFormat`. This fixes the whole class regardless of what the template does with thinking. 2. **And/or gate the override.** Only send `reasoning_format: "none"` + `enable_thinking: false` on the local sidecar when the loaded template is known to honor it — or strip inline `<think>…</think>` blocks before JSON extraction so the flags can't make things worse. 3. Related, smaller: Gemma-4's `<|"|>` string-delimiter quirk is normalized in the textual tool-call parser (`normalizeGemma4Delimiters`) but never in the agent JSON extraction path — worth unifying while in there.
Author
Owner

@kolacheee commented on GitHub (Aug 25, 2026):

Implementation starting — owner: @kolacheee. Draft PR will follow shortly on a staging-targeted branch.

<!-- gh-comment-id:5413730388 --> @kolacheee commented on GitHub (Aug 25, 2026): Implementation starting — owner: @kolacheee. Draft PR will follow shortly on a `staging`-targeted branch.
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#3076
No description provided.