Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(harness): recognize retryable errors beyond string prefixes (#21114)

Sherwin Charles.b811e5bf6734
diff --git a/internal/harness/graph/pregel/retry.go b/internal/harness/graph/pregel/retry.go
index 7b8e07a4dd..44c3f60e3b 100644
--- a/internal/harness/graph/pregel/retry.go
+++ b/internal/harness/graph/pregel/retry.go
@@ -4,6 +4,7 @@ package pregel
import (
"context"
"fmt"
+ "strings"
"time"
"ragflow/internal/harness/graph/errors"
@@ -174,33 +175,9 @@ var RetryPredicates = struct {
},
}
-// contains checks if a string contains a substring (case-insensitive).
+// contains checks for a case-insensitive substring anywhere in an error message.
func contains(s, substr string) bool {
- return len(s) >= len(substr) &&
- (s == substr ||
- len(s) > len(substr) &&
- (s[0:len(substr)] == substr ||
- containsIgnoreCase(s, substr)))
-}
-
-// containsIgnoreCase performs case-insensitive substring check.
-func containsIgnoreCase(s, substr string) bool {
- s = toLower(s)
- substr = toLower(substr)
- return len(s) >= len(substr) && s[:len(substr)] == substr
-}
-
-// toLower converts a string to lowercase.
-func toLower(s string) string {
- result := make([]byte, len(s))
- for i := 0; i < len(s); i++ {
- c := s[i]
- if c >= 'A' && c <= 'Z' {
- c += 'a' - 'A'
- }
- result[i] = c
- }
- return string(result)
+ return strings.Contains(strings.ToLower(s), strings.ToLower(substr))
}
// RetryConfig provides configuration for retry behavior.
diff --git a/internal/harness/graph/pregel/retry_predicates_test.go b/internal/harness/graph/pregel/retry_predicates_test.go
new file mode 100644
index 0000000000..bdb1559fd5
--- /dev/null
+++ b/internal/harness/graph/pregel/retry_predicates_test.go
@@ -0,0 +1,102 @@
+package pregel
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "testing"
+
+ "ragflow/internal/harness/graph/types"
+)
+
+func TestRetryPredicatesMatchEmbeddedErrorMarkers(t *testing.T) {
+ tests := []struct {
+ name string
+ predicate func(error) bool
+ err error
+ want bool
+ }{
+ {
+ name: "network failure wrapped with context",
+ predicate: RetryPredicates.NetworkErrors,
+ err: errors.New("rpc call failed: CONNECTION RESET by peer"),
+ want: true,
+ },
+ {
+ name: "HTTP status after a prefix",
+ predicate: RetryPredicates.NetworkErrors,
+ err: errors.New("request failed with HTTP 503 Service Unavailable"),
+ want: true,
+ },
+ {
+ name: "network error at start",
+ predicate: RetryPredicates.NetworkErrors,
+ err: errors.New("connection refused"),
+ want: true,
+ },
+ {
+ name: "unrelated network error",
+ predicate: RetryPredicates.NetworkErrors,
+ err: errors.New("invalid authentication credentials"),
+ want: false,
+ },
+ {
+ name: "temporary error after a prefix",
+ predicate: RetryPredicates.TemporaryErrors,
+ err: errors.New("provider replied: TOO MANY REQUESTS"),
+ want: true,
+ },
+ {
+ name: "rate limit status after a prefix",
+ predicate: RetryPredicates.TemporaryErrors,
+ err: errors.New("API call returned HTTP 429"),
+ want: true,
+ },
+ {
+ name: "unrelated temporary error",
+ predicate: RetryPredicates.TemporaryErrors,
+ err: errors.New("malformed tool arguments"),
+ want: false,
+ },
+ {
+ name: "nil error",
+ predicate: RetryPredicates.TemporaryErrors,
+ err: nil,
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := tt.predicate(tt.err); got != tt.want {
+ t.Errorf("predicate(%v) = %t, want %t", tt.err, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestRetryExecutorRetriesEmbeddedNetworkError(t *testing.T) {
+ policy := &types.RetryPolicy{
+ MaxAttempts: 2,
+ BackoffFactor: 1,
+ RetryOn: RetryPredicates.NetworkErrors,
+ }
+ executor := NewRetryExecutor(policy)
+ attempts := 0
+
+ output, err := executor.Execute(context.Background(), "tool-node", func(context.Context) (any, error) {
+ attempts++
+ if attempts == 1 {
+ return nil, fmt.Errorf("tool request failed: %w", errors.New("connection reset by peer"))
+ }
+ return "recovered", nil
+ })
+ if err != nil {
+ t.Fatalf("Execute() unexpected error: %v", err)
+ }
+ if output != "recovered" {
+ t.Errorf("Execute() output = %v, want recovered", output)
+ }
+ if attempts != 2 {
+ t.Errorf("Execute() attempts = %d, want 2", attempts)
+ }
+}