Skip to content

fix: harden Ollama autodiscovery and warning behavior#29201

Merged
vincentkoc merged 3 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/ollama-autodiscovery-hardening
Feb 27, 2026
Merged

fix: harden Ollama autodiscovery and warning behavior#29201
vincentkoc merged 3 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/ollama-autodiscovery-hardening

Conversation

@vincentkoc
Copy link
Member

Summary

  • Hardens Ollama implicit provider autodiscovery so local models are registered without requiring OLLAMA_API_KEY.
  • Keeps implicit probing quiet for users without explicit Ollama configuration, while preserving warnings when explicit config is provided and discovery fails.
  • Fixes test env restoration in the autodiscovery test so process.env.VITEST is correctly restored/deleted and does not leak as the string "undefined".

Credit

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Ollama models can be auto-discovered without pre-setting OLLAMA_API_KEY.
  • Implicit local discovery remains quiet when Ollama is not explicitly configured.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22
  • Model/provider: Ollama
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Run provider resolution without OLLAMA_API_KEY and with discoverable Ollama models.
  2. Verify providers.ollama is registered with discovered models.
  3. Verify unreachable implicit probe does not warn unless Ollama is explicitly configured.

Expected

  • Provider is auto-registered when models are discoverable.
  • No warning noise for non-explicit configs.
  • Warnings preserved for explicit config failures.

Actual

  • Matches expected.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: targeted Ollama provider tests and new autodiscovery tests.
  • Edge cases checked: explicit config failure warning path; env restoration safety in tests.
  • What you did not verify: manual local Ollama pull/run on this machine.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR or set explicit provider config.
  • Files/config to restore: src/agents/models-config.providers.ts
  • Known bad symptoms reviewers should watch for: unexpected Ollama warning noise or missing Ollama provider entries.

Risks and Mitigations

  • Risk: Implicit discovery could still be noisy in edge paths.
    • Mitigation: Explicit quiet gating + focused tests for warning behavior.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR successfully hardens Ollama autodiscovery by enabling local model registration without requiring OLLAMA_API_KEY, while keeping implicit probing quiet unless Ollama is explicitly configured.

Key improvements:

  • Auto-registers Ollama provider when models are discovered locally (no API key required)
  • Suppresses warnings for implicit local probing when Ollama isn't explicitly configured
  • Preserves warnings when explicit Ollama config is provided but discovery fails
  • Fixes test environment restoration to properly handle undefined env vars (prevents leaking "undefined" strings)

Implementation details:

  • Added quiet parameter to discoverOllamaModels and buildOllamaProvider to control warning behavior
  • Modified provider registration logic: now registers if models are discovered OR API key is present (previously only with API key)
  • Uses "ollama-local" as sentinel API key value for auto-discovered providers
  • Comprehensive test coverage for all three scenarios: successful discovery, quiet implicit probing, and explicit config warnings

The changes are backward compatible, well-tested, and align with the stated objectives. No issues found.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean with proper error handling, comprehensive test coverage, and no breaking changes. The logic for conditional warning behavior is correct, environment restoration is properly handled, and the auto-discovery feature gracefully falls back when Ollama is unavailable. All changes are well-contained within the provider resolution layer.
  • No files require special attention

Last reviewed commit: 4461b35

@vincentkoc vincentkoc merged commit fa5e71d into openclaw:main Feb 27, 2026
26 checks passed
velvet-shark pushed a commit to lailoo/openclaw that referenced this pull request Feb 27, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
vincentkoc added a commit that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (#17874)

* Changelog: add Ollama autodiscovery hardening entry (#29201)

* Changelog: add Ollama context-window unification entry (#29205)

* Changelog: add compaction audit injection removal entry (#28507)

* Changelog: add browser url alias entry (#29260)

* Changelog: add codex weekly usage label entry (#26267)
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
xiexikang pushed a commit to cclawd007/cclawd that referenced this pull request Feb 28, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
xiexikang pushed a commit to cclawd007/cclawd that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 28, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior

(cherry picked from commit 9a898bc)
newtontech pushed a commit to newtontech/openclaw-fork that referenced this pull request Feb 28, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)

(cherry picked from commit 8090cb4)

# Conflicts:
#	CHANGELOG.md
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior

(cherry picked from commit fa5e71d)

# Conflicts:
#	src/agents/models-config.providers.ts
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
venjiang pushed a commit to venjiang/openclaw that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
venjiang pushed a commit to venjiang/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)

(cherry picked from commit 8090cb4)

# Conflicts:
#	CHANGELOG.md
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior

(cherry picked from commit fa5e71d)

# Conflicts:
#	src/agents/models-config.providers.ts
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
* agents: auto-discover Ollama models without API key

* tests: cover Ollama autodiscovery warning behavior
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
* Changelog: add LanceDB custom baseUrl + dimensions entry (openclaw#17874)

* Changelog: add Ollama autodiscovery hardening entry (openclaw#29201)

* Changelog: add Ollama context-window unification entry (openclaw#29205)

* Changelog: add compaction audit injection removal entry (openclaw#28507)

* Changelog: add browser url alias entry (openclaw#29260)

* Changelog: add codex weekly usage label entry (openclaw#26267)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot change model to Ollama Deepseek-r1:latest

1 participant