Repository navigation
Conversation
normalizeOllamaToolSchema always added an empty properties: {} to any
object-typed tool schema, including free-form schemas that declare
additionalProperties: true and intentionally have no fixed
properties. Ollama reads the resulting closed-looking schema and
returns {} for tool_call.args, so tools like exec silently lose their
arguments.
Only inject properties: {} when the schema is not explicitly
free-form (additionalProperties is unset or false). Moves
normalizeOllamaToolSchema and its inferOllamaSchemaType helper into a
new extensions/ollama/src/tool-schema.runtime.ts sibling module with
focused unit tests, since stream.runtime.ts and stream-runtime.test.ts
are already over the repo's line-cap ratchet and the ratchet forbids
further growth of over-cap files.
Closes openclaw#157039
|
Codex review: needs real behavior proof before merge. Reviewed September 24, 2026, 3:54 PM ET / 19:54 UTC (Revision 5). ClawSweeper reviewWhat this changesThe Ollama plugin now preserves free-form tool argument schemas when sending native chat requests and adds schema and loopback transport tests. Merge readiness⛔ Blocked before merge - 2 items remain Current main still changes free-form Ollama tool schemas in the way the linked report identifies. This PR makes a focused repair, and the earlier nested Tool Search finding is addressed. The remaining merge blocker is after-fix proof from a native Ollama run. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw sends available tool schemas through the Ollama plugin to Ollama’s native chat API. Ollama’s returned tool calls then supply arguments to the agent’s tool dispatcher. flowchart LR
A[Agent tools] --> B[Tool schemas]
B --> C[Ollama schema normalization]
C --> D[Native chat request]
D --> E[Ollama tool call]
E --> F[Agent tool dispatcher]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +14, Tests +260. Total +274 across 4 files. View PR surface stats
Review metrics
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 schema normalization in the Ollama plugin and demonstrate a native Ollama Tool Search call returning populated nested arguments that reach the selected tool. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows the schema mutation, and the linked report provides a controlled native Ollama comparison; this read-only review did not run OpenClaw against Ollama. Is this the best way to solve the issue? Yes. Repairing the existing Ollama schema normalizer is a narrow way to preserve free-form arguments while retaining the closed-object default. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 19379a17f9f4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
pnpm tsgo:extensions:test flagged TS2532 on direct dot access into a Record-typed properties object under noUncheckedIndexedAccess. Use optional chaining instead.
Adds a loopback-HTTP regression test that drives createOllamaStreamFn through a real /api/chat NDJSON server (real fetch, real SSRF guard, real request/response serialization, nothing mocked but the network endpoint). It captures the actual outgoing request body and asserts the free-form exec-style schema keeps additionalProperties without gaining an empty properties, then asserts a populated tool_calls response from the server round-trips into populated toolCall.arguments on the parsed assistant message. Confirmed this fails on the pre-fix normalizeOllamaToolSchema (empty properties injected, request assertion fails) and passes with the fix.
…orm-tool-args' into claude/issue-157039-ollama-freeform-tool-args
ClawSweeper's review of openclaw#157435 found that the real Tool Search dispatcher tool (TOOL_CALL_RAW_TOOL_NAME in src/agents/tool-search.ts) still lost its `args` on Ollama: its nested `args` property is built with TypeBox's Type.Record(Type.String(), Type.Unknown()), which compiles to `{ type: "object", patternProperties: {...} }` rather than `additionalProperties`. The prior fix only recognized `additionalProperties` as evidence of a free-form schema, so this nested, pattern-based case still got an empty `properties: {}` injected and reproduced the original bug. normalizeOllamaToolSchema now also treats a schema with `patternProperties` as free-form. Added a unit test using the exact real Tool Call schema shape, and a real-transport test exercising the same nested dispatcher tool end to end (confirmed both fail on the narrower condition and pass with this fix).
…a test
check-test-types failed on the previous commit with TS18048
('properties.args' is possibly 'undefined') because the indexed access
on a Record<string, ...> is optional under noUncheckedIndexedAccess.
Assert the whole nested `args` schema with toStrictEqual instead, which
also states the expected free-form shape more directly.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FfpR5spYH3ffvwiPCmJtkg
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
|
Superseded by #157564 — the same change squashed into a single signed commit on current |
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 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]>
…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]>
Closes #157039
What Problem This Solves
Fixes: with the native Ollama provider (
api: "ollama"), tools whose parameters are a free-form object (additionalProperties: true, or a TypeBoxType.Record()which emitspatternProperties) come back with empty arguments (tool_call.args = {}). With Tool Search enabled (tools.toolSearch.mode: "tools"), everytool_calldispatch loses its nestedargs, so tools likeexecfail and the agent loops on retries until it is blocked. The same tools work through the OpenAI-compatible endpoint.User Impact
User impact: Ollama users get populated tool arguments for free-form tools and for Tool Search dispatches, matching what the OpenAI-compatible endpoint already returns. No config change or migration; closed object schemas (no
additionalProperties, oradditionalProperties: false) still receiveproperties: {}exactly as before.Why This Change Was Made
normalizeOllamaToolSchemainjectedproperties: {}into every object schema that had no declared properties, so Ollama saw a closed, empty object and returned{}. The normalizer now only injects it when the schema is not free-form, i.e.additionalPropertiesis unset/falseand there is nopatternProperties. The helper moved fromstream.runtime.tsinto a siblingextensions/ollama/src/tool-schema.runtime.tsbecausestream.runtime.tsand its test file are already over the line-cap ratchet, which forbids growing over-cap files.Evidence
extensions/ollama/src/tool-schema.runtime.test.ts(6 cases):additionalProperties: trueandpatternPropertiesschemas pass through untouched, including the nestedargsproperty of the real Tool Searchtool_callschema fromsrc/agents/tool-search.ts;{ type: "object" }alone andadditionalProperties: falsestill getproperties: {}; declared properties are still normalized recursively.extensions/ollama/src/tool-schema.transport.test.ts(2 cases): drivescreateOllamaStreamFnagainst a loopback/api/chatNDJSON server on 127.0.0.1 with nothing mocked (real fetch, real request serialization, real NDJSON parsing). Asserts the outgoingtools[].function.parametersreaches the wire without an injectedproperties, for both theexec-style schema and the nested Tool Search schema, and that a populatedtool_callsresponse round-trips into populatedtoolCall.arguments.node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-providers.config.ts extensions/ollama/src/tool-schema.runtime.test.ts extensions/ollama/src/tool-schema.transport.test.ts: 2 files, 8/8 passed.check-lint,check-prod-types,check-source-contracts,check-additional-extension-package-boundaryand the rest of the matrix green or skipped; onlycheck-test-types(andci-gatedownstream of it) failed, withTS18048: 'properties.args' is possibly 'undefined'in the new unit test. Fixed in the latest commit; reproduced the error withtscundernoUncheckedIndexedAccesson the old test file and confirmed it is gone on the new one.properties: {}is gone) rests on the reporter's analysis in [Bug]: Ollama native provider empties free-form object tool args (toolSearchtool_call.argsalways{}) #157039. Happy to add a redacted native run if a maintainer wants it before merge.Local vitest output
Written with AI assistance (Claude Code); I have reviewed the change and understand what it does.