fix: add one second to retry after delays

This commit is contained in:
Arthur K.
2026-07-23 14:10:27 +08:00
committed by chengyongru
parent 299bcf491b
commit 3647875aba
2 changed files with 9 additions and 7 deletions
+3 -1
View File
@@ -20,6 +20,7 @@ from nanobot.utils.helpers import sanitize_surrogates_deep
STREAM_IDLE_TIMEOUT_ENV = "NANOBOT_STREAM_IDLE_TIMEOUT_S"
DEFAULT_STREAM_IDLE_TIMEOUT_S = 90.0
MAX_STREAM_IDLE_TIMEOUT_S = 3600.0
RETRY_AFTER_BUFFER = 1
def resolve_stream_idle_timeout_s(
@@ -965,8 +966,9 @@ class LLMProvider(ABC):
)
break
retry_after = self._extract_retry_after_from_response(response)
base_delay = delays[min(attempt - 1, len(delays) - 1)]
delay = self._extract_retry_after_from_response(response) or base_delay
delay = retry_after + RETRY_AFTER_BUFFER if retry_after else base_delay
if persistent:
delay = min(delay, self._PERSISTENT_MAX_DELAY)
+6 -6
View File
@@ -3,7 +3,7 @@ import copy
import pytest
from nanobot.providers.base import GenerationSettings, LLMProvider, LLMResponse
from nanobot.providers.base import RETRY_AFTER_BUFFER, GenerationSettings, LLMProvider, LLMResponse
class ScriptedProvider(LLMProvider):
@@ -402,8 +402,8 @@ async def test_chat_with_retry_uses_retry_after_and_emits_wait_progress(monkeypa
)
assert response.content == "ok"
assert delays == [7.0]
assert progress and "7s" in progress[0]
assert delays == [7.0 + RETRY_AFTER_BUFFER]
assert progress and f"{int(7 + RETRY_AFTER_BUFFER)}s" in progress[0]
def test_extract_retry_after_supports_common_provider_formats() -> None:
@@ -444,7 +444,7 @@ async def test_chat_with_retry_prefers_structured_retry_after_when_present(monke
response = await provider.chat_with_retry(messages=[{"role": "user", "content": "hello"}])
assert response.content == "ok"
assert delays == [9.0]
assert delays == [9.0 + RETRY_AFTER_BUFFER]
@pytest.mark.asyncio
@@ -521,7 +521,7 @@ async def test_chat_with_retry_retries_429_transient_rate_limit(monkeypatch) ->
assert response.content == "ok"
assert provider.calls == 2
assert delays == [0.2]
assert delays == [0.2 + RETRY_AFTER_BUFFER]
@pytest.mark.asyncio
@@ -591,7 +591,7 @@ async def test_chat_with_retry_prefers_structured_retry_after(monkeypatch) -> No
response = await provider.chat_with_retry(messages=[{"role": "user", "content": "hello"}])
assert response.content == "ok"
assert delays == [0.2]
assert delays == [0.2 + RETRY_AFTER_BUFFER]
@pytest.mark.asyncio