From 73cecdbc26c389195ea26d1506659d4c7885fd85 Mon Sep 17 00:00:00 2001 From: aakashb95 Date: Wed, 18 Feb 2026 13:26:15 +0530 Subject: [PATCH] fix: refresh and persist RubyLLM model registry on initialization 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 synchronously during Llm::Config.initialize! to fetch the latest model list from configured providers and models.dev, then persist with save_to_json. This runs once per process on the first LLM request, adding ~1-2s to that request. Falls back gracefully to the bundled registry on failure. Co-Authored-By: Claude Opus 4.6 --- lib/llm/config.rb | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/llm/config.rb b/lib/llm/config.rb index da5f5f69e..81cd9297d 100644 --- a/lib/llm/config.rb +++ b/lib/llm/config.rb @@ -2,7 +2,6 @@ require 'ruby_llm' module Llm::Config DEFAULT_MODEL = 'gpt-4.1-mini'.freeze - INIT_MUTEX = Mutex.new class << self def initialized? @@ -12,13 +11,9 @@ module Llm::Config def initialize! return if @initialized - INIT_MUTEX.synchronize do - return if @initialized - - configure_ruby_llm - refresh_model_registry - @initialized = true - end + configure_ruby_llm + refresh_model_registry + @initialized = true end def reset! @@ -37,12 +32,10 @@ module Llm::Config private def refresh_model_registry - Thread.new do - RubyLLM.models.refresh! - RubyLLM.models.save_to_json - rescue StandardError => e - Rails.logger.warn "Failed to refresh RubyLLM model registry: #{e.message}" - end + RubyLLM.models.refresh! + RubyLLM.models.save_to_json + rescue StandardError => e + Rails.logger.warn "Failed to refresh RubyLLM model registry: #{e.message}" end def configure_ruby_llm