Skip to content

[Bug]: Ollama Cloud tool_calls fail on 2nd turn — arguments sent as JSON object instead of string (400 from Go server) — regression in 2026.6.9 #96441

Closed

Description

@EugeneClaw

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

When using any Ollama Cloud model (e.g. ollama/glm-5.2:cloud), the first agent turn succeeds (model returns a tool call, tool executes). The second turn — where OpenClaw sends conversation history including the previous tool call back to the provider — fails with:

400 json: cannot unmarshal object into Go struct field .messages.tool_calls.function.arguments of type string

OpenClaw sends tool_calls.function.arguments as a JSON object instead of a string. The OpenAI API spec requires a string. Ollama's Go server enforces this strictly and rejects the request.

This is a regression introduced in 2026.6.9. Version 2026.6.8 does not exhibit this bug with the same config and same model.

Steps to reproduce

  1. Configure ollama/glm-5.2:cloud as primary model (OpenClaw 2026.6.9 or 2026.6.10)
  2. Send a message that triggers a tool call: "What is config.gateway.port? Use the config tool to check."
  3. First turn succeeds — model returns tool call, OpenClaw executes the config.get tool
  4. Second turn fails with 400 — OpenClaw sends the tool call history back with arguments as a JSON object

Expected behavior

tool_calls.function.arguments should be sent as a JSON string per the OpenAI API spec. This is what 2026.6.8 does correctly.

Actual behavior

tool_calls.function.arguments is sent as a JSON object, causing Ollama's Go server to reject with 400.

OpenClaw version

OpenClaw 2026.6.9

Operating system

MacOS 26.5.1

Install method

npm global

Model

Ollama GLM-5.2 Cloud (also confirmed: Ollama GLM-5.1 Cloud, Ollama MiniMax M3 Cloud — all Ollama Cloud models affected)

Provider / routing chain

openclaw → ollama (localhost:11434) → ollama cloud proxy

Additional provider/model setup details

Local Ollama 0.30.10, but :cloud models proxy through Ollama's cloud servers so local version is irrelevant. The error is returned by Ollama's cloud-side Go server, not the local instance.

Non-Ollama providers work fine: zhipu-ai/glm-5.2 (same GLM-5.2 model, direct from Z.ai API) succeeds on the second turn with tool calls. This suggests Ollama's Go server is stricter about enforcing the OpenAI spec (string-only for arguments) while other providers accept both string and object.

Root cause hypothesis: In openai-completions-vbhA-xck.js, line 917 does arguments: JSON.stringify(tc.arguments) which should produce a string. However, the wire payload has an object. Something between this stringify and the HTTP request — possibly in the OpenAI SDK v6.39.1 or a provider-specific adapter — is re-parsing the string back to an object. This code path worked correctly in 2026.6.8.

Related issue: #69735 (inverse problem — arguments not deserialized from string to object on the response side). The fix direction for that issue may have introduced this regression.

Logs, screenshots, and evidence

### HTTP interceptor capture
A local HTTP proxy between OpenClaw and Ollama captured the actual request body on the failing second turn:

msg[4].tool_calls[0]: name=gateway, type=dict, value={"action": "config.get", "path": "gateway.port"}

type=dict proves arguments is a JSON object on the wire, not a string.

### Cross-version comparison (same config, same model)

| OpenClaw Version | Provider | Model | Tool call 2nd turn |
|---|---|---|---|
| 2026.6.8 | ollama (cloud) | glm-5.2:cloud | ✅ Works |
| 2026.6.9 | ollama (cloud) | glm-5.2:cloud | ❌ 400 |
| 2026.6.10 | ollama (cloud) | glm-5.2:cloud | ❌ 400 |
| 2026.6.10 | ollama (cloud) | glm-5.1:cloud | ❌ 400 |
| 2026.6.10 | ollama (cloud) | minimax-m3:cloud | ❌ 400 |
| 2026.6.10 | zhipu-ai (direct) | glm-5.2 | ✅ Works |

The error hash is identical across all Ollama Cloud models: sha256:4c32d4487e51

### Gateway log (error)
2026-06-24T12:28:54.613+01:00 warn agent/embedded {"event":"embedded_run_agent_end","isError":true,"error":"LLM request failed: provider rejected the request schema or tool payload.","failoverReason":"format","model":"glm-5.2:cloud","provider":"ollama","rawErrorPreview":"400 json: cannot unmarshal object into Go struct field .messages.tool_calls.function.arguments of type string","rawErrorHash":"sha256:4c32d4487e51","providerRuntimeFailureKind":"schema"}

Impact and severity

Affected: All Ollama Cloud model users who use tool calls (config.get, exec, read, write, etc.)
Severity: High — tool calls silently fail on the second turn, making the agent unable to perform any tool-based operation beyond a single turn
Frequency: 100% of multi-turn conversations involving tool calls with Ollama Cloud models
Consequence: Agent cannot perform config queries, file operations, or any tool-based task that requires sending conversation history back to the provider. Only simple non-tool messages work.

Additional information

  • Workaround: Roll back to 2026.6.8, or use a non-Ollama provider (e.g. zhipu-ai) for tool-calling conversations
  • Simple messages (no tool calls) work fine on all versions including 2026.6.10
  • The CLI version on PATH was 2026.6.6 (Hermes bundled) while gateway was 2026.6.9/10 — this is a separate issue but worth noting the version mismatch warning that appears in logs
  • Ollama was updated from 0.24.0 to 0.30.10 during testing — did not resolve the issue (as expected, since :cloud models proxy through Ollama's cloud servers not the local instance)

Not a duplicate of #46679, #50689, or #57103. Those issues (March 2026, all closed) reported the inverse problem: OpenClaw sent arguments as a JSON string when the Ollama NATIVE API (/api/chat) expected an object. The fix for those issues (JSON.parse string → object) overcorrected and broke the OpenAI-COMPATIBLE API path (/v1/chat/completions), which per the OpenAI spec requires arguments as a string. This bug affects api: "openai-completions", not api: "ollama" (native).

Activity

  1. clawsweeper commented on Jun 24, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 24, 2026, 9:43 AM ET / 13:43 UTC.

    Summary
    Keep open: current main and the latest release still apply native-Ollama object normalization to OpenAI-compatible Ollama payloads, matching the reporter's captured 400 on second-turn tool-call replay.

    Reproducibility: yes. source-level reproduction is high confidence: the issue provides a captured failing payload and current code shows the Ollama OpenAI-compatible wrapper converting string tool-call arguments back to objects before send. I did not run a live Ollama Cloud credential test in this read-only pass.

    Root-cause cluster
    Relationship: canonical
    Canonical: #96441
    Summary: This issue is the canonical remaining report for the OpenAI-compatible Ollama Cloud inverse of earlier native Ollama string/object replay bugs.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    This is a narrow provider payload-shape repair with a clear code path, clear regression tests, and no product decision blocker.

    Review details

    Best possible solution:

    Split the Ollama native and OpenAI-compatible replay contracts: keep object coercion only for native /api/chat, and preserve string arguments for Ollama Cloud/OpenAI-compatible Chat Completions while retaining num_ctx injection.

    Do we have a high-confidence way to reproduce the issue?

    Yes, source-level reproduction is high confidence: the issue provides a captured failing payload and current code shows the Ollama OpenAI-compatible wrapper converting string tool-call arguments back to objects before send. I did not run a live Ollama Cloud credential test in this read-only pass.

    Is this the best way to solve the issue?

    Yes, the best fix is narrow: stop applying native Ollama object coercion to OpenAI-compatible Chat Completions payloads, and add regression coverage proving both API contracts remain distinct.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No live Ollama Cloud run was performed in this read-only review, so the repair should verify a captured OpenAI-compatible request payload if credentials are available.
    • The fix must preserve native /api/chat object arguments for the closed inverse Ollama issues while keeping /v1/chat/completions arguments as strings.

    Codex review notes: model internal, reasoning high; reviewed against f0be8e7b6ee8.

    Label changes

    Label changes:

    • add P1: This is a reported latest-release regression that breaks multi-turn tool use for Ollama Cloud users after the first tool call.
    • add impact:session-state: The failure is in replaying prior assistant tool-call history back into the next model turn.
    • add impact:auth-provider: The affected surface is provider-specific Ollama Cloud/OpenAI-compatible request shaping.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P1: This is a reported latest-release regression that breaks multi-turn tool use for Ollama Cloud users after the first tool call.
    • impact:session-state: The failure is in replaying prior assistant tool-call history back into the next model turn.
    • impact:auth-provider: The affected surface is provider-specific Ollama Cloud/OpenAI-compatible request shaping.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/ollama/index.test.ts
    • node scripts/run-vitest.mjs extensions/ollama/src/stream.test.ts extensions/ollama/src/stream-runtime.test.ts

    What I checked:

    • Issue report has concrete current repro evidence: The issue reports 2026.6.9 and 2026.6.10 failing on the second tool-call turn for Ollama Cloud with a captured request showing tool_calls[0].function.arguments as a dict/object and the provider returning cannot unmarshal object ... of type string.
    • OpenAI-compatible converter initially serializes arguments correctly: Current main's Chat Completions converter maps assistant tool calls with function.arguments: JSON.stringify(tc.arguments), so the OpenAI-compatible base payload starts as a string. (src/llm/providers/openai-completions.ts:1084, f0be8e7b6ee8)
    • Ollama OpenAI-compatible wrapper mutates payloads after conversion: wrapOllamaCompatNumCtx runs through streamWithPayloadPatch, injects num_ctx, and then calls normalizeOllamaCompatMessageToolArgs on the outgoing payload before the underlying sender uses it. (extensions/ollama/src/stream.ts:250, f0be8e7b6ee8)
    • Normalization converts OpenAI-compatible tool-call arguments to objects: normalizeOllamaCompatMessageToolArgs walks messages[*].function_call.arguments and messages[*].tool_calls[*].function.arguments, replacing each value with ensureArgsObject(...), which parses JSON strings into objects. (extensions/ollama/src/stream.ts:739, f0be8e7b6ee8)
    • Latest release contains the same behavior: The v2026.6.10 tag still calls normalizeOllamaCompatMessageToolArgs from the OpenAI-compatible wrapper and still coerces tool_calls[*].function.arguments through ensureArgsObject, so this is not fixed by the latest release. (extensions/ollama/src/stream.ts:773, aa69b12d0086)
    • Dependency contract expects string arguments for Chat Completions: The OpenAI 6.39.1 Chat Completions type declarations define tool-call function.arguments and legacy function_call.arguments as strings in JSON format.

    Likely related people:

    • steipete: The over-broad Ollama tool-call replay normalization appears in the merged fix commit for fix: deserialize string tool-call arguments before sending to Ollama #52253, authored and committed by Peter Steinberger. (role: introduced behavior; confidence: high; commits: 87abcfd6a6b8; files: extensions/ollama/src/stream.ts)
    • vincentkoc: Current shallow blame on the affected lines points at the 2026.6.10 release closeout that carried this code into the latest shipped train. (role: recent area carrier; confidence: medium; commits: 0671c0890073, aa69b12d0086; files: extensions/ollama/src/stream.ts)
    • Adam-Researchh: The merged PR discussion for the inverse bug says this contributor added the cloud/OpenAI-compatible normalization hook, which is now the likely over-applied behavior. (role: original fix proposer; confidence: medium; commits: 87abcfd6a6b8; files: extensions/ollama/src/stream.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 24, 2026
  3. added a commit that references this issue on Jun 24, 2026
    2bed2d4
  4. added a commit that references this issue on Jun 29, 2026
    8ee6fe3
  5. locked as resolved and limited conversation to collaborators on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions