Skip to content

fix(ollama): tool calls fail with Tool Search enabled - #167933

Merged
steipete merged 4 commits into
mainfrom
fix/ollama-tool-call-name-collision
Oct 9, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/ollama-tool-call-name-collision

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #165787

What Problem This Solves

Ollama can turn valid native exec and other tool calls into malformed tool_call invocations when Tool Search is enabled.

User Impact

Qwen3:8b and Qwen2.5:7b can execute echo hello through the real Gateway with default Tool Search. The Ollama plugin uses collision-free wire names while execution, policies, catalog IDs, and stored history retain canonical names. No configuration or session migration is needed.

The original Windows fenced-PowerShell/silent-NO_REPLY report was not reproduced. Comparing the relevant Ollama, Tool Search, and system-prompt paths between v2026.9.7 and v2026.9.8 found only the Ollama package version bump, so the claimed release regression remains unproven. #166561 diagnoses fenced output; it does not address this captured native function-name misparse.

Why This Change Was Made

Ollama 0.40.1's generic parser retains the opening tag, then selects the earliest matching tool-name substring. Thus tool_call in <tool_call> wins before the JSON's "name":"exec". Argument extraction does not verify that JSON name against the selected tool. The installed tag was shallow-cloned and inspected at that exact commit.

One plugin-owned adapter translates definitions, assistant replay, named tool results, explicit selectors, streamed events, final/error messages, and result() consumers. It preserves the supplied system prompt byte-for-byte and appends a short, deterministic wire-name note. Tool Search descriptor references use the offered names. The adapter does not parse or rewrite core prompt sections, markers, or headings; arguments, results, and canonical history remain unchanged. Native plain-text recovery runs inside the adapter, so it sees the offered names.

Aliases are deterministic for a fixed active/replay namespace and reserve every real name before allocation. The inverse map decodes only allocated aliases. The same adapter covers the Ollama plugin's identified /v1/chat/completions route: both HTTP routes use ChatHandler, which selects the same generic parser.

The parser has no universal reserved-name table: any supplied name matching an earlier envelope substring can collide. The inspected Qwen/plural-tool, Mistral, DeepSeek, and JSON envelopes require protection for tool_call, tool_calls, TOOL_CALLS, function, name, arguments, and their substrings. This includes core ls through calls. functions does not match those inspected markers and stays unchanged. Template tag derivation can admit other custom markers.

Limits: this is a known-envelope compatibility repair, not arbitrary tool-intent recovery. Small models can still emit unoffered names, especially when explicitly prompted to use a canonical name rather than the exposed alias. Such malformed output remains subject to existing validation and loop termination. /v1/responses, /v1/messages, unidentified generic providers, and arbitrary custom template markers are outside this change. Follow-up: open an upstream Ollama issue for structural function-name parsing; no upstream issue was filed here.

Evidence

All five requested follow-up Gateway runs passed on 7e59804d7dcaffc0d9da154556b1fdb7831cad15 after deleting mapManagedTooling. The rewrite was not restored. This removes the dependency on core's internal STABLE marker, Tooling heading, and wording. The supplied system prompt is preserved before appending the existing wire-name note, following the wire-projection boundary used by the Anthropic adapter.

Tested the real pnpm openclaw Gateway and agent entry points in isolated state on port 19201, with tools.profile: full, default Tool Search, Ollama 0.40.1, and the actual local models. A loopback logging proxy retained /api/chat and /v1/chat/completions request/response bodies. No operator Gateway or shared model service was changed.

Probe Result CLI wall time
Main, Qwen3:8b, exact issue prompt Three misparsed native wrapper calls; existing repeated-failure error 33.26 s
Main, Qwen2.5:7b, exact issue prompt Same failure 25.04 s
New head, Qwen3:8b, exact issue prompt One exec, actual tool result hello, visible reply, zero failures 34.17 s
New head, Qwen2.5:7b, exact issue prompt One exec, actual tool result hello, visible reply, zero failures 16.72 s
New head, Qwen3:8b, deferred agents_list One search and one alias dispatch; canonical tool_call/agents_list receipts; agent main; zero failures 10.91 s
New head, Qwen2.5:7b, deferred agents_list One search and two alias dispatches; canonical receipts; agent main; zero failures 11.75 s
New head, Llama3.2:latest through /v1 One exec, actual result and visible reply hello; zero failures 20.36 s

The deferred smoke explicitly names the offered alias to test its round trip independently of model selection. Every successful receipt records the requested effective model and rerouted: false. The native captures retain canonical tool_call in the Tooling section, expose openclaw_tool_call in the tools array, and replay that alias after execution. System-prompt and tools bytes remain identical across each captured multi-round turn.

Commands after starting the isolated Gateway:

pnpm openclaw --profile ollama-text-tools agent --agent main \
  --session-key no-rewrite-native-echo-qwen3 --model ollama/qwen3:8b \
  --message 'Use your exec tool to run echo hello' --json

pnpm openclaw --profile ollama-text-tools agent --agent main \
  --session-key no-rewrite-native-deferred-qwen3 --model ollama/qwen3:8b \
  --message 'Use tool_search to find agents_list. Then call the exposed openclaw_tool_call function with id="agents_list" and args={}. Report the resulting agent IDs.' --json

Repeated with fresh session keys for Qwen2.5. The Llama control used the exact echo prompt with --model ollama/llama3.2:latest and the isolated provider configured for api: openai-completions at the logging proxy's /v1 URL. Its first CLI attempt reached the Gateway before background session admission completed and made no Ollama request; the run after the logged admission completion passed. That prerequisite failure is not model evidence.

Shared prompt snapshots regenerated with zero tracked changes / zero shared token delta. Removing the rewrite reduced Ollama's initial prompt counter by 7 tokens for each Qwen model versus the preceding PR head (now +53 versus the baseline capture).

Validation:

  • Six initial alias regressions failed on unmodified main. The revised prompt-preservation regression failed on the preceding PR head because it rewrote the supplied prompt, then passed after removal.
  • Current alias/plugin boundary tests: 80 passed across two files using node scripts/run-vitest.mjs ... --maxWorkers=1, 69.16 s runner wall / 63.60 s Vitest, about 2% test execution; most time was transformation. Two obsolete managed-section guard cases were removed.
  • Targeted lint, Ollama package typecheck, and focused test typecheck passed. All seven required checks passed: max-lines, line-cap, assertion-safety, timeout-race, mock-exports, config docs, and plugin inventory.
  • Committed Gateway runtime build (pnpm build qaRuntime) passed in 343.14 s wall. An earlier full build passed; the follow-up changes only the alias adapter and its regression.
  • The preceding CI head exposed an invalid empty Context fixture. Its owner was corrected to supply messages: []; the 28-file shard subsequently passed all 498 tests locally in 29.03 s and in CI in 61.88 s. No production fallback or assertion was weakened.
  • Codex autoreview: scoped-clean through P2 on 7e59804d7dcaffc0d9da154556b1fdb7831cad15, zero actionable findings; static assessment.

Production +236/-34 (net +202); tests +400/-1 (net +399); docs +10/-0. This follow-up removes 30 net production lines. Existing normalization was moved rather than duplicated. Remaining growth covers bidirectional translation across both transports, replay, selectors, descriptor references, and independent stream/result surfaces; removing unrelated behavior to offset it would weaken the fix.

Final verification on 7e59804d7dcaffc0d9da154556b1fdb7831cad15: ClawSweeper reports no findings and no Before merge items, with sufficient live proof. CI passed, including openclaw/ci-gate; the Ollama shard passed 496 tests across 28 files in 54.43 s runner wall / 52.55 s Vitest (117 s whole job). The PR remains unmerged for maintainer review.

Alias parser-sensitive tool names only at the Ollama transport boundary, preserving canonical names in execution and replay. Cover native chat and the Ollama OpenAI-compatible chat-completions route, including explicit selectors and stream terminals.
Render the managed Tooling section and Tool Search cross-references with the same names as the provider schemas, while preserving project text, compound names, and canonical session data.
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: ollama size: L labels Oct 9, 2026
@steipete
steipete marked this pull request as ready for review October 9, 2026 19:31
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The Ollama plugin temporarily renames tools that collide with model-output markers and restores their original names before execution and session recording.

Example: Ask Qwen3:8b to “Use your exec tool to run echo hello” with default Tool Search.

  • Before: The recorded baseline produces three malformed tool_call invocations and ends with the repeated-failure error.
  • After: The recorded head executes exec, receives hello, and returns a visible reply without tool failures.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong runtime proof supports the focused repair, while the broader linked report is only partially addressed.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact-head contributor-recorded Gateway runs exercise the Ollama adapter with Qwen3:8b and Qwen2.5:7b for echo execution and deferred agents_list, plus Llama3.2 through chat-completions. They show successful actual tool results, visible replies, canonical receipts, and no rerouting. Source and replay regressions verify that stored names and configuration remain unchanged; no migration is needed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: With default Tool Search enabled, supported local Ollama models can fail to execute an ordinary requested command.
Reason: The demonstrated native parser collision warrants a provider-local repair. The PR correctly uses Related because the linked report's broader Windows fenced-output and NO_REPLY behavior remains unconfirmed.

Merge readiness

✅ Ready for maintainer review

This PR addresses a demonstrated Ollama failure that current main still contains. No actionable patch defect remains; the broader Windows fenced-output report remains distinct and unresolved.

Priority: P1
Reviewed head: 7e59804d7dcaffc0d9da154556b1fdb7831cad15

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Ollama plugin translates OpenClaw conversations and tool definitions into model requests. It converts returned tool calls into events consumed by agent execution and session recording.

flowchart TD
 A[Conversation and available tools] --> B[Ollama name adapter]
 B --> C[Native or chat-completions request]
 C --> D[Ollama model and parser]
 D --> E[Returned tool events]
 E --> F[Restore original tool names]
 F --> G[Agent execution and session history]
Loading

Technical review

Best possible solution:

Keep the compatibility repair in the Ollama transport owner and retain the separate fenced-output investigation.

Do we have a high-confidence way to reproduce the issue?

Yes. Contributor-recorded real Gateway runs reproduce the malformed native calls with both Qwen models; inspected Ollama source explains the failure, and fetched main retains the affected path.

Is this the best way to solve the issue?

Yes for the captured parser collision. A plugin-owned transport projection preserves execution identities, stored history, and supplied prompt bytes without adding configuration or changing protected Markdown behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6eacab6c2940.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The merge-base-to-head diff introduces one plugin-local adapter across native Ollama and identified OpenAI-compatible chat-completions requests; existing name normalization is moved rather than duplicated. (extensions/ollama/src/tool-name-aliases.ts:133, 7e59804d7dca)
  • Canonical names and unchanged stored state: Definitions, replay, named tool results, selectors, terminal events, and result consumers are translated at the transport boundary. Arguments and tool IDs are retained; the supplied context is copied and returned names are restored. No stored format or configuration contract changes. (extensions/ollama/src/tool-name-aliases.ts:74, 7e59804d7dca)
  • Verified dependency mechanism: The PR expressly depends on Ollama's generic tool parser. At the cited revision, Add retains the opening marker, findTool selects the earliest matching name substring, and argument extraction does not reconcile that selection with the JSON function name. (tools/tools.go:193, cf2a313a2980)
  • Both repaired routes share the parser: Native /api/chat and /v1/chat/completions reach ChatHandler, which constructs the generic parser when the selected built-in parser lacks tool support. Template-derived markers explain the documented custom-template limitation. (server/routes.go:3239, cf2a313a2980)
  • Current main still needs this repair: Fetched main retains the native plain-text wrapper without tool-name aliasing. Its intervening native-stream change concerns configured thinking, outside this PR's aliasing hunks. No canonical merged replacement was established. (extensions/ollama/src/stream.runtime.ts, 6eacab6c2940)
  • Exact-head Gateway observations: The complete supplied body, sourceRevision ea5fb52d1cfc97867c46ad8661d6485352dc636926ab7dd0802ba6b9255e1a5d, records real Gateway and agent runs with Ollama 0.40.1. Qwen3:8b and Qwen2.5:7b execute echo hello and deferred agents_list; Llama3.2 succeeds through /v1. Successful receipts retain canonical names and report rerouted:false. These are contributor-recorded observations, not reviewer-executed runs. (7e59804d7dca)

PR surface

Source +202, Tests +399, Docs +10. Total +611 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 236 34 +202
Tests 2 400 1 +399
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 646 35 +611

Review metrics

Metric Value Why it matters
Production versus test growth Production +236/-34; tests +400/-1 Production growth is justified by translation across both transports, replay, selectors, and independent event and result consumers.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Captured default Tool Search turns fail to execute ordinary commands on two supported local Qwen models.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-09T19:37:12.491Z sha 7a36dce :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T19:53:50.894Z sha 05e7f5c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T20:11:47.331Z sha 05e7f5c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T21:42:59.836Z sha 7e59804 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 6:02 PM ET / 22:02 UTC (Revision 5).

@steipete steipete self-assigned this Oct 9, 2026
@steipete
steipete merged commit 8899f3b into main Oct 9, 2026
108 of 109 checks passed
@steipete
steipete deleted the fix/ollama-tool-call-name-collision branch October 9, 2026 22:48
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
* fix(ollama): preserve tool calls with Tool Search enabled

Alias parser-sensitive tool names only at the Ollama transport boundary, preserving canonical names in execution and replay. Cover native chat and the Ollama OpenAI-compatible chat-completions route, including explicit selectors and stream terminals.

* fix(ollama): align managed tool guidance with wire aliases

Render the managed Tooling section and Tool Search cross-references with the same names as the provider schemas, while preserving project text, compound names, and canonical session data.

* test(ollama): supply valid context to compat wrapper

* refactor(ollama): preserve supplied system prompt during aliasing
RomneyDa pushed a commit that referenced this pull request Oct 10, 2026
* fix(ollama): preserve tool calls with Tool Search enabled

Alias parser-sensitive tool names only at the Ollama transport boundary, preserving canonical names in execution and replay. Cover native chat and the Ollama OpenAI-compatible chat-completions route, including explicit selectors and stream terminals.

* fix(ollama): align managed tool guidance with wire aliases

Render the managed Tooling section and Tool Search cross-references with the same names as the provider schemas, while preserving project text, compound names, and canonical session data.

* test(ollama): supply valid context to compat wrapper

* refactor(ollama): preserve supplied system prompt during aliasing

(cherry picked from commit 8899f3b)
steipete added a commit that referenced this pull request Oct 13, 2026
* fix: Tool Search uses one dispatcher name across providers

Rename the generic dispatcher to dispatch_action and retain read-only historical display plus shipped policy and hook matching. Keep Ollama wire aliases only for directly advertised names that collide with its parser envelopes. Preserve tool_call invocation IDs and event contracts. Builds on #167933 and the local web-tool report from @lator57-gif in #145137.

* fix: preserve legacy dispatcher replay beside direct call tools

* test: align sorted allowlists with the dispatcher name
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…169552)

* fix: Tool Search uses one dispatcher name across providers

Rename the generic dispatcher to dispatch_action and retain read-only historical display plus shipped policy and hook matching. Keep Ollama wire aliases only for directly advertised names that collide with its parser envelopes. Preserve tool_call invocation IDs and event contracts. Builds on openclaw#167933 and the local web-tool report from @lator57-gif in openclaw#145137.

* fix: preserve legacy dispatcher replay beside direct call tools

* test: align sorted allowlists with the dispatcher name
steipete added a commit that referenced this pull request Oct 13, 2026
* fix: Tool Search uses one dispatcher name across providers

Rename the generic dispatcher to dispatch_action and retain read-only historical display plus shipped policy and hook matching. Keep Ollama wire aliases only for directly advertised names that collide with its parser envelopes. Preserve tool_call invocation IDs and event contracts. Builds on #167933 and the local web-tool report from @lator57-gif in #145137.

* fix: preserve legacy dispatcher replay beside direct call tools

* fix: local Ollama can call web tools directly by default

Keep policy-approved web_search and web_fetch directly visible in embedded native Ollama runs when Tool Search is unset. Preserve explicit Tool Search settings and defer the other optional tools. Follow up the dispatcher repair and #167933; thanks to @lator57-gif for #145137.

* test: align sorted allowlists with the dispatcher name

* test: provide complete metadata for the MCP web fixture
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…9556)

* fix: Tool Search uses one dispatcher name across providers

Rename the generic dispatcher to dispatch_action and retain read-only historical display plus shipped policy and hook matching. Keep Ollama wire aliases only for directly advertised names that collide with its parser envelopes. Preserve tool_call invocation IDs and event contracts. Builds on openclaw#167933 and the local web-tool report from @lator57-gif in openclaw#145137.

* fix: preserve legacy dispatcher replay beside direct call tools

* fix: local Ollama can call web tools directly by default

Keep policy-approved web_search and web_fetch directly visible in embedded native Ollama runs when Tool Search is unset. Preserve explicit Tool Search settings and defer the other optional tools. Follow up the dispatcher repair and openclaw#167933; thanks to @lator57-gif for openclaw#145137.

* test: align sorted allowlists with the dispatcher name

* test: provide complete metadata for the MCP web fixture
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
* fix(ollama): preserve tool calls with Tool Search enabled

Alias parser-sensitive tool names only at the Ollama transport boundary, preserving canonical names in execution and replay. Cover native chat and the Ollama OpenAI-compatible chat-completions route, including explicit selectors and stream terminals.

* fix(ollama): align managed tool guidance with wire aliases

Render the managed Tooling section and Tool Search cross-references with the same names as the provider schemas, while preserving project text, compound names, and canonical session data.

* test(ollama): supply valid context to compat wrapper

* refactor(ollama): preserve supplied system prompt during aliasing

(cherry picked from commit 8899f3b)
(cherry picked from commit c2841a2)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: ollama P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant