Skip to content

fix(watchstate): clear watched episodes without a file when unwatching a series - #2465

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-2461-unwatch-fileless-episodes
Oct 14, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-2461-unwatch-fileless-episodes

Conversation

@Quick104

@Quick104 Quick104 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2461
Related issue: N/A
Validation tasks: changes #1252 C4/C9; changes Silo-Server/silo-apple#337 C4/C9, Silo-Server/silo-apple#338 C4/C9, Silo-Server/silo-android#347 C4/C9, and Silo-Server/silo-android#348 C4/C9

Marking a series or season unwatched leaves the series in Up Next when some of its watched episodes no longer have a file, for example episodes deleted from disk after watching. Home keeps offering the episode after the last one watched, and the only way out is removing the card by hand, which only the web app offers on every Up Next layout. This change makes the unwatch clear those episodes too, so the series leaves Up Next and Continue Watching.

Series and season unwatch expanded through EpisodeRepository.ListBySeries / ListBySeasonID, which return only episodes a library holds a file for. A watched episode whose file was deleted was skipped, so its completed progress and history stayed, and Next Up, which anchors on any completed episode, kept the series.

Approach

Series and season unwatch now clear every episode with a file plus the file-less episodes the profile still has history or progress on. Both sets come from one PartitionIDsBySeries / PartitionIDsBySeason read, the same selection show history removal adopted in #2167. File-less episodes nobody watched stay out, so a long-running show with many metadata-only episodes doesn't get thousands of hide rows.

The rule lives in a new watchstate.Service.ParentUnwatchTargets, which uses the history-or-progress filter moved from favorites.go to watchstate.WatchedItemIDs. Both the native DELETE /api/v1|v2/watched/{id} path and the Jellyfin paths use it: DELETE /UserPlayedItems/{id}, its legacy route, and a user-data update with Played=false on a series or season. Mark watched is unchanged. Native unwatch of a series or season no longer loads episode metadata and file durations it didn't use.

Apple, Android and web need no change: they already send DELETE /api/v2/watched/{seriesId} and reload Home afterwards.

Validation

  • Reproduced on a sandbox built from main: watched episodes whose library membership was removed kept the series in Continue Watching after a series unwatch. With the fix, series and season unwatch both clear it, as does the ordinary case with every file present and the separate Next Up layout. A never-watched file-less special was left alone. Request matched in operational_logs (unmarkWatched, 204).
  • New Postgres test covers series and season unwatch through Next Up; it fails on main and passes here. It is registered in scripts/ci/db-contracts.txt.
  • New Jellyfin handler test covers DELETE /UserPlayedItems and user-data Played=false on a season; it fails without the new resolver.
  • Unit tests for the target selection and the moved batching filter.
  • go test for internal/watchstate, internal/jellycompat, internal/api/handlers, internal/apiv2: pass. make lint-changed: clean.

Evidence

Home on desktop web, same profile and data, after marking 1883 unwatched: before, S1E4 is still offered; after, the series is gone. The web app's code is unchanged, so phone-width layout is unaffected.

Surface and build: web Home, sandbox from main e21984f (before) and this branch (after)

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2461/

Risks

  • The Series watched/unwatched and Next Up cases (C4, C9) change for one state: a watched episode whose file was removed. Marking its series or season unwatched now clears that episode's completed progress, so the series leaves Continue Watching and Next Up instead of staying anchored on it. With every file present the outcome is unchanged. Re-test those cases on an RC with a watched episode whose file was removed. The cross-device part of C4 stays blocked by [v1] Series #1249; this PR doesn't address it.

  • v1's affected_count for a series or season unwatch now includes the cleared file-less episodes, so a retried call can report a smaller number than the first. v2 answers 204 with no count.

  • Watch providers now get the removal of manual plays on those file-less episodes, matching what unwatch already sent for episodes with files. Jellyfin-path unplayed marks still send no provider events, as before.

  • Episodes with a NULL season_id are still missed by season-level unwatch, as they are by season mark-watched and history removal; this change does not alter that.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI, Go toolchain, Playwright (headless Chromium); Codex for the adversarial review
  • Model(s): claude-opus-5-5 (implementation and review), Claude Code's sonnet model alias (two review subagents), gpt-6.1-sol (adversarial review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: before implementation, gpt-6.1-sol reviewed the plan. Adopted: build the targets from one partition read instead of two catalog reads, and fix the Jellyfin unplayed paths in the same change. Declined with reasons in Risks: NULL season_id (shared with mark-watched, not reproducible in the sandbox data) and SQLite's bound-variable limit above 32k episodes. A three-finder Claude review of the diff found no defects; its notes are in Risks. A background adversarial review by gpt-6.1-sol of 11a605b found no defects.

🤖 Generated with Claude Code

…g a series

Marking a series or season unwatched expanded it through the episode
listings, which only return episodes a library holds a file for. An
episode watched and later deleted from disk was skipped, so its completed
progress survived and Next Up kept offering the episode after it.

Series and season unwatch now take every episode with a file plus the
file-less episodes the profile still has history or progress on, from one
partition read, the same selection show history removal uses. The native
watched endpoints and the Jellyfin unplayed and user-data routes share
the new watchstate helper. File-less episodes nobody watched stay out.

Closes #2461

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: Transient error reaching the provider (openai_compatible). Try again.

openai_compatible · gpt-6.1-sol · HTTP 502 · generalist

Provider said: Our servers are currently overloaded. Please try again later.

After fixing the issue, comment @kody review on this PR to re-run the review.

Silo Kody — review incomplete

This review did not finish. Resolve the error reported above, then retry with @kody start-review in a PR comment. Treat any comments already posted as a partial review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

​

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T18:02:41.106617Z 11a605b PR opened
🔒 Security Review ✅ Completed 2026-10-14T18:03:06.181497Z 11a605b 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.

@macroscopeapp

macroscopeapp Bot commented Oct 14, 2026

Copy link
Copy Markdown

The change is visible on Apple and Android Home, where unwatching the series or season removes it from Next Up/Continue Watching. The evidence section covers desktop web only; please add before-and-after captures of the same Home section and profile/data from each client, with the surface and build identified:

  • Apple Home: before-and-after captures showing the series before and after unwatch.
  • Android Home: before-and-after captures showing the series before and after unwatch.

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

Posted via Macroscope — Visible change evidence

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e310b464-6398-4494-b49a-91b58dec12a7
📥 Commits

Reviewing files that changed from the base of the PR and between bbef279 and 11a605b.

📒 Files selected for processing: 11
  • internal/api/handlers/favorites.go
  • internal/api/handlers/favorites_history_remove_test.go
  • internal/api/handlers/items.go
  • internal/api/handlers/watch_state_service.go
  • internal/api/handlers/watch_state_unwatch_db_test.go
  • internal/jellycompat/handlers_userdata.go
  • internal/jellycompat/parent_unplayed_test.go
  • internal/jellycompat/userdata_direct.go
  • internal/watchstate/parent_unwatch.go
  • internal/watchstate/parent_unwatch_test.go
  • scripts/ci/db-contracts.txt
💤 Files with no reviewable changes: 1
  • internal/api/handlers/favorites_history_remove_test.go

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

📝 Walkthrough

Series and season unwatch operations now include watched episodes without library files when those episodes have profile history or progress. The API and Jellyfin-compatible handlers use the expanded targets. History removal uses the shared watched-item lookup.

Changes: Parent unwatch for fileless episodes

Layer / File(s) Summary
Watched-item selection
internal/watchstate/parent_unwatch.go, internal/watchstate/parent_unwatch_test.go, internal/api/handlers/favorites.go, internal/api/handlers/favorites_history_remove_test.go
watchstate adds parent-unwatch target selection and a batched, deduplicated watched-item lookup. RemoveHistory uses the shared lookup instead of its local helper. Tests cover target selection, batching, and deduplication.
API parent-unwatch handling
internal/api/handlers/items.go, internal/api/handlers/watch_state_service.go, internal/api/handlers/watch_state_unwatch_db_test.go, scripts/ci/db-contracts.txt
The API resolves series and season targets based on the requested watched state. For unwatch requests, it adds parent targets from the watch-state store. The database test checks progress clearing and affected counts for fileless episodes, and is added to the database-contract test list.
Jellyfin-compatible parent unwatch
internal/jellycompat/userdata_direct.go, internal/jellycompat/handlers_userdata.go, internal/jellycompat/parent_unplayed_test.go
The user-data service exposes parent-unwatch targets. Played-state handlers use the requested state when resolving targets. Tests cover unmarking a season through both request handlers when an episode lacks a file.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 11a60

Unwatching a series or season now also clears watched episodes that no longer have library files. This removes the series from Up Next and Continue Watching. Tests cover the new behavior, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 9 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue #2461 requires series and season unwatch to clear file-backed episodes and file-less episodes with profile history or progress. watchstate.Service.ParentUnwatchTargets partitions each parent i…
Out of Scope Changes check Passed The changes stay within issue #2461. The moved history/progress batching helper supports the shared target-selection requirement. Native and Jellyfin route updates implement the affected unwatch surfa…
Title check Passed The title clearly and concisely describes the main change: clearing watched episodes without files during series unwatch.
Description check Passed The description directly explains the problem, implementation, affected routes, tests, validation, evidence, and known risks for the changeset.
Full details: Docstring Coverage

Explanation

Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 9 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · 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-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish labels Oct 14, 2026
@Quick104

Copy link
Copy Markdown
Contributor Author

The change is in the server's Home sections response (listHomeSections), which Apple and Android render as-is; neither app's code changes, and both already send DELETE /api/v2/watched/{seriesId} and reload Home afterwards. The evidence page shows that response on web before and after, and the API checks in the notes cover the season and separate Next Up layouts. Device captures would show the same server response on the same data, so I've left them out; a maintainer can ask for them if they want the extra confirmation.

@Quick104

Copy link
Copy Markdown
Contributor Author

@kody start-review

@silo-kody

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

@macroscopeapp

macroscopeapp Bot commented Oct 14, 2026

Copy link
Copy Markdown

Major change: series/season unwatch now resolves a different server-side episode set. The recorded Web and iOS rehearsals cover watched/unwatched and Next Up, but do not document a watched episode after its file is removed; this PR clears that episode’s completed progress, which can remove the series from Continue Watching/Next Up. The cross-device progress portion of C4 remains blocked by #1249; this PR does not resolve it. The tvOS and Android Series task tables are still Not run.

The PR must explain why the C4/C9 outcomes change; its existing rationale is that file-less watched progress otherwise keeps the series as a Next Up anchor. These cases need re-validation after merge on an RC, including a watched episode whose file has been removed. Please replace the current none changed line with:

Validation tasks: changes #1252 C4/C9; changes Silo-Server/silo-apple#337 C4/C9, Silo-Server/silo-apple#338 C4/C9, Silo-Server/silo-android#347 C4/C9, and Silo-Server/silo-android#348 C4/C9

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104
Quick104 merged commit a86d05b into main Oct 14, 2026
20 checks passed
@Quick104
Quick104 deleted the fix/issue-2461-unwatch-fileless-episodes branch October 14, 2026 18:41
Quick104 added a commit to blurbery/silo-server that referenced this pull request Oct 15, 2026
Conflicts:
- internal/api/handlers/items.go: keep the lookup and expansion split and
  carry Silo-Server#2465's played parameter, so series and season unwatch still skip
  the episode listing.
- internal/contractledger/ledger_test.go: keep the clearResumePosition row
  and Silo-Server#2425's watchlist-title wording.
- internal/recommendations/taste_signals_test.go: Silo-Server#1966's stale-abandonment
  rule gives a recent low-progress row no weight, so the cleared-position
  case moves into its table test.
- web/src/components/MediaItemMenu.tsx: keep Reset Progress ahead of
  Silo-Server#2433's personal-list entries.

Main also changed two things the reset used without a textual conflict:
- Silo-Server#1966 replaced triggerProfileRefresh with notifySignalsChanged, so
  ClearResumePosition now calls the new notifier.
- Silo-Server#2425 made viewerNoContentMutation naturally idempotent for favorites
  and watchlist writes. clearResumePosition registers its operation
  directly so it stays non_retryable, as unmarkWatched does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Marking a series unwatched leaves it in Up Next when watched episodes have no file

1 participant