---
name: compute_backoff_delay
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def compute_backoff_delay(attempt: int, base_delay: float = 0.5, max_delay: float = 8.0, jitter: bool = True) -> float"
description: "Calcula el delay para exponential backoff con jitter opcional. delay = min(base_delay * 2^attempt, max_delay). Con jitter anade random.uniform(0, min(base_delay, delay))."
tags: [retry, backoff, exponential, delay, jitter]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [random]
params:
  - name: attempt
    desc: "numero de intento (0-based, siendo 0 el primer reintento)"
  - name: base_delay
    desc: "delay inicial en segundos"
  - name: max_delay
    desc: "delay maximo permitido en segundos"
  - name: jitter
    desc: "si True anade variacion aleatoria al delay"
output: "numero flotante representando el delay en segundos"
tested: true
tests: ["attempt 0 retorna base_delay sin jitter", "attempt alto se cappea a max_delay", "sin jitter es determinista"]
test_file_path: "python/functions/core/compute_backoff_delay_test.py"
file_path: "python/functions/core/compute_backoff_delay.py"
---

## Ejemplo

```python
# Primer reintento (attempt=0): delay = 0.5 * 2^0 = 0.5s
compute_backoff_delay(0, jitter=False)  # 0.5

# Tercer reintento (attempt=2): delay = 0.5 * 2^2 = 2.0s
compute_backoff_delay(2, jitter=False)  # 2.0

# Intento alto, capped a 8.0s
compute_backoff_delay(10, jitter=False)  # 8.0

# Con jitter (no determinista)
compute_backoff_delay(1)  # entre 1.0 y 1.5
```

## Notas

Usa `random` de la stdlib. Con jitter=True el resultado no es determinista, pero la funcion es clasificada como pura conceptualmente dado que el jitter es intencional y no hay I/O. Para tests deterministicos usar jitter=False.
