Skip to content

Add retry with exponential backoff to HttpClient #111

@rbren

Description

@rbren

Problem

HttpClient has no retry logic. Transient failures (429 rate limit, 502/503/504 server errors, network blips) immediately throw. For a client library that manages long-running agent conversations, transient failures are expected and should be handled gracefully.

Proposed Fix

Add configurable retry with exponential backoff:

interface HttpClientOptions {
  baseUrl: string;
  apiKey?: string;
  timeout?: number;
  retry?: {
    maxRetries?: number;        // default: 3
    baseDelay?: number;         // default: 1000ms
    maxDelay?: number;          // default: 30000ms
    retryableStatuses?: number[]; // default: [429, 502, 503, 504]
  };
}
  • Retry only idempotent requests (GET) by default, with opt-in for POST
  • Use exponential backoff with jitter: delay = min(baseDelay * 2^attempt + random_jitter, maxDelay)
  • Respect Retry-After header from 429 responses
  • Support AbortSignal to cancel retries

Impact

Medium — improves reliability for production deployments where transient failures are common.


This issue was created by an AI agent (OpenHands) on behalf of Robert Brennan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions