Repository navigation
Description
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:
-
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 inStartSessionplus a small store (Postgres table or the existing Redis pattern). Cards contain no secrets (session id, owner, profile, media file id, audio selection). -
Add a store fallback in
TranscodeManager.LoadOrReconstructSessionwhencard == niland the caller is authenticated (non-zerorequestUserID, which must matchcard.UserID— the same two-factor ownership rule reconstruct already enforces). Keep the token required for the authless bearer routes (HLS manifest/segment serving whereuserID == 0), so the security posture there is unchanged.RegisterReconstructedWithLimitsalready handles admission caps and fail-open on limit-provider errors — reuse as-is. -
Route the control-plane endpoints through the same front door (
LoadOrReconstructSessioninstead of bareGetSession): 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
PlaybackSourceCacheper 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
- Start direct play on a client with a healthy forward cache; restart the server mid-playback.
- Expected after fix: no visible interruption; server log shows
playback session reconstructed from recipe cardtriggered 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. - Regression guard: token-less reconstruct must be refused for
userID == 0routes and for a caller whose userID mismatches the card owner; TTL-expired cards must still 404.
Activity
Rhainland commentedon Oct 2, 2026
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}/replanreturned 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.