Skip to content

fix(ollama): stop dropping free-form object tool arguments - #157435

Closed
Hmache wants to merge 8 commits into
openclaw:mainfrom
Hmache:claude/issue-157039-ollama-freeform-tool-args
Closed

Hmache wants to merge 8 commits into
openclaw:mainfrom
Hmache:claude/issue-157039-ollama-freeform-tool-args

Conversation

@Hmache

@Hmache Hmache commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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 TypeBox Type.Record() which emits patternProperties) come back with empty arguments (tool_call.args = {}). With Tool Search enabled (tools.toolSearch.mode: "tools"), every tool_call dispatch loses its nested args, so tools like exec fail 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, or additionalProperties: false) still receive properties: {} exactly as before.

Why This Change Was Made

normalizeOllamaToolSchema injected properties: {} 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. additionalProperties is unset/false and there is no patternProperties. The helper moved from stream.runtime.ts into a sibling extensions/ollama/src/tool-schema.runtime.ts because stream.runtime.ts and its test file are already over the line-cap ratchet, which forbids growing over-cap files.

Evidence

  • Unit tests, extensions/ollama/src/tool-schema.runtime.test.ts (6 cases): additionalProperties: true and patternProperties schemas pass through untouched, including the nested args property of the real Tool Search tool_call schema from src/agents/tool-search.ts; { type: "object" } alone and additionalProperties: false still get properties: {}; declared properties are still normalized recursively.
  • Real-transport test, extensions/ollama/src/tool-schema.transport.test.ts (2 cases): drives createOllamaStreamFn against a loopback /api/chat NDJSON server on 127.0.0.1 with nothing mocked (real fetch, real request serialization, real NDJSON parsing). Asserts the outgoing tools[].function.parameters reaches the wire without an injected properties, for both the exec-style schema and the nested Tool Search schema, and that a populated tool_calls response round-trips into populated toolCall.arguments.
  • Local run on the PR head, 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.
  • CI on the previous head (55f6fdb): check-lint, check-prod-types, check-source-contracts, check-additional-extension-package-boundary and the rest of the matrix green or skipped; only check-test-types (and ci-gate downstream of it) failed, with TS18048: 'properties.args' is possibly 'undefined' in the new unit test. Fixed in the latest commit; reproduced the error with tsc under noUncheckedIndexedAccess on the old test file and confirmed it is gone on the new one.
  • Gap: no live run against a real Ollama server is included. The transport test proves the corrected schema is exactly what OpenClaw sends and that populated arguments survive the parse path end to end; the model-side half (Ollama returning populated args once properties: {} is gone) rests on the reporter's analysis in [Bug]: Ollama native provider empties free-form object tool args (toolSearch tool_call.args always {}) #157039. Happy to add a redacted native run if a maintainer wants it before merge.
Local vitest output
 ✓ extensions/ollama/src/tool-schema.transport.test.ts > free-form object tool schema over the real Ollama NDJSON transport (#157039) > sends the free-form schema unmodified and returns populated tool call arguments
 ✓ extensions/ollama/src/tool-schema.transport.test.ts > free-form object tool schema over the real Ollama NDJSON transport (#157039) > keeps the real Tool Search dispatcher's nested patternProperties args free-form
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > keeps free-form object schemas without injecting empty properties
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > still adds empty properties for closed object schemas with no properties
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > still adds empty properties when additionalProperties is explicitly false
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > normalizes declared properties recursively
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > keeps patternProperties-based free-form schemas without injecting empty properties
 ✓ extensions/ollama/src/tool-schema.runtime.test.ts > normalizeOllamaToolSchema > keeps a nested patternProperties args property free-form inside the real Tool Call schema

 Test Files  2 passed (2)
      Tests  8 passed (8)

Written with AI assistance (Claude Code); I have reviewed the change and understand what it does.

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
@openclaw-barnacle openclaw-barnacle Bot added triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. extensions: ollama size: M labels Sep 24, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 24, 2026, 3:54 PM ET / 19:54 UTC (Revision 5).

ClawSweeper review

What this changes

The 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
Reviewed head: 79d47391ee8dd858a6cb4bf3b174303f66ec27a9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and transport assertions provide useful confidence, but the native Ollama result remains unproven.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body reports passing tests that drive the production Ollama stream through loopback HTTP and assert the corrected outgoing schema. The local server supplies the returned arguments, so the evidence does not show native Ollama returning populated nested Tool Search arguments after the fix or the resulting tool execution. A redacted native run or runtime log would close that gap; redact private endpoints, addresses, and credentials, then update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review if it does not run automatically. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body reports passing tests that drive the production Ollama stream through loopback HTTP and assert the corrected outgoing schema. The local server supplies the returned arguments, so the evidence does not show native Ollama returning populated nested Tool Search arguments after the fix or the resulting tool execution. A redacted native run or runtime log would close that gap; redact private endpoints, addresses, and credentials, then update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review if it does not run automatically. No stored-data contract changes.
Evidence reviewed 8 items Current main still has the reported behavior: Current main inserts an empty properties map into every object schema without declared properties. The latest release contains the same source blob.
Release comparison: The v2026.9.6 source has the same insertion; this fix is neither on current main nor in that release.
Proposed normalization: The introduced condition avoids adding empty properties when an object declares additional or pattern-based properties.
Findings None None.
Security None None.

How this fits together

OpenClaw 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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body reports passing tests that drive the production Ollama stream through loopback HTTP and assert the corrected outgoing schema. The local server supplies the returned arguments, so the evidence does not show native Ollama returning populated nested Tool Search arguments after the fix or the resulting tool execution. A redacted native run or runtime log would close that gap; redact private endpoints, addresses, and credentials, then update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review if it does not run automatically. No stored-data contract changes.
  • Complete next step (P2) - Before merge, provide a redacted after-fix native Ollama run showing populated nested Tool Search arguments and successful tool execution.
Agent review details

Security

None.

PR surface

Source +14, Tests +260. Total +274 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 109 95 +14
Tests 2 260 0 +260
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 369 95 +274

Review metrics

Metric Value Why it matters
Production and test lines production +14 net, tests +260 Most production lines move from the existing module; the new tests cover schema conversion and the transport boundary.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157039
Summary: This PR is the candidate fix for the linked, still-open native Ollama argument-loss report.

Members:

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

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The linked report shows native Ollama users can lose tool arguments and enter a failed agent tool workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports passing tests that drive the production Ollama stream through loopback HTTP and assert the corrected outgoing schema. The local server supplies the returned arguments, so the evidence does not show native Ollama returning populated nested Tool Search arguments after the fix or the resulting tool execution. A redacted native run or runtime log would close that gap; redact private endpoints, addresses, and credentials, then update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review if it does not run automatically. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • holny: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a redacted after-fix native Ollama run showing a Tool Search call with populated nested args and the selected tool executing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-24T17:27:15.222Z sha 0663c20 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-24T17:37:54.618Z sha 6c196e9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-24T17:55:21.165Z sha 4b3dff1 :: needs real behavior proof before merge. :: [P1] Handle the nested Tool Search arguments schema
  • reviewed 2026-09-24T18:58:50.707Z sha 55f6fdb :: needs real behavior proof before merge. :: none

Hmache and others added 6 commits September 24, 2026 17:29
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
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 24, 2026
Hmache added a commit to Hmache/openclaw that referenced this pull request Sep 24, 2026
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
@Hmache

Hmache commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #157564 — the same change squashed into a single signed commit on current main, with a clean CI run. Closing this one to keep the history tidy.

@Hmache Hmache closed this Sep 24, 2026
obviyus added a commit that referenced this pull request Sep 25, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: ollama P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ollama native provider empties free-form object tool args (toolSearch tool_call.args always {})

1 participant