Principle:AI Shell Team Aish Exponential Backoff Reconnection
| Knowledge Sources | |
|---|---|
| Domains | MCP, Reliability, Networking |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Pattern for reconnecting to a failed server using a bounded exponential backoff ladder with a maximum number of recovery cycles before giving up.
Description
Exponential Backoff Reconnection is the mechanism that retries failed MCP server connections with increasing delays. The backoff ladder is a fixed array of delays: [500ms, 1s, 2s, 4s]. Each step in the ladder is one full connect attempt. If all four steps fail, the driver runs another ladder (up to MAX_RECOVERY_LADDERS = 2 full cycles). After exhausting all recovery ladders, the server is marked as Failed and no further automatic reconnection is attempted.
The reconnect loop is interruptible: at each step, it checks whether the driver is still current (generation + epoch match) and whether the shutdown signal has fired. If either is false, the reconnect is aborted, allowing clean shutdown and hot-reload to preempt reconnection.
This pattern solves the problem of recovering from transient network failures without hammering the server or reconnecting forever. The bounded ladder ensures that a permanently-down server is eventually given up on, freeing resources.
Usage
Use this principle when a client must reconnect to a server that may fail transiently. The backoff ladder should be bounded (not infinite), and each step should be interruptible to allow clean shutdown and reconfiguration.
Theoretical Basis
The reconnection is a bounded multi-cycle backoff ladder:
# Abstract algorithm (NOT real implementation)
BACKOFF = [500ms, 1s, 2s, 4s] # 4 steps per ladder
MAX_LADDERS = 2 # max full cycles
def reconnect_ladder(name, generation, epoch):
for delay in BACKOFF:
if not is_current(name, generation, epoch):
return STALE # superseded by reload/shutdown
sleep_interruptible(delay)
if not is_current(name, generation, epoch):
return STALE
attempt = try_connect(name)
if attempt == SUCCESS:
return CONNECTED
# else: continue to next backoff step
# After one ladder fails, increment ladder count and retry
# After MAX_LADDERS: mark as Failed, stop reconnecting
Key design ideas:
- Bounded ladder: fixed delays [500ms, 1s, 2s, 4s], not unbounded exponential growth
- Multi-cycle with ceiling: up to 2 full ladders (8 total attempts), then Failed
- Interruptible sleep: each delay is interruptible by shutdown or reconfiguration
- Staleness check: each step verifies the driver is still current before proceeding