Repository navigation
feat(player): resume progressive direct play transparently after mid-stream transport failures - #99
Conversation
…stream transport failures Implements #80: HTTP/2 stream resets, connection shutdowns, and premature EOF on ORIGINAL_HTTP progressive loads now retry inside Media3's load-error policy (gated on real per-attempt byte progress, tracked as deltas of Media3's cumulative load-task bytes), so the loader reopens a ranged DataSpec at the exact byte offset with no player error or remount. The authed data source captures the entity ETag, sends If-Range on ranged reopens, and aborts with a non-retryable EntityChangedException on mismatch, preventing Media3's silent 200 skip-splice across file revisions. Advertises direct_stream_resume_v1. HLS retry behavior and the ViewModel recovery ladder are unchanged. Code written by OpenAI Codex CLI (gpt-5.6-sol) from a Claude-authored spec; reviewed and verified by Claude. Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughAdds progressive direct-play resume support through capability negotiation, ETag/If-Range guards, byte-aware Media3 retry handling, player wiring, and unit/integration coverage. ChangesProgressive direct-play resume
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PlaybackClient
participant SiloPlayerFactory
participant SiloMediaLoadErrorHandlingPolicy
participant RefreshingHttpDataSource
participant MockWebServer
PlaybackClient->>SiloPlayerFactory: build original HTTP media item
SiloPlayerFactory->>SiloMediaLoadErrorHandlingPolicy: provide resumable URI predicate
SiloMediaLoadErrorHandlingPolicy->>RefreshingHttpDataSource: retry after byte-progress transport failure
RefreshingHttpDataSource->>MockWebServer: send ranged request with Range and If-Range
MockWebServer-->>RefreshingHttpDataSource: return partial response with ETag
RefreshingHttpDataSource-->>PlaybackClient: deliver resumed bytes or EntityChangedException
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 760cf359ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| val mediaLoadErrorHandlingPolicy = SiloMediaLoadErrorHandlingPolicy() | ||
| val mediaLoadErrorHandlingPolicy = SiloMediaLoadErrorHandlingPolicy( | ||
| isResumableProgressiveDirectPlay = { resumableProgressiveDirectPlay }, |
There was a problem hiding this comment.
Tie retry mode to the mounted media item
After an ORIGINAL_HTTP video sets this factory field true, it stays true until SiloPlayerFactory.buildMediaItem is called again; the audiobook screens build plain MediaItems directly (AudiobookPlayerScreen.kt:116-128), and the audiobook VM can mount REMUX/TRANSCODE HLS (AudiobookPlayerViewModel.kt:650-672). In that sequence, HLS load errors are evaluated as resumable direct play, so an early unexpected end of stream with no bytes loaded no longer gets the server-restart retry this policy previously guaranteed. Keep this state per media source/item, or reset it for non-video mounts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 69799a8. Replaced the factory-wide boolean with URI-scoped classification: buildMediaItem now stores the direct-play stream URI (resumableDirectPlayUri), and both the retry policy and the ETag entity guard match each failing load's own dataSpec.uri against it. Audiobook mounts that bypass buildMediaItem, subtitle sidecars, and HLS loads are no longer classified as resumable direct play. Also restored the unconditional retry for zero-progress "unexpected end of stream" failures, so the pre-existing server-restart resilience applies regardless of the flag state.
| val length = open(guardedDataSpec) | ||
| val responseEtag = responseHeaders.headerValue("ETag") | ||
| val previousEtag = entityEtag | ||
| if (previousEtag != null && responseEtag != null && responseEtag != previousEtag) { |
There was a problem hiding this comment.
Reject ambiguous full responses during ranged resume
When a ranged reopen carries If-Range and the entity has changed, the server can answer with a full 200 OK response instead of a 206 range, and some servers/CDNs may omit the new ETag. This check only aborts when a different ETag is present, so a 200/no-ETag response falls through; OkHttpDataSource then manually skips dataSpec.position bytes from the replacement entity, which can resume playback in the wrong file contents. Treat ranged resumes with a prior validator but no confirming range/validator as an entity change or restart from zero.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 69799a8. A ranged reopen with a prior validator now rejects a 200 response unless it carries an ETag matching the stored one — a full-body replacement entity (with or without a new ETag) raises EntityChangedException instead of being byte-skipped into the old buffer. Additionally, If-Range is only sent for strong validators per RFC 7233 (weak W/ ETags are still captured for the equality check), and the guard itself is now scoped to the resumable direct-play URI so HLS/subtitle opens skip it entirely.
…en ranged-resume validation Address review findings on the progressive range-resume feature: - Replace the factory-wide resumable boolean with URI-scoped classification: the retry policy and entity guard now match each failing load's own URI against the direct-play stream URI, so audiobook mounts that bypass buildMediaItem, subtitle sidecars, and HLS loads keep their existing retry semantics. - Restore unconditional retry for zero-progress "unexpected end of stream" failures (server-restart resilience, including first-attempt failures). - Reject a 200 response on a ranged reopen with a prior validator unless it carries a matching ETag; send If-Range only for strong validators per RFC 7233. - Engage the ETag entity guard only for the resumable direct-play URI. - Keep socket-level causes retryable when wrapped in ParserException; the parser veto now only blocks EOF-style premature-end classification. - Clear the active delegate before throwing EntityChangedException. - Route resume-decision logs through SiloLog (PLAYBACK) so they reach diagnostics bundles. Implementation drafted by OpenAI Codex (gpt-5.6) under review. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt (1)
207-224: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAvoid depending on OkHttp internal HTTP/2 exceptions
isResumableTransportFailure()still matchesokhttp3.internal.http2.StreamResetExceptionandokhttp3.internal.http2.ConnectionShutdownException, which are outside OkHttp’s public API. That makes this retry path brittle across OkHttp upgrades; prefer a public signal or a wrapper you control instead.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt` around lines 207 - 224, Update Throwable.isResumableTransportFailure() to remove direct checks for OkHttp internal StreamResetException and ConnectionShutdownException. Replace them with a stable public transport-failure signal or an application-controlled wrapper, while preserving resumable handling for EOFException and unexpected-end-of-stream ProtocolException and keeping findResumableTransportFailure() unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.kt`:
- Around line 207-224: Update Throwable.isResumableTransportFailure() to remove
direct checks for OkHttp internal StreamResetException and
ConnectionShutdownException. Replace them with a stable public transport-failure
signal or an application-controlled wrapper, while preserving resumable handling
for EOFException and unexpected-end-of-stream ProtocolException and keeping
findResumableTransportFailure() unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 147e5751-01b5-410d-a282-730e47b20392
📒 Files selected for processing (6)
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AuthenticatedDataSourceFactory.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicy.ktandroid-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SiloPlayerFactory.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/AuthenticatedDataSourceFactoryTest.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicyTest.ktandroid-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/ProgressiveDirectPlayResumeIntegrationTest.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/ProgressiveDirectPlayResumeIntegrationTest.kt
- android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/MediaLoadRetryPolicyTest.kt
- android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AuthenticatedDataSourceFactory.kt
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69799a86f2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CLIENT_VIDEO_TRANSFORMATIONS_FEATURE, | ||
| DEVICE_QUIRKS_V3_FEATURE, | ||
| SEEK_REANCHOR_V3_FEATURE, | ||
| DIRECT_STREAM_RESUME_V1_FEATURE, |
There was a problem hiding this comment.
Update the serialized feature expectations
Adding DIRECT_STREAM_RESUME_V1_FEATURE to the default V3 client_features list changes every serialized start request, but shared/src/commonTest/kotlin/org/siloserver/silo/network/api/PlaybackApiTest.kt still asserts the exact list ending at seek_reanchor_v1. As a result the shared API test for V3 start negotiation fails until the expected feature list is updated or this new feature is gated out of the default request.
Useful? React with 👍 / 👎.
| .withAuthHeaders(snapshot) | ||
| val length = open(guardedDataSpec) | ||
| val responseEtag = responseHeaders.headerValue("ETag") | ||
| if (previousEtag != null && dataSpec.position > 0L) { |
There was a problem hiding this comment.
Require a strong validator before ranged resume
When the first response only supplies a weak ETag, this branch still treats previousEtag != null as enough to validate a nonzero reopen even though withIfRangeHeader refuses to send weak validators. For servers/CDNs that return weak or missing ETags, a later 206 (or a 200 with the same weak tag) is accepted and Media3 can splice bytes from an unvalidated representation after a mid-stream reconnect; only allow the transparent resume path after a strong validator (or another byte-range-safe validator) has been confirmed.
Useful? React with 👍 / 👎.
Implements #80.
Problem
A Shield fills Media3's buffer, stops reading, and a proxy with nginx's default
send_timeout 60skills the idle HTTP/2 stream. OkHttp surfacesStreamResetException→ERROR_CODE_IO_UNSPECIFIED, which bypasses even the one-shot transient recovery and lands on a full server replan with a visible hiccup.What this does
MediaLoadRetryPolicy): HTTP/2 stream resets, connection shutdowns, and premature EOF become retryable for progressiveORIGINAL_HTTPloads that have made real byte progress — Media3's progressive loader then reopens a rangedDataSpecat the exact byte offset through the existing authed stack. No player error, nosetMediaItem+prepare, no replan, no ViewModel involvement.loadTaskId(cleaned up inonLoadTaskConcluded) — zero-progress reopens fall out of the retryable class and exhaust instead of looping. Existing 90s cumulative retry window and backoff still bound everything.RefreshingHttpDataSource): captures the response ETag per URI, sendsIf-Rangeon ranged reopens, and throws a non-retryableEntityChangedExceptionwhen the entity changed — closing the Media3 silent-skip hole where a 200 answer to a ranged request splices bytes from two file revisions. The single-flight 401 refresh is untouched.SiloLoadControlaudit deferred as the issue allows. Phone and TV share all of this viaandroid-shared.direct_stream_resume_v1added to advertised client features.Coordination
Verification
New coverage includes a real Media3 integration test (
ProgressiveDirectPlayResumeIntegrationTest: ExoPlayer + MockWebServer + the production data-source chain under Robolectric): kills the first 206 mid-body and asserts the next request carries the exactRangeandIf-Rangeand playback reachesSTATE_ENDEDwith no player error; plus zero-progress exhaustion, ETag-mismatch abort, and 416 terminal cases — each asserting no third request is issued. Policy unit tests and entity-guard tests cover the remaining matrix.Field check: debug build installed on a Galaxy S26 Ultra streaming against the updated dev server — clean
200 → 206ranged request pattern observed server-side, no errors.AI Disclosure
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
If-Range) to ensure the media hasn’t changed.Bug Fixes
Tests
Chores