> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safefetch.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Retry and Backoff

> Understand attempts, exponential backoff, and terminal failure handling.

## How retries work

A delivery attempt fails when SafeFetch gets a non-2xx response, network error, or timeout. If attempts remain, the action returns to `pending` with `next_retry_at`.

## Backoff formula

<Frame>
  ```text theme={null}
  backoff_seconds = min(2^attempt * 10, 3600)
  ```
</Frame>

`attempt` is 1-based after each failed attempt.

## Backoff table

| Failed attempt | Delay before next try |
| -------------- | --------------------- |
| 1              | 20s                   |
| 2              | 40s                   |
| 3              | 80s                   |
| 4              | 160s                  |
| 5              | 320s                  |
| ...            | capped at 3600s       |

## `retries`

* Set per action (`1` to `100`, default `3`).
* Once attempts are exhausted, action becomes `failed`.

## Failure callbacks

If `callback` is set, SafeFetch sends a failure callback with `status: failed` and `last_error` when the action reaches terminal failure.

## Monitoring retries

Use action reads/listing fields:

* `retries_remaining`: attempts left
* `next_retry_in_seconds`: countdown to next attempt
* `last_error`: most recent failure reason
