From 80ef455027b309f963221f9a8cda65ceace4bc31 Mon Sep 17 00:00:00 2001 From: Alex Fournier Date: Sun, 19 Jul 2026 12:13:30 -0400 Subject: [PATCH] fix(runtime): reject empty native Anthropic streams Signed-off-by: Alex Fournier --- agent/chat_completion_helpers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py index 427c2ea2407b..065d7d10028d 100644 --- a/agent/chat_completion_helpers.py +++ b/agent/chat_completion_helpers.py @@ -3282,6 +3282,15 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta= if agent._interrupt_requested: return None + if ( + base_final_message is not None + and not getattr(base_final_message, "content", None) + and getattr(base_final_message, "stop_reason", None) is None + ): + raise EmptyStreamError( + "Provider returned an empty stream with no stop_reason " + "(possible upstream error or malformed event stream)." + ) if base_final_message is not None and not stream.output_modified: return base_final_message final_message = accumulator.response(base_final_message)