fix: proper HTTP error handling across all LLM and VLM providers to prevent HTML leakage#2409
Open
Wanbogang wants to merge 7 commits intoOpenMind:mainfrom
Open
fix: proper HTTP error handling across all LLM and VLM providers to prevent HTML leakage#2409Wanbogang wants to merge 7 commits intoOpenMind:mainfrom
Wanbogang wants to merge 7 commits intoOpenMind:mainfrom
Conversation
- Separate openai.APIStatusError to log clean HTTP status code and message - Separate openai.APIConnectionError for network-level failures - Keep generic Exception as fallback with type and message info - Add 'import openai' to VLM providers that only had 'from openai import AsyncOpenAI' - Affected: openai, openrouter, gemini, deepseek, xai, near_ai, qwen LLM plugins and vlm_openai, vlm_gemini, vlm_openai_rtsp providers - Prevents raw HTML leakage to terminal/logs during 502 outages - Critical for VLM providers (10-30 fps) which could flood disk with HTML - Fixes OpenMind#1218
…and VLM providers - Add test_ask_api_status_error and test_ask_api_connection_error to all 7 LLM plugins - Add test_process_frame_api_status/connection_error to vlm_openai and vlm_gemini providers - Add test_send_batch_api_status/connection_error to vlm_openai_rtsp provider - Move new tests into TestNearAILLMAsk and TestQwenLLMAsk classes for consistency - Remove unused DummyOutputModel class and BaseModel import from LLM plugin tests
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… exception coverage - Fix test_ask_api_status_error and test_ask_api_connection_error to use chat.completions.create instead of beta.chat.completions.parse - Add test_queue_frame_unexpected_exception to cover except Exception in _queue_frame of vlm_openai_rtsp_provider
- Remove duplicate test_ask_api_connection_error - Add test_init_no_model: default model fallback branch - Add test_ask_empty_choices: empty choices warning branch - Add test_ask_no_tool_calls_returns_none: return None branch - Add test_ask_messages_none_branch: messages=None via __wrapped__ - Add test_ask_api_connection_error_branch: APIConnectionError handler - Add test_ask_unexpected_error_branch: generic Exception handler - Add test_send_batch_unexpected_error: VLM unexpected Exception handler
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.
Problem
Fixes #1218
When api.openmind.org returns a 502 (or other HTTP errors), all LLM and VLM
providers were catching the error with a generic
except Exception as ehandlerand logging
f"... error: {e}". This caused raw HTML responses to leak directlyinto terminal output and log files.
This is especially critical for VLM providers which process frames continuously
at 10–30 fps — during an upstream outage, this could flood log files with HTML
and potentially fill disk, causing system crash.
Root Cause
All 10 affected files used a single generic exception handler that did not
distinguish between HTTP status errors, connection errors, and unexpected errors.
Fix
Replaced the generic handler with three specific handlers across all affected files:
Also added
import openaito VLM providers that only hadfrom openai import AsyncOpenAI.Files Changed
LLM Plugins:
src/llm/plugins/openai_llm.pysrc/llm/plugins/openrouter.pysrc/llm/plugins/gemini_llm.pysrc/llm/plugins/deepseek_llm.pysrc/llm/plugins/xai_llm.pysrc/llm/plugins/near_ai_llm.pysrc/llm/plugins/qwen_llm.pyVLM Providers:
src/providers/vlm_openai_provider.pysrc/providers/vlm_gemini_provider.pysrc/providers/vlm_openai_rtsp_provider.pyNotes
the original bug report were investigated and found to be invalid — cortex
already guards with
if output is None: returnand there is no retry loop,only normal tick continuation.