Skip to content

fix(player): resume direct play after a later cut instead of failing - #992

Closed
Rhainland wants to merge 2 commits into
Silo-Server:mainfrom
Rhainland:fix/981-retry-window-after-progress
Closed

Rhainland wants to merge 2 commits into
Silo-Server:mainfrom
Rhainland:fix/981-retry-window-after-progress

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #981
Validation tasks: changes #7 and #8 Resilience ("mid-stream drop → auto-resume"), not yet validated

Other clients: Apple N/A (reads in bounded ranges and has its own retry code); Roku N/A (separate player stack, no shared retry policy); Web N/A (browser player, no client retry policy)

On Android TV and phone, direct play survived only the first dropped connection in a playback. When a later drop came minutes after a successful resume, such as a reverse proxy reloading or an idle reset during a pause, the app gave up on its first retry. It showed a player error, rebuilt the player and reopened the file from the start. Users see a spinner and a restart where playback should carry on from the next byte.

A direct-play file is a single Media3 load for the whole movie, and the 90 s retry window was measured from that load's first failure. A cut eleven minutes after a resumed one was already outside the window, which is the retry exhausted … attempt=2 line in the issue's second report. A load that had ridden out a long outage earlier could also still be at its retry-count limit when the next cut came.

Approach

Each outage now gets its own retry window and count. On direct play, a failure after an attempt that loaded at least 1 MiB starts a new outage. A backend that sends a few kilobytes and stalls again stays in the same outage, so it still gives up after 90 s. HLS keeps its current behaviour, because a segment retry starts over from the segment's first byte.

A TLS read failure after progress is now resumable, like an HTTP/2 stream reset. Android can report a peer that reset a TLS connection mid-read as a plain SSLException, which nothing retried. That is the likely cause of the issue's first report, which logged no retry line at all, but it is not confirmed. Handshake failures, such as a rejected certificate, stay fatal. The same rule applies to sidecar subtitle loads, where such a failure now counts against their existing two-extraction budget like a socket reset does.

The retry log now covers every failed direct-play load, not only HTTP/2 resets and EOFs. It names the exception classes in the cause chain, with the HTTP status or HTTP/2 reset code where there is one. It does not log exception messages, because they can contain the server address. The next report of this kind will show which exception it was.

This keeps one open-ended request per playback. Reading the file in bounded ranges, as proposed in discussion #980, would also avoid a cut during a long pause, but it is a separate change.

Validation

  • New Robolectric test runs a real ExoPlayer against a mock server: the stream is cut, resumes, and is cut again eleven minutes later. On main this ends in a fatal player error; with the fix it plays to the end with no error.
  • Policy tests cover a new outage after a long earlier one, a backend that keeps trickling a few kilobytes, and which TLS failures resume. All of them fail on the code before the fix.
  • ./gradlew testDebugUnitTest: every module passes except three FormattersTest cases in androidApp, which this change does not touch. They fail only because the test machine's locale formats 1,0 TB.
  • :android-shared:lintDebug, :androidApp:assembleDebug and :androidTvApp:assembleDebug pass.
  • Not run: the supply-chain scripts (no dependency changes) and the androidApp/androidTvApp lint tasks (no app code changed). Not checked on a TV behind a real proxy reload.

Evidence

No screen changes. Playback that used to end in an error now continues. Checked with tests on e8b92d2:

main policy, new integration test:
ProgressiveDirectPlayResumeIntegrationTest > a later cut after a successful resume gets its own retry window FAILED
    androidx.media3.exoplayer.ExoPlaybackException
        Caused by: androidx.media3.datasource.HttpDataSource$HttpDataSourceException
            Caused by: java.net.ProtocolException

this branch:
MediaLoadRetryPolicyTest                      tests=16 failures=0
ProgressiveDirectPlayResumeIntegrationTest    tests=5  failures=0
SidecarSubtitleLoadErrorHandlingPolicyTest    tests=9  failures=0

Risks

A direct-play stream that keeps failing after making real progress now keeps retrying. Each retry continues from where the last one stopped, so playback still moves forward. #635 changes the same log line; whichever merges second needs a small rebase.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5; claude-fable-5-2, gpt-6.2-sol, gpt-6.2-astra (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two rounds of independent review of the full diff (Claude Opus 5.5, Claude Fable 5.2, GPT-6.2 Sol and GPT-6.2 Astra, then Sol and Astra again on the revision), reconciled and checked against the code. Fixed: any progress at all reset the window, so a trickling backend could keep a spinner up for minutes; a leftover retry count from an earlier outage; exception messages in the log could expose the server address; mislabelled log outcomes; a double retry check; and the unlogged TLS failure. Kept: sidecar subtitles also retry a mid-read TLS failure, within their existing budget.

Note

Fix direct-play retry policy to resume after a later cut instead of failing

  • Replaces the per-task first-error timestamp with a MediaLoadOutage state model in MediaLoadRetryPolicy.kt. Retry delays now use the outage's own failure count and elapsed time instead of Media3's error count and time since the task's first failure.
  • A resumable direct-play load starts a fresh retry window when the prior outage recovers: at least 20 seconds elapsed, at least 512 KiB loaded in the attempt, and a cut at a different byte offset. Before, a failure on a later cut continued the old outage and could exhaust retries.
  • Adds non-handshake SSL exceptions to Throwable.isResumableTransportFailure; handshake failures stay fatal.
  • Improves retry diagnostics: Throwable.logLabel labels exceptions with HTTP status or HTTP/2 reset codes, and the resume-decision log distinguishes scheduled retries, exhausted retries, and non-retryable failures. Exception messages are no longer logged.
  • Adds unit tests with a controllable clock and an integration test that simulates an eleven-minute interval between a successful resume and a second cut.
  • Behavioral Change: non-handshake SSL read failures are now retryable for resumable direct play, and retry logging only runs for resumable direct-play loads.

Macroscope summarized d47d274.

A progressive direct-play load is one Media3 load task for the whole
file, and its retry budget ran from the task's first failure. After a
cut that resumed, the next cut minutes later (a proxy reload, an idle
reset during a pause) was already past the 90 s window, or past the
count-derived bound left by an earlier outage, and failed on its first
retry. The player then raised an error and was rebuilt, reopening the
file from the start.

Each outage now gets its own window and count: a failure after an attempt
that loaded at least 1 MiB starts a new one. A backend that trickles a few
kilobytes and stalls again stays in the same outage and still runs out of
window. HLS keeps the old behaviour, because its segment retries start over.

A TLS read failure after progress is now resumable too. Android 10 reports
a peer that reset the connection under a read as a bare SSLException,
which nothing retried, so such a cut went straight to a player error.

The retry log now records every failed direct-play load, with the cause
chain's exception classes (plus HTTP status or HTTP/2 reset code) and no
messages, which can carry the server's address.

Refs Silo-Server#981
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 18, 2026
@silo-kody

silo-kody Bot commented Nov 18, 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 ❌

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b2fe6277-8068-4b05-889d-13a14e7a0d83
Commits

Reviewing files that changed from the base of the PR and between e8b92d2 and d47d274.

Files selected for processing: 2

  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicyTest.kt

No actionable comments were generated in the recent review.

Walkthrough

The media load retry policy now tracks per-task outage windows and classifies additional TLS read failures as resumable for progressive direct play. Unit and integration tests cover retry timing, failure classification, and playback after repeated stream cuts.

Changes: Progressive media load retry behavior

Layer / File(s) Summary
Outage tracking and retry decisions
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt
The policy tracks outage start time and failure count per load task. It resets an outage after at least 1 MiB of progressive direct-play progress, updates retry logging, and treats non-handshake SSLException instances as resumable.
Policy tests and shared test helper
android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicyTest.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/SidecarSubtitleLoadErrorHandlingPolicyTest.kt
Tests cover retry delays across outage windows, retry exhaustion, and HTTP/2 and TLS read failures. The sidecar subtitle test uses the shared load-error-info helper.
Repeated-cut playback integration test
android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/ProgressiveDirectPlayResumeIntegrationTest.kt
The harness accepts a controllable clock and simulates another cut during a resumed request. The test verifies playback ends without a player error after three requests.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Player
  participant RetryPolicy
  participant RangeFixture
  Player->>RangeFixture: Request progressive media
  RangeFixture-->>Player: Partial response ends during body
  Player->>RetryPolicy: Report load error
  RetryPolicy-->>Player: Return retry delay
  Player->>RangeFixture: Request resumed range
  RangeFixture-->>Player: Partial response ends during body
  Player->>RetryPolicy: Report load error after clock advances
  RetryPolicy-->>Player: Return retry delay for new outage
  Player->>RangeFixture: Request resumed range again
  RangeFixture-->>Player: Complete response
Loading

Possibly related issues

  • Silo-Server/silo-android issue 981 — It describes direct-play failures after progress that do not resume with a ranged request. This change updates retry behavior for subsequent connection cuts after progress.

Suggested reviewers: quick104, rxwatcher

Merge Risk: Minimal · previous review e8b92

Android direct play should now resume after later connection cuts and TLS read failures instead of failing and restarting playback. The supplied evidence shows no concrete merge-blocking defect, and the change is easy to revert.

Security architecture risk: Minimal · up to e8b92

The recovery changes remain limited to media playback. Progress is required to restart the retry window, while authentication checks and changed-file protections remain in place. No material security or failure-containment regression was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A media peer or network interruption can influence retry timing and extend playback recovery after sufficient progress. The inspected change affects the selected playback load; it does not introduce a new destination-selection or credential-granting mechanism.

Trust Boundaries and Controls

  • observed — Reopened requests continue through transport approval and fresh authentication snapshots. Session credentials remain origin-scoped. Existing ranged-resume guards send If-Range for strong validators and reject detected entity changes, which the retry policy treats as terminal.

Resilience and Maintainability Implications

  • observed — Retry admission remains bounded per outage by elapsed time and backoff. A peer supplying less than 1 MiB per attempt cannot refresh that budget. Supplying at least that much eligible progress can extend total recovery across multiple outages. The shared SSL classifier also affects sidecar cut-off accounting, where existing extraction and timeout budgets remain enforced.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main behavior change: direct play resumes after a later connection cut instead of failing. The raw summary confirms the retry-window and outage changes for resumable progressive di…
Description check Passed The description explains the problem (later mid-stream drops on direct play end in a player error), the per-outage retry window approach, the TLS read-failure change, the sidecar subtitle budget, expa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main behavior change: direct play resumes after a later connection cut instead of failing. The raw summary confirms the retry-window and outage changes for resumable progressive direct play, so the title matches the changeset's primary purpose.

Full details: Description check

Explanation

The description explains the problem (later mid-stream drops on direct play end in a player error), the per-outage retry window approach, the TLS read-failure change, the sidecar subtitle budget, expanded logging, validation steps, and risks. It matches the changeset closely.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 48726798-b743-4e16-b2c2-b3c46e466a7f
Commits

Reviewing files that changed from the base of the PR and between db87f83 and e8b92d2.

Files selected for processing: 4

  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicyTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/ProgressiveDirectPlayResumeIntegrationTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/SidecarSubtitleLoadErrorHandlingPolicyTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 labels Nov 18, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 18, 2026

Copy link
Copy Markdown

The Evidence section includes policy and integration test output, but no user-facing captures.

  • Direct-play recovery: A later connection cut now resumes playback instead of ending in an error and restarting. This shared playback policy reaches Android phone, tablet, foldable (folded and open), and Android TV. Evidence is missing for all of them; please add a recording of the cut-and-resume flow on each device, with the device and build or commit identified (both foldable states).
  • Sidecar subtitle recovery: A mid-read TLS failure can now be retried, allowing sidecar subtitles to remain available through the interruption. This shared player behavior reaches Android phone, tablet, foldable (folded and open), and Android TV. Evidence is missing for all of them; please add a recording showing the subtitle behavior through the interruption on each device, with the device and build or commit identified (both foldable states).

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

) { nowMs() }
val now = nowMs()
val outage = outageByLoadTask.compute(loadErrorInfo.loadEventInfo.loadTaskId) { _, current ->
if (current == null || (resumableDirectPlay && bytesLoaded >= MEDIA_LOAD_OUTAGE_PROGRESS_BYTES)) {

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 Kody Rules high

Large partial responses can renew the retry window indefinitely

Repeated large partial responses can restart the 90-second window indefinitely, even when failures occur rapidly or at the same endpoint. Renew the window only after 20 seconds, at least 512 KiB, and a different cut endpoint; retain the previous meaningful endpoint across small or zero-byte failures.

Also found in:

  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt:351-351

Kody rule violation: Renew media retry windows only after meaningful recovery

Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt, line 70:

Large partial responses can renew the retry window indefinitely

Renew the outage window only when at least 20 seconds have passed since the previous failure, the attempt delivered at least 512 KiB, and its cut endpoint differs from the previous meaningful cut. Retain the previous meaningful endpoint across small or zero-byte failures. As written, repeated large partial responses can restart the 90-second window indefinitely, even when they fail rapidly or repeatedly stop at the same endpoint.

**Also found in:**
- `android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt:351-351`

Kody rule violation: [Renew media retry windows only after meaningful recovery](https://kodus.siloserver.org/settings/code-review/1247142403/kody-rules/88d6152c-9f94-438c-a2da-ff2c4746e2ea?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Comment on lines +70 to +71
if (current == null || (resumableDirectPlay && bytesLoaded >= MEDIA_LOAD_OUTAGE_PROGRESS_BYTES)) {
MediaLoadOutage(startedAtMs = now, failures = 1)

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 medium

Low-bitrate resumed streams still fail on later disconnects

A second disconnect after 90 seconds can fail immediately even when playback resumed successfully, because transfers under 1 MiB retain the first outage's timestamp. Account for sustained progress over time as well as MEDIA_LOAD_OUTAGE_PROGRESS_BYTES when identifying a new outage.

Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt, lines 70-71:

Low-bitrate resumed streams still fail on later disconnects

A resumed stream that transfers less than 1 MiB before a later disconnect retains the first outage's timestamp, so a second cut after 90 seconds fails immediately even if playback ran successfully between cuts. Account for sustained progress over time as well as the per-attempt byte threshold when identifying a new outage.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

A failure started a new retry window after any attempt that loaded 1 MiB.
A load that keeps dying at the same byte re-reads from the extractor's
position on each retry, so it could load that much every time and retry
forever. Start a new outage only when the attempt ran at least 20 s past
the previous failure, loaded at least 512 KiB, and was cut somewhere else
than where the outage began. The lower threshold also lets low-bitrate
streams recover.

Refs Silo-Server#981
@silo-kody

silo-kody Bot commented Nov 18, 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 ❌

@Rhainland

Copy link
Copy Markdown
Contributor Author

Closing in favour of #993, which fixes the same retry window and opened alongside this one. The one thing this PR has that #993 doesn't, retrying a TLS read failure after progress, is suggested there.

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

Labels

bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant