Reeve Docs

Docs / Architecture

Baby monitor

The baby monitor turns a household camera into an alarm a parent's phone rings for. An operator configures a profile (one monitored room: a camera, what it reacts to, and who may use it); a member's phone runs a session on it; the backend evaluates sound detections and camera motion into episodes and tells every phone with a live session. This page states the model and its rules. Endpoints, bounds, the episode transition tables, Redis keys and the phone obligations are in the baby monitor reference; the camera side (motion gate, media paths) is in camera-media.md.

Building blocks

Part Where it runs What it holds
Profiles PostgreSQL, edited under babymonitor.manage camera, sound classes, motion and quiet timings, members
Sessions, sound claims, command stream, per-profile state Redis, with TTLs short-lived operational state, including episode, camera health, recent events and the last commit time
Sound ingest every replica, on the local device-event feed appends a claimed detection to each matching profile's stream
Evaluator one replica, the owner of the baby-monitor cluster unit kind the 1-second tick: a pure episode machine plus the camera-health machine, committed per profile
Picture probe a second loop inside the evaluator's owned unit snapshot or negotiation checks of each camera with a live session
Delivery the evaluator, over SignalR (babyMonitor on DeviceUpdatesHub, backplaned by Redis) messages to a per-user group, after a confirmed commit
Phone runtime the Android companion (Reeve.Mobile.Core/BabyMonitor/, Android pieces behind ports) ringing, notifications, the per-profile episode memory, readiness

The monitor depends on Redis: while Redis does not answer, sessions, claims and episode state are unreachable, there is no camera motion, and every phone reports the monitor as not watching.

The server decides; the phone presents

The backend decides what is an alarm

The backend evaluates detections and owns episode state; the phone presents the resulting state and messages. Phone-side evaluation could not coordinate replicas or continue reliably across reconnects. The episode machine is a pure function of state, rules, one input, Redis now and a supplied episode id; it reads no clock and does no I/O, and it is total: every state and input pair has one row.

One owned unit evaluates every profile; episodes are not generated automations

Each profile is evaluated by the shared baby-monitor owned unit, placed on one replica by the cluster library, which ticks only while it holds the unit. Only the owner reads and commits profile state, and the API only appends commands (sound, ack, test, session) to the profile's Redis stream. A generated automation per profile would duplicate the evaluator's lifecycle and could not give the one-owner, conditional state commit. See Exclusive work is placed by the cluster library.

Short-lived state lives in Redis, and each profile carries its own liveness stamp

Redis holds the sessions, sound claims, command stream and per-profile episode state, because their TTLs suit ephemeral values. Each profile stores the Redis time of its last successful commit, including ticks that changed nothing, and the phone judges liveness from that per-profile value: a commit more than 60 seconds older than the response's server time means the evaluator is missing. A missing or stalled evaluator therefore reads as "not watching" rather than as healthy. Recent events share the profile's state and disappear with it when the profile has no session and no open episode: they explain current operation and are not an audit record. This is the stated exception in Postgres arbitrates ownership, liveness and held slots.

Every time the machine reads is Redis time

Episode timers, stream-entry times, commit times, response server time, recent-event times and message send times all come from Redis TIME or stream ids, so replicas with skewed clocks agree. Session expiry, claim windows and the test-alert rate limit are Redis TTLs.

The per-tick commit is native; the idle delete keeps a two-key condition

The per-tick commit is one unconditioned MULTI/EXEC: SET … IFEQ on the state read (NX when there is none), then the HDEL of lapsed sessions. The commit decides on one key, and the native compare-and-set keeps that decision without the thread-pool block a WATCH costs in StackExchange.Redis. A lost commit still removes lapsed index fields, whose sessions cannot come back. The idle delete decides on two keys (state unchanged and session index absent), and no native command conditions a delete on another key, so it alone keeps a WATCH; it is skipped when there is no state and no stream, so a quiet idle profile costs one EXISTS per tick. It runs when the last phone leaves, and on every tick after a sound for a profile nobody watches, because sound is recorded for every enabled profile. The second condition keeps a just-started session's first sound from being deleted. See Redis runs no server-side code.

Messages leave only after a confirmed commit

A message is sent at most once per transition, and only after the tick's commit is confirmed; on an ambiguous reply the owner reads back its unique tick token before dispatching. A message lost to a failed or late send reaches the phone through the State of its next heartbeat. A message's SentAtUtc is the commit's Redis time, which the phone uses to order messages and heartbeat answers that arrive on different connections.

Who receives what

The session, heartbeat, delete, state, acknowledge and test-alert endpoints, profiles/mine, and the per-user SignalR group serve cookie-authenticated connections only; a personal-access-token hub connection never joins the group. A token's device scope cannot be re-checked when the owner sends.

An alarm is delivered when its access check cannot run

Access is checked per recipient at delivery. A check that throws or gives no answer within one second is logged and the message is delivered: skipping on a database outage could silence an alarm for a recipient verified at the last heartbeat. A check cut short because the dispatch's five-second delivery budget ran out is not a failure: that recipient gets nothing and rings from heartbeat state instead, so a spent budget never widens delivery to someone the check would have refused. Once a check is cut at its timeout the database is considered hung, and later uncached recipients in that dispatch are delivered without a check. A recipient the check definitively refuses is sent one revoked message instead and loses their sessions for that profile. Only the database may say "not a member": a recipient the cached profile does not list is confirmed against the database first, because the cache can predate a member being added or re-activated.

Only a newly added member must be active

Membership is checked as the profile is saved only for users being added: an existing member later disabled keeps their place, and their use is refused by the access check (an inactive user counts as not a member there), not by membership.

A test alarm's cooldown grant cannot be cancelled once taken

A test alarm takes a 30-second Redis cooldown claim (babymonitor-test) that a cancellation cannot interrupt, since a cancel after the grant would hold the cooldown for an alarm never queued. A test that is never appended to the stream releases the grant, and an unanswered release falls to the claim's TTL. A test alarm reaches only the requesting session's own user and never touches episode state.

A phone that stops monitoring is not reported to the household

A session that lapses without a DELETE is dropped silently: no message and no recent event, and its index field is removed on the next commit. The other phone keeps monitoring, and waking the other parent to say the first one stopped helps nobody. A phone that dies reports it on itself, quietly, through its dead-man switch.

The baby monitor is turned on by a deployment option, not a household setting

BabyMonitor:Enabled (env BabyMonitor__Enabled), off by default and read once at start-up, lives in BabyMonitorOptions beside the monitor's other settings. No web or phone control changes it; clients learn it from ClientFeatureFlags.BabyMonitor on /api/auth/me, so ClientFeatureFlags carries only deployment facts. Whether a deployment offers a baby monitor is the operator's decision, made once. Turning it on or off is a rollout: phones with running sessions see the replicas restart and are told once that the operator turned it off. Profiles survive the option being off. UpdateHomeSettingsRequest.BabyMonitorEnabled is read-only: a value that differs from the option is refused.

Where the evaluator's inputs come from

Motion is the camera's counted stretch at the motion gate

The evaluator reads the motion gate's Redis key for each camera, once per tick and only while a profile with a camera is active: a counted stretch is motion; a masked stretch (a pan-tilt-zoom move), an absent key or a value the gate did not write is no motion. Motion does not require the camera to be available, because a counted stretch already proves that a source vouches for it. A stretch outlives the movement by the reporter's off-delay plus 4 to 6 seconds, so a new profile's default minimum motion duration is 25 seconds, about 15 seconds of real movement. While Redis does not answer, motion is unknown and the tick otherwise runs on database facts. The gate is described in camera-media.md.

Sound is claimed once across replicas, and the claim degrades open

Every replica hears sound detections on its local feed and finds matching profiles through a short-lived camera index. The first delivery to win a cluster-library Redis claim (babymonitor-sound) appends the sound to every matching profile stream. A claim error admits, so a Redis failure still counts the detection, possibly once per replica; a replica that is not serving claims nothing, so a serving peer counts it. A camera whose event source has stopped is indistinguishable from a quiet room.

Camera health

Camera health is probed by the evaluator's owner, off the tick

The picture is checked by a second loop inside the owned unit, once per PictureProbeIntervalSeconds per camera with a live session, which posts verdicts to an in-memory board that the 1-second tick takes once each. A snapshot or negotiation check can take up to 10 seconds, and a tick longer than 5 seconds restarts every motion run; only the owner writes health state, so the verdict has to reach the owner's tick. A verdict is stamped with the Redis time of the tick that takes it, and one lost with a failed commit or a restart is replaced by the next probe. Each probe step runs on the thread pool and is cut at its budget even when the callee blocks or ignores its token; the callee's slot stays taken until it really ends, so at most one such call per camera and step is outstanding. A verdict belongs to the route it was probed on and is lost when the camera changes source.

The probe asks the owner's replica only

The probe asks the plugin and media path the owner's replica holds. CanNegotiateAsync answers for the replica that asks, and a plugin holding its workload on another replica answers false there, so a false answer, a throw or a timeout is no observation: a camera without a snapshot is healthy when CanNegotiateAsync answers true, and a WebRTC-only camera never raises no-picture and is judged by its availability alone. A WebRTC-only camera whose stream died while it still reports itself online goes unnoticed until it reports offline. Treating a false answer as no-picture would ring falsely whenever the owner is not the replica holding the camera.

A plugin not running on the owner's replica is a fault after a warm-up

Every replica loads every plugin, so an enabled plugin that is not running is still starting or broken. The probe gives no verdict for it until PictureProbeWarmupSeconds (180) have passed since the probe loop started or the plugin was last re-enabled, and Failing after that; in safe mode it never gives one. The warm-up keeps a rollout from posting a notice to every parent, and a crashed plugin that never reports its own health is otherwise silent. A camera whose plugin stays down is listed 60 seconds after the warm-up ends.

The picture probe asks a cold plane path again instead of waiting longer

When the probe is served by the media plane's remux, it repeats the snapshot request one SnapshotTimeoutSeconds apart until PlaneReadTimeout + 2 seconds (16 by default) have passed, and reports Failing only if none gave a picture. go2rtc waits 5 seconds for an RTSP DESCRIBE, which is not configurable, while an on-demand source such as a Matter camera takes 6 to 14 seconds to start; the plane keeps starting the source after go2rtc gives up, so the next request meets a warm path. Holding the path open for the probe would keep the camera's encoder allocated all day for a check every 30 seconds. A plane camera that is really down is reported up to 16 seconds after the probe starts, and the viewer-facing snapshot still uses one attempt.

A fault is raised after 60 seconds and cleared after 30, and needs positive evidence to clear

A signal is raised when it has read Failing for HealthFailingSeconds (60) of Redis time and clears after Ok for half of that. A gap with no observation, or Redis time moving backwards, ends both runs, while a raised signal stays raised across a gap: an owner that cannot see the camera keeps a raised reason. The health state is written from the machine's step only, so a lost commit drops the step and the next tick derives it again. The detailed rule table is in the reference.

Camera health never opens, extends or ends an episode

An offline camera reports no activity, and the camera-fault notice already tells the parents that the monitor cannot see, so an episode open when the camera goes offline may end quiet while the notice stands. The episode and camera-health machines stay independent.

A cleared camera fault sends nothing

When a fault clears, the reason leaves State.Health and the phone withdraws its notice and turns the status green at its next heartbeat. Camera faults reach the phone only through State.Health, never as a message, so a fault can stay shown for up to one heartbeat interval after recovery.

Disabling the camera's plugin is quiet

A camera is operator-stopped, and not judged, when the instance row of its active source is disabled or missing; with no active source (an offline source is never active), when no source belongs to an enabled instance row. Then there is no camera-offline and no no-picture, an earlier reason clears, and the phone is told nothing. Disabling the plugin is the operator's deliberate action and must not wake the parents; while it stays disabled the monitor is blind and shows nothing. A plugin that is enabled but not running (crashed, failed to start, held by a host marker), and operator actions that keep the instance enabled (pausing, restarting or updating the workload), are faults and give the quiet notice. This is the one exception to "an operator's deliberate action ends in one quiet notification".

A retired camera is treated as deleted

A camera retired by a device-type change is refused when a profile is saved and ignored by the evaluator. Sessions stop as for a deleted camera (ended(profile-changed), heartbeat 403), and the profile shows device.replaced to managers and keeps the retired device from retention until another camera is chosen. The replacement is by definition a device of another type, and a baby monitor needs a camera; re-pointing the profile at it, or clearing the camera silently at purge, would lose the profile's meaning without a trace.

Ringing

Only a detection rings; a failure is one quiet notice

The phone rings only for a new episode and for the test alarm. A failure gives one ordinary notification that follows silent mode and Do Not Disturb, never loops and is never full-screen, plus a status on the session screen. The failures are losing the server for 60 seconds, the dead-man switch, a stale evaluator commit, and a camera offline or without a picture; a reminder after acknowledgement and the 12-hour "still on" notice are quiet too. A failure at night is rarely something a parent can fix then, and a monitor that cries wolf gets switched off; the failure still never passes silently. No server message says "ring" or "quiet": alert rings, reminder is quiet, and camera faults come only through State.Health.

An episode rings once on each phone, and OK acts on the phone where it is pressed

A phone rings for the first alert it hears of an episode. The server re-alerts an unacknowledged episode every five minutes, and the phone turns a later alert into one quiet notice. The phone remembers, per profile, the last episode it rang for, across reconnects, app restarts and reboots; a phone that joined mid-episode or was off at the first alert rings once. The alarm offers one action, OK, on the notification, the full-screen alarm and the session tile: it stops the ring and removes the alarm notification on that phone only, and sends the acknowledge call best effort, so the server records who answered and stops its re-alerts. Another phone's acknowledgement does not stop a ring that has started here, and an episode acknowledged before this phone rang for it does not ring. Parents together know which of them is getting up.

A recurring problem chimes once

The problem notification sounds only the first time a given problem appears for a profile. The same problem coming back is posted silently until the profile has had no problem for ten minutes or its session is started again. Ten minutes covers a link flapping just past the 60-second bound and still lets a separate failure later in the night sound; a new kind of problem sounds while an earlier one is latched.

The alarm plays at a per-phone level the system volume only caps

Each phone sets its own alarm level, 0 to 100 % (25 % after install), and every ring, the preview and the test alarm play at it from the first second. p % sounds as the system alarm volume would at p % of the alarm stream's range; below the stream's lowest non-zero step the gain keeps falling along the same decibel line, and 0 % makes no sound. The player scales its own gain against the alarm stream's current volume and decibel curve and never writes the system alarm volume, so a process killed mid-ring leaves no system state behind and ringer mode and Do Not Disturb treat the ring as before. A player can only attenuate, so the system alarm volume is a ceiling: below the level a ring plays at the system volume, and the readiness volume light turns amber.

The Android runtime

The Android pieces live in Platforms/Android/BabyMonitor/ behind ports; the user-facing behaviour is in the mobile reference.

Clock and wake lock. The runtime uses SystemClock.elapsedRealtime as its monotonic clock, because the .NET one stops in deep sleep. It holds a partial wake lock with no timeout, released when the last profile stops or the process dies, because .NET timers stall when the CPU suspends.

Dead-man switch. An exact alarm, re-armed on every contact. If the process dies, it fires a receiver that only posts a quiet notice. It needs USE_EXACT_ALARM on API 33 and later and SCHEDULE_EXACT_ALARM on API 31 and 32.

Reboot. A reboot ends every session silently, so the boot receiver posts one notice and clears the persisted running set. It touches no network.

Player. One looping player on the alarm stream, which sounds through a silenced ringer. Calls run on the main looper and a later call supersedes an earlier one. Audio focus is requested only with a sound. The system alarm volume is the ceiling and is never written.

Full-screen alarm. An activity built in code without MAUI, so it appears in a fresh process.

Channels. Three notification channels. The alert channel is versioned, because Android applies Do Not Disturb bypass only to a channel created while policy access exists, and a channel's settings cannot change afterwards. Readiness deletes and re-versions a pre-policy channel, never while an alarm notification is showing, since the delete would take it down and nothing re-posts it. The alert channel makes no sound of its own (the player is the sound), and importance High is what allows heads-up and the full-screen intent. Below API 28 alarms always pass the priority filter.

Readiness. Readiness lights never block Start, and each fixable red or amber item opens the right system screen.

Automation notifications. They use three fixed channels, because Android freezes a channel's importance at creation. Their intents use AddFlags (SetFlags would drop NewTask), their ids skip the baby monitor's reserved ids, and the counter restarts with the process.

Known limitations

Overlapping evaluator owners

The phone orders episode inputs by commit time and assumes one owner commits at a time. The cluster library releases a lost unit's key after StopBudget (5 seconds by default), while the last tick can run up to nine seconds after the stop (commit 2 s, read-back 2 s, dispatch 5 s), so two owners can overlap briefly at the defaults, and a phone can then take a stale calm state for an episode's end and stay silent for it. Nothing guards against it: duplicate deliveries are caught by the monitor's Redis claims, and a guard on the overlap would cost more than the case.

A plugin call that never returns keeps that camera's picture check failing

The slot of a probe call belongs to the camera and the step, not to the loaded plugin, so a call that never returns keeps that camera's picture check failing until the backend restarts, even across a plugin reload. The effect is a quiet no-picture status; nothing rings.