Skip to content
Toolkit

ADR-0107: Presence is a property of the connection, not a thing a client reports

Status: Accepted · Date: 2026-08-30 · Track: 006 phase 02

Context

Presence is the first surface in this product where more than one person is visible to each other. The usual shape is a client that announces itself: POST /presence/heartbeat every N seconds, POST /presence/leave on beforeunload. That shape has two failure modes that are not edges — a client that stops beating without leaving (a killed tab, a closed laptop, a dropped network) and a client that lies about who it is — and it needs a store that outlives both.

Meanwhile this tree already has something that knows exactly when a member arrives, keeps proving they are still there, and ends: the SSE stream. It has had it since 003.

Decision

1. Presence is derived from the SSE connection. RealtimeHandler.Stream touches the store when the stream opens, again on every heartbeat — the same beat that already keeps proxies from reaping the connection — and drops the entry when the stream ends. There is no presence endpoint a client can call to say it is here, so there is no way to be present without being connected, and no heartbeat for a client to forget.

2. The unit of accounting is a connection, not a member. Two tabs are two entries collapsed to one member on read. Keying by member instead would mean the first tab to close reports its owner as gone while they are still working in the other one.

3. Nothing is written to the database. Presence is wrong the moment a process dies, and a row that outlives the connection it describes is worse than no row: it shows a member who left as present until something remembers to clean up. So it lives in Redis when configured and in-process otherwise — exactly as the bus does — and every entry carries a TTL the connection must keep refreshing. A member disappears because their connection stopped saying otherwise, not because anything remembered to delete them. The TTL (75s) outlives the 25s heartbeat by enough that one missed beat does not evict a live connection.

4. The store key is derived from the canonical channel key, not composed a second time: presence: + ChannelWorkspace(id). A store keyed differently from the channel it publishes on is ADR-0106's tenant-boundary bug one namespace over.

5. The event carries no member list. presence.changed says the roster changed; the consumer refetches GET /api/v1/realtime/presence. A payload here would be a second place deciding what presence discloses — the shape ADR-0105 refused for cards and ADR-0083 for the public payload. The endpoint answers from the intersection of the store and the roster, so a member removed from the workspace while connected cannot appear, and presence never discloses anything about a member the caller could not already read from the members list.

6. The workspace comes from the request context, never a parameter. The middleware has already proved this caller is a member of their active workspace; a workspace_id in the query string would be a way to ask who is in a workspace you are not in.

7. The client holds one stream for all consumers. subscribeRealtime(type, handler) multiplexes over a single connection opened by the first subscriber and closed by the last. This is not only frugality: now that the server derives presence from live connections, a second stream per tab would report one member as present twice and leave a stale entry behind whichever stream closed last. The fan-out is a correctness requirement of decision 1.

Consequences

Presence cannot drift from connectivity, because it is connectivity. The cases that break the client-reports shape — the killed tab, the lost network, the client that never sends leave — are the ordinary path here: the entry expires, and the next reader sees the truth.

What it cannot express is presence without a stream. A member reading a page with the stream disconnected is not present, and that is the honest answer rather than a bug.

It also means presence is exactly as available as the SSE gateway. The gateway is best-effort by design and everything above is proved degraded without Redis (evidence/phase-02-running-stack-2026-08-30.md), so the failure mode is an empty or stale-by-one-TTL roster, never a wrong one.

Whether presence is plan-gated stays charter Blocker 4, unanswered here. The recommendation on file is that it is not: it has no separable write path, and billing a workspace for knowing who is in it is not a capability.

Source: docs/decisions/0107-presence-is-a-property-of-the-connection-not-a-thing-a-client-reports.md

Library