Skip to content

feat(agent): ping Ollama and explain why it isn't answering - #402

Merged
lightningpixel merged 2 commits into
devfrom
feat/303-ollama-error-ux
Nov 11, 2026
Merged

lightningpixel merged 2 commits into
devfrom
feat/303-ollama-error-ux

Conversation

@lightningpixel

Copy link
Copy Markdown
Owner

Closes #303

What changes

When Ollama is the active provider, the chat panel checks it on open, on URL/model change, on Retry, and after a failed turn. If something is wrong, an amber banner says why and gives the fix to copy:

Status Banner Command
unreachable Ollama is not running ollama serve
model_missing Model "" is not pulled ollama pull <m>
no_model No Ollama model selected → Settings → Agent none

A chat turn that fails while Ollama is down shows the same advice instead of the raw provider error. Other providers (local llama.cpp, external APIs) are unaffected.

Backend: GET /agent/ollama/health?base_url=&model= checks <root>/api/tags with a 3 s timeout. An untagged model name matches :latest.

Security (second commit): the API answers any origin (CORS *), so a web page could use this endpoint to probe the user's network.

  • Only http(s) loopback URLs without credentials are accepted (localhost, 127.0.0.1, ::1); anything else gets a 400.
  • Redirects are not followed.
  • The detail field is generic (connection refused / timed out / not an Ollama server) and never echoes the upstream status or body.

The Ollama preset is already fixed at localhost:11434, so this costs nothing today. A remote Ollama would need an explicit allowlist later.

Merge note

This PR conflicts with #401 (#302) on the ChatPanel.tsx import lines only, and the two work together. Whichever merges second needs a one-line rebase; I'll handle it.

Test plan

  • python -m unittest tests.test_agent_ollama_health: 13 OK (statuses, tag matching, timeout, rejection of non-local URLs, generic detail)
  • ollamaHealth.test.ts: 8/8
  • pre-push hook (npm test, full suite) passed on both commits
  • eslint on the changed TS/TSX files: clean
  • Manual: open the chat with Ollama stopped, then with a model not pulled

Add GET /agent/ollama/health: checks the configured Ollama server
(/api/tags, 3s timeout) and reports ok / unreachable / model_missing /
no_model with the model name and pulled models.

The chat panel pings it on mount and when the Ollama URL or model
changes, and shows a banner with the fix ("ollama serve" or
"ollama pull <model>", copyable) and a Retry button. A failed Ollama
turn re-pings and replaces the raw provider error with the same advice.
Only shown when Ollama is the active provider.

Closes #303
The API answers any origin (CORS *), so a web page could call
/agent/ollama/health with any base_url and read the result, turning it into a
probe of the user's network. Accept only http(s) loopback URLs without
credentials (400 otherwise), don't follow redirects, and report generic
reasons ("connection refused", "timed out", "not an Ollama server") instead of
echoing the upstream status or exception text.

Refs #303
@lightningpixel
lightningpixel force-pushed the feat/303-ollama-error-ux branch from ea567a5 to 374b8e5 Compare November 11, 2026 09:42
@lightningpixel
lightningpixel merged commit f7270ab into dev Nov 11, 2026
4 checks passed
@lightningpixel
lightningpixel deleted the feat/303-ollama-error-ux branch November 11, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant