From 33d2f7892d710c067dade5bf45c533a38d2a43f0 Mon Sep 17 00:00:00 2001 From: TheArchitectit Date: Wed, 29 Apr 2026 20:46:32 -0500 Subject: [PATCH] fix: detect raw JSON errors in streaming path When a provider returns a JSON error (e.g., {"error":{"message":"..."}}) without SSE framing (no "data:" prefix), the SSE parser was silently ignoring it and hanging. Now detects and surfaces these errors. Also handles HTML responses that lack SSE framing. Co-Authored-By: Claude Opus 4.7 --- rust/crates/api/src/providers/openai_compat.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/rust/crates/api/src/providers/openai_compat.rs b/rust/crates/api/src/providers/openai_compat.rs index 42fdce76..38416b91 100644 --- a/rust/crates/api/src/providers/openai_compat.rs +++ b/rust/crates/api/src/providers/openai_compat.rs @@ -1521,6 +1521,7 @@ fn parse_sse_frame( body: trimmed.chars().take(500).collect(), retryable: false, suggested_action: suggested_action_for_status(status), + retry_after: None, }); } } @@ -1536,6 +1537,7 @@ fn parse_sse_frame( body: trimmed.chars().take(200).collect(), retryable: false, suggested_action: Some("verify the API endpoint URL is correct".to_string()), + retry_after: None, }); } return Ok(None); @@ -1575,22 +1577,6 @@ fn parse_sse_frame( }); } } - // Detect HTML or other non-JSON responses early for better error messages - let trimmed_payload = payload.trim(); - if trimmed_payload.starts_with('<') || trimmed_payload.starts_with("(&payload) .map(Some) .map_err(|error| ApiError::json_deserialize(provider, model, &payload, error))