RubyLLM uses a static bundled models.json as its model registry. New
models released by providers (e.g., gpt-5.1, gpt-5.2) are not available
until the gem is updated, causing ModelNotFoundError for self-hosted
users who configure newer models.
Refresh the model registry asynchronously via a background thread during
Llm::Config.initialize! to fetch the latest model list from configured
providers and models.dev, then persist with save_to_json. The bundled
registry is available immediately; the refresh updates it in the
background without blocking the first LLM request.
Use double-checked locking with a mutex to prevent concurrent threads
from spawning duplicate refresh operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>