← Back to PRs

#21033: fix(failover): classify connection errors as timeout for model failover

by zerone0x open 2026-02-19 15:37 View on GitHub →
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