#21033: fix(failover): classify connection errors as timeout for model failover
agents
size: XS
experienced-contributor
## Summary
Connection-related errors like `Connection error.`, `ECONNREFUSED`, `ECONNRESET`, `ENOTFOUND`, `ECONNABORTED`, `socket hang up`, and `fetch failed` were not matched by any `ERROR_PATTERNS` entry. This caused `classifyFailoverReason()` to return `null`, preventing fallback models from being attempted when the primary provider had transient network issues.
## Changes
- Add connection error patterns to `ERROR_PATTERNS.timeout`: `/\bconnection\s+error\b/i`, `/\bconnect error\b/i`, `econnrefused`, `econnreset`, `enotfound`, `econnaborted`, `socket hang up`, `fetch failed`
- Add test covering all new patterns
## Testing
All 32 existing + new tests pass:
```
✓ src/agents/pi-embedded-helpers.isbillingerrormessage.e2e.test.ts (32 tests) 36ms
```
Fixes #20931
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds connection error patterns (`Connection error.`, `ECONNREFUSED`, `ECONNRESET`, `ENOTFOUND`, `ECONNABORTED`, `socket hang up`, `fetch failed`) to the `ERROR_PATTERNS.timeout` array in `errors.ts:587-604`, enabling model failover when primary providers experience transient network issues. Previously these errors returned `null` from `classifyFailoverReason()`, preventing fallback attempts. The implementation is well-tested with comprehensive test coverage for all new patterns.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are minimal, well-tested, and address a specific failover issue. All new patterns are covered by tests, and the implementation follows existing patterns in the codebase. Note that `ECONNRESET` and `ECONNABORTED` are already handled via error code matching in `failover-error.ts:169`, but adding them to the string pattern matching provides redundancy for cases where they appear as error messages rather than error codes.
- No files require special attention
<sub>Last reviewed commit: 869d3b0</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21516: fix: classify connection errors as timeout for model failover (#20931)
by echoVic · 2026-02-20
90.6%
#5031: fix: add network connection error codes to failover classifier
by shayan919293 · 2026-01-30
86.6%
#19077: fix(agents): trigger model failover on connection-refused and netwo...
by ayanesakura · 2026-02-17
85.4%
#15163: fix(errors): classify connection errors as retryable failover reason
by fagemx · 2026-02-13
85.0%
#15815: Fallback LLM doesn't trigger if primary model is local
by shihanqu · 2026-02-13
84.2%
#12314: fix: treat HTTP 5xx server errors as failover-worthy
by hsssgdtc · 2026-02-09
80.8%
#22359: fix(agents): classify overloaded service errors as timeout
by AIflow-Labs · 2026-02-21
80.0%
#7229: fix: add network error resilience to agentic loop failover
by ai-fanatic · 2026-02-02
79.5%
#21017: fix: treat HTTP 502/503/504 as failover-eligible (timeout reason)
by taw0002 · 2026-02-19
79.3%
#17231: fix(failover): recognize model_cooldown as rate-limit for fallback
by thebtf · 2026-02-15
78.9%