Skip to content

fix: keep a failed video's failure when prepare clears an older error - #217

Merged
j0ker70 merged 2 commits into
mainfrom
fix/try-again-after-live
Nov 22, 2026
Merged

j0ker70 merged 2 commits into
mainfrom
fix/try-again-after-live

Conversation

@j0ker70

@j0ker70 j0ker70 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #212

A bug fix that makes the app match openspec/specs/player/spec.md's "Details and playback both fail" scenario, so no OpenSpec change. The maintainer subagent's plan check gave "Verdict: Build" on the second round. The first round's "Fix first" asked for the whole hand-check list, which ran as listed below.

What changed and why

  • The cause. ExoPlayer clears an error only in prepare() (ExoPlayerImpl at 1.11.1). With the network off, the live stream in the mini player failed (errorCode 2001) while the new video's links loaded. The links then failed too, so the service reported NETWORK and left the player empty. The session's queued prepare() then ran on that empty player and cleared the live stream's old error. onPlayerErrorChanged(null) took that as a player that plays again, and cleared the new video's NETWORK failure. The screen then had a details failure but no playback failure, so its one "Try again" retried only the details (sharesFailure was false), and the video area showed the empty, ended player: the disabled "Play again" at 0:00 from the issue. Without an earlier player error, that prepare() fires no error change, which is why it needed something in the mini player to fail.
  • The fix. clearsFailure(errorGone, hasItem) in PlaybackErrors.kt: PlaybackService clears the failure only while the player has an item. Play from the notification after a failure prepares the same item again, so it still clears. PlaybackConnection.prepare still clears the failure for every new start. docs/architecture.md's Failures bullet says so.
  • The regression test. TryAgainOfflineTest (emulator) reproduces it without a live stream or timing. The first video's files fail, so the player holds a network error in the mini player. Then a second video opens with the network off. The test waits until the player is ended with no item, which it is only once the session's prepare has run on the empty player, and checks that the failure is still NETWORK. Then it turns the network on and checks that the one "Try again" plays the video. With only the test commit (the test commit, ee291f5, on f0aa199), it failed on the Android 17 emulator with expected:<NETWORK> but was:<null>. With the fix, it passes.
  • Fakes. FakeNetwork switches the fake YouTube calls and AssetMedia off and on. TestVideo has a second video with the same files, which the same search finds. Both start on, so SearchThenPlayTest runs as before.
  • Test isolation. Both emulator tests now end with stopPlayback, which stops PlaybackService. The tests share one process. A service that outlives a test keeps that test's Hilt objects, so the next test's connection waited for a session forever: TryAgainOfflineTest timed out 2 of 2 times after SearchThenPlayTest before this. Android 10: the video screen's background and minimize button vanish while a video plays #211's branch, in progress, plans to build on this helper.
  • Unit test. PlaybackErrorsTest covers clearsFailure's four cases.
  • Docs. docs/testing.md describes the new test, FakeNetwork, the second test video and stopPlayback.

Not fixed here: if the old item's error reaches the service after the links' failure was reported but before Media3 sets the empty list, the old item's category replaces the new one's. In #212's case both are NETWORK. The maintainer subagent noted it as not blocking.

New dependencies

None.

Checklist

  • OpenSpec change archived, or not needed: not needed, a bug fix that makes the app match the player spec
  • docs/architecture.md updated, or the structure of the app didn't change: the Failures bullet explains the rule
  • ADR added for any decision that would be hard to reverse, or there was none: none

Checks

  • ./gradlew spotlessCheck detekt lint test testDebugScreenshotTestDefaultTestSuite assembleDebug :app:assembleDebugAndroidTest passes, and scripts/scan_screenshot_tests.py passes.

  • Pre-push gate on 56570d8, on main at f0aa199 (the last lines):

    PASS gate's own tests tests=128
    PASS branch contains origin/main
    PASS commit ee291f5 test: check Try again after an earlier player error
    PASS commit 56570d8 fix: keep a failed video's failure when prepare clears an older error
    PASS nothing uncommitted
    PASS full build and every test
    PASS the build changed no file
    PASS: the gate passed.
    
  • Emulator tests (am instrument with HiltTestRunner, both classes in one run): pass 3 of 3 on Android 17 (API 37), and pass on Android 12L (API 32) and Android 10 (API 29).

  • Hand checks, November 22, 2026, one emulator at a time: Android 17 (Dewfall_Pixel_6_API_37, -feature -HardwareDecoder), Android 12L (Dewfall_Pixel_6_API_32), and Android 10 (a temporary Pixel 4 AVD with android-29 google_apis arm64, since the machine's own one is off limits, deleted afterwards).

    • A video opened offline stays stopped after Try again when a live stream was in the mini player #212's steps, with the live stream's errorCode=2001 failure in the mini player before the second video opened. Android 17: 10 runs. 9 played after "Try again". Run 4 retried playback, and the second stream links call failed with BROKEN, a YouTube-side failure, so it showed "YouTube isn't loading right now", not this bug. Runs 6 to 10 then played 5 in a row. 5 more runs, where the live stream hadn't failed yet, also played. Android 12L: 5 of 5 in a row. Android 10: 5 of 5 in a row. Each set had one run with a 10 s wait before "Try again".
    • All three versions: Networks (off while playing, the failure, "Try again" with it on, no stale failure), mobile data only, Failures in the background, the mini player running out of data and playing on, its pause, play and close, Live, Playing (a 14 s video's pause, play, end and "Play again"), The end in the background, The background (notification title, channel and Pause), media keys, audio focus with a phone call, Leaving early, Minimizing (button, back gesture, quick double tap, while loading), Stopping (recents removal), fullscreen (landscape, the failure with "Try again", back gesture to portrait), the screen off for 10 minutes and forced Doze, and the log and media session (no link, ID or title, no Media3 tags).
    • Android 17 and 12L: Playing again after the foreground ended, and Coming back with make-uid-idle. Android 17: Android 17's background audio with hardening "throw", the picture in the background (5.7 MB/min visible, 2.2 in the background) and minimized (7.3 open, 1.8 minimized), Minimized in the background (the end of the process, minimizing while loading and going home, and a paused one after make-uid-idle), fullscreen's controls hiding and showing, its exit button, home and back, and the end of the process in fullscreen (waits at 2:34, play goes on from there), the screen timeout, a theme change, the mini player's layout at font 2.0, and A video that can't decode, minimized (on a boot without -feature -HardwareDecoder: the mini player plays its sound, and the video screen says "This video can't play on this phone.").
    • Android 10: Dismissing, A notification left behind, and the back gesture on Search with the mini player (the sound plays on, and the notification reopens Search with the mini player).
    • Not run: three-button navigation and keyboard layout of the mini player, the minimize animation watch, fullscreen controls with a hardware keyboard, the accessibility timeout and TalkBack, the cutout and largest-font fullscreen title, Android 17's bar icons with a keyboard, fullscreen on large screens (no foldable or tablet AVD), and on Android 10 a long 1080p video and the picture's bytes. These are layout and timing checks of code this PR doesn't change.
    • Found, on main, not from this PR: on Android 10 in landscape with three-button navigation, when the bars show, the navigation bar (x 2148 to 2280 of 2280) covers fullscreen's exit button at about x 2158, so a tap there goes to the navigation bar. The back gesture still exits. "Fullscreen on a phone" asks that the bars cover no part of the control row. It needs its own issue.

CodeRabbit

Reviewed 56570d8: "No actionable comments were generated", with no inline, nitpick or outside-diff comments. Its title, linked-issue and out-of-scope checks passed. Nothing to fix or decline.

Reviewer

Final verdict: Ready

  • Round 1 (Needs changes): run the hand checks and the gate before closing A video opened offline stays stopped after Try again when a live stream was in the mini player #212, push under a typed branch name, and note that the unit test only covers the rule. The hand checks, the gate, the branch name and this description cover them.
  • Round 2 (Ready): one Should fix, done: docs/testing.md's AssetMedia bullet now names SearchThenPlayTest as the test that checks the request counts.
  • Its question for the maintainer: should the Android 10 navigation bar over fullscreen's exit button get its own issue on the board?

🤖 Generated with Claude Code

- TryAgainOfflineTest reproduces #212 without a live stream or timing:
  the first video's files fail, so the player holds a network error in
  the mini player, and then a second video opens with the network off.
  It checks that the failure is still NETWORK once the session's prepare
  has run on the empty player, and that the one "Try again" then plays
  the video. It fails on main with "expected NETWORK but was null".
- FakeNetwork switches the fake YouTube calls and AssetMedia off and on,
  and TestVideo gets a second video with the same files, which the same
  search finds. Both start as before, so SearchThenPlayTest is unchanged.
- Both tests end with stopPlayback, which stops PlaybackService, because
  a service that outlives a test keeps that test's Hilt objects, and the
  next test's connection then waits for a session forever. The new test
  timed out that way after SearchThenPlayTest.
- docs/testing.md describes the tests and the fakes.
- ExoPlayer clears an error only in prepare. When a video's links fail,
  the player is left empty, and the session's prepare then clears the
  error of the item before it, such as a live stream that failed in the
  mini player while the links loaded. PlaybackService took that as a
  player that plays again and cleared the new video's failure, so the
  video screen's one "Try again" retried only the details, and the
  video stayed stopped (#212).
- clearsFailure clears it only while the player has an item, so play
  after a failure still clears it, and an empty player keeps the
  failure that its links reported.
- docs/architecture.md's Failures bullet says so.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change updates playback failure handling so an error-free but empty player retains its failure. It adds configurable offline test fakes and an integration test that verifies a video can play after network access is restored and the user taps “Try again.”

Changes: Offline playback retry

Layer / File(s) Summary
Offline playback test fakes
app/src/androidTest/kotlin/io/github/dewfallapp/fake/*, docs/testing.md
The fakes now support two video IDs and separate YouTube and media reachability flags. Unreachable services return network failures, and AssetMedia throws IOException when media is unreachable.
Playback failure retention
core/playback/src/main/kotlin/io/github/dewfallapp/core/playback/*, core/playback/src/test/kotlin/io/github/dewfallapp/core/playback/PlaybackErrorsTest.kt, docs/architecture.md
PlaybackService clears a failure only when the error is gone and the player has a current item. A unit test checks the predicate. The architecture documentation describes the condition.
Offline retry integration test
app/src/androidTest/kotlin/io/github/dewfallapp/{TryAgainOfflineTest.kt,StopPlayback.kt,SearchThenPlayTest.kt}, docs/testing.md
The new integration test checks that a second video plays after network access returns and the user taps “Try again.” Both emulator tests stop playback during teardown. The testing documentation describes the test and fake setup.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Test as TryAgainOfflineTest
  participant Network as FakeNetwork
  participant YouTube as FakeYouTubeModule
  participant Player as PlaybackService
  Test->>Network: Disable network
  Test->>YouTube: Open second video
  YouTube-->>Test: Return NETWORK failure
  Player->>Player: Retain failure while player has no item
  Test->>Network: Restore network
  Test->>YouTube: Tap “Try again”
  YouTube-->>Player: Provide video details and stream links
  Player-->>Test: Play second video
Loading

Possibly related PRs

  • dewfallapp/dewfall#206: This PR changed playback lifecycle handling in PlaybackConnection, which is part of the playback path modified here.
  • dewfallapp/dewfall#209: This PR introduced the emulator-test harness and fakes that this change extends.
Merge Risk: Minimal · up to 56570

Playback failures are now kept when the player has no item. This lets Try again retry both the details and the playback after a new video fails offline. The change is small and covered by a unit test and a new emulator test. No merge-blocking risk was found.

Security architecture risk: Minimal · up to 56570

The change preserves a failed video's error when an empty player clears an older error. New playback starts and service teardown retain their existing reset behavior. No introduced security, ownership, or failure-containment risk was identified.

Pre-merge checks: Passed 3

Check name Status Explanation
Title check Passed The title uses the conventional commit type "fix" with a colon and space, so it meets the title format requirement. It describes the main change: the PR changes the failure-clearing rule so that a que…
Linked Issues check Passed Objective [#212]: after a failed new video, one "Try again" must retry both details and playback, as openspec/specs/player/spec.md's "Details and playback both fail" scenario requires.

Evidence at he…
Out of Scope Changes check Passed Each changed area supports the #212 fix or its regression test:
- core/playback PlaybackErrors.kt and PlaybackService.kt: the clearsFailure rule and its call site. This is the fix.
- core/playback P…
Full details: Title check

Explanation

The title uses the conventional commit type "fix" with a colon and space, so it meets the title format requirement. It describes the main change: the PR changes the failure-clearing rule so that a queued prepare() on an empty player no longer clears a failure reported for the current video. The title is specific and matches the changeset (PlaybackService, PlaybackErrors.clearsFailure, and the new TryAgainOfflineTest).

Full details: Linked Issues check

Explanation

Objective [#212]: after a failed new video, one "Try again" must retry both details and playback, as openspec/specs/player/spec.md's "Details and playback both fail" scenario requires.

Evidence at head:

  • PlaybackErrors.kt defines clearsFailure(errorGone, hasItem) = errorGone &amp;&amp; hasItem. The doc comment names the cause: an empty player's prepare() clears an older item's error.
  • PlaybackService.kt onPlayerErrorChanged calls clearsFailure(error == null, player.currentMediaItem != null) before sessions.clearFailure(). A failure that the links reported therefore survives the empty-player prepare. The screen's retry then covers both failures.
  • The PR adds TryAgainOfflineTest, which reproduces the bug without timing. The PR reports that it failed on the base commit (expected:&lt;NETWORK&gt; but was:&lt;null&gt;) and passes with the fix. I did not run the emulator test. This result rests on the author's report.
  • Hand checks reported in the PR description: Android 12L 5 of 5 in a row, Android 10 5 of 5 in a row, Android 17 five runs in a row (runs 6 to 10) after one run that hit a YouTube-side BROKEN failure. This meets the issue's "at least 5 runs in a row" criterion on all three versions. The Android 17 result is also author-reported.

Stack: no stack review evidence was supplied. Only the current PR contributes to this objective. No other stack member is relevant.

Not addressed, by the PR's own statement: the race where an older item's error replaces the new failure category before Media3 sets the empty list. The issue does not require this. In #212's case both categories are NETWORK. The objective is therefore Addressed for the reported behavior.

Rules: openspec/specs/player/spec.md ("Details and playback both fail") and docs/testing.md ("Checking the player by hand"). The issue's acceptance criteria are coding and manual-check items. Manual checks are not coding requirements, so they support the PASS but do not decide it.

Full details: Out of Scope Changes check

Explanation

Each changed area supports the #212 fix or its regression test:

  • core/playback PlaybackErrors.kt and PlaybackService.kt: the clearsFailure rule and its call site. This is the fix.
  • core/playback PlaybackErrorsTest.kt: unit tests for the four clearsFailure cases. Supports the fix.
  • androidTest TryAgainOfflineTest.kt: the regression test for #212.
  • androidTest fake/FakeNetwork.kt, AssetMedia.kt, FakeYouTubeModule.kt, TestVideo.kt: network-off switches and a second test video. The regression test needs these to force the failure sequence. SearchThenPlayTest keeps its behavior because both videos start with the network on.
  • androidTest StopPlayback.kt and SearchThenPlayTest.kt: a stopPlayback teardown. The PR says this prevents a retained service from making the next emulator test wait. It supports the new test running in the same process.
  • docs/architecture.md and docs/testing.md: document the new rule, the test, the fakes and stopPlayback. Documentation for the change itself is in scope.

No change was found that is unrelated to #212. The PR's Android 10 navigation-bar finding is a separate main-branch issue. The PR does not change code for it, and the PR says it needs its own issue.

I did not read the whole-PR diff. The diff read failed because the changed blobs are missing from the checkout. The file list comes from the supplied summary. The summary is consistent with the head source I read for PlaybackErrors.kt and PlaybackService.kt.

Rules: AGENTS.md scope rules as applied to this review. Supporting tests and docs count as in scope when they implement the objective.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f0aa199 and 56570d8.

Files selected for processing: 12

  • app/src/androidTest/kotlin/io/github/dewfallapp/SearchThenPlayTest.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/StopPlayback.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/TryAgainOfflineTest.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/fake/AssetMedia.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/fake/FakeNetwork.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/fake/FakeYouTubeModule.kt
  • app/src/androidTest/kotlin/io/github/dewfallapp/fake/TestVideo.kt
  • core/playback/src/main/kotlin/io/github/dewfallapp/core/playback/PlaybackErrors.kt
  • core/playback/src/main/kotlin/io/github/dewfallapp/core/playback/PlaybackService.kt
  • core/playback/src/test/kotlin/io/github/dewfallapp/core/playback/PlaybackErrorsTest.kt
  • docs/architecture.md
  • docs/testing.md

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

@j0ker70
j0ker70 merged commit c2a4cd8 into main Nov 22, 2026
3 checks passed
@j0ker70
j0ker70 deleted the fix/try-again-after-live branch November 22, 2026 11:31
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.

A video opened offline stays stopped after Try again when a live stream was in the mini player

1 participant