Skip to content

0006: TV session supervisor inside the TV container

  • Status: Superseded by 0009/0013 (owner, 2026-11-14): Gamescope drives the TV and the runner serves the Home Assistant control; the Moonlight TV client this supervised left the stack, Wolf is being replaced, not kept as a fallback.
  • Date: 2026-11-13

Context

The TV client starts one stream and stops there. When the stream ends with an error (Wolf restarted, network drop), Moonlight shows an error dialog and waits for someone to dismiss it, so the TV stays on that dialog (seen 2026-11-13: the client stayed "up" 40 minutes on a dead stream). After a clean end it exits, and with restart: "no" nothing starts it again; after a host reboot nothing starts it at all. Options: a separate supervisor container that restarts the TV container through the Docker socket, Home Assistant automations over SSH, or a loop inside the TV container.

Decision

A small supervisor (stack/tv/supervisor.py) runs inside the TV container and owns Moonlight: quit the old Wolf session, stream, and when the stream ends start again. A stream counts as ended when Moonlight exits, or when it logs an error (Qt Critical) and is still running after a grace period; then the supervisor stops it. Not its video stats line: Moonlight prints that whenever it rebuilds the decoder, also mid-stream. Quick failures back off (up to a minute) so a broken Wolf is not hammered. Restart requests never cut short the wait that lets Wolf tear the old session down. On stop it ends the stream and then the Wolf session. Compose restarts the container unless-stopped, which also covers host reboots.

For Home Assistant, the supervisor serves POST /restart and GET /status on a port, only when TV_CONTROL_TOKEN is set, and only with that token. No Docker socket and no SSH.

Consequences

  • Detection relies on Moonlight's log text; a Moonlight update must re-check it (the test fixtures name the lines). A way of getting stuck that logs no Qt Critical is not caught; the Home Assistant button is the fallback.
  • Every new stream quits the old session first, as before: never resume (the memory runaway).
  • The control port is reachable on the LAN (host network); the token is the only guard, so it must be long and random.