fix: prevent retry amplification by disabling SDK retries

This commit is contained in:
pikaxinge 2026-04-02 17:29:08 +00:00 committed by Xubin Ren
parent 6fbcecc880
commit dbdf7e5955
3 changed files with 23 additions and 0 deletions

View File

@ -49,6 +49,8 @@ class AnthropicProvider(LLMProvider):
client_kw["base_url"] = api_base
if extra_headers:
client_kw["default_headers"] = extra_headers
# Keep retries centralized in LLMProvider._run_with_retry to avoid retry amplification.
client_kw["max_retries"] = 0
self._client = AsyncAnthropic(**client_kw)
@staticmethod

View File

@ -135,6 +135,7 @@ class OpenAICompatProvider(LLMProvider):
api_key=api_key or "no-key",
base_url=effective_base,
default_headers=default_headers,
max_retries=0,
)
def _setup_env(self, api_key: str, api_base: str | None) -> None:

View File

@ -0,0 +1,20 @@
from unittest.mock import patch
from nanobot.providers.anthropic_provider import AnthropicProvider
from nanobot.providers.openai_compat_provider import OpenAICompatProvider
def test_openai_compat_disables_sdk_retries_by_default() -> None:
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI") as mock_client:
OpenAICompatProvider(api_key="sk-test", default_model="gpt-4o")
kwargs = mock_client.call_args.kwargs
assert kwargs["max_retries"] == 0
def test_anthropic_disables_sdk_retries_by_default() -> None:
with patch("anthropic.AsyncAnthropic") as mock_client:
AnthropicProvider(api_key="sk-test", default_model="claude-sonnet-4-5")
kwargs = mock_client.call_args.kwargs
assert kwargs["max_retries"] == 0