Repository navigation
fix(audiobook): start a fresh session when the server expired the old one - #708
Conversation
… one After an outage longer than the server's session grace, the server stops the audiobook's playback session. The next stream request then gets 410, the recovery replan gets 404 "Playback session not found", and the player showed that as a terminal error: Play did nothing and the viewer had to leave the player and start again. A replan or reanchor that answers session-not-found now starts a fresh session for the same file at the position the player held, the way the heartbeat-driven renewal already did. Any other playback failure leaves Play (and the TV error screen's new Retry action) able to start playback again at the current position, and the TV error screen now has a focused action and a Back action instead of none.
Three gaps in the expired-session recovery: - A server reanchor that failed for any reason other than an expired session only set the error and kept the old stream, so Play and the TV Retry action had nothing to restart. It now ends the stream the same way a failed replan does, keeping the seek target as the position to resume. - After a failure cleared the stream, the 250 ms position poll kept reading the outgoing Media3 item and wrote its player-relative time over the position Retry resumes from. Polls of any item other than the published stream are now ignored. - A renewal driven by a progress 404 could replace a seek's renewal of the same expired session and resume at the last reported position instead of the seek target. Only one renewal now runs per stale session.
…d the error screen
…r a failure" The change covered the server-reanchor failure path and lifecycle-driven renewal, which audiobooks on Android don't use today (they always direct-play), and review found it kept the pre-seek position on retry. Leave those paths as they were until a server-produced audio stream exists to test them against.
|
Warning Review limit reachedThis review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Next included review available in 20 minutes. View limit details
|
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:
|
|
Evidence is incomplete:
The linked evidence page should show the phone and TV captures as well, including a recording of the TV error screen’s focus landing on Retry/Back. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| capabilities: ClientCodecCapabilities? = null, | ||
| clientPlaybackContext: ClientPlaybackContext? = null, | ||
| ) { | ||
| val profileId = profileRepository.getActiveProfileId() ?: return |
There was a problem hiding this comment.
Race condition identified in session renewal: a newer seek or track load can advance loadGeneration while profileRepository.getActiveProfileId() suspends, and the subsequent increment makes the obsolete renewal current again, allowing its old position to replace newer playback intent. Capture loadGeneration before the lookup and afterward reject renewal if the generation changed, isClosing is true, or _uiState.value.sessionId no longer matches staleSessionId.
Also found in:
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudiobookPlayerViewModel.kt:1247-1247
Kody rule violation: Revalidate asynchronous ownership before publication, launch, and cleanup
val generationBeforeProfileRead = loadGeneration
val profileId = profileRepository.getActiveProfileId() ?: return
if (
generationBeforeProfileRead != loadGeneration ||
isClosing ||
_uiState.value.sessionId != staleSessionId
) return
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudiobookPlayerViewModel.kt:
Line 294:
Race condition identified in session renewal: a newer seek or track load can advance loadGeneration while profileRepository.getActiveProfileId() suspends, and the subsequent increment makes the obsolete renewal current again, allowing its old position to replace newer playback intent. Capture loadGeneration before the lookup and afterward reject renewal if the generation changed, isClosing is true, or _uiState.value.sessionId no longer matches staleSessionId.
**Also found in:**
- `android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudiobookPlayerViewModel.kt:1247-1247`
Suggested Code:
val generationBeforeProfileRead = loadGeneration
val profileId = profileRepository.getActiveProfileId() ?: return
if (
generationBeforeProfileRead != loadGeneration ||
isClosing ||
_uiState.value.sessionId != staleSessionId
) return
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.
Fixed in 37d6d4b: the renewal records the load generation before the profile lookup and stops if it changed, the player is closing, or the session ID changed.
There was a problem hiding this comment.
Thanks—the guard described in 37d6d4b42 addresses this race by rejecting an obsolete renewal after the profile lookup, before it can advance loadGeneration and override newer playback intent.
I haven’t independently verified the commit, but the described fix matches the suggestion.
| startSingleFileSession( | ||
| fileId = fileId, | ||
| profileId = profileId, | ||
| startGlobal = state.positionSeconds, | ||
| generation = generation, |
There was a problem hiding this comment.
Resume offset loss occurs when the initial single-file session start fails: loadDetail resolves startGlobal, but neither loadDetail nor the failed start publishes it to uiState.positionSeconds before Retry reads state.positionSeconds, causing a book opened at a saved or explicitly requested nonzero position to restart at 0:00. Retain the attempted start position on failure and use it for the next startSingleFileSession call.
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudiobookPlayerViewModel.kt:
Line 1250 to 1254:
Resume offset loss occurs when the initial single-file session start fails: loadDetail resolves startGlobal, but neither loadDetail nor the failed start publishes it to uiState.positionSeconds before Retry reads state.positionSeconds, causing a book opened at a saved or explicitly requested nonzero position to restart at 0:00. Retain the attempted start position on failure and use it for the next startSingleFileSession call.
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.
Fixed in 37d6d4b: the single-file start publishes its start position before the request, and position polls are ignored while no stream is published, so Retry resumes at the saved position instead of 0:00.
There was a problem hiding this comment.
Thanks for fixing this in 37d6d4b42. Publishing the attempted start position before the request and ignoring position polls while no stream is published addresses the reported offset loss: Retry retains the saved or explicitly requested position instead of restarting at 0:00.
|
Not adding tablet/foldable captures. The recovery logic is in the shared ViewModel, and the Retry control's layout is unchanged from the existing error state. The phone and Android TV runs on the evidence page show the recovery flow. |
…nd retry - A session renewal claimed the load generation only after the active profile lookup returned. A seek, track load or close in that window was then superseded by the older renewal, which restarted at its old position. The renewal now notes the generation before the lookup and gives up if it moved, the player is closing, or the session changed. - When the first start of a single-file book failed, Retry resumed from 0:00 instead of the saved position: the position was set only once a session started, and the 4 Hz poll of the empty player then wrote 0 over it. The start position is now published before the request, as the multi-part path already does, and polls are ignored while no stream is published, so a seek made in the error state is recorded directly.
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 latest commit changes the user-visible retry position: after a failed first single-file start, retry now preserves the saved or sought position. This shared ViewModel reaches the phone app on phones, tablets, and foldables (folded and open), as well as Android TV. The Evidence section identifies phone and TV runs, but not tablet or foldable captures; the linked page should show this retry flow on those missing form factors. Suggested fix: No diff; add a recording of a failed start followed by retry at a nonzero position on a tablet and a foldable, both folded and open. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Quick104
left a comment
There was a problem hiding this comment.
Review of 37d6d4b. One finding, inline below. I'm fixing it in a commit on this branch, so there's no need to change it yourself.
🤖 Claude Code (claude-opus-5-5)
…ssion A replan that answers 410 playback_session_ended means an administrator stopped the session, and the server answers that way so the player exits instead of starting a fresh one. The replan classifier treated it like any other failure, which left canRetryPlayback true: the phone Play button and the TV Retry action then started a new session with one tap. Classify it as Ended and keep Retry off while the UI state carries sessionEndedByServer. Phone Play stays disabled and the TV error screen offers only Back, as before this branch. A newly published session clears the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Review summaryReviewed head: Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green) The PR fixes a real gap that blocks Android's network-interruption validation case (C5 on #349 and #350). After an outage longer than the server's session grace, the audiobook player now starts a fresh session where it used to stop for good. It hooks in at the right place: the replan and reanchor paths that already receive the server's "session not found" answer. The shared session lifecycle never reports a missing sequenced session, so the old renewal path couldn't run for audiobooks. Video playback and the shared lifecycle are unchanged. Addressed in this review
Left for maintainers
Verification
ValidationNo case recorded as passed on the 1.0 board touches the audiobook player. User manual and parity
🤖 Claude Code (claude-opus-5-5) |
| AudiobookReplanRecovery.Ended, | ||
| AudiobookReplanRecovery.Fail -> | ||
| _uiState.update { it.copy(error = result.message.ifBlank { "Seek failed" }) } |
There was a problem hiding this comment.
Incomplete session cleanup in the seek-reanchor Ended branch only sets error after a 410 playback_session_ended response, leaving sessionEndedByServer false and retaining the stream, session, and unpaused state so buffered audio can continue after the administrator's stop. Handle Ended separately with applyFailedSessionStart(message, expectedSessionId = sessionId, sessionEndedByServer = true), as onPlayerError does.
AudiobookReplanRecovery.Ended -> applyFailedSessionStart(
result.message.ifBlank { "Seek failed" },
expectedSessionId = sessionId,
sessionEndedByServer = true,
)
AudiobookReplanRecovery.Fail ->
_uiState.update { it.copy(error = result.message.ifBlank { "Seek failed" }) }
Prompt for LLM
File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudiobookPlayerViewModel.kt:
Line 1412 to 1414:
Incomplete session cleanup in the seek-reanchor Ended branch only sets error after a 410 playback_session_ended response, leaving sessionEndedByServer false and retaining the stream, session, and unpaused state so buffered audio can continue after the administrator's stop. Handle Ended separately with applyFailedSessionStart(message, expectedSessionId = sessionId, sessionEndedByServer = true), as onPlayerError does.
Suggested Code:
AudiobookReplanRecovery.Ended -> applyFailedSessionStart(
result.message.ifBlank { "Seek failed" },
expectedSessionId = sessionId,
sessionEndedByServer = true,
)
AudiobookReplanRecovery.Fail ->
_uiState.update { it.copy(error = result.message.ifBlank { "Seek failed" }) }
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Problem
Related issue: Silo-Server/silo-server#1253
Validation tasks: unblocks #349 C5; unblocks #350 C5
If the server is unreachable long enough for an audiobook's playback session to expire (about 70 s or more), the Android player can't recover once it's back. The next seek outside the buffer, or the next chapter, stops with "Playback session not found", and Play does nothing; the user has to leave the player and start again. On Android TV the error screen has nothing to focus, so the remote can't even dismiss it.
The player now starts a new session at the same position when the server reports the old one is gone, and every remaining error offers a retry.
Approach
After expiry the server answers the stream with 410 and replan or progress with 404
not_found"Playback session not found"; the client already recognises that problem. Audiobook sessions are sequenced v3 sessions, for which the shared session lifecycle only logs a 404, so the audiobook's existing renewal path never ran. A replan or reanchor that gets session-not-found now starts a fresh session at the player's position through the same renewal code. Any other failure sets a retry state: on phone and tablet Play stays enabled and starts playback again, and on TV the error screen shows a focused Retry button and Back. Video playback and the shared session lifecycle are unchanged. On TV, the error screen's Back, the Back key and the Stop button now share one exit routine.A renewal checks that it is still current after looking up the profile: a seek, track load or close made during that lookup wins. Retry keeps the position the book was opening at, or the position the user sought while the error showed, instead of starting at 0:00. Player position polls are ignored while no stream is loaded, so the empty player can't reset that position.
Validation
ReflowStyleTest > line height flows from settingsin the phone app, which this change doesn't touch.e6df1d8ed, server cut by stopping the network relay, session expiry confirmed through the admin sessions API. Phone: before, an 80 s cut then Next chapter gave "Playback session not found" and Play didn't recover. After, an 85 s cut followed by a seek, and a 170 s cut with a seek during the outage, both started a fresh session and kept playing (at 2:00:12 and 3:00). Android TV (Android 14): before, a full-screen error with nothing to focus; after, two runs recovered at the next chapter, and the error screen shows Retry focused with Back below it.dc1101a): a replan that answers 410playback_session_ended(an administrator ended the session) no longer offers Retry. The classifier test covers the new outcome, and both apps compile. Not run on a device.Evidence
Evidence: https://evidence.siloserver.org/r/silo-android/pr-708/
Surface and build: Android phone (Android 16) and Android TV (Android 14) audiobook player, Hours of Static; before on
origin/maine9c410096, after on this branch; same synthetic book.Risks
The server-reanchor path (seeking outside the window of a server-produced stream) still has no retry for failures other than an expired session, and a retry there could restart at the pre-seek position. Android audiobooks always direct-play today, so that path doesn't run; it should be fixed together with any server-produced audio route (Silo-Server/silo-server#3175).
While a player is still playing from its buffer after an outage, progress reports keep failing until it needs more data, which is when the new session starts. Starting it on the first failed progress report would change the session lifecycle that video shares, so that is left for a follow-up.
A same-part seek made while a renewal request is in flight is lost: the renewal starts at the position it captured. The replan path on main has the same window.
Checklist
AI Disclosure
37d6d4b): Retry after an administrator-ended session was fixed indc1101a; a paused book starting when a new stream mounts predates this PR and is tracked in [bug] Paused audiobook starts playing when a new part or session stream loads #779.Note
Start a fresh audiobook session when the server expired the old one
AudiobookReplanRecoveryto classify failed replan and reanchor results asStartFreshSession,Ended, orFailin AudiobookPlayerViewModel.kt. Missing-session errors trigger a fresh session at the current position; server-ended sessions are recorded in UI state and block retry viacanRetryPlayback.retryPlaybackso the play control restarts detail loading, a timeline track, or a single-file session from the stored position when retry is available.renewExpiredSessionagainst races: renewal results are discarded when a newer load, seek, or close occurred, and ready sessions returned late are stopped.togglePlaynow retries playback instead of only toggling pause whencanRetryPlaybackis true;applyFailedSessionStarttakes a newsessionEndedByServerargument.Macroscope summarized dc1101a.