11import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce" ;
2+ import { isTransientNetworkError } from "../../infra/retryable-network-errors.js" ;
23import {
34 extractLeadingHttpStatus ,
45 parseApiErrorInfo ,
@@ -9,26 +10,10 @@ import {
910 isRateLimitErrorMessage ,
1011} from "./message-patterns.js" ;
1112import type { FailoverClassification , FailoverReason , FailoverSignal } from "./signal.js" ;
12- const TIMEOUT_ERROR_CODES = new Set ( [
13- "ETIMEDOUT" ,
14- "ESOCKETTIMEDOUT" ,
15- "ECONNRESET" ,
16- "ECONNABORTED" ,
17- "ECONNREFUSED" ,
18- "ENETUNREACH" ,
19- "EHOSTUNREACH" ,
13+ const FAILOVER_TIMEOUT_ERROR_CODES = new Set ( [
2014 "EHOSTDOWN" ,
2115 "ENETRESET" ,
22- "EPIPE" ,
23- "EAI_AGAIN" ,
2416 "ERR_STREAM_PREMATURE_CLOSE" ,
25- // Keep these aligned with src/infra/retryable-network-errors.ts.
26- "UND_ERR_CONNECT_TIMEOUT" ,
27- "UND_ERR_DNS_RESOLVE_FAILED" ,
28- "UND_ERR_CONNECT" ,
29- "UND_ERR_SOCKET" ,
30- "UND_ERR_HEADERS_TIMEOUT" ,
31- "UND_ERR_BODY_TIMEOUT" ,
3217] ) ;
3318const NO_BODY_HTTP_WRAPPER_RE =
3419 / ^ (?: n o b o d y (?: r e s p o n s e ) ? | n o r e s p o n s e b o d y | s t a t u s c o d e \( n o b o d y \) ) $ / i;
@@ -349,7 +334,10 @@ export function classifyFailoverReasonFromCode(raw: string | undefined): Failove
349334 case "OVERLOADED_ERROR" :
350335 return "overloaded" ;
351336 default :
352- return TIMEOUT_ERROR_CODES . has ( normalized ) ? "timeout" : null ;
337+ return FAILOVER_TIMEOUT_ERROR_CODES . has ( normalized ) ||
338+ isTransientNetworkError ( { code : normalized } )
339+ ? "timeout"
340+ : null ;
353341 }
354342}
355343export function classifyCoreFailoverReasonFromErrorType (
0 commit comments