diff --git a/llm/retry.go b/llm/retry.go index 9247c14..c2149e3 100644 --- a/llm/retry.go +++ b/llm/retry.go @@ -52,8 +52,17 @@ func IsRetryableModelError(err error) bool { // don't unwrap cleanly to typed errors. Cheap belt-and-braces; // only reached when no typed match found above. msg := strings.ToLower(err.Error()) - if strings.Contains(msg, "429") || strings.Contains(msg, "529") || - strings.Contains(msg, "rate limit") || strings.Contains(msg, "overloaded") { + // Bounded forms so a bare "429"/"529" inside a request id or unrelated + // 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 false diff --git a/llm/retry_test.go b/llm/retry_test.go index 0d65ee4..1c26e81 100644 --- a/llm/retry_test.go +++ b/llm/retry_test.go @@ -8,6 +8,7 @@ import ( anthropic "github.com/anthropics/anthropic-sdk-go" openai "github.com/sashabaranov/go-openai" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestIsRetryableModelErrorAnthropic429(t *testing.T) { @@ -89,3 +90,13 @@ func TestIsRetryableModelErrorUnrelatedError(t *testing.T) { err := errors.New("some other failure") 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)) +}