Live relay nodes
Browsers talk only to the installation’s own servers (ADR 0334). A live conversation (speech to speech, OpenAI Realtime), real-time recognition (Mistral) and the live avatars (the live tutor and the presenter, LiveAvatar; ADR 0335) go through a relay node: the browser connects to the node, the node connects to the provider. The provider sees the node’s address, never the person’s.
A node is its own process (apps/relay), stateless per session. The main server runs one by default. When live sessions grow, more nodes run on more servers. Run them with the installation’s other servers, under the same provider and data protection terms.
How a session runs
Section titled “How a session runs”- The browser asks the API for a live session. The API checks the person’s rules (minors, restriction of AI processing), the operator’s approval of the provider (ADR 0311), minutes and limits.
- The API mints the provider’s short-lived session secret (minutes; never the account’s key) and picks a node: enabled, beat in the last 45 seconds, with room, the API’s region first, then the least loaded.
- The API writes a
relay_sessionsrow: the node, who (ids only), provider, mode, the provider’s host, the SHA-256 of a one-time ticket, and the secret sealed to that node’s key (X25519, AES-256-GCM, bound to the row). The browser gets only the node’s address and the ticket, valid for 60 seconds. - The browser opens
wss://<node>/v1/sessionand sends the ticket as its first message (never in the address, so no log holds it). The node takes the row once: the ticket and the sealed secret are cleared in the same statement. Another node, a changed or used ticket, or a late one: closed (4401). - The node opens the secret with its private key and connects to the provider’s endpoint named there, only if its host is the provider’s own (
api.openai.com,api.mistral.ai, or one the operator added for that provider). Never a URL from the browser: the node is no open proxy. - Audio goes as binary PCM16 frames, a short list of events as JSON, both ways. The browser can’t change the session the API set up (instructions, model, voice); the provider’s session details don’t come back.
- At the end the node records how long it ran and how many frames went each way. No audio, text or address is stored or logged. Rows go after 30 days.
Limits: per node (RELAY_CAPACITY), per person per node (RELAY_MAX_PER_USER, 3), per person across nodes (5 open sessions or unused tickets), and each session’s time (what the API allowed, at most two hours).
Since ADR 0358: the capacity and the heartbeat’s active_sessions count only sessions whose ticket the node took. A socket that hasn’t sent its ticket yet counts apart, at most RELAY_MAX_WAITING_PER_ADDRESS (4) per address, and is closed after 3 seconds without one. The address is the last X-Forwarded-For entry, the one the nginx or Caddy in front adds (the node listens on the loopback address only). What waits for a provider that isn’t ready is capped at 2 MiB per session; beyond, the session ends as stalled (4429). The node asks every 3 seconds which of its sessions the API wants stopped (stop_requested_at) and ends them like a normal end, LiveAvatar’s session included. The minutes of a relayed conversation or recognition are booked from the node’s own seconds (charged_at), not from what the browser reports.
Live avatars
Section titled “Live avatars”The live tutor and the presenter (ADR 0335) are a session of their own kind (live_avatar):
- The browser watches the avatar in the installation’s LiveKit room (one room per session, a token to watch and listen only) and sends its microphone to the node as in a live conversation.
- The node holds two provider connections: OpenAI Realtime (it hears the person and answers with its voice) and LiveAvatar’s session WebSocket (it gets that voice for the lip-sync). LiveAvatar’s server joins that LiveKit room with a token that may only publish there, and puts the avatar’s picture and voice into it.
- The node starts LiveAvatar’s session only once the browser is connected, and stops it whenever the session ends (with the session’s own token; the organisation’s key never reaches the node).
- Hosts the node opens for it:
api.liveavatar.com(https) and the avatar server LiveAvatar names, belowliveavatar.com(wss). If LiveAvatar names a server elsewhere, the session ends withupstream_refusedinrelay_sessions.end_reason: add the host (or*.domain) withRELAY_PROVIDER_HOSTS=liveavatar:…after checking it belongs to LiveAvatar.
Capacity. A live avatar counts twice against RELAY_CAPACITY (two provider connections, its audio both ways; still a few kB/s and a little CPU per session). The video doesn’t pass the node: it goes from LiveAvatar’s server through the installation’s LiveKit to the browser, one stream per session (about 1–2 Mbit/s at LiveAvatar’s “high” quality). Plan the media server’s bandwidth and its TURN for that: with 50 avatar sessions at once, about 100 Mbit/s out of LiveKit and as much in.
LiveKit must be set up (LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET), and its address reachable from LiveAvatar’s servers (the public wss://rtc.<base host>): without it the live avatars aren’t offered.
The node on the main server
Section titled “The node on the main server”deploy/update.sh sets it up on the first deploy where the database runs on the server (the install module relay; #RELAY_NODE= in the API’s settings leaves it out):
- the database role
academy_relay(only its two tables, see database-consumers.md), its rights again on every deploy; /etc/academy/relay.env(mode 600) with a new node key,RELAY_PUBLIC_URL=wss://relay.<base host>(ACADEMY_RELAY_HOSTin the deploy settings for another name);- the unit
academy-relay(its own throwaway user, nothing to write), restarted with the other services; - the site
relay.<base host>in nginx with a certificate from certbot (deploy/nginx-relay.conf; with Caddy the block indeploy/Caddyfile). Only the path/v1/sessionis forwarded; no access log.
DNS: an A/AAAA record relay.<base host> pointing at the server, before the deploy.
With the database on a server of its own (a provision, ADR 0444) the portal server is never the database’s superuser:
- The role
academy_relaycomes fromdeploy/db/setup.sh(deploy/db/relay-role.sql), made over the network with the admin access; its rights on the relay’s tables fromdeploy/db/grants.sql, which every update applies as the portal’s own role after the migrations. - Its address lands in
CONFIG_DIR/database.env(/etc/academy/portal/database.env) asRELAY_DATABASE_URL.install.shwrites/etc/academy/relay.envfrom it, withRELAY_DATABASE_SSL_CA_FILEset to the database server’s CA (DB_CA_FILE). - From then on, every update sets up only the unit, the site and the check.
- Until that file is there, the update says the node waits for it.
Without a healthy node the live modes aren’t offered: the conversation mode goes turn by turn.
More nodes, and switching one off
Section titled “More nodes, and switching one off”Adding a node on another server (network to the database, its key, settings, unit, TLS, the check) and switching one off are the platform team’s: the admin console’s handbook, Runbooks (the console’s docs/handbooks/platform/en/runbooks.md), and the console’s Live → Relay nodes page (ADR 0477, the console’s ADR 0010). A node one version behind keeps working as long as the release notes say nothing else: the protocol between API and node is the relay_sessions row.
The table relay_nodes
Section titled “The table relay_nodes”The console’s (platform.relay_nodes, its migration 0024; on an installation made before, the console’s install.sh --db-setup moves the portal’s table there once this version is in). A node writes only its own report through the console’s role academy_platform_relay, which its login role academy_relay is given; the API reads the nodes, the console alone switches enabled. Both the API and the node find the table through their search path (public, platform).
| Column | Meaning |
|---|---|
id |
The node’s id (the sessions point at it) |
name |
Unique, lower case (main, scw-par-1) |
region |
The API prefers nodes of its own REGION |
public_url |
Where browsers connect (wss://…, no path) |
capacity |
Sessions at once (a live avatar counts twice) |
public_key |
The node’s X25519 public key (base64 SPKI): what the API seals to |
enabled |
Set by the operator in the console; a node never changes it itself |
version |
What the node reported (RELAY_VERSION) |
active_sessions |
Open connections at the last beat (a live avatar counts twice) |
last_seen_at |
The last beat (every 15 seconds) |
created_at |
When it first registered |