Skip to content

fix(realtime): name the series on watched and progress events - #2504

Merged
Quick104 merged 8 commits into
Silo-Server:mainfrom
rangoDJ:fix/user-state-series-id-796
Oct 29, 2026
Merged

Quick104 merged 8 commits into
Silo-Server:mainfrom
rangoDJ:fix/user-state-series-id-796

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #796
Follows: #857 (merged), which left this case open: the uncached-episode thread. No other open PR depends on this.
Validation tasks: changes #1252 C4, C9

Why C4 and C9 change: Their recorded roll-up of watched state per series and season changes: after another device marks or plays an episode this page hasn't loaded, the open series page now updates its seasons instead of staying stale until a reload. Re-validate both after merge; this doesn't touch C4's separate block on #1249's progress rule. C3 (playback and resume) and C8 (hierarchy) don't change.

#857 made the web's realtime refresh targeted: a user-state event refreshes only the cached queries it can tie to the event's item. A series page caches the series, its season list, and the episodes of the season it shows. When another device plays or marks an episode outside those episodes, the event names only the episode. Nothing in the cache links it to the series, so the series' watched totals and its seasons' progress stay stale until a reload.

The event payload already has a series_id field, but the server leaves it empty for watched and progress events.

Approach

Of the two options in #857's thread, this fills the existing series_id and refreshes that series, instead of refreshing every aggregate list whenever the parent is unknown, which would bring back the unrelated refreshes #857 removed.

  • Watched marks (SetWatchedState): resolveWatchedTargets already loads a season's or an episode's row to check access. It now also returns that row's series, and the watched event carries it. A series mark still names only the series itself, and a movie names none.
  • Progress (SyncProgress, v1 and v2): after the writes, the batch's item IDs are looked up in one episodes query, and each episode's event carries its series. A series is named only for an episode the viewer may see: one the v2 sync already access-checked, or, for the v1 sync's unchecked IDs, one the viewer's scope allows. If the lookup fails, the events still go out, without a series, as before.
  • Resume resets (ClearResumePosition, from feat(progress): reset a partly watched item's resume position #2440): the reset's progress event names an episode's series too, from the target it already loads.
  • Web: handleUserStateEvent passes series_id to the surface refresh. relatedItemIds then counts the series and its cached seasons as related, so the series detail, the season list and the season pages refresh. The series' other cached episodes don't, because one episode's change doesn't move them.

No API contract changes: series_id is an existing, optional field of the user_state.changed payload.

Validation

Run in WSL2 and on Windows:

  • Server:
    • TestSyncProgressEventsNameTheEpisodeSeries: one lookup for the batch, an episode's event names its series, a movie's doesn't, and a failed lookup still publishes.
    • TestParentUnwatchClearsEpisodesWithoutLibraryFilePostgres: now also checks the watched event's series_id for a season, for a series (empty) and for an episode, against Postgres.
    • internal/api/handlers builds and vets; changed-package lint is clean.
  • Web:
    • mediaSurfaceRefresh.test.ts: an uncached episode's event with a series refreshes the series detail, its season list, its season pages and its open season's episodes, but not the series' other episodes or another series.
    • RealtimeEventsProvider.test.tsx: a progress event's series_id reaches the refresh.
    • All 61 tests in both files pass; TypeScript, ESLint and Prettier are clean.
  • In a browser: see Evidence.

Evidence

The same local server data on both builds: a two-season show, with Season 1's episode list loaded by the page and Season 2's not. The series page is open in the browser, and a second session (another device, through the API) marks S2E1 watched. Desktop and phone width (375 px), dark theme.

Page open After the other device marks S2E1 watched
Before (main at 27310a5ef) Series page on main: Season 2 shows 2 episodes, none watched Same page after the mark: Season 2 still shows 2 episodes with no progress, though the server reports 1 of 2 watched
After (this branch) Series page on this branch: Season 2 shows 2 episodes, none watched Same page after the mark: Season 2 now shows 1 of 2 episodes with a progress bar, without a reload
Before, phone width Phone width on main: Season 2 shows 2 episodes, none watched Phone width on main after the mark: Season 2 still shows 2 episodes with no progress
After, phone width Phone width on this branch: Season 2 shows 2 episodes, none watched Phone width on this branch after the mark: Season 2 shows 1 of 2 episodes with a progress bar, without a reload

On this branch, the page refetched the series and its seasons a moment after the event and left the "similar titles" row alone. On main, the season stayed at "2 episodes" while the server's season list already reported one watched.

Surface and build: web, Vite dev builds of 27310a5ef and this branch, each against its own server build, on one local database with generated media.

Risks

  • One extra indexed episodes query per progress sync batch that publishes events. A batch is at most a few hundred items, and the query is by primary key.
  • Clients that ignore series_id are unaffected; it was already in the payload, just empty.

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 (Claude desktop app, Code tab)
  • Tool(s): Claude Code, GitHub CLI, Go, pnpm, Vitest, the in-app browser
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Self-review. It checked that the series from a watched mark comes from the row already loaded for the access check (no extra query), that a failed episode lookup doesn't drop progress events, and that the web adds only the series and its cached seasons, not the series' other episodes, so fix(web): scope realtime query invalidation by item #857's narrowing holds for everything else.

🤖 Generated with Claude Code

Note

Include parent series ID on watched and progress realtime events

  • ItemsHandler.resolveWatchedTargets in items.go now returns the parent series ID for season and episode targets, and watch_state_service.go passes it into watched and resume-clear user-state events
  • ProgressHandler.SyncProgress in progress.go resolves series IDs for a batch in one episode lookup, scoped via LibraryLookup.FilterAccessibleContentIDs for unchecked items; lookup failures are logged and events publish without a series ID
  • The web handleUserStateEvent in RealtimeEventsProvider.tsx and relatedItemIds/scheduleMediaSurfaceInvalidation in mediaSurfaceRefresh.ts invalidate the named series, its seasons, and cached season details; coalescing keeps an earlier series ID when a later event omits it
  • Router wiring in router.go supplies the episode repository as the progress handler's new EpisodeLookup dependency
  • Behavioral Change: movie, ebook, and series targets publish events without a series ID; only season and episode targets name their parent series

Macroscope summarized 3f2ce08.

A series page refreshes its seasons and watched totals from user-state
events, but since Silo-Server#857 only for items it can tie to the series from its
cache. When another device marked or played an episode the page hadn't
loaded, the event named only the episode, so the series and its seasons
stayed stale until a reload (Silo-Server#796).

The server now fills the event's existing series_id: watched marks take
the season's or episode's series from the target they already resolve,
and a progress sync looks up the batch's episodes in one query. The web
refreshes the named series and its cached seasons, without the series'
other episodes.

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

silo-kody Bot commented Oct 15, 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 15, 2026

Copy link
Copy Markdown

The realtime watched/progress refresh changes the series page’s watched totals and season progress (web/src/hooks/queries/mediaSurfaceRefresh.ts); the evidence covers desktop only, so please add before-and-after mobile web captures of the same series page (or a recording covering both viewports).

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 go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 15, 2026
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 4463ebc2-1fe5-4947-9b52-6b627fafdc1e
📥 Commits

Reviewing files that changed from the base of the PR and between 18da931 and 5e25719.

📒 Files selected for processing: 4
  • internal/api/handlers/progress.go
  • internal/api/router.go
  • web/src/components/RealtimeEventsProvider.tsx
  • web/src/hooks/queries/mediaSurfaceRefresh.ts

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

Walkthrough

Watched and progress events now include series IDs when available. The web client uses those IDs to invalidate queries for the named series and its cached seasons.

Changes: Series-aware event refresh

Layer / File(s) Summary
Resolve series IDs for watched events
internal/api/handlers/items.go, internal/api/handlers/watch_state_service.go, internal/api/handlers/watch_state_unwatch_db_test.go, internal/api/handlers/clear_resume_position_db_test.go
Watched-target resolution returns a series ID for season and episode targets. Watched and progress events include the resolved ID. Tests check event IDs and update the resolver call for its additional return value.
Add series IDs to progress events
internal/api/handlers/progress.go, internal/api/router.go, internal/api/handlers/progress_bulk_test.go
Progress event publishing looks up visible episodes in a batch and includes available series IDs. The router wires the episode repository into the handler. Tests cover access checks, lookup failures, and event publication.
Invalidate queries for the named series
web/src/hooks/queries/mediaSurfaceRefresh.ts, web/src/components/RealtimeEventsProvider.tsx, web/src/hooks/queries/mediaSurfaceRefresh.test.ts, web/src/components/RealtimeEventsProvider.test.tsx
The web client passes the event’s series ID to query invalidation. Related IDs include the named series and its cached seasons. Coalesced invalidations retain a previously supplied series ID. Tests check related and unrelated queries.

Priority: Low

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ProgressHandler
  participant EpisodeLookup
  participant EventHub
  participant RealtimeEventsProvider
  participant mediaSurfaceRefresh
  ProgressHandler->>EpisodeLookup: Get episode records for visible content IDs
  EpisodeLookup-->>ProgressHandler: Return episodes with series IDs
  ProgressHandler->>EventHub: Publish progress event with series_id
  EventHub-->>RealtimeEventsProvider: Deliver user_state.changed event
  RealtimeEventsProvider->>mediaSurfaceRefresh: Pass itemId and seriesId
Loading

Suggested reviewers: quick104

Merge Risk: Minimal · up to 5e257

Watched and progress events now name the series, so the web client can refresh series and season pages for episodes it has not cached. No concrete merge-blocking risk is visible in the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 11 files. 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 Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: adding series IDs to watched and progress realtime events.
Description check Passed The description is directly related to the changeset and explains the problem, implementation, validation, evidence, and risks.
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Main (Silo-Server#1966) replaced the progress and watched handlers' profile refresh
with notifySignalsChanged. Keep that; the progress handler keeps its
EpisodeLookup and both events keep their series_id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread internal/api/handlers/progress.go Resolved
@macroscopeapp

macroscopeapp Bot commented Oct 15, 2026

Copy link
Copy Markdown

Major validation change — #1252 C4 and C9 (Web). The #1252 rehearsal records the watched/season roll-up as passing; C4's cross-device resume portion remains blocked on #1249's progress-rule decision. This PR intentionally changes the displayed series/season roll-up after an uncached episode's watched/progress event, so C4 and C9 need re-validation after merge. The PR must explicitly explain why these recorded outcomes change; this does not unblock C4's separate progress-rule blocker.

C3's playback/resume behavior and C8's hierarchy/grouping do not change. Suggested replacement:

Validation tasks: changes #1252 C4, C9

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

Posted via Macroscope — v1 validation impact

@macroscopeapp

macroscopeapp Bot commented Oct 15, 2026

Copy link
Copy Markdown

C4 and C9 need re-validation after merge. The Series — Web task comment records a rehearsal on server 4a0cff41f (explicitly not an RC). This PR makes watched/progress events for uncached episodes refresh the named series and its cached seasons, changing the roll-up shown on an open series page. The PR must explain why this previously exercised display behavior is changing (the current description gives the reason), and C4/C9 need re-validation on a published RC. The progress-rule block in #1249 remains because this change does not alter stored progress semantics. C3's playback checks and C8's hierarchy/grouping are unchanged.

Suggested fix — no diff; update the PR description to:
Validation tasks: changes #1252 C4, C9

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

Posted via Macroscope — v1 validation impact

…scing

The v1 progress sync writes item IDs without an access check, so naming
an episode's series could tell a restricted profile which series an
out-of-scope episode belongs to. Name a series only for an episode the
sync already checked, or one the viewer's scope allows; without a scope,
unchecked IDs get none.

On the web, a later event for the same item without a series no longer
replaces the series an earlier event in the coalescing window named.

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

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

rangoDJ and others added 2 commits October 15, 2026 08:45
Main (Silo-Server#2440) split the watched-target lookup out of resolveWatchedTargets
and added a resume-position reset that publishes a progress event. Take
its structure: resolveWatchedTargets returns the target's series through
watchedTarget.seriesID, and the reset's event names it as well. On the
web, keep both the event's series and main's known related IDs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's Silo-Server#2511 regenerated contracts/api/v2/fixtures/ignore_unmatched_item_not_found.json,
which was stale on main and failed TestContractFixtures here. Main's
Silo-Server#2522 also lints new code more widely; its nestif check flagged
episodeSeries, so the scope check moves into markInScope, unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 16, 2026
The repository's size ratchet caps mediaSurfaceRefresh.test.ts at 800
lines, and this PR's three tests took it to 802. They cover events that
name an uncached episode's series (Silo-Server#796), so they move, unchanged, to
mediaSurfaceRefresh.series.test.ts.

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

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

rangoDJ and others added 2 commits October 22, 2026 11:08
Main now describes the eslint-disable comments in NotifiedSeriesList.tsx,
which failed the web checks here. The merge is clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's Silo-Server#3010 adds a recordRewatch parameter to SetWatchedState, and this
branch has resolveWatchedTargets return the target's series. Keep both:
main's signature, and the series the watched event names. This branch's
unwatch test passes recordRewatch false, as main's own call there does.

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

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 3f2ce089ce6ea962dd34b2eda0292e03e377caa6 with no new actionable findings. The earlier access-filtering and coalesced-series-hint findings are fixed in the current source.

Focused progress tests, watched/clear-resume database tests, and all 71 selected frontend tests passed. The disposable database container and volume were removed and absence verified. No live client or multi-node test was performed.

Validation tasks: changes #1252 C4, C9. Re-validate their previously passing rehearsal roll-up portions after this change; C4's separate progress-rule block remains. The PR already explains this intentional change. Full board enumeration is unavailable because the token lacks read:project; dated rehearsal comments were included in the review.

Reviewed with Codex using gpt-6.1-sol at xhigh, including independent finders, verification and a final sweep.

@Quick104
Quick104 merged commit 20b1d35 into Silo-Server:main Oct 29, 2026
21 checks passed
@rangoDJ
rangoDJ deleted the fix/user-state-series-id-796 branch November 15, 2026 00:45
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 priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants