Skip to content

fix(player): reconnect and resume after a mid-stream server drop - #1808

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/web-player-reconnect
Oct 3, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/web-player-reconnect

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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_recovery replan, 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-op track_change replan 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 browser online event triggers an attempt right away. A stream that fails before its own first frame still goes through the existing startup guard and failure_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

  • Player tests pass (56 files); new tests cover reconnect and resume, a restart answered with 404, the full backoff and give-up path, subtitles off staying off, a refused burn-in subtitle falling back, user exit cancelling retries, and a replacement stream that fails before its first frame taking route recovery instead.
  • Manual, web app against a Docker build of these fixes: during direct play the server was stopped and the player sought past the buffer; it showed "Reconnecting…", and about one second after the server was healthy it resumed playing at the same position (replan 404, new session, old one stopped). Repeated after the review fix with the same result.
  • An HLS (transcode) drop was not reproduced manually; it is covered by tests.
  • The full gate from CONTRIBUTING.md ran on a branch combining all nine Series — Web #1252 fixes: every step passes except make test-go. Its failures also occur on unmodified main on this macOS host (hardware-acceleration probe tests whose fake ffmpeg is killed, and TestAdminResourceCapabilitiesAndScope); three jellycompat transcode-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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (running in T3 Code)
  • Tool(s): Claude Code (Bash, Read, Edit, Write, sub-agents, browser automation through the T3 Code preview), GitHub CLI, Docker, FFmpeg
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: An independent Claude Code review agent (claude-opus-5-5) reviewed the diff against main for 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

  • Adds a reconnect cycle to 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.
  • VideoPlayer routes 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.
  • Refactors the transient-error predicate into a shared isTransientPlayerRequestError helper used by session start, stop, and progress senders. See player-fetch.ts.
  • Documents the client reconnect behavior in the v3 playback protocol. See playback-protocol-v3.md.
  • Risk: plan-failure reporting is now suppressed while the connection is not connected, and the plan-failure key includes the plan revision in VideoPlayer.tsx; transport failures that occur before a transport's first frame still go through startup recovery rather than reconnect.

Macroscope summarized 7ba785f.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 93aea643-98de-4c5f-bca0-2c43a3de33a0

📥 Commits

Reviewing files that changed from the base of the PR and between 271edd9 and 7ba785f.

📒 Files selected for processing (14)
  • docs/architecture/playback-protocol-v3.md
  • web/src/player/components/VideoPlayer.reconnect.test.tsx
  • web/src/player/components/VideoPlayer.test.tsx
  • web/src/player/components/VideoPlayer.tsx
  • web/src/player/components/WatchPage.test.ts
  • web/src/player/components/WatchPage.trickplay.test.ts
  • web/src/player/components/WatchPage.tsx
  • web/src/player/hooks/usePlaybackSession.test.ts
  • web/src/player/hooks/usePlaybackSession.ts
  • web/src/player/playback-errors.test.ts
  • web/src/player/playback-errors.ts
  • web/src/player/player-fetch.ts
  • web/src/player/session-mutations.ts
  • web/src/player/start-v2.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-kody

silo-kody Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 2, 2026

Copy link
Copy Markdown

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 Not run; do not record a result until a human tests the merged build.

Suggested fix: Link #1792 under #1252 C5’s Related findings and keep the result Not run until that post-merge test.

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" ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1242 to +1246
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 2844 to +2849
useEffect(() => {
const reconnectFrom = reconnectFromSessionRef.current;
if (reconnectFrom !== null && reconnectFrom !== sessionId) {
reconnectFromSessionRef.current = null;
subtitleSelectionWasManualRef.current = true;
setActiveSubtitleIndex(grantedSubtitleIndexRef.current);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Rhainland Rhainland mentioned this pull request Oct 2, 2026
10 tasks
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.
@Rhainland
Rhainland force-pushed the fix/web-player-reconnect branch from eecadd1 to 7ba785f Compare October 2, 2026 20:40
@silo-kody

silo-kody Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 2, 2026

Copy link
Copy Markdown

#1252's rehearsal note records #1792 against C5 on b4cf819a4; its later run included open PRs and is not an RC. This PR unblocks the #1792 mid-stream finding, so changes understates the impact. Keep the formal Results cell Not run until a human retests the merged RC.

Suggested fix: Validation tasks: unblocks #1252 C5

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Rhainland

Copy link
Copy Markdown
Contributor Author

Agreed, the line now reads unblocks #1252 C5. C5 also needs #1807 (hung browse reads, #1793); the case passes only once both are merged and re-tested on an RC.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Web player stays on an error after a mid-stream server drop instead of resuming

2 participants