A platform for community discussion. Free, open, simple.
FIX: Reduce false positives in AI LLM status problem check (#35304)
Rafael dos Santos Silva376ba06bcdc2
diff --git a/plugins/discourse-ai/app/services/problem_check/ai_llm_status.rb b/plugins/discourse-ai/app/services/problem_check/ai_llm_status.rbindex 23739a06403..8e6c0d94abb 100644--- a/plugins/discourse-ai/app/services/problem_check/ai_llm_status.rb+++ b/plugins/discourse-ai/app/services/problem_check/ai_llm_status.rb@@ -3,6 +3,9 @@class ProblemCheck::AiLlmStatus < ProblemCheckself.priority = "high"self.perform_every = 6.hours+ self.max_retries = 2+ self.retry_after = 1.minute+ self.max_blips = 2def callllm_errors@@ -13,6 +16,7 @@ class ProblemCheck::AiLlmStatus < ProblemCheckdef llm_errorsreturn [] if !SiteSetting.discourse_ai_enabledLlmModel.in_use.find_each.filter_map do |model|+ next if model.seeded?try_validate(model) { validator.run_test(model) }endend@@ -22,6 +26,23 @@ class ProblemCheck::AiLlmStatus < ProblemCheckblk.callnilrescue => e+ # Skip problem reporting for rate limiting and temporary service issues+ # These are expected to resolve on their own+ if rate_limit_error?(e)+ Rails.logger.info(+ "AI LLM Status Check: Rate limit detected for model #{model.display_name} (#{model.id}), skipping problem report",+ )+ return nil+ end++ # Log transient errors but still return a problem+ # The framework's max_retries and max_blips will handle retries and alert suppression+ if transient_error?(e)+ Rails.logger.info(+ "AI LLM Status Check: Transient error for model #{model.display_name} (#{model.id}): #{e.message}",+ )+ end+details = {model_id: model.id,model_name: model.display_name,@@ -52,4 +73,40 @@ class ProblemCheck::AiLlmStatus < ProblemCheckmessage.to_sendend++ def rate_limit_error?(error)+ error_message = error.message.to_s.downcase++ # Check for rate limit indicators in the error message+ rate_limit_indicators = [+ "rate limit",+ "rate_limit",+ "ratelimit",+ "too many requests",+ "quota exceeded",+ "retry after",+ "throttled",+ "429",+ "503",+ "temporarily unavailable",+ "service unavailable",+ "overloaded",+ ]++ rate_limit_indicators.any? { |indicator| error_message.include?(indicator) }+ end++ def transient_error?(error)+ # Network errors and timeouts are transient - may succeed on retry+ transient_errors = [+ Errno::ECONNREFUSED,+ Errno::ECONNRESET,+ Errno::ETIMEDOUT,+ Net::OpenTimeout,+ Net::ReadTimeout,+ IOError,+ ]++ transient_errors.any? { |error_class| error.is_a?(error_class) }+ endenddiff --git a/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb b/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rbindex 804a7a9cd36..bb19aec80f0 100644--- a/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb+++ b/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb@@ -70,6 +70,66 @@ RSpec.describe ProblemCheck::AiLlmStatus dostub_request(:post, post_url).to_return(status: 200, body: success_response, headers: {})expect(check).to be_chill_about_itend++ it "skips seeded LLMs" do+ SiteSetting.ai_summarization_enabled = false++ seeded_llm = Fabricate(:seeded_model)+ ai_persona_seeded = Fabricate(:ai_persona, default_llm_id: seeded_llm.id)+ SiteSetting.ai_summarization_persona = ai_persona_seeded.id+ SiteSetting.ai_summarization_enabled = true++ stub_request(:post, "https://cdck.test/").to_return(+ status: 403,+ body: error_response,+ headers: {+ },+ )+ expect(check).to be_chill_about_it+ end++ it "does not report problems for rate limit errors" do+ rate_limit_response = { message: "Rate limit exceeded. Please retry after 60s." }.to_json++ stub_request(:post, post_url).to_return(status: 429, body: rate_limit_response, headers: {})+ expect(check).to be_chill_about_it+ end++ it "does not report problems for 503 errors (service unavailable)" do+ service_unavailable_response = { message: "Service temporarily unavailable" }.to_json++ stub_request(:post, post_url).to_return(+ status: 503,+ body: service_unavailable_response,+ headers: {+ },+ )+ expect(check).to be_chill_about_it+ end++ it "reports problem for network timeout errors" do+ stub_request(:post, post_url).to_timeout++ problems = described_class.new.call+ expect(problems.length).to eq(1)+ expect(problems.first).to have_attributes(+ identifier: "ai_llm_status",+ target: llm_model.id,+ priority: "high",+ )+ end++ it "reports problem for authentication errors" do+ stub_request(:post, post_url).to_return(status: 401, body: error_response, headers: {})++ problems = described_class.new.call+ expect(problems.length).to eq(1)+ expect(problems.first).to have_attributes(+ identifier: "ai_llm_status",+ target: llm_model.id,+ priority: "high",+ )+ endendendend