Quick Start
Defaults work out of the box
Flow control is enabled by default — no configuration needed. Every session gets a 256-message inbox and the gateway disconnects clients whose transport buffer exceeds 1 MB.
How It Works
Two checks protect the gateway from overload:| Event type | When buffer is full |
|---|---|
presence | Silently dropped |
typing | Silently dropped |
status | Silently dropped |
| All other types | Connection closed with code 1013 |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
max_inbox | int | 256 | Maximum queued messages per session. 0 = unlimited. Negative values raise ValueError. |
max_buffered_bytes | int | 1048576 | Maximum buffered bytes before a slow consumer is disconnected. 0 = disable slow-consumer checks. Negative values raise ValueError. |
max_inbox is set on SessionConfig; max_buffered_bytes is set on GatewayConfig.
gateway.yaml:
Client-Side Error Contract
When the inbox is full, the gateway sends this JSON frame before rejecting the message:max_buffered_bytes for a critical event, the gateway closes the WebSocket with:
- Code:
1013(Try Again Later) - Reason:
slow consumer
Common Patterns
Chat-heavy workloads — Tighten the inbox to shed load early and fail fast:Best Practices
Never set max_inbox=0 in production
Never set max_inbox=0 in production
An unlimited inbox (
max_inbox=0) lets a slow or malicious client queue messages indefinitely, eventually exhausting gateway memory. Reserve it for local testing only.Size max_buffered_bytes against your payload
Size max_buffered_bytes against your payload
A typical chat message is a few kilobytes. Set
max_buffered_bytes to at least 10× your largest expected event payload. For file-transfer or streaming use cases, increase to 4–8 MB.Handle inbox_full on the client side
Handle inbox_full on the client side
When your client receives
{"code": "inbox_full"}, pause new sends and retry with exponential backoff (e.g., 1 s → 2 s → 4 s). Do not flood the gateway with immediate retries.React to a 1013 slow-consumer close
React to a 1013 slow-consumer close
On receiving WebSocket close code
1013, reconnect after a short delay and replay any messages that were in-flight. The gateway preserves session state during the resume_window (default 24 h), so conversation context is not lost.Related
Gateway
Full gateway configuration and YAML reference
Gateway Error Handling
Error handling patterns for the gateway

