Multiple clients

How one conversation serves many clients at once: connections, participants, subscriptions, fan-out, and what each client must do to stay correct.

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:

ConceptWhat it isLifetime
PrincipalAn authenticated identity, from a bearer token (for example par_alice).As long as the token is valid.
ParticipantA 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.
SubscriptionA 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

  1. A client sends a command with a command_id it generated. The server validates it against the conversation’s current state.
  2. 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.
  3. Every subscription on that conversation receives those events as frames, in journal order. This includes the sender’s own other connections.
  4. 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.

One command, every client A phone sends a command. The server appends events to the journal, returns the receipt to the phone, and sends the events to every subscribed client, including the laptop. Laptopsubscribed · cursor 47 Phonesubscribed · sent c9 Protocol serverchecks the commandappends events oncefans out in order Journal… 47 · 48 · 49one position eachreceipts stored too command c9 receipt ACCEPTED frames 48–49 append Both clients see events 48 and 49 in the same order. Only the phone received the receipt.
The phone sends a command; the laptop sees its effects. Receipts go to the sender; events go to everyone subscribed.

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:

SituationWhat the client doesWhat the server does
The cursor is still in the journalread_after the cursor, or subscribe from itSends the missing frames, then up_to_date
The cursor is too old to serveSubscribes again from a snapshotSends resnapshot_required, then a snapshot
The client fell behind while readingThe SDK’s bounded queue reports ErrSlowConsumer; the client resumes from its checkpointKeeps 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_id per 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