Skip to content

fix(downloads): count an offline stop in the end credits as watched - #1038

Merged
Quick104 merged 1 commit into
mainfrom
fix/offline-credits-watched
Nov 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/offline-credits-watched

Conversation

@Quick104

@Quick104 Quick104 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #1037
Validation tasks: none

Other clients: Apple Silo-Server/silo-apple#1256 (same client-side approach, from Silo-Server/silo-apple#1255); Roku N/A (no downloads); Web N/A (no downloads, and the server decides watched state for streaming)

Silo-Server/silo-server#5133 has the server mark a streamed movie or episode watched once playback reaches the played file's end credits, or passes the "Mark watched at" percentage, whichever comes first. Downloads don't get that. The phone app queues a downloaded title's position and sends it to POST /api/v2/sync/progress when it reconnects. That write doesn't say which file played, so the server can only apply the percentage. A download stopped in its end credits stays unwatched and in Continue Watching after it syncs.

The app also had no way to know where the credits are with no network. Downloaded playback reads markers only from the live item detail, and the app saved none from the download manifest.

Approach

This matches Apple's fix in Silo-Server/silo-apple#1256.

  • Capture: when a video download completes, the app reads marker_segments (or credits), duration_seconds, and episode_id from the offline manifest it already fetches. It stores where the end credits start as OfflineTrackInfo.endCreditsStartSeconds. The new MarkerTimeline.endCreditsStart follows the server's CreditsLimits.EndCreditsStart: the latest credits start inside the file's end window, which is the last 450 s or 40% of an episode, and the last 900 s or 25% of anything else. Credits placed earlier in the file never count. The manifest decode for this step is separate from the tracks decode, so markers the app can't read never cost a download its audio and subtitle data.
  • Play: the phone player keeps that value for each downloaded playback run and clears it on every new load. A position it records at or past the credits start is flagged on all three download write paths: the periodic sample, the run's last position, and the exit write.
  • Sync: for a flagged sample, the queued SET_POSITION sends the full duration, which the server stores as watched, as it does a streamed stop in the credits. Below the credits the real position goes up, so the admin's percentage still applies. The local resume point keeps the real position.

The TV app has no downloaded-video playback, and audiobooks are out of scope, as on the server. Streaming is unchanged.

Validation

  • Live, phone emulator: the sandbox server ran feat(playback): mark an item watched when playback reaches its end credits silo-server#5133, with downloads on, "Mark watched at" at 95%, and a credits marker at 1080–1290 s on a 1304 s episode.
    • On main, the episode was downloaded, played in airplane mode, and left at 1187 s, inside the credits. After reconnecting, the server held it at 1187 s, unfinished, and Home kept it in Continue Watching.
    • On this branch, the downloaded episode stored a credits start of 1080 s. A control stop at 1004 s, before the credits, synced as 1004 s, unfinished. A stop at 1152 s, inside the credits, queued the full duration while the local resume row kept 1152.9 s. After reconnecting, the server marked it watched with no resume point, and Continue Watching moved on to the next episode.
  • Tests: three new tests cover the end-window rule and the manifest decode (OfflineTracksTest), and the full-duration payload with the real local position (RoomUserItemStateRepositoryTest). They call APIs this change adds, so they can't run on main. Each one fails when the fix is undone in place, either by sending the real position or by dropping the end window. ./gradlew testDebugUnitTest passes across all modules. The lint and assemble tasks CONTRIBUTING lists also pass.

Evidence: https://evidence.siloserver.org/r/silo-android/issue-1037/

Risks

  • A 100% "Mark watched at" setting: the server's percentage check is strict, so a full-duration sample isn't watched at 100%. That already happens to any offline download played to its very end.
  • Downloads made before this change have no stored credits start and keep the percentage rule until they're downloaded again.
  • The credits start is captured once, when the download completes. Credits added or moved on the server afterwards don't reach an existing download.
  • The app copies the server's end-window rule. If the server changes its window, the two can drift. One small gap exists already: the server also gives episode bounds to a file whose episode number came from its file name and that isn't linked to an episode yet, and the manifest doesn't say so.
  • Same-run seek-back: offline samples from one playback run collapse to the latest. Seeking back out of the credits and stopping mid-file syncs the mid-file position, as with the percentage today. Tracked as Offline playback loses a watched finish when a later seek-back sample replaces it #1039, which follows this merge.
  • Until the queued write is sent, an offline title stopped in its credits still offers Resume there, as one stopped past 90% does today.

Follow-ups

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets the repository's testing rules.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

Council review

Rounds: 1, last reviewed e9a78d9

Member Round 1
Sol (gpt-6.2-sol, medium) 7/10
Opus (claude-opus-5-5, medium) 8/10
Gemini (gemini-4-neon, medium) 9/10

Answered: Opus's O1 (move the rule into the manifest) is tracked with the server route in Silo-Server/silo-server#5162. Sol, which returned without posting: a skip previewed and then Back within 200 ms counts the previewed position, which main already saves as the resume point; the 10 s sampler throttle can drop a crossing before process death, as it can a 90% crossing on main.

Visual review: skipped; no screen, layout, or text changes. The captures show watch state the existing screens already display.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code; T3 Code delegated reviews (Codex, Claude, Antigravity)
  • Model(s): claude-opus-5-5 (implementation); gpt-6.2-sol, claude-opus-5-5, gemini-4-neon (plan and background reviews); claude-sonnet-5-5 (code-review finder and validation)
  • Involvement: AI-generated and verified on an emulator by the agent; not yet verified by a person
  • Adversarial review: code-review at high, which changed one helper's form and one doc line. In the plan round, Sol and Gemini showed that a 100% threshold defeats a client-only fix, and the maintainer chose to match Apple anyway. Gemini added the exit write path and the movie and episode window choice. Opus confirmed the flag and the stored value were minimal. A simplify pass ran. See Council review.

Downloaded playback queues its position for POST /api/v2/sync/progress,
which doesn't name the played file, so the server could only apply the
"Mark watched at" percentage. A download stopped in its end credits
stayed unwatched and in Continue Watching after it synced.

At download completion the app now stores where the file's end credits
start, read from the offline manifest with the server's end-window rule.
A downloaded position at or past it queues the full duration, which the
server stores as watched; the local resume point keeps the real position.
This matches the Apple app's fix.

Closes #1037

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 23, 2026
@silo-kody

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:21:15.158933Z e9a78d9 PR opened
🔒 Security Review ✅ Completed 2026-11-23T03:23:17.365985Z e9a78d9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

Offline playback now reads an end-credits start from the download manifest and tracks whether playback reaches it. Flagged progress syncs with the full duration while local resume progress keeps the recorded position.

Changes: Offline end-credits progress

Layer / File(s) Summary
Decode offline end-credits threshold
shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt, shared/src/commonMain/kotlin/org/siloserver/silo/model/download/OfflineTracks.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/OfflineTrackAssetFetcher.kt, shared/src/commonTest/kotlin/org/siloserver/silo/model/download/OfflineTracksTest.kt
The manifest decoder resolves the last qualifying credits marker and stores its start with offline track information. Tests cover marker selection and unreadable markers.
Track end-credits status
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/FinalPlaybackPositionWriter.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/PlayerInfraModule.kt
Downloaded playback compares its position with the stored threshold and passes the resulting status into periodic and final position writes.
Queue full-duration progress
shared/src/commonMain/kotlin/org/siloserver/silo/repository/port/UserItemStatePort.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/data/repository/RoomUserItemStateRepository.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/data/repository/RoomUserItemStateRepositoryTest.kt
When credits were reached and a valid duration is available, the queued payload uses the full duration. Local playback progress keeps the recorded position. A test verifies both values.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Suggested reviewers: rhainland, rxwatcher, zzebrahz

Merge Risk: Low · up to e9a78

Downloaded playback that stops in the end credits now syncs as watched. In a rare case, exiting during a quick-skip seek that jumps past the credits start can mark a title watched even though playback never reached the credits. The impact is small and recoverable, so the change is mergeable with that known edge case.

Security architecture risk: Minimal · up to e9a78

Downloaded videos can now sync as watched when playback reaches the end credits while keeping the actual stop point for offline resume. The change does not grant new access or expand who can update playback history.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The new input affects the position value for an existing account- and profile-scoped item progress operation. It does not select the server, account, profile, or target item.

Trust Boundaries and Controls

  • observed — The repository still rejects a stale playback scope by checking server, profile, credential generation, and identity generation. Temporary sign-ins still cannot enqueue durable progress for replay.

Resilience and Maintainability Implications

  • observed — The local sample and queued payload commit together. Coalescing replaces pending writes without mutating an in-flight payload, and settlement updates the local sync timestamp rather than substituting the full-duration value for the resume position.
Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Directly linked issue #1037 asks that offline playback reaching the played version's end-credits marker count as watched and sync as watched. The PR implements this for Android phone downloads. TOOL_E… Confirm from repository evidence at the reviewed head that the TV app has no downloaded-video playback path (for example, a search of the TV module for offline or download playback code that reads markers or writes progress). If a TV downlo…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: an offline stop in the end credits now counts as watched for Android downloads, and it uses the conventional fix(scope) form. The changeset adds end-credits capture fr…
Out of Scope Changes check Passed All changed areas connect to the offline credits behavior in #1037. The changes are: the manifest decode in OfflineTracks.kt and OfflineTrackAssetFetcher.kt; the end-window rule in MarkerTimeline.kt; …
Description check Passed The description is specific and on-topic. It names the bug (downloaded end-credits playback not marking titles watched after sync), the approach (end-credits start captured from the offline manifest, …
Full details: Title check

Explanation

The title names the main change: an offline stop in the end credits now counts as watched for Android downloads, and it uses the conventional fix(scope) form. The changeset adds end-credits capture from the offline manifest, a reachedEndCredits flag, and a full-duration sync payload, which matches the title.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the offline credits behavior in #1037. The changes are: the manifest decode in OfflineTracks.kt and OfflineTrackAssetFetcher.kt; the end-window rule in MarkerTimeline.kt; the reachedEndCredits flag through UserItemStatePort, FinalPlaybackPositionWriter, and PlayerInfraModule; the outbox payload change in RoomUserItemStateRepository.kt; PlayerViewModel write paths; and the three tests. The PR's own text excludes streaming, TV, and audiobooks, and the diff summaries show no changes in those areas. The supporting tests and the decode separation are part of implementing the objective.

Full details: Description check

Explanation

The description is specific and on-topic. It names the bug (downloaded end-credits playback not marking titles watched after sync), the approach (end-credits start captured from the offline manifest, full-duration sync payload for flagged samples, local resume point kept), the affected files and paths, validation on an emulator, tests, and risks. It is clearly related to the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #1037 asks that offline playback reaching the played version's end-credits marker count as watched and sync as watched. The PR implements this for Android phone downloads. TOOL_EVIDENCE and the PR summary show: MarkerTimeline.endCreditsStart selects the latest credits start in the file's end window; OfflineTracks stores endCreditsStartSeconds from the manifest; PlayerViewModel flags samples at or past that start; RoomUserItemStateRepository queues the full duration when reachedEndCredits is true, and keeps the real position locally. Two points stay open. (1) The issue names phone and TV. The PR states the TV app has no downloaded-video playback. A directory listing of the reviewed head at path 'tv' returned no entries, and the root listing was truncated, so this claim is not confirmed from repository evidence. (2) The issue's first option says to record the title watched locally. The PR instead sends full duration to the server and keeps the local position unchanged; the watched state therefore depends on the sync. The issue allows either option, but the local watched state is not set directly. Parent-context and TV coverage cannot be fully confirmed without the TV download playback code.

Resolution

Confirm from repository evidence at the reviewed head that the TV app has no downloaded-video playback path (for example, a search of the TV module for offline or download playback code that reads markers or writes progress). If a TV download playback path exists, the PR must cover it or the scope must be narrowed with the issue owner. Confirm that the sync-based watched state is acceptable for the issue's 'record watched locally' bullet.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@macroscopeapp

macroscopeapp Bot commented Nov 23, 2026

Copy link
Copy Markdown

Offline playback stopped in end credits now syncs as watched and removes the item from Continue Watching; the PR describes phone-emulator validation only. The linked evidence should show before-and-after captures of the same Home/Continue Watching screen with the same data on an Android tablet and an Android foldable both folded and open. TV is unaffected because its video player is streaming-only. Suggested fix: No diff; add those captures to the evidence page.

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

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working priority: P2 Limited scope, workaround exists, or polish labels Nov 23, 2026

@Quick104 Quick104 left a comment

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.

Adversarial review (claude-opus-5-5, reviewed e9a78d9)

One design finding, no correctness defects found. I checked the outbox coalescing key, the SyncEngine settle path (markProgressSent and clearPlaybackProgressBefore key on the event time, not the payload position, so sending duration while the local row keeps the real position settles correctly), the FinalPlaybackPosition requeue, the scope and identity check in recordPosition, the persisted OfflineTrackInfo JSON (nullable field with a default, and the reader uses ignoreUnknownKeys, so upgrade and downgrade both read), the per-load reset, and every caller. TvPlayerViewModel and AudiobookPlayerViewModel keep the false default, which is correct because neither plays video downloads.

O1 (design, low): the server should publish the end-credits start in the manifest so the client doesn't copy the rule. See the inline comment.

Reviewed with Claude Code (model claude-opus-5-5). This review was written by an AI agent.

*/
fun endCreditsStart(durationSeconds: Double, isEpisode: Boolean): Double? {
if (!durationSeconds.isFinite() || durationSeconds <= 0.0) return null
val tail = if (isEpisode) minOf(450.0, durationSeconds * 0.4) else minOf(900.0, durationSeconds * 0.25)

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.

O1 (design, low). This copies the server's credits rule into the client: the 450 s/40% and 900 s/25% tail windows, the choice between episode and movie bounds, and the latest-start-in-window pick.

Trigger: the server changes CreditsLimits, or a file only the server counts as an episode (its EpisodeNumber parsed from the file name, with no linked episode), or a zero-length credits segment. Two of these are already listed as known gaps.

Impact: a downloaded stop in the credits marks the item watched on one side and not the other, and nothing warns when the two drift apart.

Evidence: the server already computes this value for each file and sends it to Jellyfin clients as EndCreditsStart (markers.CreditsLimitsFor(...).EndCreditsStart(...) in jellycompat's PlaybackInfo). The download manifest builder in internal/downloads/manifest.go holds the selected *models.MediaFile at the line where it sets m.MarkerSegments. #5133 is still open.

Suggested repair: add end_credits_start_seconds to the manifest in #5133, computed with markers.CreditsLimitsForFile(file).EndCreditsStart(selected.EffectiveMarkerSegments(), float64(file.Duration)). Then make decodeOfflineManifestEndCreditsStart read that field, falling back to this computation only when the field is missing (servers without #5133). That keeps one source for the rule, closes both gaps, and Apple can read the same field.

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.

Agreed that the server should own this rule. This PR keeps the client copy on purpose, to match Apple's Silo-Server/silo-apple#1256 without widening silo-server#5133. A manifest field would remove the copy but still leaves the 100% setting and existing downloads open. Naming the played file on /sync/progress closes all three, so the server-side fix is tracked as Silo-Server/silo-server#5162. Once that lands, both apps drop their copies.

🤖 Claude Code (claude-opus-5-5)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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: c1900799-c49a-4cc4-80ac-a79f9d5795a0
Commits

Reviewing files that changed from the base of the PR and between bbbfdee and e9a78d9.

Files selected for processing: 10

  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/data/repository/RoomUserItemStateRepository.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/PlayerInfraModule.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/OfflineTrackAssetFetcher.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/FinalPlaybackPositionWriter.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/data/repository/RoomUserItemStateRepositoryTest.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/domain/player/MarkerTimeline.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/download/OfflineTracks.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/repository/port/UserItemStatePort.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/download/OfflineTracksTest.kt

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@Quick104
Quick104 merged commit 137fca3 into main Nov 23, 2026
11 checks passed
@Quick104
Quick104 deleted the fix/offline-credits-watched branch November 23, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline playback doesn't count reaching the end credits as watched

1 participant