@@ -28,24 +28,6 @@ def _raise_timeout(run_id: str, exc: Union[Exception, None]) -> NoReturn:
2828 raise TimeoutError (f"Fetching task run result for run id { run_id } timed out." ) from exc
2929
3030
31- def _is_retryable_error (status_code : int ) -> bool :
32- """Determine if an error is retryable.
33-
34- We retry the following HTTP status codes within the SDK:
35- - 408 (Request Timeout): The server timed out waiting for the request
36- - 503 (Service Unavailable): The server is temporarily unable to handle the request
37- - 504 (Gateway Timeout): The gateway server timed out
38-
39- These errors typically indicate temporary issues with the server or network
40- that may resolve upon retry. We don't include 429 (Too Many Requests) as this
41- indicates rate limiting, which requires backing off rather than immediate retries.
42-
43- Note: This is a low-level retry mechanism within the SDK. Customers may want to
44- implement their own retry logic at the application level for other error types.
45- """
46- return status_code in (408 , 503 , 504 )
47-
48-
4931@contextlib .contextmanager
5032def timeout_retry_context (run_id : str , deadline : float ) -> Iterator [None ]:
5133 """Context manager for handling timeouts and retries when fetching task run results.
@@ -67,7 +49,8 @@ def timeout_retry_context(run_id: str, deadline: float) -> Iterator[None]:
6749 exc = e
6850 continue
6951 except APIStatusError as e :
70- if _is_retryable_error (e .status_code ):
52+ # retry on timeouts from the API
53+ if e .status_code == 408 :
7154 exc = e
7255 continue
7356 raise
0 commit comments