fix(llm): scope retry classifier to bounded 429/529 forms
This commit is contained in:
1 parent
04f02c56d6
commit
9292731d79
2 files changed
+22
-2
No files matched your search
+11
-2
@@ -52,8 +52,17 @@ func IsRetryableModelError(err error) bool {
|
|||||||
// don't unwrap cleanly to typed errors. Cheap belt-and-braces;
|
// don't unwrap cleanly to typed errors. Cheap belt-and-braces;
|
||||||
// only reached when no typed match found above.
|
// only reached when no typed match found above.
|
||||||
msg := strings.ToLower(err.Error())
|
msg := strings.ToLower(err.Error())
|
||||||
if strings.Contains(msg, "429") || strings.Contains(msg, "529") ||
|
// Bounded forms so a bare "429"/"529" inside a request id or unrelated
|
||||||
strings.Contains(msg, "rate limit") || strings.Contains(msg, "overloaded") {
|
// digits doesn't trigger a retry. Word matches stay as-is (specific).
|
||||||
|
for _, sig := range []string{
|
||||||
|
"status 429", "code: 429", "code:429", " 429 ", "429 too many requests",
|
||||||
|
"status 529", "code: 529", "code:529", " 529 ", "529 overloaded",
|
||||||
|
} {
|
||||||
|
if strings.Contains(msg, sig) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.Contains(msg, "rate limit") || strings.Contains(msg, "overloaded") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
anthropic "github.com/anthropics/anthropic-sdk-go"
|
anthropic "github.com/anthropics/anthropic-sdk-go"
|
||||||
openai "github.com/sashabaranov/go-openai"
|
openai "github.com/sashabaranov/go-openai"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsRetryableModelErrorAnthropic429(t *testing.T) {
|
func TestIsRetryableModelErrorAnthropic429(t *testing.T) {
|
||||||
@@ -89,3 +90,13 @@ func TestIsRetryableModelErrorUnrelatedError(t *testing.T) {
|
|||||||
err := errors.New("some other failure")
|
err := errors.New("some other failure")
|
||||||
assert.False(t, IsRetryableModelError(err))
|
assert.False(t, IsRetryableModelError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRetry_DigitsInRequestIDNotRetryable(t *testing.T) {
|
||||||
|
err := errors.New("request failed: req_abc429def something went wrong")
|
||||||
|
require.False(t, IsRetryableModelError(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRetry_RealStatus429Retryable(t *testing.T) {
|
||||||
|
err := errors.New("openai: error, status 429 too many requests")
|
||||||
|
require.True(t, IsRetryableModelError(err))
|
||||||
|
}
|
||||||
Reference in new issue
Block a user