Repository navigation
fix(player): reconnect and resume after a mid-stream server drop - #1808
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 39 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (14)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
The web C5 interruption path is ready for a human re-test after merge: #1792 documents a reproduction tied to #1252 C5, and this PR changes the web reconnect path. The task’s Results row remains Suggested fix: Link #1792 under #1252 C5’s Related findings and keep the result Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
| error instanceof PlayerFetchError && | ||
| (error.status === 408 || | ||
| error.status === 429 || | ||
| error.code === "installation_changed" || |
There was a problem hiding this comment.
Incorrect retryable-replan classification of installation_changed causes every reconnect attempt to receive the same 409 after the endpoint switches installations, exhausting the retry budget without reaching the fresh-start path because replanV2 always resends the old session's installation ID and never refreshes capabilities. Remove installation_changed from this classification so reconnect can start a new session and use startPlaybackV2's capability-reset handling.
Prompt for LLM
File web/src/player/hooks/usePlaybackSession.ts:
Line 118:
Incorrect retryable-replan classification of `installation_changed` causes every reconnect attempt to receive the same 409 after the endpoint switches installations, exhausting the retry budget without reaching the fresh-start path because `replanV2` always resends the old session's installation ID and never refreshes capabilities. Remove `installation_changed` from this classification so reconnect can start a new session and use `startPlaybackV2`'s capability-reset handling.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Confirmed, and fixed in 7ba785f, slightly differently from the suggestion. replanV2 always sends the old session's installation, so a replan refused with installation_changed can never succeed; it now falls through to a new-session start immediately. A start refused with installation_changed stays retryable, because startPlaybackV2 drops the cached capabilities on that refusal and the next attempt reads the new installation. A test covers both: a replan 409 leads straight to a start, a first start 409 retries, and the second attempt reconnects on a new session; it fails with the old classification.
There was a problem hiding this comment.
That distinction addresses the issue more precisely than removing installation_changed from retryable errors everywhere:
- Replan: the old installation ID cannot recover through retries, so fall through immediately to a new-session start.
- Start: the refusal clears cached capabilities, so retrying can discover the new installation and succeed.
The regression test you described covers both transitions and catches the original classification bug. Based on that, this resolves the concern raised in my suggestion.
Quick104
left a comment
There was a problem hiding this comment.
Reviewed eecadd19cbd60d5419f93c98680ea6d93af3fa18. Two independently reproduced findings are attached.
AI disclosure: gpt-6.1-sol in T3 Code using the Codex provider. Reproductions exercised the production player and session hook with mocked media and network transport.
| if (isFailureRecovery && playbackStartedRef.current && isRetryableReconnectError(err)) { | ||
| // The stream broke and the server could not be reached to replace | ||
| // it: the connection failed, not necessarily the route. Reconnect | ||
| // rather than strand the viewer on an error. | ||
| beginReconnectRef.current(options.positionSeconds, playbackPlayingRef.current, false); |
There was a problem hiding this comment.
[P2] Preserve playing intent across the failed transport's automatic pause
When an already-playing viewing switches to an HLS transport that cannot start, VideoPlayer.failHlsStartup clears the source and calls load(), and the player's state callback reports playing: false. If its failure_recovery request then fails because the server is unreachable, this branch saves that forced pause as the reconnect's resume intent. A subsequent successful reconnect consequently adopts the plan with shouldAutoPlay: false, although the viewer never paused. I reproduced this through the production player and session hook: playing direct stream → HLS quality change → startup timeout → rejected recovery request → successful reconnect, which returned connected but disabled autoplay. Preserve the playing intent from before transport teardown instead of sampling the element's forced pause when the request rejects.
There was a problem hiding this comment.
Confirmed, thanks for the repro. The reconnect read the playing intent when the recovery request failed, which was after the failed transport's teardown had reported its forced pause. Fixed in 7ba785f: the intent is now taken when the recovery replan is sent, and until the current plan's transport has shown a frame it is the intent the plan was adopted with, so a teardown pause on a transport that never played doesn't count. A new player + session-hook test (VideoPlayer.reconnect.test.tsx) replays your sequence (playing direct stream → HLS quality change → startup timeout → rejected recovery → successful reconnect) and checks the session ends connected with autoplay on; it fails without the fix.
| useEffect(() => { | ||
| const reconnectFrom = reconnectFromSessionRef.current; | ||
| if (reconnectFrom !== null && reconnectFrom !== sessionId) { | ||
| reconnectFromSessionRef.current = null; | ||
| subtitleSelectionWasManualRef.current = true; | ||
| setActiveSubtitleIndex(grantedSubtitleIndexRef.current); |
There was a problem hiding this comment.
[P2] Apply the reconnect subtitle selection before sending track intent
This handover runs after the authoritative subtitle-selection effect above. On the first render of a replacement session, activeSubtitleIndex still contains the old track, so that earlier effect sends it to onSubtitleTrackChange before this effect schedules the granted selection. In the refused burn-in fallback added here, the restart successfully returns a subtitle-free plan, then the player immediately requests the same rejected burn-in track again. I reproduced the full sequence with the production player and session hook: track 3 selected → replan 404 → burn-in restart refused → restart without subtitles succeeds → extra track_change selecting track 3. That extra refusal sets session.error after the successful fallback. Suppress subtitle intent synchronization during the handover, or apply the granted selection before that synchronization runs.
There was a problem hiding this comment.
Confirmed. On the first render of the replacement session the player still held the old track and sent it before the handover applied the granted selection. Fixed in 7ba785f: the player now detects a pending reconnect handover during render (a reconnect started from a different session) and sends no subtitle change until the granted selection is applied. A player + session-hook test replays your sequence (track 3 selected → replan 404 → burn-in restart refused → restart without subtitles succeeds) and checks that no replan is sent on the new session and the session has no error; without the fix it records the extra track_change for track 3.
When the server went away during playback, the web player reported the media element's network error as a failed route. The recovery replan could not reach the server either, so the viewer was left on "Silo could not start playback right now" with only Go Back, and nothing retried once the server was back. A network failure on a stream that already showed frames (a media element network error, a fatal hls.js network error, or a recovery replan that gets no answer) now puts the session into a reconnecting state. The player pauses at the saved position, shows a reconnecting notice the viewer can leave, and retries with backoff (1s doubling to 15s, about two minutes). Each attempt asks for the current route again with a no-op track_change, which keeps the route eligible instead of excluding it as failure_recovery would. If the session did not survive (a server restart answers 404), it starts a new session at the same position with the current tracks. Any adopted plan ends the cycle, leaving or another start cancels it, and a cycle that runs out offers Try again instead of a start-failure message. Failures before the first frame keep the existing route recovery. Closes Silo-Server#1792
A reconnect that has to start a new session already sends the lost plan's subtitle selection, and a start that names no subtitle track plays without one: the protocol has no other spelling of "off" and rejects a negative index. But the player treated the new session as a new title and auto-selected subtitles from the profile again, so subtitles the viewer had turned off came back on. A session change that a reconnect caused now adopts the selection the server granted and pins it. A reconnect start whose burned-in subtitle is refused now takes the same retry without subtitles that a refused bitmap subtitle gets at the initial start, with the same notice, instead of ending on the error screen. The retry keeps the audio track.
Whether the stream had played was tracked once per player, so after any transport showed a frame, every later network failure went to the reconnect, including one from a new transport that had never shown a frame. A quality change onto a transcode the browser cannot reach then retried the same route for two minutes and ended on "Connection lost", instead of the startup guard reporting the route as failed so the server could pick another. The flag now resets whenever the transport is rebuilt and is set again by that transport's first frame. A replacement that fails before its first frame takes the ordinary startup recovery. If that recovery cannot reach the server either, it joins the reconnect and continues the running budget, so a server that keeps dropping new streams still ends in "Connection lost".
Keep the viewer's playing intent through a failed transport. When a playing stream switched to an HLS rung that could not start, tearing that transport down forced a pause, and a recovery request that then failed sampled the pause as the resume intent. The reconnect that followed came back paused. The intent is now taken when the recovery is requested, and until the current plan's transport has shown a frame it is the intent the plan was adopted with. Send no subtitle change during the reconnect handover. On the first render of a session that a reconnect started, the player still held the lost session's subtitle and sent it to the server before the handover applied the granted selection. After a refused burned-in subtitle fell back to playing without subtitles, that re-requested the refused track and left an error on a session that had recovered. Stop retrying a replan the server refuses with installation_changed. A replan always carries the old session's installation, so repeating it could not succeed; it now falls through to a fresh start, whose own installation_changed refusal drops the cached capabilities and is retried on the next attempt. The player and session hook now have integration tests that replay the reported sequences.
eecadd1 to
7ba785f
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Suggested fix: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Problem
Closes #1792
Related issue: #1252
Validation tasks: unblocks #1252 C5
When the server went away during playback (a restart, or a refused connection), the web player showed "Silo could not start playback right now. Please try again." with only Go Back, and never recovered after the server came back; the viewer had to leave and press play again. The 1.0 criteria require pausing and resuming automatically on reconnect.
The player now pauses, shows "Reconnecting…", retries with backoff and resumes at the same position once the server answers. If it gives up, it says "Connection lost" and offers Try again as well as Go Back. Real start failures keep their existing message.
Approach
A network failure on a stream that has already shown a frame is treated as a lost connection, not a failed route. The player used to send a
failure_recoveryreplan, which tells the server to skip the current route, so a direct-play viewer could come back on a transcode. Each attempt is now a no-optrack_changereplan at the saved position, which keeps the route; if the session is gone (404 after a restart) it starts a new session at the same position with the same audio and subtitle choice, then stops the old one. Attempts back off (1, 2, 4, 8 s, then every 15 s) for 12 attempts, one at a time; leaving the player cancels them, and the browseronlineevent triggers an attempt right away. A stream that fails before its own first frame still goes through the existing startup guard andfailure_recovery, because that route may be one this browser cannot reach.docs/architecture/playback-protocol-v3.md§6.2 describes the rule for the native clients.Validation
make test-go. Its failures also occur on unmodifiedmainon this macOS host (hardware-acceleration probe tests whose fake ffmpeg is killed, andTestAdminResourceCapabilitiesAndScope); threejellycompattranscode-session tests that failed once under full-suite load pass in isolation on both. Linux CI is the authority for those.Risks
After a short blip the stream is rebuilt from a fresh plan, so there is a brief restart at the saved position rather than an in-place resume. If the host silently drops packets, each attempt can wait up to the 45 s replan timeout, so giving up takes longer. The Apple and Android players should follow the same rule (§6.2); their follow-ups are not filed yet. Server-side session rebuild after a restart is #333.
Checklist
AI Disclosure
mainfor correctness. It found that the "has played" flag was never reset when the stream was rebuilt, so a new stream on an unreachable route would loop in reconnect instead of moving to another route. Fixed in this PR with tests; the reconnect was re-checked against a running build.Note
Add mid-stream reconnect and resume to the player after a server drop
usePlaybackSession: on a lost connection it retries the current session at the saved position, falls back to a fresh start when the session is gone, and preserves the selected audio and subtitle tracks. Retries use exponential backoff (1s, capped at 15s) with a 12-attempt budget, then move to a lost state with a manual Try again action. See usePlaybackSession.ts.VideoPlayerroutes post-first-frame network errors (both media element and hls.js) to reconnect instead of plan failure, pauses playback during reconnect, and shows a reconnecting/lost overlay. A reconnect-created session adopts the subtitle selection granted by its start plan. See VideoPlayer.tsx.isTransientPlayerRequestErrorhelper used by session start, stop, and progress senders. See player-fetch.ts.VideoPlayer.tsx; transport failures that occur before a transport's first frame still go through startup recovery rather than reconnect.Macroscope summarized 7ba785f.