fix(bedrock): only retry transient botocore errors#83
Merged
dpomian merged 1 commit intoMay 18, 2026
Merged
Conversation
The previous 'except Exception' caught and retried KeyError from malformed responses, missing-credential errors, and other programmer or config mistakes -- wasting up to 6s of backoff per failed call and hiding the real cause. Narrow the catch to (ClientError, BotoCoreError) and gate retries with _is_retryable, which only retries throttling, 5xx, transient model errors, and transport-level BotoCoreError. Permanent ClientError codes (ValidationException, AccessDeniedException, ResourceNotFoundException) and any non-botocore exception surface immediately. Addresses the Copilot review comment on PR AmadeusITGroup#69.
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts the AWS Bedrock Titan embedding retry loop to only retry transient boto3/botocore failures, allowing permanent errors to surface immediately instead of being masked by backoff.
Changes:
- Replace broad
except Exceptionretry handling withexcept (ClientError, BotoCoreError)and a retryability gate. - Introduce
_RETRYABLE_BEDROCK_CODESand_is_retryable()to classify retryable Bedrock error codes / HTTP 5xx responses.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+43
to
+49
| def _is_retryable(self, exc: Exception) -> bool: | ||
| if isinstance(exc, ClientError): | ||
| code = exc.response.get("Error", {}).get("Code", "") | ||
| status = exc.response.get("ResponseMetadata", {}).get("HTTPStatusCode", 0) | ||
| return code in _RETRYABLE_BEDROCK_CODES or 500 <= status < 600 | ||
| # BotoCoreError covers connection/read timeouts and other transport-level issues | ||
| return isinstance(exc, BotoCoreError) |
Contributor
There was a problem hiding this comment.
Thank you so much for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the Copilot review comment on #69.
Replaces
except Exceptionin the Bedrock retry loop withexcept (ClientError, BotoCoreError)plus_is_retryable(exc). Only retries throttling, 5xx, transient modelerrors, and transport-level timeouts. Permanent errors (
ValidationException,AccessDeniedException, malformed-responseKeyError, etc.) now surface immediatelyinstead of being hidden under up to 6s of backoff.