Every Sloppy Voice server pushes events to clients over one WebSocket at {base}/v1/events. The socket is a one-way feed: apart from a handful of session.* control messages, the client never sends commands on it. Sending a message, joining a channel or starting a call all go over HTTPS (HTTP API, 03 §6.2). A change you make over HTTPS is usually also reported as an event on the socket, and the two can arrive in either order (03 §2.8).

This page walks through the socket in the order a client meets it: connecting, the hello, the envelope, streams and subscriptions, sequencing, resume and resync, keeping the socket alive, and closing and reconnecting. The full rules are in document 03, §5 to §7.

Before you connect

You need three things before you open a socket to a server:

  • The base URL. Discovery gives it to you (Discovery). The socket URL is the base URL with https replaced by wss, plus /v1/events. For the base URL https://chat.sloppyvoice.com/server the socket is wss://chat.sloppyvoice.com/server/v1/events (03 §5.1).
  • A fresh read of {base}/meta. Read it before your first connection to a server, and again after 3 consecutive handshake failures, and apply its versions and minClient. Browsers can't read why a handshake failed, so /meta is how a web client learns it must show "update required" (03 §5.1 item 5, 03 §12.4). Its limits member advertises the limits this page refers to: maxEventBytes, maxSubscriptions and maxReplayEvents. Use the advertised values, and assume a limit's floor when limits doesn't list it (03 §16.1 rule 3, 03 §16.2).
  • A token for this server. At your home server that is the home-session access token, or a bot token for a bot. At any other server it is a remote-session token you created from a HomeAssertion (Accounts, Federation). Send a token only to the server that issued it (03 §3.2 rule 3).

Open at most one socket per client session (03 §5.12). A client that uses three servers has three sockets, one per server. A client signed in to two accounts on the same server has two sockets there, because those are two client sessions. If a second socket of the same session authenticates, the server keeps the new one and closes the old one with 4010 (see Close codes). A web client that can run in several tabs MUST share one socket across them, for example through a SharedWorker or a leader elected with the Web Locks API, so that tabs never replace each other (03 §5.12 item 4).

Opening the socket

The handshake is a plain RFC 6455 upgrade with no credentials. The token goes in the first message, session.hello, because browsers can't set headers on a WebSocket handshake and tokens never go in URLs (03 §3.2 rule 1, 03 §5.1 item 4).

GET /server/v1/events HTTP/1.1
Host: chat.sloppyvoice.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Protocol: sloppyv.v1

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: sloppyv.v1

The socket may also run over HTTP/2 (RFC 8441) or HTTP/3 (RFC 9220) where both ends support it (03 §2.3 item 1). The rules for the handshake (03 §5.1):

  1. The URL carries no query string and no fragment.
  2. Offer the subprotocol sloppyv.v1. A client that supports later major versions lists them first, in order of preference, for example sloppyv.v2, sloppyv.v1.
  3. If the handshake succeeds with no subprotocol, or with one you didn't offer, close at once with 1002 (4000 from a browser, 03 §5.2 item 6), because you can't know what the server will send.
  4. A server that supports none of your subprotocols refuses the handshake with HTTP 400 and a core.unsupported_version problem. A client that can read that response re-reads /meta and applies the version rules of 02 §7.4.
  5. Servers rate-limit handshakes per IP address (policy handshake, floor 10 per 60 s). When you offered a subprotocol the server supports, it SHOULD complete an over-limit handshake and refuse it in-band: error with core.rate_limited, session.closing with rate_limited and retryAfterMs, then close 4029. Otherwise it answers HTTP 429 with a core.rate_limited problem (03 §5.1 item 4, 03 §15.3).
  6. permessage-deflate is allowed only with both server_no_context_takeover and client_no_context_takeover. If the server's extension response lacks either parameter, close the connection. Per-message compression stops an attacker from learning one event's content through the compressed size of a later event they caused (03 §18.5). Non-browser clients SHOULD NOT compress session.hello or session.reauth, which carry tokens.
  7. The server doesn't use Origin for authorization, and the handshake response carries no CORS headers.

Every WebSocket message after the handshake is one JSON envelope sent as a text message (03 §5.2). A binary message is closed with 1003, invalid UTF-8 with 1007, and a message larger than maxEventBytes (default 1 MiB, floor 256 KiB) with 1009. A browser can close only with 1000 or 3000 to 4999, so where the spec says 1002, 1003, 1007 or 1009, a browser client closes with 4000 instead (03 §5.2 item 6).

WebSocket Ping and Pong frames may flow, but they don't count as the protocol heartbeat, because browser code can't see them. The heartbeat is session.ping (Heartbeats and timeouts).

The envelope

Every message in either direction is an Envelope (03 §6.1):

Member Server to client Client to server Meaning
v Required Required Envelope version, always 1 on sloppyv.v1.
t Required Required The type, <area>.<name>, or the reserved type error.
id Required Required UUIDv7 of this envelope. For a durable event it is fixed when the event is sequenced and is the same in every delivery and replay.
re Only on replies Only on session.pong The id of the message being answered.
ctx On every event; absent on control messages Absent The stream the event belongs to: a context reference, me or community.
seq On durable events only Absent The event's position in the stream ctx names.
ts Required Optional; ignored Server timestamp. For a durable event, when it was sequenced.
d Required Required The payload, defined by the owner of t. {} when there is nothing to carry.

Ignore envelope members you don't know (03 §2.4 item 6). The member is called ctx even when its value is me or community, which aren't context references. Device clocks are often minutes off, so estimate your clock offset to each server from its Date headers and envelope ts values, and use the corrected time in signed objects you build for that server (03 §2.3 item 4).

The envelope's shape tells you what kind of message it is: a durable event has ctx and seq, an ephemeral event has ctx and no seq, and a control message (session.* or error) has neither.

A durable event:

{
  "v": 1,
  "t": "message.created",
  "id": "01938f2e-7c1a-7b3e-9d1e-5f2a8c7d9e01",
  "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
  "seq": 4182,
  "ts": "2026-12-04T18:22:31.512Z",
  "d": {
    "mid": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
    "sender": { "addr": "alice@a.com", "name": "Alice", "did": "q2bS9xVg3m0yJpQe1vT0Aw" },
    "content": { "text": "Hello", "replyTo": null, "attachments": [] }
  }
}

The payload is abbreviated; Messaging and message.created define the full object. An ephemeral event and a control message follow. 03 uses typing.started only to illustrate an ephemeral event; the real typing events, their payload and the sessions they are sent to are defined in 11 (03 §6.1, Messaging).

{ "v": 1, "t": "typing.started", "id": "01a2424b-2914-72a4-bb1c-9f00aa55e7c3",
  "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566", "ts": "2026-12-04T18:22:31.700Z",
  "d": { "addr": "alice@a.com" } }
{ "v": 1, "t": "session.ping", "id": "01a2424b-9d88-7111-a222-333344445557",
  "ts": "2026-12-04T18:23:01.512Z", "d": {} }

If the server sends an envelope with v other than 1, drop it, close with 4000 and reconnect with backoff (03 §6.1). If the server sends a text message that isn't a JSON object or lacks a required envelope member, drop it, close with 4000 and reconnect with resume; resume recovers any durable event the bad message might have been (03 §5.2 item 3).

What a client may send

These are the only messages a client sends on the socket (03 §6.2):

Type Purpose Reply
session.hello Authenticate and subscribe session.ready or error
session.subscribe Add or change subscriptions session.subscribed
session.unsubscribe Remove subscriptions session.unsubscribed
session.state Foreground state None
session.reauth Extend the authentication deadline session.reauthed or error
session.ping Liveness check session.pong
session.pong Answer to the server's session.ping None

Anything else is answered with error (session.unsupported_message) and ignored. The server accepts at least 20 client messages per socket per 10 s; beyond its limit it answers core.rate_limited with retryAfterMs, and after 3 such errors within 60 s it MAY close with 4029. Your session.pong answers never count toward the limit (03 §7.6).

Errors on the socket

A WebSocket error is an envelope with t: "error" and a problem object in d, the same ProblemObject HTTP errors use. It has re when it answers one of your messages, and never ctx or seq (03 §6.3):

{
  "v": 1,
  "t": "error",
  "id": "01a2424b-9d88-7111-a222-333344445558",
  "re": "01a2424b-2270-7000-8000-000000000009",
  "ts": "2026-12-04T18:23:01.512Z",
  "d": {
    "type": "urn:sloppyv:error:core.rate_limited",
    "code": "core.rate_limited",
    "title": "Too many requests",
    "status": 429,
    "retryable": true,
    "retryAfterMs": 4000,
    "userAction": "wait",
    "data": { "policy": "socket" }
  }
}

An error that ends the connection is followed by session.closing and a close code (03 §5.10); the codes below say which session.* errors are fatal. Problems with one stream in a subscription request go in that stream's result, not in an error.

The session.* error codes occur only on the socket, all with status 400 and userAction none (03 §10.6):

Code When Fatal
session.hello_required Something other than session.hello arrived first Yes, close 4000
session.duplicate_hello A second session.hello on a ready socket No, ignored
session.unsupported_message A message type clients may not send No, ignored
session.subscription_limit Over maxSubscriptions; only inside a SubscriptionResult No
session.wrong_session session.reauth with another client session's token No, ignored

session.hello

Send session.hello as the first message, within 10 s of the handshake, or the server closes with 4008 hello_timeout (03 §5.3). It authenticates the socket and sets up every subscription in one round trip (03 §5.4):

Member Required Meaning
token Yes The client-session access token, or a bot token at the bot's home server. Never an S2S token. At most 4,096 characters.
client Yes Product and version, 1 to 128 printable ASCII characters, for example sloppyvoice-desktop/1.0.3. Diagnostics only.
protocol No The protocol version you implement, major.minor. Default "1.0".
features Yes The features you support, at most 64 entries. May be empty.
resume No Map from stream name to your position (an integer ≥ 0). Each entry asks for a full subscription that replays everything after that position. Position 0 asks for the stream from its start.
subscribe No Streams to subscribe at full from their current head, with no replay.
heads No Context references to subscribe at level heads.
foreground No Initial foreground state. Default false. A client with a visible user interface MUST send true when it is visible.
{
  "v": 1,
  "t": "session.hello",
  "id": "01a2424b-2270-7000-8000-000000000001",
  "d": {
    "token": "rs_4kJ7yQm2xV0bP9sLwT3e",
    "client": "sloppyvoice-desktop/1.0.3",
    "protocol": "1.0",
    "features": ["voice-dc/1", "video-dc/1", "sfu-rtp/1"],
    "resume": { "ch:01938a11-2b3c-7d4e-8f90-112233445566": 4182, "me": 77, "community": 301 },
    "subscribe": ["gdm:01a2424b-223e-75c3-8123-456789abcdef"],
    "heads": ["ch:01938a11-2b3c-7d4e-8f90-aabbccddeeff"],
    "foreground": true
  }
}

Rules for the three subscription lists (03 §5.4):

  • me is always subscribed at full, from its current head unless resume names it. me in subscribe or heads is ignored.
  • A stream named in more than one list counts only in the first, in the order resume, subscribe, heads.
  • community in heads is refused with core.invalid_request, because only context references may be subscribed at heads. Like every problem with one stream, the refusal goes in that stream's SubscriptionResult, not in an error (03 §6.3).
  • Every stream except me counts against maxSubscriptions (default 1,000, floor 250). Streams over the limit are refused one by one with session.subscription_limit; the hello as a whole still succeeds. The server fills the limit from resume, then subscribe, then heads. Which resume entries lose when resume alone is over the limit is unspecified, because a JSON object has no order, so stay within the limit.
  • If your hello would exceed maxEventBytes, put part of the subscriptions in the hello and send the rest in session.subscribe messages after session.ready (03 §16.2 rule 4).

foreground defaults to false so that a client that never reports its state never suppresses phone pushes; a duplicate notification is harmless, a missed one isn't (03 §5.4).

What can go wrong at hello

The server answers a failed hello with error, then session.closing, then a close code (03 §5.3):

Problem error code session.closing reason Close
Invalid payload: a required member missing or of the wrong type, more than 64 features, a malformed protocol core.invalid_request with data.errors protocol_error 4000
Bad, expired or revoked token core.unauthenticated or core.token_expired; for a revoked home-session or bot device, auth.session_revoked unauthenticated 4001
protocol below the server's minClient, if the server enforces it core.unsupported_version unsupported_version 4026
Envelope v other than 1 core.unsupported_version unsupported_version 4026
Any other message before hello session.hello_required protocol_error 4000
No hello within 10 s None hello_timeout 4008

session.ready

session.ready answers a successful hello, with re set to the hello's id. The server sends nothing but error and session.closing before it (03 §5.5).

{
  "v": 1,
  "t": "session.ready",
  "id": "01a2424b-2858-73e1-9d1e-5f2a8c7d9e01",
  "re": "01a2424b-2270-7000-8000-000000000001",
  "ts": "2026-12-04T18:22:31.512Z",
  "d": {
    "conn": "01a2424b-2914-72a4-bb1c-9f00aa55e7c2",
    "account": "bob@a.com",
    "did": "q2bS9xVg3m0yJpQe1vT0Aw",
    "server": "sloppyvoice.com",
    "protocol": "1.0",
    "features": ["voice-dc/1", "video-dc/1"],
    "pingIntervalMs": 30000,
    "idleTimeoutMs": 75000,
    "authExpiresAt": "2026-12-04T18:34:02.000Z",
    "subscriptions": [
      { "stream": "me", "level": "full", "status": "ok", "headSeq": 79, "replayThrough": 79 },
      { "stream": "ch:01938a11-2b3c-7d4e-8f90-112233445566", "level": "full", "status": "ok", "headSeq": 4190, "replayThrough": 4190 },
      { "stream": "community", "level": "full", "status": "ok", "headSeq": 9120 },
      { "stream": "gdm:01a2424b-223e-75c3-8123-456789abcdef", "level": "full", "status": "refused",
        "problem": { "type": "urn:sloppyv:error:core.not_found", "code": "core.not_found", "title": "Not found",
                     "status": 404, "retryable": false, "userAction": "none" } },
      { "stream": "ch:01938a11-2b3c-7d4e-8f90-aabbccddeeff", "level": "heads", "status": "ok", "headSeq": 88 }
    ]
  }
}

What to take from it:

  • conn identifies the connection for diagnostics and support.
  • account, did and server confirm whom the socket belongs to.
  • protocol is the highest minor version of your major version that the server implements. Don't rely on behaviour from a higher minor version (03 §12.1).
  • features is the effective feature set, the intersection of the server's metadata features and yours. Neither side uses a feature outside it (03 §12.2).
  • pingIntervalMs is 30000 and idleTimeoutMs is 75000 in this version.
  • authExpiresAt is the socket's authentication deadline, or null for a token that doesn't expire (Reauthentication).
  • subscriptions holds one SubscriptionResult per stream you named, plus me. Each has stream, level and status (ok or refused); headSeq when ok, which is 0 if the stream has no events yet; replayThrough when replay follows, equal to headSeq; and problem when refused (03 §5.6).

After session.ready, for each stream, the server sends session.resync_required if the stream needs it, then the replayed events, then live events. Different streams interleave (03 §5.5). In the example, the client's community position 301 is too far behind headSeq 9120, so there is no replayThrough for it and a session.resync_required follows.

Streams

A stream is a sequence of durable events with its own seq counter on one server (03 §7.1). There are three kinds:

Stream Name in ctx What it carries
Context stream The context reference: ch:<UUIDv7>, dm:<22 base64url characters> or gdm:<UUIDv7> Timeline items, the context's membership and settings, MLS handshakes
Account stream me One per account per server: read state and presence, metadata hints; at the home server also the DM index, message requests, account, device and identity changes; at a remote or hosting server also the account's own membership, moderation, invites, reports and role events there, identity refresh hints for DMs it hosts, notify.triggered and remote-session endings
Community stream community One per server: community settings, the channel list, roles and community membership

The exact assignment of each event type to a stream is in its owner's registration, indexed at 03 §11.3. Addresses and 03 §8.3 give the grammar of context references. me and community are stream names only. They never appear in a {ctx} path parameter; the me in paths such as /v1/me/devices is a path segment that happens to be spelled the same (03 §2.6 item 3).

A server keeps an account's me stream, with its seq counter, for as long as it holds any record about the account, independently of client sessions. A remote session that ends and a new one created hours later continue the same me stream, and durable me events are sequenced while you are offline. A me stream never restarts at 1 while it exists; if a server deletes one and later recreates it, it answers a resume of it with session.resync_required (server_reset) (03 §7.1).

There is no ordering between streams. Don't assume an event in one stream happened before or after an event in another because of its seq or ts. Within a stream, order is seq only, never an ID or a timestamp (03 §7.1, 03 §9 item 7).

Subscription levels

Each subscribed stream has one of two levels (03 §5.6):

  • full: the socket receives every durable and ephemeral event of the stream.
  • heads: the socket receives only session.heads updates for the stream, enough to show an unread indicator. Only context references may be subscribed at heads.

Subscribe at full only to the contexts the user is viewing, or has open in a call, and use heads for the rest. That keeps traffic down and tells the server less about what the user reads (03 §18.11). Targeted events, such as call.ringing or mls.commit_needed, reach a connected session whatever it subscribes to, so heads never costs you a ring or a prompt (03 §7.2 E5). An owner that picks one session for a duty, such as the designated MLS committer, may still prefer sessions with a full subscription to the stream (03 §1.3, 03 §18.11).

Warning

From the join request until your participation ends, keep a full subscription to the call's context on its hosting server, renew it after every reconnect, and never move it to heads, even after a slow-consumer close. Untargeted call events go only to full subscribers (03 §7.6, 15 §3.1, Calls).

session.heads

session.heads is a control message: no seq, no replay, and the server merges pending updates under backpressure (03 §5.7). Its d.heads maps each context reference to a Head:

{
  "v": 1,
  "t": "session.heads",
  "id": "01a2424b-9d88-7111-a222-333344445556",
  "ts": "2026-12-04T18:23:01.512Z",
  "d": { "heads": { "ch:01938a11-2b3c-7d4e-8f90-aabbccddeeff": { "headSeq": 90, "lastItemSeq": 90, "lastItemAt": "2026-12-04T18:23:01.104Z" } } }
}

headSeq is the stream's latest seq. lastItemSeq is the seq of the latest timeline item that this account would receive with its full payload, and lastItemAt its ts; both are absent if there is none. Compare lastItemSeq with the user's read position (Messaging) to decide whether to show an unread indicator. Withheld events don't count, so a member never sees an unread indicator for something it can't read. Mention counts aren't here; they come through Notifications.

The server sends one session.heads covering every new heads subscription right after session.ready or session.subscribed, then an update when a stream's lastItemSeq changes, at most one per socket every 2 s, listing only the streams that changed.

Changing subscriptions

After session.ready, change subscriptions with session.subscribe, which takes the same resume, subscribe and heads members as the hello. At least one must be non-empty (03 §5.6):

{ "v": 1, "t": "session.subscribe", "id": "01a2424b-3a10-7c00-8a00-000000000002",
  "d": { "subscribe": ["ch:01938a11-2b3c-7d4e-8f90-aabbccddeeff"] } }
  • A resume entry for a stream you already have restarts it from that position, with replay. This is how you repair a gap (Processing events).
  • A subscribe entry for a stream already at full changes nothing and returns ok with the current headSeq.
  • Naming a heads stream in resume or subscribe upgrades it to full. Naming a full stream in heads downgrades it.

The server answers with session.subscribed, re set, whose d.subscriptions has one SubscriptionResult per stream named, in any order. Resyncs and replays for the new subscriptions follow, as after session.ready. An invalid session.subscribe or session.unsubscribe (no non-empty member, or a member of the wrong type) gets a non-fatal error core.invalid_request with data.errors and re set, and is otherwise ignored.

session.unsubscribe takes {"streams": [...]} with at least one entry. Streams you don't have, and me, are ignored. The server answers session.unsubscribed listing the streams it removed, and sends no event of those streams after that message.

Refusals and ended subscriptions

A SubscriptionResult with status: "refused" carries the problem the equivalent HTTP read would return (03 §5.6). Treat an unknown status as refused. Common ones:

  • core.not_found: the context doesn't exist, or you aren't allowed to know it exists. The server never answers core.forbidden for a hidden context, so subscriptions don't reveal private contexts.
  • security.account_required or security.device_not_enrolled: the context is end-to-end encrypted and the account or device isn't set up for it. These lead to the G1 and G2 screens (Secure accounts).
  • core.invalid_request: a malformed stream name.
  • session.subscription_limit: over maxSubscriptions.

The server re-checks authorization whenever your right to read a stream may have changed: a kick, a ban, leaving, a permission change, deletion of the context, the context becoming secure while the account is insecure, device revocation or the end of the session. When the right is lost, it stops delivering the stream and sends session.subscription_ended. The owner may make the durable event that records the change, such as your own removal, the last event on the stream (03 §5.6). Its problem says why, for example core.forbidden (permission removed), core.gone (context deleted) or security.account_required (the context became secure and the account is insecure):

{
  "v": 1,
  "t": "session.subscription_ended",
  "id": "01a2424b-9d88-7111-a222-333344445555",
  "ts": "2026-12-04T18:23:01.512Z",
  "d": {
    "stream": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
    "problem": {
      "type": "urn:sloppyv:error:security.account_required",
      "code": "security.account_required",
      "title": "This channel is end-to-end encrypted",
      "status": 403,
      "retryable": false,
      "userAction": "enable_encryption",
      "data": { "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566" }
    }
  }
}

Remove the stream from your subscription set and from your next resume. Show the problem's userAction if the user is looking at that context. You may subscribe again later, for example after turning on encryption.

Durable and ephemeral events

Every event type has one class, declared by its owner and never changed within protocol version 1 (03 §7.2, 03 §11.2).

Durable events are for anything you cache as persistent state: timeline items, edits, deletions, reactions, membership, roles, settings, MLS handshakes and the DM index. The server guarantees (03 §7.2 D1 to D8):

  • Each durable event belongs to exactly one stream. The first has seq 1, and each next one has the previous seq plus 1. A seq is never skipped, reused or rolled back.
  • The seq is assigned in the same atomic step as the change it reports, so you never see an event for a change that didn't commit.
  • Every full subscriber receives every seq from its subscription point on, in order. Nobody gets a gap because they may see less: a subscriber who may see nothing of an event still receives its envelope.
  • id and ts are the same in every delivery and replay. On replay, an event whose content has since been deleted, moderated or expired may arrive in its owner's tombstone form, with the same t, seq, id and ts.
  • Applying a durable event to state that already reflects it changes nothing. That lets you apply events over a fresh HTTP snapshot without working out where the snapshot ends.

When you may see nothing of an event and the owner defines no reduced payload, you get the withheld form: the same t, ctx, seq, id and ts, with d set to {"withheld": true} (the WithheldPayload). The owner may add members that identify the affected object. Advance your position past it and do nothing else: it never appears in the timeline and doesn't count toward lastItemSeq (03 §7.2 D4a). For example, on replay 11 §8.3 delivers a message.created whose root message has since been purged or expired like this:

{ "v": 1, "t": "message.created", "id": "01a2424b-4c20-7e01-8b11-2233445566aa",
  "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566", "seq": 4191,
  "ts": "2026-12-04T18:24:10.020Z", "d": { "withheld": true } }

Ephemeral events are transient signals: typing, presence, lease ticks, call state, prompts to act now such as mls.commit_needed, and pairing relay messages (03 §7.2 E1 to E5):

  • They carry no seq, are never replayed and arrive at most once.
  • An untargeted ephemeral event goes only to sockets with a full subscription to its stream.
  • The server may coalesce or drop them under backpressure.
  • An owner may target one at particular sessions or devices, for example call.ringing to every session of the called account or mls.commit_needed to the designated committer. A targeted event reaches every ready socket of each targeted session on that server, whatever the socket's subscription level, and its ctx still names the stream it concerns. It is lost for a targeted session that isn't connected.

No owner makes an ephemeral event the only way to learn state you need after reconnecting. Each provides an HTTP read or a durable event instead (E4). For example, a socket that gains a full subscription to a call's context, including by the resume of every reconnect, receives a targeted call.state with the current call or null, after the stream's SubscriptionResult, and again after any session.resync_required for that stream. Call events are never replayed, so this is how a client catches up on everything it missed while disconnected (15 §3.1).

Control messages are the session.* messages and error. They carry no seq, have no ctx, and are never replayed.

Processing events

Keep a position P for each stream you follow at full: the seq of the last durable event you applied. Key positions by server canonical domain, account and stream (03 §7.3).

  1. On a fresh subscription (from subscribe, no replay), P is the result's headSeq.
  2. For each durable event e of stream s:
    • e.seq ≤ P: a duplicate. Ignore it.
    • e.seq = P + 1: apply it and set P = e.seq. An event of an unknown type is applied by ignoring its payload, and still advances P.
    • e.seq > P + 1: a gap, which an honest server never causes. Don't apply it. Drop further events of s until the repair completes, and send session.subscribe with resume: {s: P}. The repair completes when the SubscriptionResult for s arrives in session.subscribed, or a session.resync_required for s arrives.
    • If gaps happen 3 times on the same stream within 5 minutes, record a diagnostic and resync the stream yourself: mark it as resyncing and queue its events, send session.subscribe with subscribe: [s] (which returns the current headSeq without replay), and run the resync procedure with that headSeq.
  3. Ephemeral events never change P. Ignore ephemeral types you don't know.
  4. Store P atomically with the state you derived from events up to P. If you can't, store a value no greater than what you have durably applied. If you lost the cached state but kept P, don't resume from P: subscribe fresh and refetch over HTTP.
  5. Discard positions when the user signs out of that account, when the account is deleted, and when a resync replaces them.
  6. HTTP responses never advance P. A seq or headSeq you see in an HTTP response or a timeline page is not a reason to jump; jumping would silently skip the events in between (03 §2.8).

Note

A state change you make over HTTP, such as posting a message, also arrives as an event. The HTTP response and the event can come in either order. Reconcile them by the object's ID (for messages, the mid), not by arrival order (03 §2.8).

The worked trace from 03 §17.8, on stream ch:01938a11-2b3c-7d4e-8f90-112233445566 starting at P = 4182:

Received Action P after
Durable message.created, seq 4183 Apply 4183
Durable message.created, seq 4183 again Duplicate; ignore 4183
Ephemeral call.tick Apply; P unchanged 4183
Durable x-acme.thing, seq 4184 (unknown type) Ignore the payload, advance 4184
Durable message.created, seq 4186 Gap: drop it and later events of the stream; send session.subscribe with resume: {"ch:01938a11-2b3c-7d4e-8f90-112233445566": 4184} 4184
session.subscribed (replayThrough: 4186), then seq 4185 and 4186 Apply both 4186

Keep reading from the socket while you process events, queuing them internally. The server measures how fast you drain the socket, and a client that stops reading looks like a slow consumer (03 §7.6).

Resume and replay

On every connection after the first, put your positions in the hello's resume. For each entry, the server compares your position P with the stream's head H (03 §7.4):

Condition Result
Not authorized refused with the problem
P = H ok, no replay; live events follow from H + 1
P < H, within maxReplayEvents, every event retained, and read access never lapsed after P ok with replayThrough: H; events P + 1 to H are replayed in order, then live events follow
P < H, too many events ok, then session.resync_required with gap_too_large
P < H, events no longer retained ok, then session.resync_required with expired
P < H, read access lapsed and was regained after P ok, then session.resync_required with access_changed
P > H ok, then session.resync_required with ahead

A server MUST be able to replay any gap of up to maxReplayEvents events (default 5,000, floor 1,000) whose oldest event was sequenced less than 24 h ago, and may replay more. Replayed events of a stream come in seq order before any live event of that stream; streams interleave freely.

A server never replays events sequenced while the account had no read access to the stream, because that could reveal messages sent while the person wasn't a member. Where it can't tell, it sends access_changed and you refetch through HTTP, where the owners' visibility rules apply (03 §18.9).

The server keeps no acknowledgement state for your session. Your resume positions are the only record of what you have seen, which is why P must be stored with the state it describes.

Example decisions on a server with maxReplayEvents 5,000 and 7 days of retention (03 §17.7):

Head H Your P Outcome
4190 4190 ok, no replay; live from 4191
4190 4182 ok, replayThrough: 4190; replays 4183 to 4190
9120 301 ok, then resync gap_too_large, headSeq: 9120
4190 5000 ok, then resync ahead

session.resync_required

The server sends session.resync_required when it can't bring a stream up to date by replay. It can arrive at any time, not only after subscribing, for example after the server dropped a slow socket's queue (03 §7.5).

{
  "v": 1,
  "t": "session.resync_required",
  "id": "01a2424b-2914-72a4-bb1c-9f00aa55e7c4",
  "ts": "2026-12-04T18:22:31.700Z",
  "d": { "stream": "community", "reason": "gap_too_large", "headSeq": 9120 }
}

reason is one of gap_too_large, expired, ahead, access_changed, buffer_overflow or server_reset; treat an unknown value like gap_too_large. headSeq is the stream's head when the message was sent, and live events continue from headSeq + 1.

The procedure (03 §7.5):

  1. Mark the stream as resyncing. Queue its live events (seq > headSeq) in order without applying them.
  2. Refetch what you cache for the stream over HTTP: for a context, its latest timeline page, membership and settings; for community, the community, channel list and roles; for me, the account, devices and DM index.
  3. Process the queued events in seq order. You may skip queued events whose seq is not greater than the lowest headSeq among the HTTP responses you fetched in step 2, because the snapshot already has them. If no response reported a headSeq, apply them all; re-applying is harmless (D8).
  4. Set P to the greater of the resync headSeq and the highest queued seq you processed or skipped, then clear the mark. The headSeq of an HTTP response never sets P.

A resync replaces only state derived from the stream's events: the timeline cache, membership, settings and the like. With reason ahead or server_reset, discard that derived state before step 2, because the server no longer has, or has renumbered, events you saw, and record a diagnostic.

Secure contexts only

A resync of any reason MUST NOT by itself make you discard MLS group state, history keys (K_hist), identity pins or AccountVault data. In a secure context, keep processing MLS from your current epoch by catching up from the hosting server's handshake log; use a resync external commit only when document 13's own conditions for one hold, never merely because of this message. Report an ahead or server_reset resync to the hosting server through POST /v1/diagnostics with kind transport and data {"event": "resync", "reason": <reason>, "stream": <stream>}, because an honest server never loses events a client has seen. The user's diagnostics consent setting governs that upload as it does every other (03 §7.5, 15 §14.4, MLS and sealed messages).

A resync is silent. In a timeline, show the latest page at once and load older messages when the user scrolls back. Never show a prompt, and show a "Loading…" placeholder only where content is actually missing (03 §7.5).

Heartbeats and timeouts

Both sides watch for a dead connection (03 §5.9):

  1. The server sends session.ping (d is {}) every 30 s on every ready socket, whatever other traffic flows, with up to 1 s of jitter.
  2. Answer each session.ping at once with session.pong, re set to the ping's id, d {}.
  3. The server closes a socket from which it has received nothing for 75 s, with 4008 idle_timeout. Answering pings is enough to stay alive.
  4. If you have received nothing for 75 s, the connection is dead: close it with 4008 and reconnect at once.
  5. You may send your own session.ping at any time, for example after the device wakes or the network changes, but not more than once per 5 s. If no session.pong arrives within 10 s, you SHOULD treat the connection as dead.
  6. If session.ready doesn't arrive within 15 s of your hello, close with 4008 and back off (03 §5.3).
{ "v": 1, "t": "session.pong", "id": "01a2424b-9d90-7c00-8f00-000000000003",
  "re": "01a2424b-9d88-7111-a222-333344445557", "d": {} }

30 s keeps NAT and proxy mappings alive, and 75 s is two missed pings plus margin, so one delayed ping doesn't drop a healthy connection.

During a call the timing is tighter. While you participate in a call hosted on this server, send session.ping whenever no call.tick has arrived on the socket for 3 s, at most once per 3 s, and treat a missing session.pong after 3 s as a dead connection. The WebSocket copy of the lease tick is the hosting server's own channel to you: it reaches you even when your relay connection is down, and it lets you recover from a relay that withholds or wedges ticks. That is why a half-open socket mustn't go unnoticed for 75 s (03 §5.9 item 6, 15 §4.4, Calls).

Reauthentication

A socket is authenticated only until its authentication deadline: the expiry of the most recent token accepted on it, in the hello or in session.reauth. session.ready reports it as authExpiresAt (03 §5.13). When the deadline has passed by 60 s without an accepted session.reauth, the server sends error (core.token_expired), session.closing (unauthenticated) and closes with 4001.

This bounds what a stolen access token is worth: a thief has no refresh token, so their socket lasts at most the token's own lifetime plus 60 s (03 §18.1). Your client keeps its socket open by extending the deadline in place:

  • After every silent refresh (home session, Accounts) or remote-session renewal (Federation), send session.reauth with the new token on that server's socket.
  • When the deadline is less than 120 s away, refresh or renew even if you made no HTTP request meanwhile, then send session.reauth.
{ "v": 1, "t": "session.reauth", "id": "01a2425c-1d00-7a10-8b20-3c4d5e6f7a80",
  "d": { "token": "sva_9pQm2xV0bP9sLwT3eRkW" } }
{ "v": 1, "t": "session.reauthed", "id": "01a2425c-1d40-7c11-9d22-4e5f60718293",
  "re": "01a2425c-1d00-7a10-8b20-3c4d5e6f7a80", "ts": "2026-12-04T18:32:40.115Z",
  "d": { "authExpiresAt": "2026-12-04T18:47:40.000Z" } }

If the token is invalid or expired, the server answers error with core.unauthenticated, core.token_expired or, for a revoked device, auth.session_revoked. A valid token of a different client session gets session.wrong_session. In both cases the server keeps the current deadline and doesn't close the socket. session.reauth counts toward the socket rate limit.

Ending the client session (sign-out, revocation, account deletion, device revocation) closes the socket at once with 4004, whatever the deadline (03 §5.13 item 4). The home server closes the sockets of a revoked session at once; a remote server MUST close them within the 60 s that federation allows for revocation fan-out (03 §18.1).

session.state and foreground

session.state tells the server whether the user can see the app. Its only member is foreground (03 §5.8):

{ "v": 1, "t": "session.state", "id": "01a2424b-a001-7d00-8c00-000000000004",
  "d": { "foreground": false } }
  • Send foreground: false when the app goes to the background, all its windows are hidden or minimized, or its browser tab is hidden. You may send it at any time, for example just before the operating system suspends the app, and the server applies it at once.
  • Send foreground: true when the app becomes visible again, at most once per 5 s. A server may ignore a faster change to true.
  • There is no reply. A closed socket is never a foreground session.

The server uses this to decide whether to push. A hosting server sends message notifications only to recipients without an attentive session on it: a socket in state ready, whose last session.state (or hello) declared foreground: true, and whose presence idle flag is false (19 §4.3, Notifications). An app that opens its socket while the user can't see it, for example a mobile app woken by a push for a call, MUST send foreground: false in the hello and MUST NOT send true until the user can see it (19 §4.3). A desktop app that stays connected while minimized must still get pushes, which is why being connected isn't enough. Report false promptly: a stale "foreground" loses notifications, while a stale "background" only duplicates one.

Close codes

Before closing a socket on purpose, the server SHOULD send session.closing (a SessionClosing) and close within 1 s (03 §5.10):

{ "v": 1, "t": "session.closing", "id": "01a2424b-b100-7e00-8d00-000000000005",
  "ts": "2026-12-04T18:40:00.000Z",
  "d": { "reason": "server_shutdown", "reconnect": true, "retryAfterMs": 12000 } }

reason names why, reconnect says whether to reconnect automatically, retryAfterMs gives a minimum delay, and problem carries a problem object for session_ended, unauthenticated, unsupported_version and rate_limited.

Precedence. For a close code in the table below, the table decides what you do, and reconnect and retryAfterMs only refine it, for example by setting the delay. For an unknown reason or close code, follow reconnect and retryAfterMs, and without them reconnect with backoff. Ignore the close code and session.closing of a socket you have already replaced or abandoned, for example after opening a new socket on a network change.

Code reason Meaning What you do
1000 — Normal closure by the client Nothing.
1001 — Going away Reconnect with backoff if still needed.
1002, 1003, 1007 — Protocol violation, binary message, invalid UTF-8 Reconnect with backoff; record a diagnostic.
1009 too_large A message exceeded maxEventBytes Reconnect with backoff; record a diagnostic.
1011 — Internal server error Reconnect with backoff.
1012 server_shutdown Restart, or the connection is being moved Reconnect after retryAfterMs, or after a random 1 to 10 s if none was given. In a call, cap the delay at 2 s.
1013 — Try again later Reconnect after retryAfterMs, or with backoff of at least 5 s.
4000 protocol_error Invalid envelope or hello, or a message before hello Reconnect with backoff; record a diagnostic.
4001 unauthenticated Token invalid, expired or revoked at hello, or the deadline passed without session.reauth Recover the token, then reconnect: at once the first time after a successful recovery, otherwise with backoff.
4004 session_ended The client session ended Don't reuse the token. Follow the problem's userAction; for a remote session, create a new one silently first.
4008 hello_timeout, idle_timeout No hello within 10 s, or nothing for 75 s Reconnect at once, then with backoff.
4010 replaced A newer socket of the same session took over Reconnect silently once, only if you know no other instance of the app is running.
4011 slow_consumer You couldn't keep up Reconnect with backoff of at least 1 s; move streams the user isn't viewing to heads, never a call's context.
4026 unsupported_version Protocol below minClient, or an unknown envelope v Stop; show "update required".
4029 rate_limited Too many messages or connections Reconnect after retryAfterMs, or 60 s if none was given.

Notes on the codes that need more than a timer:

  • 4001. Recover as 03 §3.3 says: at the home server, refresh the access token silently and retry; if the refresh fails, show the sign-in screen. At a remote server, get a fresh HomeAssertion and create a new remote session silently; only a core.unauthenticated from the home server itself leads to a sign-in screen. A remote server can never push the user into signing in: its sign_in only triggers silent recreation of the remote session, at most once per 60 s per server, and if that keeps failing while the home server is fine, treat that server as unavailable (03 §10.2). A bot can't refresh; it stops and reports.
  • 4004. The session is gone, so the token is useless even when the problem says core.token_expired. For a remote session the problem is often federation.session_ended, sometimes preceded by the event federation.session_ended on me; that event is informational (03 §5.10).
  • 4010. Reconnect once only if you hold a local single-instance lock: on the web the Web Locks lock or SharedWorker leadership, on desktop and mobile a single-instance process lock. If you can't tell, or you are replaced again within 60 s of that reconnect, don't reconnect automatically. Record a diagnostic and, if the app still needs the socket, show a quiet notice such as "Sloppy Voice is open in another window" with a button that reconnects (03 §5.12). The single silent reconnect means a socket opened with a stolen token can't keep the real app disconnected, while two real copies of the app still stop fighting after one round.
  • 4026. Show "update required" for this server only. Other servers keep working (03 §12.4).

A client itself closes only with 1000, 1001 or 4008, or with the protocol-violation codes 1002, 1003, 1007, 1009 and 4000 (4000 for all of them in a browser). Any close reason text is the reason value and has no other meaning (03 §5.10).

Reconnecting

Reconnect with full-jitter exponential backoff (03 §5.11):

  1. Retry n, starting at n = 0, waits a uniformly random delay in [0, min(30 s, 1 s × 2^n)], but never less than the minimum the close code or retryAfterMs sets. The upper bounds for n = 0 to 6 are 1, 2, 4, 8, 16, 30 and 30 s (03 §17.9).
  2. Reset n to 0 only after a socket has stayed in ready for 60 s. Don't reset it at session.ready, so that a server that accepts and then closes at once can't put you in a tight loop.
  3. When the operating system reports that the network came back, or the app returns to the foreground, reconnect at once (as n = 0), at most once per 5 s.
  4. Every reconnect's hello lists in resume your position for every stream you had at full, and in heads your heads streams. That restores the whole subscription set in one round trip.
// Delay before reconnect attempt n (0-based), in ms.
function reconnectDelay(n: number, minimumMs = 0): number {
  const bound = Math.min(30_000, 1_000 * 2 ** n);
  return Math.max(minimumMs, Math.random() * bound);
}

When a server restarts, it spreads retryAfterMs uniformly over 0 to 30 s across its sockets, and gives sockets in a call at most 2 s (03 §5.10).

Reconnecting is silent. You may show a small "Reconnecting…" status line, but only after 5 s without a ready socket, and never a dialog or prompt. Messages the user sends meanwhile wait in the outbox, which uses HTTP and doesn't depend on the socket (Messaging). This never delays the talk indicator: whenever the client can't transmit while push-to-talk is held, for any reason including a lost socket, the indicator says so at once (03 §5.11 item 5, Client requirements).

Backpressure

The server keeps one outbound queue per socket, limited to the larger of 4 MiB and 4 × maxEventBytes, with a 30 s age limit on the oldest queued durable event (03 §7.6). When a queue passes its limit, the server first coalesces ephemeral events (the newest call.tick per call, the newest typing event per context and person, the newest presence event per account, merged session.heads), then drops the remaining queued ephemeral events. If that isn't enough, it either closes with 4011 slow_consumer or drops one or more streams' queued durable events and sends session.resync_required with buffer_overflow. It never drops a durable event any other way.

On your side that means three things:

  • Keep reading the socket while you process, so the server sees your real drain rate.
  • After 4011, reconnect with at least 1 s of backoff and move streams the user isn't viewing to heads.
  • Never move a call's context to heads while the call lasts.

Client state machine

Run one of these per server and account (03 §5.3):

State Event Action Next state
idle The app needs this server (a context, the community or the account is in use) Open the socket connecting
connecting Handshake succeeds with sloppyv.v1 Send session.hello with resume positions awaiting_ready
connecting Network failure, 429, 5xx, or a failure whose status you can't read Schedule a retry. After 3 consecutive failures, re-read /meta and apply versions and minClient backoff, or stopped with "update required"
connecting HTTP 400 core.unsupported_version (clients that can read it) Re-read /meta and apply 02 §7.4 step 5: "update required" only if every version the server lists is newer than yours; otherwise the server is too old (discovery.version_unsupported) stopped
awaiting_ready session.ready Record subscription results; process the events that follow ready
awaiting_ready No session.ready within 15 s Close with 4008 backoff
awaiting_ready or ready Close 4001 Recover the token. Reconnect at once the first time after a successful recovery, otherwise with backoff. If recovery fails, follow 03 §3.3 (at the home server, show sign-in) connecting, backoff or stopped
ready Nothing received for 75 s, or the in-call check fails Close with 4008; reconnect at once connecting
ready A token for this session was refreshed or renewed, or the deadline is less than 120 s away Refresh or renew if needed; send session.reauth ready
ready Socket closed Act on the close code backoff, connecting or stopped
backoff Timer fires, the network comes back, or the app returns to the foreground Open the socket connecting
any The app no longer needs this server, or the user signs out Close with 1000 idle

Alongside it, each stream you follow at full is in one of three states of its own: applying events normally, repairing a gap (waiting for session.subscribed), or resyncing (queuing events while you refetch over HTTP).

A complete connection

The trace from 03 §17.10, with ch:…5566 a channel the user is viewing, gdm:…cdef a group DM the account can't read, and ch:…eeff a channel followed only for its unread indicator:

C: [WebSocket handshake to wss://chat.sloppyvoice.com/server/v1/events, Sec-WebSocket-Protocol: sloppyv.v1]
S: [101 Switching Protocols, Sec-WebSocket-Protocol: sloppyv.v1]
C: session.hello      resume {ch:…5566: 4182, me: 77, community: 301}, subscribe [gdm:…cdef], heads [ch:…eeff]
S: session.ready      subscriptions: me ok (replayThrough 79), ch:…5566 ok (replayThrough 4190),
                      community ok, gdm:…cdef refused (core.not_found), ch:…eeff heads ok
S: session.resync_required   {stream: community, reason: gap_too_large, headSeq: 9120}
S: session.heads      {ch:…eeff: {headSeq: 88, lastItemSeq: 88}}
S: [me 78, me 79, ch:…5566 4183 … 4190, interleaved; each stream in order]
C: [GET /v1/community, channels and roles; applies community events > 9120 queued meanwhile]
S: session.ping
C: session.pong (re = ping id)
C: session.state      {foreground: false}            (the user minimized the window)
C: session.reauth     {token: <fresh access token>}  (after a silent refresh, before authExpiresAt)
S: session.reauthed   {authExpiresAt: …}             (re = reauth id)
S: session.subscription_ended  {stream: ch:…5566, problem: security.account_required}
                                                     (the channel became secure; the account is insecure)
S: session.closing    {reason: server_shutdown, reconnect: true, retryAfterMs: 12000}
S: [close 1012]
C: [waits 12 s, reconnects with resume positions for me, community and the remaining streams]

The reference entry for GET /v1/events summarises the endpoint. For how events fit with the HTTP side of the protocol, see HTTP API; for what each owner puts on the streams, see Messaging, Communities, Direct messages and Calls.