Skip to content

feat: Add structured retry/backoff engine#59

Merged
rexlunae merged 4 commits intomainfrom
feat/retry-engine
Feb 17, 2026
Merged

feat: Add structured retry/backoff engine#59
rexlunae merged 4 commits intomainfrom
feat/retry-engine

Conversation

@rexlunae
Copy link
Copy Markdown
Owner

Summary

Adds a generic retry engine with exponential backoff from @aecs4u (PR #21).

Features

Retry Reasons

Classifies transient failures:

  • Connect failures
  • Timeouts
  • Rate limiting (429)
  • Server errors (5xx)
  • Request timeouts

Backoff Strategies

  • Exponential backoff with jitter
  • Configurable base delay, max delay, max attempts
  • Respects Retry-After headers from rate-limited responses

Usage

use rustyclaw::retry::{RetryExecutor, RetryPolicy};

let policy = RetryPolicy {
    max_attempts: 3,
    base_delay: Duration::from_secs(1),
    max_delay: Duration::from_secs(30),
    jitter: true,
};

let executor = RetryExecutor::new(policy);
let result = executor.execute(|| async {
    make_api_call().await
}).await;

Files

  • src/retry/mod.rs — Core retry executor and types (226 lines)
  • src/retry/policy.rs — Configurable retry policies (74 lines)

No New Dependencies

Uses only std::time::Duration and std::future::Future.

Attribution

Original implementation by @aecs4u

Adds a generic retry engine with exponential backoff from @aecs4u (PR #21).

## Features

### Retry Reasons
- Connect failures
- Timeouts
- Rate limiting (429)
- Server errors (5xx)
- Request timeouts

### Backoff Strategies
- Exponential backoff with jitter
- Configurable base delay, max delay, max attempts
- Optional retry-after header support (rate limiting)

### RetryExecutor
Generic executor that wraps any async operation:
```rust
use rustyclaw::retry::{RetryExecutor, RetryPolicy};

let executor = RetryExecutor::new(RetryPolicy::default());
let result = executor.execute(|| async {
    // Your fallible operation
    make_api_call().await
}).await;
```

### RetryPolicy
Configurable retry behavior:
- `max_attempts` — Maximum retry count (default: 3)
- `base_delay` — Initial backoff delay (default: 1s)
- `max_delay` — Maximum backoff delay (default: 30s)
- `jitter` — Add randomness to prevent thundering herd

## Files
- src/retry/mod.rs — Core retry executor and types
- src/retry/policy.rs — Configurable retry policies

## Attribution
Original implementation by @aecs4u
@rexlunae rexlunae merged commit cb734b2 into main Feb 17, 2026
10 checks passed
@rexlunae rexlunae deleted the feat/retry-engine branch February 17, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant