Live delivery across replicas
A client needs nothing from the load balancer. It may connect to any replica, and it may move to another replica at any time. Source-hash stickiness is harmless but not required. What changes with the replica a client reaches is how promptly it sees the per-delta stream, and only on the built-in WebSocket.
The three delivery classes
Section titled “The three delivery classes”Every event type has one class, set in server/crates/sc-hub/src/delivery_class.rs.
The match has no wildcard arm, so a new event type must be classified to compile.
| Class | Examples | Crosses replicas |
|---|---|---|
| Control | Gates, questions, approvals, terminal outcomes | Yes, through the relay |
| Signal | Board and badge changes, pushed commits, subtask state | Yes, through the relay |
| Stream | Agent text, thinking, tool calls, container logs, workflow node events | No, on the built-in WebSocket it stays on the replica that runs the task |
SUPACLOUD_HUB_EVENT_RELAY carries the first two classes. With more than one replica
it must be true. Otherwise a person on the other replica does not see a gate open or
a task finish until the next read.
Browser on the realtime transport
Section titled “Browser on the realtime transport”With SUPACLOUD_REALTIME_PILOT=true and a ready transport, a browser connects to the
Centrifugo cluster, not to a replica. Each replica captures its original events and a
persisted event comes from the database, so all three classes reach the channel whichever
replica produced them. A replica that also receives a relayed copy stores nothing twice,
because the capture is keyed by the event id.
The browser reads a large event by reference through any replica. Delivery is live for every class and needs nothing from the load balancer.
Browser on the built-in WebSocket
Section titled “Browser on the built-in WebSocket”The browser falls back to the built-in socket when the pilot is off and while the realtime transport is not ready. It keeps checking and switches when the transport is ready.
The socket is held by one replica. That replica delivers control and signal events of every replica, and stream events only of the tasks it runs itself. For a task on another replica the page therefore does not show a live delta stream. It catches up in steps:
- A relayed event arrives with a sequence number past the last one the page applied.
- The follow engine reads the gap from the persisted events with
?after_sequence=<last>and renders it in order.
Everything in the persisted run log arrives this way, in order and without duplicates. A hub-only event that was never written to the log does not.
Moving to another replica
Section titled “Moving to another replica”When a socket drops, or a draining replica sends its reconnect frame, the browser opens
a new socket, sends its subscriptions again and fires a resync. The follow engine then
backfills from the exact cursor. The server keeps no per-client state that the move
loses, so the new replica needs no handover. Authentication rides the session cookie.
A relay connection that was cut and restored has the same effect: the replica sends a
resync frame to its sockets, and the browser backfills what the relay may have lost.
Telegram and Discord live mode
Section titled “Telegram and Discord live mode”One replica holds each chat bot through a singleton lease, so a followed task may run on
another replica. With SUPACLOUD_HUB_REPLICAS above 1, the flush tick also reads every
followed task from the persisted event log, once a second. Live messages keep updating
with that delay, and a follow session survives a failover because chat_sessions is
durable.
What to set
Section titled “What to set”| Setting | Value with more than one replica |
|---|---|
SUPACLOUD_HUB_EVENT_RELAY |
true |
SUPACLOUD_HUB_REPLICAS |
The number of serving processes, which also divides the per-IP limits |
SUPACLOUD_REALTIME_PILOT |
true for live per-delta delivery from every replica |
| Load balancer | Any balancing, with WebSocket upgrades allowed |