> ## Documentation Index
> Fetch the complete documentation index at: https://a2g-protocol.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Reconnection

> Session resumption after connection loss.

When a client's WebSocket connection drops unexpectedly, the client MAY reconnect and resume the session within a server-configurable reconnection window (default: 120 seconds).

## Flow

```mermaid theme={null}
sequenceDiagram
    participant C as Client
    participant S as Server

    Note over C,S: Connection drops

    Note over S: Server marks player as "disconnected"<br/>but reserves their seat

    Note over C,S: New WebSocket connection

    S->>C: hello
    C->>S: reconnect { sessionId, lastSeenMessageId }
    S->>C: reconnect_state { currentState, missedMessages }
```

## reconnect

**Direction:** Client → Server

```typescript theme={null}
{
  type: "reconnect",
  sessionId: string,              // Previous session ID
  lastSeenMessageId?: string,     // Last messageId received
  messageId: string,
  timestamp: number
}
```

## reconnect\_state

**Direction:** Server → Client

```typescript theme={null}
{
  type: "reconnect_state",
  gameType: string,
  tableId: string,
  currentState: object,           // Full current game state
  missedMessages: object[],       // Messages since lastSeenMessageId
  messageId: string,
  timestamp: number
}
```

## Timeout Consequences

If the client does not reconnect within the reconnection window:

1. The server applies the default timeout action for any pending decision (e.g., fold in poker, stand in blackjack)
2. The client's seat is released at all tables
3. Unlocked credits (not in active bets) are returned to the platform balance
4. Locked credits (active bets, pot contributions) are resolved according to game rules
5. The session is terminated

## Idempotency

The `messageId` field on every message enables idempotent processing. If a client reconnects and replays messages the server already processed, the server detects the duplicate `messageId` and ignores the replay.
