redis backend extends that guarantee across every replica.
Quick Start
1
Single replica — already correct, no config
One gateway process serialises turns with the in-process default. Nothing to set.
2
Multiple replicas — switch the backend to redis
Scaling to
replicas > 1 needs a distributed lease so two pods can’t run one session’s turns at once.3
Or configure it in gateway.yaml
How It Works
The gateway holds a lease keyed on the resolved session id for the whole turn; a second replica blocks until the first releases, and a crashed holder’s lease expires afterttl so a healthy session is never wedged.
Release is identity-checked and idempotent: only the exact token handed out may release the lease, so a stale token never frees another owner’s turn.
Configuration Options
TurnLockConfig from praisonaiagents/gateway/config.py.
The
enabled property returns True only when a distributed backend is selected (backend != "local").
Full field, type, and default reference for
TurnLockConfig, TurnLockProtocol, LocalTurnLock, and TurnLeaseTokenWhen to Enable
Match the backend to your replica count.Backward Compatibility
local is the default and reproduces today’s in-process asyncio.Lock byte-for-byte — single-replica deployments are unchanged and the core protocol adds no new dependency.
Best Practices
Size ttl to outlast your slowest turn
Size ttl to outlast your slowest turn
The lease must survive the longest legitimate turn, or a slow turn’s lease expires and a second replica starts a concurrent turn. Keep it short enough that a crashed replica unblocks quickly — the default
60.0 suits most turns.Reuse the gateway's RedisConfig unless you need a separate store
Reuse the gateway's RedisConfig unless you need a separate store
Leave
url unset and the distributed lock reuses the gateway’s configured RedisConfig. Set url only when the lock lives on a different Redis than push/delivery.Monitor lease expiries
Monitor lease expiries
A lease that expires mid-turn means
ttl is too short for real traffic. Watch for expiry-then-reacquire on the same session and raise ttl if you see it.Enable it before you scale, not after
Enable it before you scale, not after
Flip
backend='redis' before raising replicaCount. Scaling first leaves a window where two pods run concurrent turns on one session.Related
Cross-Platform Sessions
The in-process turn lock this extends across replicas.
Helm Chart (Gateway)
Scale the gateway on Kubernetes with
replicaCount.Gateway Admission Control
Sibling robustness knob — concurrency ceiling and backpressure.
Gateway Liveness
Sibling robustness knob — reap half-open connections.

