Repository navigation
fix(ollama): tool calls fail with Tool Search enabled - #167933
Conversation
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.
|
🦞👀 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. What this changesThe 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +202, Tests +399, Docs +10. Total +611 across 6 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 9, 2026, 6:02 PM ET / 22:02 UTC (Revision 5). |
|
Merged via squash.
|
* 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
* 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)
* 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
…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
* 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
…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
* 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]>
Related: #165787
What Problem This Solves
Ollama can turn valid native
execand other tool calls into malformedtool_callinvocations when Tool Search is enabled.User Impact
Qwen3:8b and Qwen2.5:7b can execute
echo hellothrough 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_REPLYreport was not reproduced. Comparing the relevant Ollama, Tool Search, and system-prompt paths betweenv2026.9.7andv2026.9.8found 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_callin<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/completionsroute: 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 corelsthroughcalls.functionsdoes 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
7e59804d7dcaffc0d9da154556b1fdb7831cad15after deletingmapManagedTooling. 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 openclawGateway and agent entry points in isolated state on port 19201, withtools.profile: full, default Tool Search, Ollama 0.40.1, and the actual local models. A loopback logging proxy retained/api/chatand/v1/chat/completionsrequest/response bodies. No operator Gateway or shared model service was changed.exec, actual tool resulthello, visible reply, zero failuresexec, actual tool resulthello, visible reply, zero failuresagents_listtool_call/agents_listreceipts; agentmain; zero failuresagents_listmain; zero failures/v1exec, actual result and visible replyhello; zero failuresThe 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 canonicaltool_callin the Tooling section, exposeopenclaw_tool_callin 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:
Repeated with fresh session keys for Qwen2.5. The Llama control used the exact echo prompt with
--model ollama/llama3.2:latestand the isolated provider configured forapi: openai-completionsat the logging proxy's/v1URL. 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:
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.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.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.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, includingopenclaw/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.