fix: bot presence stays offline after vision model change

ping() was calling ollama.AsyncClient.list() which parses /api/tags with
ollama==0.3.3 pydantic models. Vision models carry metadata fields that 0.3.x
cannot deserialise, raising ValidationError -> OllamaUnavailableError. This
made the /health/detailed ollama field 'error: ...' instead of 'ok', so
ab_ai_bot.py REQUIRED_SYSTEMS check failed and the bot never went online even
though the service was up.

Fix: ping() now uses httpx GET /api/version — model-agnostic, no metadata
parsing, always fast regardless of which model is loaded.

Also fix LLMRouter to accept direct backend injection for testability
(ollama=, claude=, privacy_mode=, env_overrides= kwargs), add _env_overrides
lookup in hybrid get_backend(), and fix cloud mode to return ollama when
_claude is None. All 6 test_llm_router tests now pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Carlos Garcia
2026-05-20 19:15:39 -04:00
parent 2f9791f925
commit b23ab77ee9
2 changed files with 53 additions and 26 deletions

View File

@@ -70,12 +70,18 @@ class OllamaBackend:
self._active -= 1
async def ping(self) -> None:
"""Raise if Ollama is unreachable."""
import ollama
client = ollama.AsyncClient(host=self._url)
"""Raise if Ollama is unreachable.
Uses /api/version rather than /api/tags so the check is model-agnostic
and not affected by vision-model metadata that older ollama-python
releases cannot deserialise.
"""
import httpx
try:
await asyncio.wait_for(client.list(), timeout=5)
except asyncio.TimeoutError:
async with httpx.AsyncClient() as client:
r = await client.get(f'{self._url}/api/version', timeout=5.0)
r.raise_for_status()
except httpx.TimeoutException:
raise OllamaUnavailableError('Ollama ping timed out')
except Exception as exc:
raise OllamaUnavailableError(f'Ollama ping failed: {exc}') from exc