Cortex icon indicating copy to clipboard operation
Cortex copied to clipboard

Medium: tag-only model checks serially fetch metadata for every installed Ollama model

Open dovvnloading opened this issue 3 weeks ago • 0 comments

Severity

Medium / admission latency — the tag-only list_installed() operation issues an Ollama show(model) call for every installed model, even when the caller only needs the set of model names. A slow or busy Ollama instance with a large library can delay every new generation before the user's message is admitted.

Source evidence

  • services/models.py:130–155: ModelService.list_installed calls list_installed_details(), which calls inventory(). The latter serially invokes _with_show_details(item) for every model.
  • services/models.py:358–421: each _with_show_details separately calls the live show(model) API.
  • services/model_catalog.py:45–61: the combined GGUF+Ollama catalog's tag-only list_installed also goes through the full metadata inventory.
  • api/routes.py:473–493: generation admission calls deps.models.list_installed() before preparing the prompt / saving the turn. The expensive show calls are not required to validate the exact selected tag.
  • ModelService.check() already uses the cheaper extract_model_tags(gateway.list()) for tag-only checks (models.py:170–176), showing this behavior is avoidable.

Deterministic performance reproduction

  1. Supply a fake Ollama gateway with 80 installed tags; list() returns them immediately, and each show(model) sleeps 100 ms before returning metadata.
  2. Call CombinedModelCatalog.list_installed() once.
  3. Actual: one list() and 80 serial show() calls, adding roughly 8 seconds to an operation intended to retrieve names only. A new chat generation waits in admission for this work.
  4. Expected: one list() plus the bounded GGUF filename scan, no per-model details query on the hot path; rich show metadata remains available through inventory() for Settings.

Fix and regression

Separate a fast ModelService.list_installed that extracts tags from one list() response from the optional UI metadata-enrichment path. Make the combined catalog union these tags with GGUF names, without invoking expensive Ollama show(). Add a fake-gateway call-count test asserting zero show calls for tag-only checks and one-per-model only for deliberate details retrieval. Consider caching rich metadata between inventory polls as a follow-up.

Reviewed revision: e824fe2dcba0d1be127c9fff165f776186dc37e9. Deterministic call graph; timing benchmark/integration test not executed.

dovvnloading avatar Nov 09 '26 15:11 dovvnloading