fix(typescript): handle undici timeout errors and retry network failures#15559
fix(typescript): handle undici timeout errors and retry network failures#15559devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
- Detect Node.js undici timeout errors (UND_ERR_HEADERS_TIMEOUT, UND_ERR_BODY_TIMEOUT, ETIMEDOUT) and classify them as reason: timeout instead of reason: unknown - Include full error cause chain in unknown error messages so underlying error codes surface to users instead of just 'fetch failed' - Retry on network-level failures (connection resets, socket errors) in addition to retryable HTTP status codes (408, 429, 5xx) Co-Authored-By: rishabh <rishabh@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Timeout and abort errors should propagate immediately without retries. Only transient network errors (ECONNRESET, ECONNREFUSED, etc.) are retried. Co-Authored-By: rishabh <rishabh@buildwithfern.com>
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Description
Fixes an issue where Node.js's built-in
fetch(backed by undici) has a hard 300sheadersTimeoutthat fires before the SDK'stimeoutInSeconds, causing generic "fetch failed" errors on long-running requests. Reported upstream at elevenlabs/elevenlabs-js#379.Changes Made
1. Detect undici timeout errors (
Fetcher.ts)isTimeoutError()helper that checks for undici-specific error codes (UND_ERR_HEADERS_TIMEOUT,UND_ERR_BODY_TIMEOUT,ETIMEDOUT) in the error cause chainreason: "timeout"instead ofreason: "unknown", allowing SDK users to handle them with proper timeout error handling2. Surface error cause chain (
Fetcher.ts)getErrorMessageWithCause()helper that walks theerror.causechain to build a descriptive error message including underlying error codeserrorMessage: "fetch failed"— opaque, unhelpfulerrorMessage: "fetch failed -> Headers Timeout Error [UND_ERR_HEADERS_TIMEOUT]"— actionable3. Retry on network-level failures (
requestWithRetries.ts)fetch(not just HTTP status codes)ECONNRESET,ECONNREFUSED,EPIPE) are retried with exponential backoff up tomaxRetriesAbortError(SDK timeout / user abort) and undici timeout errors (UND_ERR_HEADERS_TIMEOUT,UND_ERR_BODY_TIMEOUT,ETIMEDOUT) propagate immediately without retries viaisRetryableError()filtermaxRetriesSeed snapshots
Fetcher.tsandrequestWithRetries.tsseed fixtures acrossseed/ts-sdk/Testing
pnpm check(biome lint) passespnpm formatpassesLink to Devin session: https://app.devin.ai/sessions/234b24e109924874ab8af5e9b07f397e