Repository navigation
fix(ollama): stop dropping free-form object tool arguments - #157564
Conversation
normalizeOllamaToolSchema always added an empty `properties: {}` to any
object-typed tool schema, including free-form schemas that declare
`additionalProperties: true` or `patternProperties` (TypeBox's
Type.Record()) and intentionally have no fixed properties. Ollama reads
the resulting closed-looking schema and returns `{}` for tool_call.args,
so tools like exec, and every Tool Search `tool_call` dispatch, silently
lose their arguments.
Only inject `properties: {}` when the schema is not free-form. Move
normalizeOllamaToolSchema and its inferOllamaSchemaType helper into a
sibling extensions/ollama/src/tool-schema.runtime.ts module with focused
unit tests plus a real-transport loopback test, since stream.runtime.ts
and stream-runtime.test.ts are already over the line-cap ratchet.
Squashed from openclaw#157435.
Closes openclaw#157039
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FfpR5spYH3ffvwiPCmJtkg
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 8:41 PM ET / September 25, 2026, 00:41 UTC (Revision 4). ClawSweeper reviewWhat this changesThe Ollama plugin now preserves free-form object tool parameters in native chat requests and adds schema and transport regression coverage. Merge readiness✅ Ready for maintainer review Current main and the latest release still contain the reported Ollama schema behavior. This PR remains a useful, focused fix; the updated proof now shows populated arguments reaching a registered tool through a real Ollama server on the reviewed head. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw sends agent tool definitions through its Ollama plugin to Ollama’s native chat API. The plugin parses returned tool calls before OpenClaw dispatches them to tools. flowchart LR
A[Agent tool definitions] --> B[Ollama plugin]
B --> C{Free-form object?}
C -->|Yes| D[Preserve open schema]
C -->|No| E[Normalize closed schema]
D --> F[Native Ollama chat]
E --> F
F --> G[Parsed tool call]
G --> H[Tool dispatch]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +12, Tests +266. Total +278 across 4 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep the Ollama-specific correction and its root and closed-object controls, then land it through the normal exact-head review and merge gates. Do we have a high-confidence way to reproduce the issue? Yes. Current source shows the schema mutation, and the linked issue supplies a controlled native Ollama comparison; this read-only review did not execute a failing current-main turn. Is this the best way to solve the issue? Yes. Repairing the Ollama request producer addresses the malformed wire schema without adding configuration or a competing schema owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 37b47bf9652d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged as 4bfac2b. Thank you @Hmache for the fix and @markomiric for reporting #157039 and isolating the schema trigger. The Ollama request normalizer now preserves free-form objects without changing closed-object behavior. Built-Gateway fake-server before/after proof showed three empty-argument dispatch failures with the main normalizer versus populated arguments, successful real exec, and completion after the fix; the closed-object control was unchanged. Real Ollama 0.34.4 with qwen2.5:3b then delivered populated free-form arguments to a registered tool in all three candidate attempts. That small model also preserved arguments in the two completed baseline attempts (the first timed out), so the live trace establishes compatibility rather than a live reproduction of the reporter's model-specific failure. All attempts and the native request/response excerpt are documented above. 203 focused tests passed, exact-head CI was green, and hosted ClawSweeper marked the merged head ready. The temporary Ollama container, model volume, and image have been removed. |
…157564) Closes openclaw#157039 Supersedes openclaw#157435. ## What Problem This Solves Fixes: native Ollama tool calls lose free-form object arguments, causing Tool Search dispatch to fail repeatedly. ## User Impact User impact: free-form tool input survives native Ollama schema conversion, including nested Tool Search arguments. Closed objects and the root object fallback keep their existing behavior. No configuration changes are required. ## Why This Change Was Made The request normalizer added `properties: {}` to open objects. Keep the repair in the Ollama request producer, preserving explicitly open objects, pattern-based records, and nested objects with implicit additional properties. The extracted inference and recursive normalization logic is unchanged apart from the empty-properties predicate. The Tool Search transport regression now uses the actual `id` plus nested `args` response contract. ## Evidence ### Real Ollama inference through the built Gateway Tested head `1071871aa7a9105862e381737071cf2eb0774789` against **Ollama 0.34.4, qwen2.5:3b**, in a throwaway CPU-only Docker container (8 CPUs, 8 GiB, loopback-only port). Image digest: `sha256:8262851b2846b87c649eddf3e76beb270c52f4d1bc94559f47efde16b0841551`. A transparent loopback recording proxy forwarded requests and streamed responses unchanged; unlike the fixture below, it generated no model responses. A registered plugin tool recorded its received arguments independently. Same prompt on both sides: > Use proof_record exactly once now. Set payload to this JSON object exactly, preserving all keys and values: {"message":"OLLAMA_PROOF_OK","count":7}. After recording it, reply DONE. Do not just describe the tool call. | Side / attempt | Actual outcome | | --- | --- | | Main normalizer / 1 | Gateway timed out at 300.821 s, no tool execution. The upstream model eventually returned populated arguments after the Gateway deadline; this is not counted as a successful turn. | | Main normalizer / 2 | After setting `num_thread: 8` to match the container CPU quota, real tool call delivered `{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}`; final `DONE`, 192.372 s. | | Main normalizer / 3 | Same populated tool arguments; final `DONE`, 3.411 s. | | PR / 1 | Same populated tool arguments; final `DONE`, 3.475 s. | | PR / 2 | Same populated tool arguments; final `DONE`, 3.250 s. | | PR / 3 | Same populated tool arguments; final `DONE`, 3.208 s. | **Scope:** the real model emitted tool calls on both sides. Qwen2.5 3B did **not** reproduce the reporter's empty-argument inference behavior: both successful baseline turns preserved the payload despite the injected empty property map. The candidate's three successful real inference turns establish after-fix compatibility and actual tool execution, not a live red/green reproduction of that model-specific failure. The source/schema regression and deterministic Tool Search red/green comparison below remain separate evidence. Observed native wire excerpt (description omitted only for brevity): ```json { "before_payload_schema": {"type":"object","additionalProperties":true,"properties":{}}, "after_payload_schema": {"type":"object","additionalProperties":true}, "real_after_tool_calls": [ {"id":"call_7fdun0ne","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}}, {"id":"call_l5jkfqoy","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}}, {"id":"call_d2fnvsic","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}} ], "tool_received_each_time": {"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}, "gateway_each_after_turn": {"status":"ok","assistantTurns":2,"toolSummary":{"calls":1,"tools":["proof_record"],"failures":0},"final":"DONE"} } ``` ### Deterministic Tool Search regression and closed-object control A built Gateway was exercised through `node openclaw.mjs agent --agent main --message ... --json`, using isolated state and a loopback native `/api/chat` NDJSON fixture. The baseline used the main normalizer in the otherwise identical candidate checkout, then the candidate normalizer was restored and rebuilt. The fixture records the exact request and models the reporter's schema-sensitive response: it emits empty nested arguments only when the request gained `properties: {}`. This section is deterministic Gateway/transport/tool-dispatch proof, separate from the real inference runs above. | Scenario | Observed result | | --- | --- | | Main normalizer, Tool Search | Wire `args` schema gained `properties: {}`. Three `tool_call` responses carried `args: {}`; all three failed target-input validation with `command: must have required property 'command'`. Four provider requests, no successful tool execution. The fixture then ended the bounded reproduction. | | Fixed normalizer, Tool Search | Wire `args` retained `patternProperties: {"^.*$": {}}` with no `properties`. Response `{id: "openclaw:core:exec", args: {command: "printf OLLAMA_PROOF_OK"}}` reached the dispatcher; real `exec` returned `OLLAMA_PROOF_OK`, exit code 0. Two provider requests, one successful dispatch, final `OLLAMA_PROOF_COMPLETE`. | | Closed-object negative control, before and after | A registered plugin tool with `additionalProperties: false`, required string `value`, and declared properties received `{value: "OLLAMA_PROOF_OK"}` in both runs. Serialized schemas were identical; both turns completed in two provider requests. | Focused command: `node scripts/run-vitest.mjs extensions/ollama/src/tool-schema.runtime.test.ts extensions/ollama/src/tool-schema.transport.test.ts extensions/ollama/src/stream-runtime.test.ts --maxWorkers=1`: **203 passed**, 16.83 seconds wall including preparation. With the main normalizer restored, the two schema regression files produced **6 failures and 3 passes**: free-form cases failed on injected empty properties, while root fallback, closed-object, and recursive normalization controls passed. The isolated runtime build (`scripts/build-all.mts gatewayWatch`) passed. The transport fixture makes no claim to test model inference. Its assertions protect the outgoing schema and parsed nested argument contract; the Gateway exercise separately verifies real dispatch and tool execution. After merging current main for the unrelated build repair, all four Ollama files remained unchanged. At `1071871aa7a9105862e381737071cf2eb0774789`, the focused suite again passed 203 tests (22.96 seconds wall), the built Gateway again completed the Tool Search/exec turn in two provider requests with one successful dispatch, and the runtime build passed. Co-authored-by: Ayaan Zaidi <[email protected]>
Backport #157564: 4bfac2b Backport #157881: 0b234fc Backport #158240: df5e316 Preserve native Ollama free-form schema parameters, project Twitch Disabled to explicit deny-all, and retain TUI session ownership across delayed state. No new policy, dependencies or version changes. Co-authored-by: Hmache Abdellah <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vyctorbrzezowski <[email protected]> Co-authored-by: steipete <[email protected]> Co-authored-by: jalehman <[email protected]>
Closes #157039
Supersedes #157435.
What Problem This Solves
Fixes: native Ollama tool calls lose free-form object arguments, causing Tool Search dispatch to fail repeatedly.
User Impact
User impact: free-form tool input survives native Ollama schema conversion, including nested Tool Search arguments. Closed objects and the root object fallback keep their existing behavior. No configuration changes are required.
Why This Change Was Made
The request normalizer added
properties: {}to open objects. Keep the repair in the Ollama request producer, preserving explicitly open objects, pattern-based records, and nested objects with implicit additional properties. The extracted inference and recursive normalization logic is unchanged apart from the empty-properties predicate. The Tool Search transport regression now uses the actualidplus nestedargsresponse contract.Evidence
Real Ollama inference through the built Gateway
Tested head
1071871aa7a9105862e381737071cf2eb0774789against Ollama 0.34.4, qwen2.5:3b, in a throwaway CPU-only Docker container (8 CPUs, 8 GiB, loopback-only port). Image digest:sha256:8262851b2846b87c649eddf3e76beb270c52f4d1bc94559f47efde16b0841551. A transparent loopback recording proxy forwarded requests and streamed responses unchanged; unlike the fixture below, it generated no model responses. A registered plugin tool recorded its received arguments independently.Same prompt on both sides:
num_thread: 8to match the container CPU quota, real tool call delivered{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}; finalDONE, 192.372 s.DONE, 3.411 s.DONE, 3.475 s.DONE, 3.250 s.DONE, 3.208 s.Scope: the real model emitted tool calls on both sides. Qwen2.5 3B did not reproduce the reporter's empty-argument inference behavior: both successful baseline turns preserved the payload despite the injected empty property map. The candidate's three successful real inference turns establish after-fix compatibility and actual tool execution, not a live red/green reproduction of that model-specific failure. The source/schema regression and deterministic Tool Search red/green comparison below remain separate evidence.
Observed native wire excerpt (description omitted only for brevity):
{ "before_payload_schema": {"type":"object","additionalProperties":true,"properties":{}}, "after_payload_schema": {"type":"object","additionalProperties":true}, "real_after_tool_calls": [ {"id":"call_7fdun0ne","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}}, {"id":"call_l5jkfqoy","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}}, {"id":"call_d2fnvsic","function":{"name":"proof_record","arguments":{"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}}} ], "tool_received_each_time": {"payload":{"count":7,"message":"OLLAMA_PROOF_OK"}}, "gateway_each_after_turn": {"status":"ok","assistantTurns":2,"toolSummary":{"calls":1,"tools":["proof_record"],"failures":0},"final":"DONE"} }Deterministic Tool Search regression and closed-object control
A built Gateway was exercised through
node openclaw.mjs agent --agent main --message ... --json, using isolated state and a loopback native/api/chatNDJSON fixture. The baseline used the main normalizer in the otherwise identical candidate checkout, then the candidate normalizer was restored and rebuilt. The fixture records the exact request and models the reporter's schema-sensitive response: it emits empty nested arguments only when the request gainedproperties: {}. This section is deterministic Gateway/transport/tool-dispatch proof, separate from the real inference runs above.argsschema gainedproperties: {}. Threetool_callresponses carriedargs: {}; all three failed target-input validation withcommand: must have required property 'command'. Four provider requests, no successful tool execution. The fixture then ended the bounded reproduction.argsretainedpatternProperties: {"^.*$": {}}with noproperties. Response{id: "openclaw:core:exec", args: {command: "printf OLLAMA_PROOF_OK"}}reached the dispatcher; realexecreturnedOLLAMA_PROOF_OK, exit code 0. Two provider requests, one successful dispatch, finalOLLAMA_PROOF_COMPLETE.additionalProperties: false, required stringvalue, and declared properties received{value: "OLLAMA_PROOF_OK"}in both runs. Serialized schemas were identical; both turns completed in two provider requests.Focused command:
node scripts/run-vitest.mjs extensions/ollama/src/tool-schema.runtime.test.ts extensions/ollama/src/tool-schema.transport.test.ts extensions/ollama/src/stream-runtime.test.ts --maxWorkers=1: 203 passed, 16.83 seconds wall including preparation. With the main normalizer restored, the two schema regression files produced 6 failures and 3 passes: free-form cases failed on injected empty properties, while root fallback, closed-object, and recursive normalization controls passed. The isolated runtime build (scripts/build-all.mts gatewayWatch) passed.The transport fixture makes no claim to test model inference. Its assertions protect the outgoing schema and parsed nested argument contract; the Gateway exercise separately verifies real dispatch and tool execution.
After merging current main for the unrelated build repair, all four Ollama files remained unchanged. At
1071871aa7a9105862e381737071cf2eb0774789, the focused suite again passed 203 tests (22.96 seconds wall), the built Gateway again completed the Tool Search/exec turn in two provider requests with one successful dispatch, and the runtime build passed.