AI Transport streams survive connection drops automatically. When a client disconnects, Ably handles reconnection. When it comes back, the client resumes from exactly where it left off - no lost tokens, no broken responses, no manual retry logic.
How it works
The durable session (Ably channel) persists independently of any single connection. When a client's connection drops:
- The agent continues streaming tokens to the channel - the stream is not tied to the client's connection.
- Ably's client SDK automatically reconnects.
- On reconnection, the client transport uses
untilAttachto load any messages it missed during the gap. - The conversation state is restored seamlessly - the client sees the complete response.
No application code needed. This is built into the transport layer.
Recovery scenarios
There are two recovery paths depending on how long the client was disconnected:
When the disconnection is brief, Ably's connection protocol handles it automatically. The client reconnects and the SDK uses untilAttach to load any messages published while the client was away. There is no gap - the response resumes exactly where it left off.
When the client has been offline for a longer period (beyond the channel's persistence window for live recovery), it loads the full conversation from channel history on reconnect. The client can paginate through history using view.loadOlder() to reconstruct the complete conversation.
Encoder recovery
On the server side, the encoder handles transient failures during streaming. If an append operation fails (for example, due to a network blip between the server and Ably), the encoder falls back to a full message update:
- Append the next token to the message (normal path).
- If the append fails, send a full update with the accumulated content (recovery path).
- Continue appending from the recovered state.
This happens automatically inside turn.streamResponse(). The accumulated response is never lost, even if individual append operations fail.
Mid-stream joins
When a client joins a channel while a response is already streaming, the lifecycle tracker ensures it receives the correct sequence of events. Missing lifecycle events (like the stream start) are synthesized so the client can process the in-progress stream correctly.
This means a client can open a second tab while the agent is mid-response and immediately see the streaming content.
Load history on reconnect
The client transport loads conversation history using Ably's untilAttach parameter:
1
const { nodes, hasOlder, loadOlder } = useView(transport, { limit: 30 })useView automatically loads history on mount. The untilAttach flag ensures no gap between historical messages and live messages - every message is accounted for.
To load older messages beyond the initial window:
1
2
3
4
5
6
7
const { nodes, hasOlder, loadOlder } = useView(transport, { limit: 30 })
// hasOlder indicates whether there are more messages to load
if (hasOlder) {
await loadOlder()
// The view window expands internally - nodes updates with the older messages
}Related features
- Token streaming - what gets recovered.
- Multi-device sessions - reconnection across devices.
- History and replay - loading conversation history.
- Client transport API - reference for client transport connection and recovery methods.
- Sessions and turns - how durable sessions enable recovery.
- Get started - build your first AI Transport application.