Skip to content

Commit 0ff51dc

Browse files
committed
fix: 流式连接中断(cancelled)时自动重试,避免调用技能时停止工作
1 parent 117b726 commit 0ff51dc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/src/main/java/com/xiaomo/androidforclaw/agent/context/ContextErrors.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,19 @@ object ContextErrors {
126126
fun isTransientHttpError(errorMessage: String?): Boolean {
127127
if (errorMessage.isNullOrBlank()) return false
128128
val trimmed = errorMessage.trim()
129-
val status = extractLeadingHttpStatus(trimmed) ?: return false
130-
return status in TRANSIENT_HTTP_ERROR_CODES
129+
// HTTP status code check
130+
val status = extractLeadingHttpStatus(trimmed)
131+
if (status != null && status in TRANSIENT_HTTP_ERROR_CODES) return true
132+
// Connection-level errors: cancelled streams, reset connections, broken pipes
133+
val lower = trimmed.lowercase()
134+
return lower.contains("cancelled") ||
135+
lower.contains("connection reset") ||
136+
lower.contains("broken pipe") ||
137+
lower.contains("connection was closed") ||
138+
lower.contains("unexpected end of stream") ||
139+
lower.contains("stream was reset") ||
140+
lower.contains("socket closed") ||
141+
lower.contains("canceled") // OkHttp American spelling
131142
}
132143

133144
/**

0 commit comments

Comments
 (0)