Implementation:AI Shell Team Aish RECONNECT BACKOFF
| Knowledge Sources | |
|---|---|
| Domains | MCP, Reliability, Networking |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for reconnecting to failed MCP servers using a bounded exponential backoff ladder provided by the aish-mcp crate.
= Description
The RECONNECT_BACKOFF constant is a fixed array of four delays: [500ms, 1s, 2s, 4s]. The reconnect_ladder method walks this array, attempting a connection at each step with the preceding delay. Each delay is interruptible — if the driver is superseded (stale generation/epoch) or the shutdown signal fires, the reconnect is aborted.
After one full ladder fails, the driver increments a ladder counter. After MAX_RECOVERY_LADDERS (2) full ladders, the server is marked Failed and no further automatic reconnection is attempted.
This is a Pattern Doc: the reconnection logic is a loop within the driver task using the constant array, not a standalone function.
Usage
This pattern is internal to the MCP driver task. The backoff ladder runs automatically when a connection is lost. No external API call is needed.
Code Reference
Source Location
- Repository: aish
- File: crates/aish-mcp/src/manager.rs
Signature
const RECONNECT_BACKOFF: [Duration; 4] = [
Duration::from_millis(500),
Duration::from_millis(1000),
Duration::from_millis(2000),
Duration::from_millis(4000),
];
const MAX_RECOVERY_LADDERS: usize = 2;
// Internal method in the driver loop:
async fn reconnect_ladder(&self, name: &str, generation: u64, epoch: u64) -> Attempt
Import
// Internal to aish-mcp; no direct import needed
// The pattern is used by the driver task automatically
I/O Contract
This is a pattern, not a callable API. The driver task uses the backoff ladder internally.
| Name | Type | Description |
|---|---|---|
| RECONNECT_BACKOFF | [Duration; 4] | Fixed delays: 500ms, 1s, 2s, 4s |
| MAX_RECOVERY_LADDERS | usize | Max full ladder cycles before Failed (2) |
Usage Examples
Backoff Ladder Behavior
// The reconnection happens automatically inside the driver:
// 1. Connection drops
// 2. Driver enters reconnect loop
// 3. Waits 500ms → try connect → fail
// 4. Waits 1s → try connect → fail
// 5. Waits 2s → try connect → fail
// 6. Waits 4s → try connect → fail
// 7. Ladder 1 complete, retry ladder 2
// 8. After 2 ladders (8 attempts) → ServerStatus::Failed
// No user code needed — the driver manages this internally