CLOSED · OPEN · HALF_OPEN · 2.0x Exponential Backoff

3-State Circuit Breaker Mechanics & Exponential Backoff Recovery

Retrying a dead upstream on every incoming request wastes latency and amplifies cascading outages. FuelRouter persists an independent 3-state circuit breaker for every upstream in SQLite WAL, isolating failing hosts after 3 consecutive failures and probing recovery safely.

Circuit Breaker State Transition Parameters

ParameterConfigured ValueOperational Effect
failure_threshold3 consecutive failuresTrips circuit from CLOSED to OPEN; 4th request sends 0 hits to tripped host
open_cooldown_s45s (ai_chat_json) / 60s (other 4 pools)Base quarantine duration on first open_trips == 1
backoff_multiplier2.0x per failed probeEscalates cooldown: 60s -> 120s -> 240s -> 480s -> 900s
max_cooldown_s900s (15 minutes)Hard upper ceiling so no upstream stays quarantined permanently
half_open_probe_limit1 concurrent probePrevents thundering-herd probe storms upon cooldown expiration
recovery_success_threshold1 verified HTTP 2xx hitResets state to CLOSED, consecutive_failures: 0, open_trips: 0
retry_after_cap_s300s (5 minutes)Honors upstream Retry-After headers without allowing malicious multi-day locks

Exact Exponential Backoff Equation

Whenever consecutive_failures reaches 3 (or an upstream triggers an enforced 429 / CAPTCHA quarantine), FuelRouter increments open_trips and calculates backoff_s = min(open_cooldown_s * (2.0 ** (open_trips - 1)), 900). If the upstream supplied a Retry-After header, cooldown_s = min(max(backoff_s, retry_after_s), 900).

Until the current Unix timestamp reaches circuit_open_until_ts, every request skips the OPEN upstream completely—zero network sockets opened, zero wasted milliseconds.

Single-Probe HALF_OPEN Gate & Operator Overrides

As soon as now_ts >= circuit_open_until_ts, the next dispatch transitions the upstream to HALF_OPEN and increments half_open_in_flight to 1. Any concurrent threads arriving while that probe is running skip the upstream so a fragile provider is never hammered by parallel probes.

If the single probe passes the Anti-Fake-200 gate, the circuit closes immediately. If it fails, open_trips increments and the circuit re-opens at double the previous cooldown. Operators can also force immediate recovery via POST /v1/router/circuit/reset.

Manually Reset a Tripped Circuit After External Provider Recovery

curl -fsSL -X POST "https://fuelrouter.fastmesh.dev/v1/router/circuit/reset" \
  -H "Content-Type: application/json" \
  -d '{
    "pool_id": "web_search",
    "upstream_id": "search_tavily_free"
  }'

Circuit Breaker Verification Scenarios

Frequently Asked Technical Questions

Does a 400 or 422 caller validation error trip an upstream's circuit breaker?

No. Client statuses 400 and 422 are classified as non_retryable_client_statuses and never penalize upstream health.

Why limit HALF_OPEN probes to 1 in-flight request?

Under high concurrency, allowing 20 threads to probe simultaneously creates a thundering herd that immediately re-trips a recovering upstream.

Where is circuit breaker state persisted?

All circuit states, open_trips, and unlock timestamps are persisted atomically in SQLite WAL inside the configured --state-dir.

Live Try-Now Console & Machine Discovery

Test failover routing, dry-run quotes, and circuit breaker metrics on the live gateway or connect via JSON-RPC 2.0 MCP.

Related FuelRouter Architecture Guides