Reeve Docs

Docs / Reference

Realtime hubs

The backend exposes five SignalR hubs:

Hub Path Carries
DeviceUpdatesHub /hubs/devices Device state, availability, command status, logical-device lifecycle
WorkflowExecutionHub /hubs/workflows Per-workflow node start and finish events for the editor's live replay
WorkflowDebugHub /hubs/workflow-debug Step-through debugger state and snapshots
AdminUpdatesHub /hubs/admin Workload-status updates (integrations.manage), recovery updates (home.manage) and AlertsChanged (the view permission of the alert's kind)
WorkloadLogStreamHub /hubs/workload-logs Live log lines of a workload instance (integrations.manage); the hub polls the provider every 2 seconds and sends only lines that extend what was already sent

The admin hub has no single admin group. A connection joins one perm:{code} group for each realtime permission it holds (integrations.manage, home.manage and the view permission of every alert kind), so a message reaches exactly the holders of the permission that guards the same data over REST. AlertsChanged for an alert whose kind is filtered by a device, automation or workflow goes to per-user alerts_user:{id} groups instead, which a connection joins while it holds the view permission of a device, automation or workflow alert kind, because who may see that alert depends on the subject and not on a permission code alone. A scene alert goes the same way to alerts_user_scenes:{id}, joined while the connection holds scenes.manage, so a token without that permission keeps its device and automation pushes.

The device hub has no per-device delivery and carries its owner's in-app notifications, so it admits a personal access token only when the token stands in for its owner: no scope, or every permission over all devices. Any narrower token is aborted at connect, with one warning in the server log, and reads devices over REST instead. An admitted token never joins the baby-monitor group.

A connection opened with a personal access token is bounded by the permissions its claims carried at connect: the recheck gives it the intersection of the owner's current permissions and that ceiling, so it can lose a group but never gain one, and a revoked or expired token leaves every group.

Admin group membership is rechecked against current active-user role permissions when an access change is applied on the replica and every 5 seconds as a backstop. A user who loses one permission leaves that permission's group and keeps the others; one who loses all is removed within one backstop interval when the database works; during a database outage, failed checks are retried on later passes and a connection is removed after RecheckGrace has elapsed since its last successful check and its check is processed. Checks run one at a time, so with a stalled database removal can take RecheckGrace plus one check timeout per admin connection tracked on that replica. Replicas recheck their own connections.

AdminPermissionRevalidation:Interval (default 5 s) and CheckTimeout (default 5 s) must be from 1 ms through the maximum timer delay (about 49.7 days). RecheckGrace (default 15 s) may be zero but not negative.

All require the same authorization policy as the REST surface. The app authenticates with an HttpOnly session cookie, never a bearer token: the browser sends it with the WebSocket upgrade, so the client has no access-token factory.

Execution events carry node data in Inputs (NodeStarted, NodeCompleted, NodeFailed) and Outputs (NodeCompleted). Events are sent only while a client watches the workflow: the hub adds a watcher after its workflow ownership check and removes it on leave or disconnect. Watchers are tracked across replicas, so a client that joins on one replica receives events from the others. A lost join hint is corrected within one lease refresh, and a failed replica's leases expire after two minutes.

The hub masks secret-looking keys in structured values and applies Workflow:MaxPayloadValueBytes per value. JSON carried inside a string is text, and failure Error text is capped but not masked. Debug Paused and SnapshotCaptured events sanitise the input, output and variable maps in their snapshot JSON. Unknown output shapes, malformed values and truncated previews are redacted before broadcast, and a debug event over 1 MiB is replaced by {}.

The REST debug-session snapshot endpoint and execution detail endpoint return stored snapshots/checkpoints without this SignalR sanitizer. There is no server-sent-event route for workflow node data.

Connecting without negotiate

Every client opens the hub WebSocket directly, skipping the /negotiate round trip. A negotiated connection id exists only in the memory of the replica that issued it, and a balancer without session affinity sends the transport request that follows to another replica, which answers 404. A direct socket is a single request, so it works behind plain round-robin. The cost is the fallback: a route that drops WebSocket upgrades gets no realtime at all, because the hubs offer the WebSocket transport only.

In the web application every hub connection is built by hubConnectionBuilder in frontend/src/lib/hubConnection.ts. The Android app's SignalRDeviceHubConnectionFactory sets the same two options (WebSockets only, negotiation skipped). Every hub accepts WebSockets only, so a client cannot fall back to server-sent events or long polling. The cluster library tracks every hub connection, and ReeveFenceSink aborts them when the replica is fenced.

A hub call the cluster refuses rejects with a HubException carrying replica_not_serving, replica_fenced, replica_behind or write_refused. The web application stops that connection (stopOnClusterRefusal) and its restart loop (createRestartLoop) reconnects, normally to another replica. The device, workflow and workflow-debug hubs use that loop.

Delivery

The device hub has no subscriptions: every connection receives every event its user may see, and the client applies a push only to the devices it holds in its cache. Its one client-callable method is SetDeviceStream(bool enabled), which takes the connection out of its user's device group (false) or puts it back (true); the phone mutes a connection it keeps while suspended.

Every connection joins its user's group (user_{userId}) on connect, and every device notifier delivers through those groups, never to a connection id: a per-connection send reaches only the connections on the replica that raised the event, while a group send crosses replicas through the backplane.

The notifier asks for the device's viewers in the access state of the generation it reads: a request or hub invocation reads its pin, and background ingest pins for that one push. The audience is built with the state, not cached on its own, so an acknowledged change to a role, override or user status filters the next push on every serving replica. Each audience carries its viewers' group-name list, shared by every device with the same viewer set, so an event goes out in one Clients.Groups(list) call and is serialized once, not once per authorized user. A device no override names reaches the default audience, so a device created a moment ago is delivered. One nobody may see sends nothing, and so does a replica that does not serve a configuration generation: the push is skipped, not queued.

Client rules

  • On a reconnect or a restart after a drop, invalidate the device-detail queries currently in the cache at once, one per visible device, and refetch each device list once, at a random moment within five seconds. Pushes missed during the gap are not replayed, and a list query does not refetch by itself when its stale time expires, so the lists (typed devices, physical devices, the paged logical lists, the scene forms' bulk device read) are read again once. The random delay spreads the clients that reconnect together after a backend restart; a list refetch per device or per push is a thundering herd on a large inventory. The first connection refetches no list.
  • A push is written to the cache again once a fetch of the same entry that was in flight when it landed settles. A command's follow-up read can reach the database just before the device's state frame is ingested and still be answered after the push, which would put the older state over the newer one. The push is the newer truth, so no further GET is made; this covers detail entries, lists and the availability, command-status and logical-device patches. A caller that folds a fetched device into the list itself (the Home tile) skips the fold when a push was counted during its fetch, and never moves capturedAtUtc backwards.
  • An availability verdict older than the last one applied for that device is dropped. Its updatedAtUtc is the device row's change stamp, which never moves backwards (a write whose clock reads earlier keeps the stored stamp), so a verdict that arrives late, from another sender or from a replica whose clock lags cannot overwrite a newer one. Two verdicts with the same stamp both apply, in arrival order. The stamps applied so far are forgotten when the hub connects or reconnects; the refetch after the gap covers what was missed, and a refetch needs no reset because the next verdict's stamp is never below the last. The web app and the phone app both do this.
  • The device hub probes the session before a restart and when a reconnect begins, not before its first connection. A 401 on that probe is caught by the shared HTTP interceptor, which tears the session down cleanly.

See frontend.md for how the web client wires this, and mobile.md for the phone's lifecycle handling.

Telemetry

Metric Labels Meaning
reeve_signalr_messages_sent_total filtered=true|false Device-event deliveries, one per authorized user of each send. filtered=true marks a send that reached fewer users than were eligible.

See operations: observability for the full instrument catalog.

Deliberate limits

  • No per-device or per-room subscriptions. A connection cannot narrow what it receives below what its user may see; a client that renders a few devices drops the rest of the pushes itself.
  • No scene, workflow or helper events on this hub — those live on other hubs.

Delivery mechanics

  • The per-user group is the cross-replica delivery path: it travels over the Redis backplane, and automation notifications reach the user's backgrounded phones through it.
  • State ingest does not wait for its pushes. The pushes a plugin instance raises for its devices are queued once the write commits and sent in commit order by one task per instance. A failed send is skipped and logged. The queue is bounded by bytes (DeviceIngest:SinkQueueByteBudget, at most 10 000 pushes, and the process-wide DeviceIngest:RealtimeProcessQueueByteBudget of 64 MiB). When it is full, the oldest push is dropped and counted in reeve_device_ingest_queue_dropped_total{sink_kind="realtime",reason="evicted"}. A push that cannot fit even in an empty queue is dropped with reason="budget", and one larger than the queue's budget with reason="oversized". Pushes still queued when the instance stops are dropped. A dropped push is not replayed: the client reads the device again on its next push or reconnect. A device event is still sent inline, in the plugin's call.
  • A debugger command answers with its outcome, Applied when it took effect.