Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Error codes are as followed:

### Retries

Certain errors are automatically retried 2 times by default, with a short exponential backoff.
Certain errors are automatically retried 0 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
429 Rate Limit, and >=500 Internal errors are all retried by default.

Expand Down
6 changes: 3 additions & 3 deletions src/runloop_api_client/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# default timeout is 1 minute
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
DEFAULT_MAX_RETRIES = 2
DEFAULT_MAX_RETRIES = 0
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)

INITIAL_RETRY_DELAY = 0.5
MAX_RETRY_DELAY = 8.0
INITIAL_RETRY_DELAY = 1.0
MAX_RETRY_DELAY = 5.0
52 changes: 26 additions & 26 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_copy_default_options(self) -> None:
# options that have a default are overridden correctly
copied = self.client.copy(max_retries=7)
assert copied.max_retries == 7
assert self.client.max_retries == 2
assert self.client.max_retries == 0

copied2 = copied.copy(max_retries=6)
assert copied2.max_retries == 6
Expand Down Expand Up @@ -706,20 +706,20 @@ class Model(BaseModel):
"remaining_retries,retry_after,timeout",
[
[3, "20", 20],
[3, "0", 0.5],
[3, "-10", 0.5],
[3, "0", 1],
[3, "-10", 1],
[3, "60", 60],
[3, "61", 0.5],
[3, "61", 1],
[3, "Fri, 29 Sep 2023 16:26:57 GMT", 20],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 1],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 1],
[3, "Fri, 29 Sep 2023 16:27:37 GMT", 60],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5],
[3, "99999999999999999999999999999999999", 0.5],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "", 0.5],
[2, "", 0.5 * 2.0],
[1, "", 0.5 * 4.0],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 1],
[3, "99999999999999999999999999999999999", 1],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 1],
[3, "", 1],
[2, "", 1 * 2.0],
[1, "", 1 * 4.0],
],
)
@mock.patch("time.time", mock.MagicMock(return_value=1696004797))
Expand All @@ -729,7 +729,7 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
headers = httpx.Headers({"retry-after": retry_after})
options = FinalRequestOptions(method="get", url="/foo", max_retries=3)
calculated = client._calculate_retry_timeout(remaining_retries, options, headers)
assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType]
assert calculated == pytest.approx(timeout, 1 * 0.875) # pyright: ignore[reportUnknownMemberType]

@mock.patch("runloop_api_client._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
@pytest.mark.respx(base_url=base_url)
Expand Down Expand Up @@ -820,7 +820,7 @@ def test_copy_default_options(self) -> None:
# options that have a default are overridden correctly
copied = self.client.copy(max_retries=7)
assert copied.max_retries == 7
assert self.client.max_retries == 2
assert self.client.max_retries == 0

copied2 = copied.copy(max_retries=6)
assert copied2.max_retries == 6
Expand Down Expand Up @@ -1442,20 +1442,20 @@ class Model(BaseModel):
"remaining_retries,retry_after,timeout",
[
[3, "20", 20],
[3, "0", 0.5],
[3, "-10", 0.5],
[3, "0", 1],
[3, "-10", 1],
[3, "60", 60],
[3, "61", 0.5],
[3, "61", 1],
[3, "Fri, 29 Sep 2023 16:26:57 GMT", 20],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 1],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 1],
[3, "Fri, 29 Sep 2023 16:27:37 GMT", 60],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5],
[3, "99999999999999999999999999999999999", 0.5],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "", 0.5],
[2, "", 0.5 * 2.0],
[1, "", 0.5 * 4.0],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 1],
[3, "99999999999999999999999999999999999", 1],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 1],
[3, "", 1],
[2, "", 1 * 2.0],
[1, "", 1 * 4.0],
],
)
@mock.patch("time.time", mock.MagicMock(return_value=1696004797))
Expand All @@ -1466,7 +1466,7 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
headers = httpx.Headers({"retry-after": retry_after})
options = FinalRequestOptions(method="get", url="/foo", max_retries=3)
calculated = client._calculate_retry_timeout(remaining_retries, options, headers)
assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType]
assert calculated == pytest.approx(timeout, 1 * 0.875) # pyright: ignore[reportUnknownMemberType]

@mock.patch("runloop_api_client._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
@pytest.mark.respx(base_url=base_url)
Expand Down