Skip to content

fix(detail): label the Play button Resume when playback will resume - #622

Merged
Quick104 merged 6 commits into
Silo-Server:mainfrom
Rhainland:fix/resume-play-label
Oct 6, 2026
Merged

Quick104 merged 6 commits into
Silo-Server:mainfrom
Rhainland:fix/resume-play-label

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #337 C3

Merge order: this branch starts with the commits of #621. Merge that first; review only the commits after them here. Both change the detail page's Play button.

The iPhone series page's Play button always read "Play S1·E2", even when that episode was part-watched and the tap would ask to resume. The movie page always read "Play". The button now reads "Resume S1·E2" or "Resume" when the item has a resume point.

Approach

The label uses the PlaybackResumePoint rule the resume prompt uses (more than 30 s in and not within 5 s of the end), applied to the page's saved watch state. The tap still re-reads the server (#621), so if another device moved the position the label can be one state behind until the page reloads. The resume-or-restart dialog is unchanged.

Validation

  • Unit tests for series and movie titles and the 30-second and end-of-item thresholds: pass.
  • Manual, iPhone simulator: Breaking Bad with S1·E1 part-watched reads "Resume S1·E1".
  • scripts/ci/check-no-api-v1.sh: pass.
  • All 22 app fixes from this validation run, merged together on main (6242652): the full iOS unit suite ran 2,691 tests. The only failures are ArtworkURLTests.testDeliveryCapabilityOnIOSUsesV2RouteAndResets and ImageSizeCapabilityTests.testResetClearsCapability, which fail the same way on main. tvOS build-for-testing and the macOS build succeed.
  • Local builds used Swift 6.3.3, which needs the ThumbHash type annotations from fix(build): annotate ThumbHash cosine tables so Swift 6.3.3 can type-check them #608 to compile. That change was applied locally and is not part of this PR.

Simulator screenshots (iOS 26.5, tvOS 26.5):

a5-label

Risks

None identified.

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 subagents, xcodebuild, Xcode Simulator (simctl, Maestro), GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: A separate Claude Code reviewer agent (claude-opus-5-5) read this branch's diff against main at medium effort, checking behaviour, platform guards (iOS, tvOS, macOS), tests and commit hygiene. It found that the commit message described a change made in fix(detail): resume from the server's latest position #621's commit, and that a doc comment claimed the label always matches the tap. Both were reworded.

Problem: a series or movie detail page keeps the watch state it loaded with. When another device moved the position while the page stayed open, tapping Play showed "You stopped at" with the old time, and Resume passed that cached time to the player as an explicit position, which beats the fresh position the playback bridge reads from the server.

Fix: a Play tap on the phone/iPad/Mac detail page now re-reads the item's watch state (the same watch-detail endpoint the bridge uses) before deciding. The resume prompt shows that position and Resume passes exactly that position to the player. The page's cached state is used only when the server is known unreachable, the read fails, or it takes longer than 3 seconds, so offline playback of downloads and slow servers still respond.

Why this over passing no explicit position and letting the bridge resolve it: that alone fixes where streaming starts but leaves the prompt showing the stale time, and the explicit position is also what the downloaded-copy choice, the unreachable-server retry and the engaged-TV handoff carry. Refreshing once at the tap fixes the prompt and every one of those paths without touching the bridge or the other callers (Continue Watching cards, retries, replans). The prompt now appears whenever the fresh state has a resumable position, rather than keying on the cached in-progress flag.

Test: DetailResumeStateTests covers the decision (fresh state beats the snapshot, fresh "no progress" suppresses a stale resume, near-end suppression, snapshot fallback) and the fetch wrapper (success, error, timeout cancels the stalled fetch).
Problem: the Apple TV detail page passed the watch position it loaded with to the player. When another device moved the position while the page stayed open, Resume started from the old time, because an explicit position beats the fresh one the playback bridge reads. The phone's Play on TV button had the same problem: it sent the page's cached position to the TV.

Fix: Resume/Play on the tvOS movie and series pages (action row and the episode rail's quick play) re-reads the item's watch state with DetailResumeState before opening the player, and passes that position. The cached position is used only when the server is known unreachable, the read fails, or it takes longer than 3 seconds. Start Over skips the read. Version and track picks are captured at the press, and leaving the page cancels a pending read. Play on TV on iPhone/iPad/Mac does the same read before building the cast request.

Continue Watching cards are unchanged: their positions come from the home feed, not a long-lived page snapshot.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

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 27 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
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ea76f3d1-f74d-4972-a94c-c69f9c02407c
📥 Commits

Reviewing files that changed from the base of the PR and between 6242652 and 77e57af.

📒 Files selected for processing (8)
  • iosApp/Tests/DetailPlayLabelTests.swift
  • iosApp/Tests/DetailResumeStateTests.swift
  • iosApp/iosApp/Screens/Detail/DetailPlayLabel.swift
  • iosApp/iosApp/Screens/Detail/DetailResumeState.swift
  • iosApp/iosApp/Screens/Detail/ItemDetailView.swift
  • iosApp/iosApp/Screens/Detail/MovieDetailContent.swift
  • iosApp/iosApp/Screens/Detail/SeriesDetailContent.swift
  • iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 5, 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 Rhainland mentioned this pull request Oct 5, 2026
11 tasks
Comment thread iosApp/Tests/DetailPlayLabelTests.swift Outdated
if let position { fields.append("\"positionSeconds\":\(position)") }
if let duration { fields.append("\"durationSeconds\":\(duration)") }
if position != nil { fields.append("\"isInProgress\":true") }
return try JSONDecoder().decode(

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 medium

Decoder configuration mismatch in iosApp/Tests/DetailPlayLabelTests.swift pairs a default JSONDecoder with camelCase fixture keys, testing a different decoding convention that can miss failures in the actual server payload contract (also in iosApp/Tests/DetailResumeStateTests.swift:15-15). Use the production decoder configuration for this fixture, including .convertFromSnakeCase.

Kody rule violation: Use consistent API normalization and production-equivalent decoding

Prompt for LLM

File iosApp/Tests/DetailPlayLabelTests.swift:

Line 31:

Decoder configuration mismatch in `iosApp/Tests/DetailPlayLabelTests.swift` pairs a default `JSONDecoder` with camelCase fixture keys, testing a different decoding convention that can miss failures in the actual server payload contract (also in `iosApp/Tests/DetailResumeStateTests.swift:15-15`). Use the production decoder configuration for this fixture, including `.convertFromSnakeCase`.

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.

Fixed in 77e57af (DetailPlayLabelTests) and 72218a6 from #621 (DetailResumeStateTests): both fixtures now decode snake_case user_data into the v2 WatchRollup with HTTPClient.makeJSONDecoder() and project it through LeafItemUserData(catalog:), as the detail reads do.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks—based on your description, that addresses the decoder mismatch in both test files. Using snake_case user_data, HTTPClient.makeJSONDecoder(), and the WatchRollup → LeafItemUserData(catalog:) projection aligns the fixtures with the production detail-read path.

No further changes are needed for this suggestion.

}
resumeLookupTask = Task {
let state = await refreshedResumeState(contentId: id)
guard !Task.isCancelled, isPageVisible else { return }

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

Stale-scope playback in iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift can occur because the post-await guard checks cancellation and page visibility but not the authentication owner or server/profile scope, allowing a session or scope change while the page remains visible to start playback with an obsolete scope's resume position (also in iosApp/iosApp/Screens/Detail/ItemDetailView.swift:548-548). Capture the owner and active scope before starting the watch-state lookup task, verify both before clearing the task handle or invoking play, and invalidate the lookup when that scope changes.

Kody rule violation: Fence asynchronous results by scope and invalidation generation

Prompt for LLM

File iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:

Line 624:

Stale-scope playback in `iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift` can occur because the post-await guard checks cancellation and page visibility but not the authentication owner or server/profile scope, allowing a session or scope change while the page remains visible to start playback with an obsolete scope's resume position (also in `iosApp/iosApp/Screens/Detail/ItemDetailView.swift:548-548`). Capture the owner and active scope before starting the watch-state lookup task, verify both before clearing the task handle or invoking play, and invalidate the lookup when that scope changes.

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.

Not changing. This code comes from #621, and the same finding is answered there. A server, profile, or sign-in change takes the router out of .authenticated or re-keys the routed content, which removes this page. onDisappear then cancels the lookup, and the post-await guard drops it. On tvOS the profile and server controls are in the top bar, which is hidden while a detail page is pushed. SiloAPI.watchDetail also throws requestIdentityChanged if the owner changed during the read, so another owner's position is never used.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Understood—I withdraw this suggestion for #622.

The finding assumed the detail page could remain active across a scope change. Your explanation addresses that: routing removes or re-keys the page, onDisappear cancels the lookup, and the post-await guard rejects canceled or no-longer-visible work. watchDetail also rejects owner changes during the read.

This code belongs to #621, where the finding was already addressed; #622’s review should cover only the final label-change commit. No change requested here.

… cancellation

The Play tap's watch-state read raced a 3 second timer inside a task
group. A task group waits for every child before it returns, so when
the read was parked where cancellation does not reach, such as joining
HTTPClient's shared token-refresh flight, the tap stayed unanswered
until that wait ended instead of falling back to the page's position.

The read and the timer now run as separate tasks and the first answer
wins. The read is cancelled and left to finish in the background, and
cancelling the caller returns at once as well. Tests cover a read that
ignores cancellation and a cancelled caller.
DetailResumeStateTests decoded LeafItemUserData from camelCase keys
with a default JSONDecoder. The app never decodes it that way: the
watch read decodes the server's snake_case user_data into the v2
WatchRollup with HTTPClient's decoder and projects it. The fixtures
now take that path, so a change to the wire model or the projection
fails these tests too.
The iPhone series page's Play button always read "Play S1·E2", even when that episode was part-watched and the tap would ask to resume. The movie page always read "Play".

The button now reads "Resume S1·E2" on a series and "Resume" on a movie when the item has a resume point: more than 30 seconds in and not within 5 seconds of the end. That is the PlaybackResumePoint rule the resume prompt uses, applied to the page's saved watch state. The resume-or-restart dialog is unchanged.

DetailPlayLabelTests covers the series and movie titles and the 30-second and end-of-item thresholds.

Found during the Series validation, silo-apple#337.
DetailPlayLabelTests decoded LeafItemUserData from camelCase keys with
a default JSONDecoder, a path the app never uses. The fixtures now
decode the server's snake_case user_data into the v2 WatchRollup with
HTTPClient's decoder and project it, as the detail reads do.
@Rhainland
Rhainland force-pushed the fix/resume-play-label branch from 8364e8b to 77e57af Compare October 5, 2026 23:59
@silo-kody

silo-kody Bot commented Oct 5, 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 ❌

private func refreshedResumeState(contentId: String) async -> DetailResumeState {
guard ConnectionMonitor.shared.isServerReachable else { return .unavailable }
let libraryId = libraryId
return await DetailResumeState.load {

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

Stale watch-state results can escape the shared refresh because it neither captures nor rechecks the authentication owner, active server/profile scope, or applicable invalidation generation; capturing libraryId alone does not fence these identities, including at iosApp/iosApp/Screens/Detail/ItemDetailView.swift:550-550 and iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:624-624. Capture the request scope before loading, await into a local result, validate the scope and generation before returning usable state, and ensure callers distinguish invalidated operations from ordinary unavailability to prevent playback using an obsolete cached snapshot.

Kody rule violation: Fence asynchronous results by scope and invalidation generation

Prompt for LLM

File iosApp/iosApp/Screens/Detail/ItemDetailView.swift:

Line 838:

Stale watch-state results can escape the shared refresh because it neither captures nor rechecks the authentication owner, active server/profile scope, or applicable invalidation generation; capturing libraryId alone does not fence these identities, including at `iosApp/iosApp/Screens/Detail/ItemDetailView.swift:550-550` and `iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift:624-624`. Capture the request scope before loading, await into a local result, validate the scope and generation before returning usable state, and ensure callers distinguish invalidated operations from ordinary unavailability to prevent playback using an obsolete cached snapshot.

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.

Not changing. This helper comes from #621 (7e75465), not from this PR's own commits. It is not a shared refresh. Each caller runs it inside a task the page owns: the cast-button lookup and the Movie/Series Play lookups on iOS, and resumeLookupTask on tvOS. onDisappear cancels that task, and the post-await guard drops a cancelled result. The read calls SiloAPI.watchDetail directly, with no request pool or response cache, so no result can carry over from another scope. watchDetail captures the owner before the request and throws requestIdentityChanged if the owner changed by the time it returns. Every server, profile, PIN or sign-in change re-keys the routed content or moves the router out of .authenticated, which removes the page and cancels the lookup. A PIN recovery that lands while a lookup is running posts siloProfileSelectionRequired. Its handler clears presentedPlayer and resets the path, so a player that opened from the fallback is closed. That fallback is the same profile's snapshot, which the Play tap used directly before this change.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Understood. I withdraw this recommendation for #622.

The helper comes from #621 (7e754658), so it is outside this PR’s requested review scope. Calling it a “shared refresh” was also inaccurate.

Given the safeguards you described—page-owned task cancellation, post-await cancellation checks, watchDetail’s owner validation, routing changes that remove the page, and PIN-recovery handling that closes playback—I haven’t established a concrete path where an obsolete scope’s result reaches playback. The fallback also preserves the page-snapshot behavior that existed before this change.

The absence of a request pool or cache alone would not rule out an asynchronous race, but it does not justify demanding additional generation fencing without showing a gap in those existing safeguards. No change is warranted from this finding.

@Quick104
Quick104 merged commit 5f140ab into Silo-Server:main Oct 6, 2026
6 checks passed
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.

2 participants