diff --git a/run_agent.py b/run_agent.py index ad0d3672..d349e4b5 100644 --- a/run_agent.py +++ b/run_agent.py @@ -5143,6 +5143,7 @@ class AIAgent: _TRANSIENT_TRANSPORT_ERRORS = frozenset({ "ReadTimeout", "ConnectTimeout", "PoolTimeout", "ConnectError", "RemoteProtocolError", + "APIConnectionError", "APITimeoutError", }) def _try_recover_primary_transport( diff --git a/tests/run_agent/test_primary_runtime_restore.py b/tests/run_agent/test_primary_runtime_restore.py index 57cc3f02..74119c30 100644 --- a/tests/run_agent/test_primary_runtime_restore.py +++ b/tests/run_agent/test_primary_runtime_restore.py @@ -262,6 +262,30 @@ class TestTryRecoverPrimaryTransport: assert result is True + def test_recovers_on_openai_api_connection_error(self): + agent = _make_agent(provider="custom") + error = _make_transport_error("APIConnectionError") + + with patch("run_agent.OpenAI", return_value=MagicMock()), \ + patch("time.sleep"): + result = agent._try_recover_primary_transport( + error, retry_count=3, max_retries=3, + ) + + assert result is True + + def test_recovers_on_openai_api_timeout_error(self): + agent = _make_agent(provider="custom") + error = _make_transport_error("APITimeoutError") + + with patch("run_agent.OpenAI", return_value=MagicMock()), \ + patch("time.sleep"): + result = agent._try_recover_primary_transport( + error, retry_count=3, max_retries=3, + ) + + assert result is True + def test_skipped_when_already_on_fallback(self): agent = _make_agent(provider="custom") agent._fallback_activated = True