feat(agent): el auto-update difiere hasta que no haya stream activo

Un auto-update reiniciaba el daemon al momento y cortaba la
reproducción en curso (mata la sesión HLS viva → freeze → F5). Ahora
el path AUTO (OnUpgrade) difiere indefinido mientras haya streams
activos y aplica solo en idle. Ningún update en segundo plano vale
cortar un visionado.

- HLSSessionRegistry.Count() + playerSessionRegistry.count() →
  GetActiveStreamCount() = player (HLS/direct/remux) + transcode HLS.
- deferAutoUpgradeUntilIdle: guard de un solo waiter, ticker 30s,
  aplica al llegar a 0 streams.
- `unarr update` (manual) SIN cambios: aplica al momento = escape
  hatch para un fix urgente.
- SyncRequest.agentStatus ("updating") reportado antes del restart
  para que la web pueda avisar en vez de dar error de sesión.
This commit is contained in:
Deivid Soto 2026-06-12 09:46:23 +02:00
parent 91ee5e4b6f
commit 59da949a53
6 changed files with 84 additions and 1 deletions

View file

@ -59,6 +59,10 @@ type SyncClient struct {
// WireGuard tunnel is up, the mode, and the exit server) so the web can track
// which agent holds the single WG slot.
GetVPNState func() (active bool, mode, server string)
// GetAgentStatus returns the daemon lifecycle state ("running" | "updating"
// | "shutting_down") so the web can show "agent updating" during an upgrade
// restart instead of a hard error. Empty → treated as "running".
GetAgentStatus func() string
// GetFunnelURL returns the CloudFlare Quick Tunnel public hostname if one
// is active, else "". Sent on every sync so the web picks it up live.
GetFunnelURL func() string
@ -217,6 +221,9 @@ func (sc *SyncClient) buildRequest() SyncRequest {
if sc.GetVPNState != nil {
req.VPNActive, req.VPNMode, req.VPNServer = sc.GetVPNState()
}
if sc.GetAgentStatus != nil {
req.AgentStatus = sc.GetAgentStatus()
}
if sc.GetFunnelURL != nil {
req.FunnelURL = sc.GetFunnelURL()
}