Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Surface an untyped Responses error frame instead of skipping it (#8650)
Daniel Hanab9f23bc926c
diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.pyindex 47e626edb48..ece5baf5674 100644--- a/studio/backend/core/inference/external_provider.py+++ b/studio/backend/core/inference/external_provider.py@@ -5513,6 +5513,18 @@ class ExternalProviderClient:# a Responses request with Chat Completions frames, so skipping# an unrecognisable frame beats failing the whole completion.# The ChatGPT path stays strict, where the shape is guaranteed.+ # An error payload is the exception: the bare {"error": ...} an+ # OpenAI-compatible proxy emits has no type and no event name+ # either, so skipping it returned zero chunks and no error.+ if isinstance(event, dict) and isinstance(+ event.get("error"), (dict, str)+ ):+ yield _error_sse_line(+ 502,+ _openai_response_error_message(event),+ self.provider_type,+ )+ breakcontinue_record_openai_response_id(event)diff --git a/studio/backend/tests/test_external_provider_usage_chunk.py b/studio/backend/tests/test_external_provider_usage_chunk.pyindex 54db68a974c..d09f9ec351b 100644--- a/studio/backend/tests/test_external_provider_usage_chunk.py+++ b/studio/backend/tests/test_external_provider_usage_chunk.py@@ -708,3 +708,96 @@ def test_an_sse_event_name_does_not_carry_past_its_blank_line(monkeypatch):lines = _drive(run())assert not [line for line in lines if '"provider_error"' in line], linesassert len(_usage_chunks(lines)) == 1, lines+++def test_an_untyped_error_frame_is_surfaced_rather_than_skipped(monkeypatch):+ """An OpenAI-compatible proxy emits its errors as a bare ``{"error": {...}}`` with no+ ``type`` and no SSE event name, so skipping it returned zero chunks and no error."""+ body = b'data: {"error":{"message":"you are rate limited","type":"rate_limit_error"}}\n\n'++ def handler(request: httpx.Request) -> httpx.Response:+ return httpx.Response(200, content = body, headers = {"content-type": "text/event-stream"})++ _mock_http_client(monkeypatch, handler)++ async def run():+ client = ExternalProviderClient(+ provider_type = "openai",+ base_url = "https://api.openai.com/v1",+ api_key = "sk-openai-test",+ )+ out = await _collect(+ client.stream_chat_completion(+ messages = [{"role": "user", "content": "hi"}], model = "gpt-5"+ )+ )+ await client.close()+ return out++ chunks = _drive(run())+ assert chunks, "the error frame was swallowed and the answer came back empty"+ assert any("rate limited" in str(chunk) for chunk in chunks), chunks+++def test_a_chat_completions_frame_on_the_responses_path_is_still_skipped(monkeypatch):+ """The case the skip exists for stays skipped: no type, no event name, no error key."""+ body = (+ b'data: {"choices":[{"delta":{"content":"ok"}}]}\n\n'+ b"event: response.completed\n"+ b'data: {"type":"response.completed"}\n\n'+ )++ def handler(request: httpx.Request) -> httpx.Response:+ return httpx.Response(200, content = body, headers = {"content-type": "text/event-stream"})++ _mock_http_client(monkeypatch, handler)++ async def run():+ client = ExternalProviderClient(+ provider_type = "openai",+ base_url = "https://api.openai.com/v1",+ api_key = "sk-openai-test",+ )+ out = await _collect(+ client.stream_chat_completion(+ messages = [{"role": "user", "content": "hi"}], model = "gpt-5"+ )+ )+ await client.close()+ return out++ chunks = _drive(run())+ assert not any("502" in str(chunk) for chunk in chunks), chunks++[email protected]("payload", [b"null", b"[]", b'"text"', b"7"])+def test_a_valid_but_non_object_frame_is_skipped_not_fatal(monkeypatch, payload):+ """`data: null` and `data: []` are valid JSON but not dicts, so the error check must+ not call .get() on them: that raised AttributeError and killed the stream."""+ body = (+ b"data: "+ + payload+ + b'\n\nevent: response.completed\ndata: {"type":"response.completed"}\n\n'+ )++ def handler(request: httpx.Request) -> httpx.Response:+ return httpx.Response(200, content = body, headers = {"content-type": "text/event-stream"})++ _mock_http_client(monkeypatch, handler)++ async def run():+ client = ExternalProviderClient(+ provider_type = "openai",+ base_url = "https://api.openai.com/v1",+ api_key = "sk-openai-test",+ )+ out = await _collect(+ client.stream_chat_completion(+ messages = [{"role": "user", "content": "hi"}], model = "gpt-5"+ )+ )+ await client.close()+ return out++ chunks = _drive(run())+ assert not any("502" in str(chunk) for chunk in chunks), chunks