Skip to content

fix(ollama): propagate supportsTools, disable idle watchdog, fix thinking and keep_alive#81915

Closed
velteyn wants to merge 1 commit into
openclaw:mainfrom
velteyn:fix/ollama-tools-idle-timeout
Closed

fix(ollama): propagate supportsTools, disable idle watchdog, fix thinking and keep_alive#81915
velteyn wants to merge 1 commit into
openclaw:mainfrom
velteyn:fix/ollama-tools-idle-timeout

Conversation

@velteyn

@velteyn velteyn commented May 14, 2026

Copy link
Copy Markdown

Summary

Four fixes for Ollama model compatibility in OpenClaw, making tool-using agents (librarian) work reliably with local Ollama models:

  1. supportsTools propagationbuildOllamaModelDefinition now always sets compat.supportsTools, defaulting to true when capabilities are unknown (Ollama's /api/chat universally supports tool calls). Added compat?: ModelCompatConfig to AgentModelEntryConfig as a static override path.

  2. Idle watchdog disabled for local providersresolveLlmIdleTimeoutMs now checks isLocalProviderBaseUrl before any configured timeout clamping. Local providers (Ollama, LM Studio, llama.cpp) always get idleTimeout=0 because network silence during prompt evaluation/thinking is legitimate, not a hang signal. The overall run timeout still applies at the agent level.

  3. Thinking parameter fix — Non-reasoning Ollama models (e.g., qwen2.5:3b, mistral:7b) now get think: false forced regardless of runtime think level, preventing Ollama's 400 error.

  4. keep_alive defaultbuildOllamaChatRequest now sends keep_alive: "1h" by default, keeping the model loaded in memory between calls. Overridable via model config params.keep_alive.

Verification

  • All 98 relevant tests pass: 13 provider-models, 65 idle-timeout, 20 agent-defaults
  • Live trajectory proves idleTimedOut: false after fix (was true before)
  • Ollama qwen2.5:3b correctly identified as tool-capable (no false 400 errors)
  • Rebuilt from source, installed, gateway health OK on port 8080

Files changed

  • extensions/ollama/src/provider-models.ts — supportsTools default + reasoning boolean
  • extensions/ollama/src/stream.ts — think guard + keep_alive default
  • src/agents/pi-embedded-runner/run/llm-idle-timeout.ts — local provider check moved to top
  • src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts — updated expectations
  • src/config/types.agent-defaults.ts — added compat to AgentModelEntryConfig
  • src/config/zod-schema.agent-defaults.ts — added compat schema
  • src/config/zod-schema.core.ts — exported ModelCompatSchema

…king and keep_alive

- buildOllamaModelDefinition: compat always includes supportsTools,
  defaulting to true when capabilities are unknown (Ollama's /api/chat
  universally supports tool calls)
- AgentModelEntryConfig: add optional compat override path
- resolveLlmIdleTimeoutMs: move isLocalProviderBaseUrl check to top
  so local providers always get idleTimeout=0 (network silence during
  prompt evaluation is not a hang signal)
- createConfiguredOllamaCompatStreamWrapper: guard think parameter with
  model.reasoning check; non-reasoning models get think:false forced
- buildOllamaChatRequest: add keep_alive: "1h" default with requestParams
  spread override so model-level config can customize
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: ollama size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 14, 2026
@clawsweeper

clawsweeper Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR changes Ollama model compatibility metadata, native Ollama chat request shaping, local-provider idle-timeout resolution/tests, and agent-default model config typing/schema.

Reproducibility: unclear. for the claimed live qwen2.5/tool and idle-timeout failures because the PR only asserts live verification without artifacts. Source inspection gives a high-confidence path for the PR-introduced regressions against current docs and tests.

Real behavior proof
Needs real behavior proof before merge: Missing: the PR body only asserts live Ollama verification; the contributor should add redacted terminal output, logs, screenshots, recordings, or linked artifacts, then update the PR body for automatic re-review or ask for @clawsweeper re-review.

Next step before merge
Needs contributor-supplied real behavior proof and a re-scoped patch; the repair lane should not take over an external PR while its required real-environment proof is missing.

Security
Cleared: Cleared: the diff changes Ollama request/config handling and tests, with no dependencies, CI permissions, secret handling, packaging, or new code-execution surface.

Review findings

  • [P2] Preserve configured local idle timeouts — src/agents/pi-embedded-runner/run/llm-idle-timeout.ts:102-111
  • [P2] Honor explicit Ollama thinking params — extensions/ollama/src/stream.ts:399-404
  • [P2] Wire compat overrides into model resolution — src/config/zod-schema.agent-defaults.ts:74-76
Review details

Best possible solution:

Rework this into narrower Ollama fixes that preserve explicit timeout and request params, use the existing provider-model compat surface unless a fully wired new config surface is intentionally approved, and drop the now-covered thinking overlap.

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

Unclear for the claimed live qwen2.5/tool and idle-timeout failures because the PR only asserts live verification without artifacts. Source inspection gives a high-confidence path for the PR-introduced regressions against current docs and tests.

Is this the best way to solve the issue?

No. The branch mixes useful Ollama fixes with contract changes and a no-op config surface; the safer path is a narrow request/compat fix that preserves documented user configuration.

Full review comments:

  • [P2] Preserve configured local idle timeouts — src/agents/pi-embedded-runner/run/llm-idle-timeout.ts:102-111
    Moving the local-provider return ahead of configured timeout handling makes modelRequestTimeoutMs, models.providers..timeoutSeconds, and agents.defaults.timeoutSeconds stop controlling local Ollama streams, contrary to current docs and tests that say explicit local/self-hosted timeouts still apply.
    Confidence: 0.91
  • [P2] Honor explicit Ollama thinking params — extensions/ollama/src/stream.ts:399-404
    This branch forces think:false whenever model.reasoning is not exactly true, so a configured native Ollama model can no longer use params.think or params.thinking to force thinking as documented. Preserve explicit model params, and after the merged focused fix, suppress truthy think only for models known to be reasoning:false.
    Confidence: 0.88
  • [P2] Wire compat overrides into model resolution — src/config/zod-schema.agent-defaults.ts:74-76
    Adding compat to agents.defaults.models validation makes that config parse, but runtime model resolution only reads entry.params from that map and still takes compat from the provider/discovered model. As written, users can configure compat there and OpenClaw will ignore it.
    Confidence: 0.88
  • [P2] Keep Ollama keep_alive opt-in — extensions/ollama/src/stream.ts:444
    Adding keep_alive:"1h" to every native chat request changes the current request contract and breaks the existing exact request-shape expectation that omits keep_alive when no model param is configured. Keep this per-model through params.keep_alive unless maintainers explicitly change the documented default.
    Confidence: 0.84

Overall correctness: patch is incorrect
Overall confidence: 0.9

Acceptance criteria:

  • node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts extensions/ollama/src/stream-runtime.test.ts src/agents/pi-embedded-runner/run/llm-idle-timeout.test.ts src/config/zod-schema.agent-defaults.test.ts
  • Add inspectable redacted real Ollama proof showing after-fix tool, thinking, keep_alive, and idle-timeout behavior.

What I checked:

Likely related people:

  • steipete: GitHub path history shows repeated recent work on Ollama native capabilities, request behavior, provider-model compatibility, and idle-timeout handling across the touched files. (role: recent area contributor; confidence: high; commits: 7a4574376a79, a1b89317a8bb, 433203774f72; files: extensions/ollama/src/provider-models.ts, extensions/ollama/src/stream.ts, src/agents/pi-embedded-runner/run/llm-idle-timeout.ts)
  • joshavant: Authored recent Ollama native num_ctx migration work touching the runtime model resolver and Ollama docs near the params/default-model override paths implicated by this PR. (role: recent adjacent contributor; confidence: medium; commits: bd0555d5fc8e; files: src/agents/pi-embedded-runner/model.ts, docs/providers/ollama.md)
  • leno23: Authored the merged focused fix for native Ollama non-reasoning think forwarding that overlaps one useful part of this PR. (role: recent related contributor; confidence: medium; commits: eebdbabae977; files: extensions/ollama/src/stream.ts, extensions/ollama/src/stream-runtime.test.ts)
  • BruceMacD: Earlier merged Ollama capability work contributed to the same /api/show capability and model-definition surface changed here. (role: introduced related capability behavior; confidence: medium; commits: ac3f55504cbe; files: extensions/ollama/src/provider-models.ts)

Remaining risk / open question:

  • No inspectable live Ollama artifact, terminal output, or redacted log confirms the claimed qwen2.5 tool, idle-timeout, thinking, and keep_alive behavior after this patch.
  • The merged focused thinking fix means this branch is now partially overlapping and should be rebased or re-scoped before review.
  • The branch changes user-visible timeout and keep_alive defaults, which needs explicit maintainer acceptance if retained.

Codex review notes: model gpt-5.5, reasoning high; reviewed against caf8fa2ebf39.

@dutifulbob

Copy link
Copy Markdown
Contributor

Maintainer repro update: I could only reproduce one issue from this PR on current main.

The reproduced issue is the Ollama fallback path: when OpenClaw cannot read Ollama capabilities, it leaves supportsTools unset, so tools can be hidden even though native Ollama chat supports tool schemas.

I could not reproduce the other claims as current-main bugs. Current main already disables the default local-provider idle watchdog while preserving explicit timeouts, already avoids sending truthy thinking to non-thinking Ollama models, and keep_alive is currently documented as a per-model opt-in rather than a default.

I could not push a cleanup commit to this contributor branch because GitHub rejected the fork push with 403, so I opened a focused replacement PR with only the reproduced fix: #84055

@osolmaz

osolmaz commented May 19, 2026

Copy link
Copy Markdown
Member

Closing, see earlier comment by @dutifulbob

@osolmaz osolmaz closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: ollama size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants