From 92057474f3d2dfe38c1be8900cabbae3e696cf41 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 14 Jul 2026 23:52:29 +0530 Subject: [PATCH] fix(streaming): distinguish empty-stream exhaustion from connection failure in status message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An exhausted EmptyStreamError previously reported 'Connection to provider failed' — misleading, since the connection succeeded (stream opened) and the provider simply sent nothing. Add a dedicated third branch so users debugging a misconfigured endpoint aren't sent chasing network issues. Follow-up to #64420. --- agent/chat_completion_helpers.py | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py index 2204c44f925a..9f114d7e6528 100644 --- a/agent/chat_completion_helpers.py +++ b/agent/chat_completion_helpers.py @@ -2949,17 +2949,32 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta= mid_tool_call=False, diag=request_client_holder.get("diag"), ) - agent._buffer_status( - "❌ Provider returned malformed streaming data after " - f"{_max_stream_retries + 1} attempts. " - "The provider may be experiencing issues — " - "try again in a moment." - if _is_stream_parse_err else - "❌ Connection to provider failed after " - f"{_max_stream_retries + 1} attempts. " - "The provider may be experiencing issues — " - "try again in a moment." - ) + if _is_stream_parse_err: + _exhausted_msg = ( + "❌ Provider returned malformed streaming data after " + f"{_max_stream_retries + 1} attempts. " + "The provider may be experiencing issues — " + "try again in a moment." + ) + elif _is_empty_stream: + # The connection SUCCEEDED (stream opened) but the + # provider sent no chunks — saying "connection + # failed" here sends users chasing network issues + # when the problem is the provider/endpoint. + _exhausted_msg = ( + "❌ Provider returned an empty response stream " + f"after {_max_stream_retries + 1} attempts. " + "The provider may be experiencing issues — " + "try again in a moment." + ) + else: + _exhausted_msg = ( + "❌ Connection to provider failed after " + f"{_max_stream_retries + 1} attempts. " + "The provider may be experiencing issues — " + "try again in a moment." + ) + agent._buffer_status(_exhausted_msg) else: _err_lower = str(e).lower() _is_stream_unsupported = (