Repository navigation
Description
What happened
A viewer finished an episode, the TV sat on the last frame, and the server ended up running a full video transcode for a session that was not playing anything. The admin view still showed that session as playing a transcode 17 hours later.
Two problems combine here. They share a cause with #666 (progress heartbeats count as liveness), but this case is different: the client did not go away. It is alive, connected over WebSocket, and parked at the end of the file.
1. Failures at end-of-file count as route failures and walk the plan ladder down to a transcode
Timeline (UTC, 2026-11-05), Silo Android TV 1.0.0 on a Fire TV (model AFTKRT, MediaTek AVC decoder), one TV episode with two versions:
- version A: Blu-ray remux, H.264 [email protected] 8-bit, DTS-HD MA 5.1, about 28.9 Mbps
- version B: WEB-DL, H.264 [email protected] 8-bit, EAC3 5.1, about 8.5 Mbps
Neither file has multiple_pps set. The episode is 2673 s long.
| Time | Event | Plan |
|---|---|---|
| 09:45:23 | start | server_remux_hls of A (video copy, DTS → stereo AAC). First frame in 481 ms; plays normally to the end (~10:30). |
| 10:50:00 | plan_invalidated / output_route_changed |
replan with start_position=2673 (end of file). Remux of A; ffmpeg starts and exits at once. |
| 10:58:16 | plan_failed / player_failure, ERROR_CODE_TIMEOUT (1003) |
original_http of B |
| 10:58:38, 10:58:39 | output_route_changed ×2 |
server_remux_hls of A again; ffmpeg exits at once each time |
| 10:58:50 | player_failure 1003 |
original_http of B |
| 11:02:51 | player_failure 1003 |
server_remux_hls of B (video and audio copy); ffmpeg exits at once |
| 11:13:04 | player_failure 1003 |
server_transcode_hls of B: h264 QSV encode plus stereo AAC downmix, seek_seconds=2672. Frozen recipe has "video_copy_failed": true. ffmpeg exits at once; a seek restart (reason=transcode_not_running, segment 1335) also exits at once. |
Every replan after 10:50 asked for start_position 2672–2673, the last second of the file. Each ffmpeg had nothing left to produce and exited immediately, and the player then timed out waiting for media (ERROR_CODE_TIMEOUT). The decoder had played this exact stream for 45 minutes. Its failures came from asking to play past the end, not from video copy.
The replan path still counted each one as a failure of the current route. It appended the plan key to the attempted keys, and with open PR #3475 applied it also set the sticky video_copy_failed mark (internal/api/handlers/playback_v3.go, record.FrozenRecipe.VideoCopyFailed = true, which only excludes network/subtitle/node failures). After direct play and both remux variants were used up, the only route left was a full video transcode.
Nothing was played after 11:13. If the viewer had pressed play again (start over, or play the next episode in the same attempt), they would have got a transcode of a file this device direct-plays.
2. The finished session never ends
From 11:13 on Nov 5 until at least 04:26 UTC on Nov 6, the client POSTed /api/v1/playback/{session_id}/progress every 10 s and fetched no segments. The playback_sessions_sync row at 04:26:
play_method | transcode
position_seconds | 2672
is_paused | f
has_websocket | t
target_video_codec| h264
transcode_hw_accel| qsv
started_at | 2026-11-05 09:45:23
No ffmpeg process was running for it (checked against the live process list). The admin activity view still listed it as a transcode, so an operator counting transcodes counts a session that is doing nothing.
It never expires because:
SessionManager.updateProgress(internal/playback/session.go) callstouchSessionLockedon every progress sample, whatever its position or pause state, so the idle grace never runs out while heartbeats arrive.DefaultPausedSessionGrace(30 min) applies only once progress stops. A paused client that keeps heartbeating lives forever, and here the client did not even report paused.- The comment on
remoteTransportGracenotes that "there is no absolute session lifetime cap in this manager". - The Android TV client did not send a stop when playback reached the end. That part is a client issue.
Steps to reproduce
Seen once in production. The likely steps:
- On Silo Android TV, play an H.264 episode that has a remux route (for example DTS audio, so the server remuxes) and a second version.
- Let it play to the end and leave the player on the last frame without pressing back.
- Change the audio output route (for example the TV or AVR switching off over HDMI-CEC), which sends
output_route_changedand a replan at the end position. - Watch the replans walk direct play → remux → transcode, then check the admin activity view hours later.
Expected behavior
- A replan or a
player_failureat or near the end of the file is not evidence against the route. It must not add the route to the attempted keys or setvideo_copy_failed, and it should not run a new ffmpeg to produce zero segments. - A session that has reached the end of the file and stays there ends by itself, releases its stream/transcode slot, and leaves the activity view.
- A paused session, or one whose position has stopped moving, ends within a bounded time even while heartbeats keep arriving.
Suggested fixes
-
End-of-file guard on replan and start. If
start_positionis within a few seconds of the source duration (or past the last segment), treat it as "playback ended". Answer with an ended outcome, or clamp to a short tail, instead of planning a route. Do not record a route failure for failures in that window. This change also has to cover theVideoCopyFailedlogic in PR feat(playback): try a remux of multi-PPS H.264 first and transcode only after it fails #3475 before it merges. -
Auto-end near the end. On the server, end a session whose position has stayed within the last ~30 s (or past the credits marker, when one exists) for a few minutes with no segment or byte requests. On Android, send a stop when the player reaches the end. That needs a
silo-androidfollow-up. -
Reap paused or stalled sessions on position, not heartbeats. Track the time since the position last advanced, separately from
LastActivityAt. Proposed limits:- paused (or not advancing) for 2 hours: end the session and release its slots, even if heartbeats continue.
- claiming to play, but the position has not moved and no bytes have been served for 15–30 minutes: end it.
2 hours covers a long dinner or film-break pause; 6 hours seems too long given that a parked session holds a transcode slot against
max_transcodes. The reason the paused grace was kept long in Playback freezes / won't resume on player state changes (resume after long pause, intro-skip, manual seek) #243 still applies: reaping kills the transcode, so pressing Play after a reap must recover through a replan/restart instead of freezing the player. Confirm that path before shortening anything.
Items 2 and 3 overlap with #666. #666 is about clients that stopped fetching media but keep heartbeating. This issue adds a live client parked at end-of-file and paused clients. One position-based liveness rule would cover all of them.
Version
Production build: a local fork of main at 6aa6791 with open PR #3475 applied (the source of the video_copy_failed mark). The attempted-keys exhaustion and the progress-based liveness are on main; I have not reproduced this on an unmodified main.
Deployment: Docker Compose, single node, Intel QSV.
AI-use disclosure: Claude Code (claude-opus-5-5) investigated this from production logs, playback tables, and the source, and drafted this issue. Filed at a maintainer's request.
Activity
Rhainland commentedon Nov 9, 2026
Reproduced the replan half on
origin/mainat 4018816 with a synthetic H.264 + DTS file, through the v1 playback API. The server started a remux. Anoutput_route_changedreplan at the last second of the file (180 of 180 s) returnedserver_transcode_hlswith-ss 180, and that ffmpeg exited within about 70 ms. Aplayer_failureat 179.5 s then ended in a terminal response. The same failures at 60 s walk the same ladder, which is correct mid-file. v2 was not run live; it sharesreplanPlaybackApplicationV3andexecuteReplanV3with v1.Cause:
executeReplanV3adds the current plan key to the attempted keys for any failure-shaped replan, whatever the position.I have not changed any code, because the fix depends on a client contract decision. Android (
PlaybackSessionManager.kt) and Apple (PlaybackSessionBridge.swift) raise a fatalreplan_loop_detectedwhen a failure replan returns a key they already sent. They add the failed key themselves, so simply not counting the route at end of file brings the same key back and shows the viewer an error on the last frame. Android's unchanged-outputoutput_route_changedis failure-shaped too, so this issue's own trigger would hit that check.Options:
silo-appleandsilo-android, and until those ship, clients would probably show it as a generic terminal.output_route_changedat end of file would still walk the ladder, so this only partly meets the expected behavior.Whichever is chosen,
VideoCopyFailedin #3475 needs the same end-of-file exemption. The second half of this issue, the session that never ends, depends on the protocol decision #666 is waiting on, so I left it out.Which option should this take?
AI disclosure: reproduced and analysed by Claude Code (claude-opus-5-5) at the maintainer's direction.
blurbery commentedon Nov 13, 2026
Thanks for the repro. I'd like to pick this up, and I'd go with B, using C as the fallback for clients that haven't opted in.
What viewers see before any client ships depends on how the current clients react, so I read through both (silo-android
9ce12edf1, silo-apple5780c84f):attempted_plan_keyson everyfailure_recovery. That includesoutput_route_changedwhen the route hasn't changed, because Android has nooutput_changeoperation (PlaybackSessionManager.kt98-105, 1152-1162). A repeated key raisesreplan_loop_detected(1267-1286), which stops the session, shows the error screen and cancels Up Next. So A on its own swaps today's transcode for an error on the last frame.outcomeis an error on both (invalid_playback_outcomeon Android,invalid_replanon Apple), and an unknown terminal reason gets the generic error screen. Android doesn't readretryable.So the new answer has to be opt-in. Until a client opts in, the only answer it handles cleanly is a playable plan with a key it hasn't tried, which is C.
Proposed shape:
playback_ended(adaptation_unavailable, not retryable), sent only to clients that advertise a newplayback_ended_v1client feature, with a matching server feature. I'd use a terminal reason rather than a new outcome: both clients already have a terminal path, and the outcome pair stays as it is.executeReplanV3before the attempted-keys block (internal/api/handlers/playback_v3.go:5843on0387303d9). It covers failure recovery, seek failure recovery and the output and quality intent replans whenposition_secondsfalls inside a short window at the end of the effective file. The route isn't counted, no ffmpeg starts, and theVideoCopyFailedmark from feat(playback): try a remux of multi-PPS H.264 first and transcode only after it fails #3475, which goes in that same block, never sees it. A seek reanchor keeps its existinginvalid_seek_positioncheck.output_route_changedfrom Android can still step down one rung, which needs the Android change below.Client follow-ups I'd file:
playback_ended_v1and treatplayback_endedas the end of playback (keep the finished or Up Next state, stop the session, no error). Separately, stop sendingoutput_route_changedasfailure_recoverywhen the route hasn't materially changed, or afterSTATE_ENDED.Two questions before I start:
playback_ended? A terminal replan leaves the session running today (playback_v3.go:5250-5268), so without that the activity view keeps listing it. It's a decision on an explicit replan rather than a heartbeat rule, so I don't think it has to wait for [bug] Progress updates alone keep dead sessions alive forever — ghost sessions hold transcode slots for 15h with zero byte flow #666. If you'd rather keep all session-ending in [bug] Progress updates alone keep dead sessions alive forever — ghost sessions hold transcode slots for 15h with zero byte flow #666, I'll leave it out.If that works for you, I'll do the server part with handler tests and open the two client issues.