Repository navigation
fix(ollama): stop forcing tool_calls.arguments back to an object on the openai-completions path - #96498
fix(ollama): stop forcing tool_calls.arguments back to an object on the openai-completions path#96498googlerest wants to merge 3 commits into
Conversation
…he openai-completions path
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR has the right production shape, but #96474 is the stronger open landing path for the same Ollama Cloud/OpenAI-compatible tool-call argument regression because it carries the same deletion with proof-positive captured HTTP-path evidence and native sibling coverage. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Land #96474 as the canonical fix, optionally fold any unique wrapper-level assertions from this PR, then close the duplicate candidate branches for the same regression. So I’m closing this here and keeping the remaining discussion on #96474. Review detailsBest possible solution: Land #96474 as the canonical fix, optionally fold any unique wrapper-level assertions from this PR, then close the duplicate candidate branches for the same regression. Do we have a high-confidence way to reproduce the issue? Yes. The linked issue supplies captured failing payload evidence, and current source inspection shows the OpenAI-compatible wrapper converting string arguments back to objects before send. Is this the best way to solve the issue? No as the landing branch. The production change is right, but #96474 is the better solution path because it carries the same deletion with stronger captured HTTP-path proof and native sibling coverage. Security review: Security review cleared: The diff only changes Ollama TypeScript payload shaping and tests, with no dependency, workflow, secret, permission, package, or supply-chain surface added. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against c6ade83a5ccb. |
…rguments stay strings
|
Closing as superseded by #96474, now merged on The landed change removes the same OpenAI-compatible Ollama argument re-coercion while preserving native Thanks for independently tracing the regression and adding focused wrapper coverage. |
Fixes #96441
What Problem This Solves
Ollama Cloud models (e.g.
ollama/glm-5.2:cloud) fail every second agent turn after a tool call: OpenClaw sendstool_calls.function.argumentsas a JSON object instead of a JSON string when replaying conversation history through the OpenAI-compatible endpoint, and Ollama's Go server rejects it with400 json: cannot unmarshal object into Go struct field .messages.tool_calls.function.arguments of type string. This is a regression — the first turn works, the tool executes, then the agent is stuck.Why This Change Was Made
src/llm/providers/openai-completions.tsalready correctlyJSON.stringifystool_calls.function.argumentswhen building the outgoing request (this is the OpenAI Chat Completions wire format, which Ollama's Go server enforces strictly on:cloudmodels routed throughmodel.api === "openai-completions").extensions/ollama/src/stream.ts'swrapOllamaCompatNumCtxran a payload patch (normalizeOllamaCompatMessageToolArgs) right before send that re-coerced those already-correct JSON strings back into objects, undoing the stringify. Tracing this back to its origin: it was added in the same commit (87abcfd6a6, fixing #52253) that correctly addedensureArgsObject()for the native Ollama/api/chatpath (extractToolCalls/convertToOllamaMessages), where Ollama's native API does want an object. The same object-coercion was mistakenly also wired into the unrelatedopenai-completionspayload-patch path, breaking the opposite contract there.Fix: remove
normalizeOllamaCompatMessageToolArgs(and its only call site) fromwrapOllamaCompatNumCtx. The native-path fix for #52253 (ensureArgsObjectinsideextractToolCalls) is untouched.User Impact
Restores multi-turn tool use for Ollama Cloud (and any other provider routed through
model.api === "openai-completions"withshouldInjectOllamaCompatNumCtxenabled). No change for native Ollama (model.api === "ollama") users.Evidence
Behavior addressed:
wrapOllamaCompatNumCtx's payload patch mutated already-stringifiedtool_calls.function.arguments(and legacyfunction_call.arguments) back into an object on the openai-completions path, before the request left the process.Real environment tested: macOS arm64 (M4), Darwin 25.5.0, Node v25.9.0, branch
fix/ollama-cloud-tool-call-arguments-string, commit0564c6d637.Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix: added two regression tests for
wrapOllamaCompatNumCtx(tool_calls and legacy function_call) assertingargumentsstays a JSON string after the patch runs. Confirmed both new tests fail against the pre-fix code ({ query: 'weather' }received instead of'{"query":"weather"}') and pass after the fix, isolating exactly the regression described in #96441.What was not tested: did not run against a live Ollama Cloud account (no credentials in this environment) — this is a payload-construction unit fix verified by reproducing the exact wire-shape assertion the Go server's
400implies, not a live round-trip.