Repository navigation
fix(ollama): preserve tool_calls arguments as JSON strings in OpenAI-compatible path - #96501
Conversation
…compatible path - Remove normalizeOllamaCompatMessageToolArgs call from wrapOllamaCompatNumCtx — the upstream OpenAI-compatible converter (openai-completions.ts) already serializes arguments as JSON strings per the OpenAI API spec. - The removed call was re-parsing string arguments back to objects, causing Ollama Cloud Go server to reject with 400 on second-turn tool calls. - Native Ollama /api/chat path has its own normalization elsewhere. - Add wrap-ollama-compat.test.ts with 4 test cases verifying that tool_calls[*].function.arguments remain as strings after wrapping. Fixes openclaw#96441
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this branch targets the right Ollama Cloud regression, but #96474 is the stronger open canonical path with the same production deletion, positive captured HTTP-path proof, clean mergeability, and no unused-helper validation failure. 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 proof-positive canonical fix, optionally consolidate any desired tests there, then close duplicate candidate paths for the same Ollama Cloud regression. So I’m closing this here and keeping the remaining discussion on #96474. Review detailsBest possible solution: Land #96474 as the proof-positive canonical fix, optionally consolidate any desired tests there, then close duplicate candidate paths for the same Ollama Cloud regression. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection reproduces the payload-shape bug: the OpenAI-compatible converter creates string arguments and current main's Ollama wrapper parses them back to objects before send; the linked issue adds captured provider-error evidence. Is this the best way to solve the issue? No as a landing branch. The code direction is right, but #96474 is the better solution because it removes the helper entirely and includes positive captured HTTP-path proof. 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 4ae0a5d958a0. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Ollama Cloud models fail on the second agent turn when tool calls are involved. OpenClaw sends
tool_calls.function.argumentsas a JSON object instead of a JSON string, causing Ollama's Go server to reject the request with400.Root cause: The
wrapOllamaCompatNumCtxfunction in the Ollama extension (extensions/ollama/src/stream.ts) callednormalizeOllamaCompatMessageToolArgs, which converts tool call arguments from JSON strings back to objects. The upstream OpenAI-compatible converter (openai-completions.ts) already correctly serializes arguments as strings per the OpenAI API spec — this normalization was over-applied.Fix: Removed the over-application of
normalizeOllamaCompatMessageToolArgsfrom the OpenAI-compatible wrapper while keeping the native Ollama/api/chatnormalization intact.Fixes #96441
Real behavior proof (required for external PRs)
Behavior addressed: Ollama Cloud returns 400
cannot unmarshal object into Go struct field .messages.tool_calls.function.arguments of type stringon second-turn tool call replay.Evidence type: terminal (unit tests + code review)
Real setup tested:
Exact steps or command run after fix:
pnpm test -- --project extension-providers extensions/ollama/src/After-fix evidence:
Observed result after the fix: All 266 tests pass. New regression tests confirm that
tool_calls[*].function.argumentsremain as JSON strings throughwrapOllamaCompatNumCtx. The native Ollama path (normalizeOllamaToolCallArguments) is unaffected.What was not tested: End-to-end Ollama Cloud credential test (requires a live Ollama Cloud API key). The existing issue report already provides HTTP interceptor evidence showing the wire-format problem, and the code-level fix is directly verifiable from the payload structure.
Tests and validation
wrap-ollama-compat.test.ts— verifies arguments stay as stringsstream.test.tsstream-runtime.test.tsRisk checklist
Did user-visible behavior change? (
No)Did config, environment, or migration behavior change? (
No)Did security, auth, secrets, network, or tool execution behavior change? (
No)What is the highest-risk area?
/api/chatpath: not affected — it usesnormalizeOllamaToolCallArgumentsinbuildOllamaChatRequest, a completely separate code path.How is that risk mitigated?