Multiple clients

A person rarely uses one device. The same user may read a conversation on a laptop, answer an approval on a phone, and have a terminal open on a server. Robotelos is built so that every one of those clients sees the same conversation, in the same order, and no client can make another one wrong.
Four things, not one
Most confusion comes from mixing these up:
| Concept | What it is | Lifetime |
|---|---|---|
| Principal | An authenticated identity, from a bearer token (for example par_alice). | As long as the token is valid. |
| Participant | A principal’s role in a conversation: owner, member, guest or observer. An agent is a participant too. | As long as it is a member of the conversation. |
| Connection (session) | One transport link from one client: a WebSocket, an SSE stream or a gRPC stream. | From dial until the link closes. |
| Subscription | A connection’s request to follow one conversation from a cursor. | Until the client unsubscribes, the connection closes, or the server asks for a new snapshot. |
A principal can hold several connections at once, one per device or process. Each connection has its own subscriptions. Identity belongs to the principal, not to the device.
The journal is the only source of truth
Every change to a conversation is written once, as an event with the next position in the journal. The server does not keep a per-client copy of the conversation. Each client keeps a view: the conversation reduced from the events it has seen.
This has three consequences:
- Two clients that have seen the same positions have the same view, byte for byte.
- A client that was offline does not need a special sync protocol. It asks for the events after its cursor.
- Nothing a client does can fork the history. A client can only propose a command; the server decides what is accepted, and the decision is an event.
What a command does across clients
- A client sends a command with a
command_idit generated. The server validates it against the conversation’s current state. - If the command is accepted, the server appends its events in one transaction and returns a receipt to the connection that sent the command. The receipt names the positions of the events.
- Every subscription on that conversation receives those events as frames, in journal order. This includes the sender’s own other connections.
- A command that the server has already applied is not applied again. Sending it again returns the original receipt. This is what makes retries safe across a flaky network, and it is also what makes two clients racing on the same command harmless.
A client never has to guess whether its own command landed: the receipt says so, and the frame that follows confirms it for the other clients.
Approvals from another device
Approvals are the case where more than one client matters most. An agent asks for permission; the owner may answer from any device.
- The obligation is an event. Every subscribed client sees it as an open obligation with a version and a digest.
- Any connection of a responder can answer. The answer names the version and the digest that the answering client saw.
- The server checks the responder, the version, the digest and the expiry, then records the answer once.
- Other clients receive the answered obligation as a frame. A late answer from a second device is refused as
STALE, and nothing changes.
So a phone that answers first is the answer. A laptop that tries a moment later gets STALE, and its view updates to show the answer that was recorded. See Approvals for the checks.
Staying correct while offline
Each client keeps a cursor: the position of the last event it applied. On reconnect it does one of three things:
| Situation | What the client does | What the server does |
|---|---|---|
| The cursor is still in the journal | read_after the cursor, or subscribe from it | Sends the missing frames, then up_to_date |
| The cursor is too old to serve | Subscribes again from a snapshot | Sends resnapshot_required, then a snapshot |
| The client fell behind while reading | The SDK’s bounded queue reports ErrSlowConsumer; the client resumes from its checkpoint | Keeps the events; nothing is lost |
The Go SDK does this for you in client.Follow. You never need to deduplicate frames by hand: the cursor makes every frame idempotent.
Rules a client must follow
- Generate one
command_idper intent and keep it. Retry with the same ID and the same payload only. - Never apply a frame out of order. The SDK refuses a gap; if you bypass it, you will see
ErrGap. - Render from the view, not from your own optimistic copy. Show your own message as pending until its event returns.
- Treat a removed membership as an ended stream. A removed participant receives
resnapshot_required, and a new subscribe says the conversation is unknown.
What is built and what is not
For how members and agents are added and removed, read Groups and participants.
Next steps
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.