Skip to content

playback: restart resilience misses control-plane endpoints — progress 404 kills recoverable streams within 10s #333

Open

Description

@Quick104

Summary

A server restart still visibly interrupts playback on every native client (black screen + spinner), even when the client has a large forward cache and could keep playing untouched. The restart-resilient playback work in #174 already solves this for the data plane — /stream/{session_id} reconstructs a missing session from the ?st= recipe token, and clients verifiably preserve that token. But the control plane was never wired in: session-scoped endpoints that don't carry the token still do a plain GetSession and return the playback_session_not_found 404.

The killer is HandleUpdateProgress. Clients POST progress every ~10 seconds and treat that exact 404 sentinel as "session dead → tear down and renew playback" (Apple: PlayerViewModel.startProgressReporting → attemptStaleSessionRenewal; Android: equivalent logic in PlaybackSessionLifecycle.kt / PlaybackSessionManager.kt). So after every restart the client kills an otherwise perfectly recoverable stream within ≤10s — usually before the stream path ever gets a chance to demonstrate that reconstruct works.

Affected endpoints (plain GetSession → playback_session_not_found, no reconstruct)

Endpoint Location Post-restart consequence
HandleUpdateProgress internal/api/handlers/playback.go (~1761) Clients declare session dead within one 10s heartbeat → visible playback teardown
HandleChangeAudioTrack internal/api/handlers/playback.go (~1873) Audio switch fails after restart
HandleSubtitle internal/api/handlers/stream.go (~195) Subtitle track fetches 404 after restart
Session websocket attach internal/api/handlers/session_ws.go (~72) Realtime (AI subtitles, admin commands) can't reattach
HandleStartTranscode internal/api/handlers/playback.go (~2348) Post-restart fallback/upgrade to transcode fails

HandleStopPlayback 404ing is fine (stop of an unknown session is a no-op from the client's perspective).

Why the existing token can't cover these

The ?st= stream token rides only on the serve URL, and by explicit design (LoadOrReconstructSession doc comment) it is the sole reconstruction descriptor — "there is no shared per-session store to fall back on." Progress/audio/websocket requests never carry it. The durable Redis recipe store (noderecipe) exists only for the remote transcode-node path.

Proposed implementation

Extend #174's own machinery rather than adding a new mechanism:

  1. Persist identity recipe cards durably at session start for all play methods (direct/remux/transcode), keyed by session id, TTL = playback.MaxTokenTTL (24h, filter-on-read like the existing pattern). The card type already supports all three play methods (NewDirectRecipeCard / NewRemuxRecipeCard / NewRecipeCard); this is one write in StartSession plus a small store (Postgres table or the existing Redis pattern). Cards contain no secrets (session id, owner, profile, media file id, audio selection).

  2. Add a store fallback in TranscodeManager.LoadOrReconstructSession when card == nil and the caller is authenticated (non-zero requestUserID, which must match card.UserID — the same two-factor ownership rule reconstruct already enforces). Keep the token required for the authless bearer routes (HLS manifest/segment serving where userID == 0), so the security posture there is unchanged. RegisterReconstructedWithLimits already handles admission caps and fail-open on limit-provider errors — reuse as-is.

  3. Route the control-plane endpoints through the same front door (LoadOrReconstructSession instead of bare GetSession): progress, audio change, subtitle serve, websocket attach, start-transcode.

Payoff

Server restarts become invisible to every client — Apple, Android, web — with zero client changes. The 10-second progress heartbeat flips from being the trigger that kills playback to being the resurrection vector: the first POST after a restart quietly reconstructs the session, which also restores it in the admin activity view and keeps LastActivity fresh for the reaper (good interplay with #279).

Delete the durable card on clean session stop so a stopped session stays a genuine 404.

Out of scope (client-side work, tracked in silo-apple)

  • Outage-without-restart interruptions: the Apple origin reconnect ladder gives up after ~8–15s and escalates on demuxer starvation instead of playhead runway — needs runway-aware escalation client-side.
  • Client discards its source cache on session renewal (fresh PlaybackSourceCache per load) — cache reuse keyed by file identity is a client fix.
  • Clients should also soften the progress-404 kill switch (e.g. only renew after the stream path also fails) so they degrade gracefully against older servers.

Verification sketch

  1. Start direct play on a client with a healthy forward cache; restart the server mid-playback.
  2. Expected after fix: no visible interruption; server log shows playback session reconstructed from recipe card triggered by the next progress POST (not only by /stream); session reappears in the admin activity view; audio-track change and subtitle fetch work without re-planning.
  3. Regression guard: token-less reconstruct must be refused for userID == 0 routes and for a caller whose userID mismatches the card owner; TTL-expired cards must still 404.

Activity

  1. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  2. added theissue type on Sep 20, 2026
  3. removed
    bug
    on Sep 20, 2026
  4. Rhainland commented on Oct 2, 2026

    @Rhainland
    Contributor

    More evidence from the web player, seen during the Series validation (#1252 C5) on a Docker build of main.

    After a server restart mid-playback, the old session's control-plane calls kept failing: POST /api/v2/playback/{session_id}/replan returned 404, and the web player asked for a playback-control socket ticket (POST /api/v2/playback/sessions/{session_id}/control/ws-ticket) every 5 seconds, getting 404 each time, while its progress posts were still accepted with 200. Before #1808 the player never recovered.

    #1808 (#1792) works around this on the web. When the replan returns 404 it starts a new session at the saved position and stops the old one, which resumed playback about one second after the server was healthy. docs/architecture/playback-protocol-v3.md §6.2 in that PR describes the rule for the native clients. Rebuilding the session server-side, as this issue proposes, would let replans succeed in place and avoid the brief restart.

    AI disclosure: observed and written with Claude Code (claude-opus-5-5) at the maintainer's direction; human verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions