The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: require terminal signal for streamed errors
beiyesi5cbc645d0907
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.pyindex c4104e77695..ff9822c010b 100644--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@ -319,6 +319,8 @@ def _provider_stream_error_from_text(finish_reason_text = str(finish_reason or "").lower()has_error_finish = finish_reason_text in _PROVIDER_STREAM_ERROR_FINISH_REASONS+ if not has_error_finish:+ return Nonefor event in _parse_provider_sse_events(text):event_name = str(event.get("event") or "").strip().lower()@@ -3882,13 +3884,6 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta=if pending_text_parts or _provider_stream_text_may_be_sse(delta.content):pending_text_parts.append(delta.content)pending_text = "".join(pending_text_parts)- provider_stream_error = _provider_stream_error_from_text(- pending_text,- None,- response=getattr(stream, "response", None),- )- if provider_stream_error is not None:- raise provider_stream_errorif _provider_stream_text_may_be_sse(pending_text):continue_flush_pending_stream_text()diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.pyindex 775d6504f88..dc11e0ed48e 100644--- a/tests/run_agent/test_run_agent.py+++ b/tests/run_agent/test_run_agent.py@@ -5668,9 +5668,12 @@ class TestStreamingApiCall:call.args[0] for call in agent.stream_delta_callback.call_args_list] == ["id: product-42\n", "is ready"]- def test_literal_sse_error_example_with_stop_is_not_provider_error(self, agent):+ def test_full_bailian_sse_error_example_with_stop_is_literal_text(self, agent):+ error_text = _provider_sse_429_text(message="Example error payload.")+ split_at = len(error_text) // 2chunks = [- _make_chunk(content='event: error\ndata: {"example": true}\n'),+ _make_chunk(content=error_text[:split_at]),+ _make_chunk(content=error_text[split_at:]),_make_chunk(finish_reason="stop"),]agent.client.chat.completions.create.return_value = iter(chunks)@@ -5678,10 +5681,10 @@ class TestStreamingApiCall:resp = agent._interruptible_streaming_api_call({"messages": []})- assert resp.choices[0].message.content == 'event: error\ndata: {"example": true}\n'+ assert resp.choices[0].message.content == error_textassert [call.args[0] for call in agent.stream_delta_callback.call_args_list- ] == ['event: error\ndata: {"example": true}\n']+ ] == [error_text[:split_at], error_text[split_at:]]def test_bare_sse_error_payload_with_stop_is_literal_text(self, agent):error_text = _provider_bare_sse_error_text(message="Example error payload.")