fix(cli): model-catalog cache — key by exact API key, shorten TTL, skip Ollama#6468
Open
joaomdmoura wants to merge 1 commit into
Open
fix(cli): model-catalog cache — key by exact API key, shorten TTL, skip Ollama#6468joaomdmoura wants to merge 1 commit into
joaomdmoura wants to merge 1 commit into
Conversation
… Ollama Follow-ups to #6462's caching: 1. Key the catalog cache by the exact API key (via a short, non-reversible sha256 digest — never the key itself), not just key-present vs absent. Switching to a different key for the same provider now misses the previous account's entry and refetches, instead of showing the old account's models. 2. Never cache local providers (Ollama). /api/tags is fast and installed models change out-of-band, so caching could keep offering a model the user just deleted until the entry expired. _is_cacheable() gates both cache read and write; the picker now re-probes every call and reflects what's installed. 3. Shorten the dynamic catalog TTL from 6h to 5m — a stale list (new/removed models, account changes) is worse than a ~1s refetch, and the cache only needs to spare repeated fetches within a wizard session. Tests: distinct-key cache entries, digest never stores the raw key, Ollama not cached (reflects deletions / never written), and dynamic TTL expiry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RBYGqJHC2TMC6fonFziuuh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe dynamic model catalog's TTL was reduced to 300 seconds, and cache keying was reworked to hash provider API keys (truncated SHA-256) instead of special-casing Ollama. A new ChangesModel Catalog Cache Rework
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups to the model-catalog cache from #6462. Two correctness bugs + a freshness tweak.
1. Cache key didn't distinguish which API key
The catalog cache key only encoded key-present vs absent (
openai#key/openai#nokey). After a live fetch was cached, swapping to a different key for the same provider still hit the old entry and showed the previous account's model list (for up to the TTL).Fix: key the cache by the exact API key via a short, non-reversible
sha256digest —openai#<digest>(never the raw key). A different key → different entry → refetch. Absent key stays#nokey.2. Local (Ollama) lists were cached
Successful Ollama lists were written with the full dynamic TTL, and the cache was read before hitting
/api/tags. The key only reflected the base URL, not installed models — so after you deleted a model locally, the picker could keep offering it until the entry expired.Fix: never cache local providers.
_is_cacheable()gates both cache read and write (Ollama excluded);/api/tagsis fast, so the picker re-probes every call and always reflects what's installed.3. Dynamic TTL shortened 6h → 5m
A stale list (new/removed models, account changes) is worse than a ~1s refetch; the cache only needs to spare repeated fetches within a wizard session.
Tests
ruff format --check+ruff check+mypyclean;test_model_catalog.py39 passed.Note
These are the two items you flagged from #6462. The
sha256-digest approach keeps the raw API key out of the on-disk cache (~/.crewai/model_catalog_cache.json) — a truncated digest is non-reversible, so no secret is persisted.🤖 Generated with Claude Code
Note
Low Risk
CLI-only wizard model picker caching; changes improve correctness and freshness without touching runtime crew execution or secrets beyond hashed cache keys.
Overview
Fixes model catalog caching in the crew-creation wizard so lists stay correct per account and for local Ollama.
Cache keys now use a short SHA-256 digest of the API key (
provider#<digest>), not just key-present vs#nokey. Switching keys for the same provider refetches instead of reusing another account’s cached models. The raw key is never written to~/.crewai/model_catalog_cache.json.Ollama is excluded via
_is_cacheable(): no read or write of the catalog cache, so every picker call hits/api/tagsand reflects install/uninstall changes immediately.Dynamic catalog TTL drops from 6h to 5m so stale vendor lists don’t linger; negative fallback TTL stays 5m.
Tests cover per-key cache separation, digest-only keys, Ollama non-caching, and expired dynamic entries.
Reviewed by Cursor Bugbot for commit 0690a7f. Bugbot is set up for automated code reviews on this repo. Configure here.