Repository navigation
fix: add LLM-level retry for transient Bedrock errors (ServiceUnavailableException) - #18
Merged
omerhochman merged 4 commits intoApr 23, 2026
Conversation
…ableException) Wrap chat model with LangChain's .withRetry() to transparently retry transient errors (503, throttling, network) with exponential backoff. This preserves agent conversation state instead of restarting the entire test. - Add llmRetryAttempts config option (default: 3, 0 to disable) - Add isTransientError() classifier for retryable error detection - Add specific formatAgentError branch for ServiceUnavailableException - Add comprehensive tests for retry logic and error classification Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
techjacker
marked this pull request as ready for review
April 21, 2026 12:49
elonsalfati
approved these changes
Apr 21, 2026
Comment on lines
+257
to
+260
| errorMessage.includes("ServiceUnavailableException") || | ||
| errorMessage.includes("503") || | ||
| errorMessage.includes("unable to process your request") | ||
| ) { |
Member
There was a problem hiding this comment.
Should we create custom errors instead of searching for text within the error message?
…handler Replace string-based error detection in formatAgentError with instanceof check on a custom TransientLLMError class. Transient errors are now wrapped in the catch block using isTransientError() before being passed to the error formatter.
omerhochman
approved these changes
Apr 23, 2026
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.
Summary
v0.3.0ServiceUnavailableException, throttling, network) using LangChain's built-in.withRetry()on the chat modelllmRetryAttemptsconfig option (default: 3, set to 0 to disable) so consumers can tune retry behaviorServiceUnavailableExceptionwhen retries are exhausted, replacing the generic "Unexpected error" outputProblem
Bedrock intermittently returns
ServiceUnavailableException(503) during the LangChain ReAct agent loop. This kills the entireagent.invoke()call, losing all accumulated agent state (tool calls, reasoning steps). The error falls through to a generic catch-all with an unhelpful message:The existing test-level retry (
maxAttempts) restarts the entire test from scratch — wasteful for a transient infrastructure hiccup on a single LLM call mid-conversation when test suites can take 45 mins to run.Solution
Retry at the LLM call level using
model.withRetry(), which is available on all LangChainRunnableinstances. This is the optimal layer because:RunnableRetryhandles backoff internallyonFailedAttemptcallback re-throws auth errors, validation errors, etc. immediatelyllmRetryAttempts: 3kicks in automaticallyError classification (
isTransientError)Retries only for errors classified as transient:
ServiceUnavailableException(Bedrock 503)ThrottlingException,429,rate limitModelStreamErrorException,overloadedECONNRESET,ETIMEDOUT,socket hang upAll other errors (401, API key, validation, recursion limit) fail immediately.
Misc Extra Fixes
App prints dynamic version from obtained from
package.json.