Skip to content

fix(web): re-read the series page after the player's stop lands - #4423

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/web-series-page-refresh-after-stop
Nov 17, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/web-series-page-refresh-after-stop

Conversation

@blurbery

@blurbery blurbery commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4374
Related issue: N/A
Validation tasks: changes #1252 C4 and C9 (both Not run)

Other clients: Apple N/A (already safe: on iOS and macOS the detail page waits for the player's cleanup, which awaits the stop, before it reloads; on tvOS the player reloads the cached detail pages after the stop); Android: Silo-Server/silo-android#954 fixed Android TV; the phone app isn't handled here and doesn't wait for the stop either, Silo-Server/silo-android#985; Roku N/A (the detail screen already reads again a few seconds after the player closes because the stop may still be on its way, refreshAfterPlayback in components/screens/detail/DetailPlayback.bs)

After you leave the web player, the series page can keep showing old watch state until you reload it. The page reads its episodes and Next Up while the player's session stop is still on its way to the server, and nothing reads them again once the stop lands.

Most of a play is already saved by then, because the player waits up to 1 s for its final progress report before it closes, and that report sets the watched mark. The stop writes more, though. For a multi-episode file (say S01E05-E06 in one file) only the stop marks the later episodes watched. When the stop takes longer than the page's reads, episode 6 stays unwatched on the series page until a reload. Season cards read the same seasons endpoint at the same moment, so their watched counts would lag the same way; my test show has one season, so I didn't see that directly. In my runs Next Up already pointed at episode 7 before the fix, so the visible failure was the later episode's watched mark. The fix also covers a single-episode file whose last progress report misses the 1 s window, which I didn't reproduce.

I reproduced it on a local server by putting a proxy in front of Postgres that delays each packet:

  • Database on the same machine: the stop finished a few milliseconds ahead of the page's reads, and the page came out right (3 of 3 runs).
  • 1 ms round trip: the page showed episode 6 unwatched in 1 of 3 runs.
  • 2 ms round trip: the stop took about 170 ms, the series page read first, and episode 6 showed unwatched in every run. It stayed that way for the 6 s I watched, while the server had it watched.

Approach

PlayerConfig gets an optional onSessionStopped callback. usePlaybackSession calls it once the stop it sends on unmount settles, whether it lands or gives up after its own retry budget. A page that is unloading doesn't call it. WatchPlaybackChrome passes a callback that runs invalidatePlaybackSurfaceQueries again, so whatever page you returned to reads its catalog, progress and history queries once more after the stop.

The existing invalidation when the player unmounts stays. The page still updates straight away from what the progress report wrote, and the second pass picks up what the stop wrote. Leaving the player never waits on the network. This is the web version of what Silo-Server/silo-android#954 did on Android TV.

Validation

  • Web unit test: a new case in usePlaybackSession.test.ts holds the stop's response and checks the host is told only after it arrives. It fails on main (the callback never runs) and passes with the fix.
  • vitest run on usePlaybackSession.test.ts and src/playback: 155 passed.
  • Prettier and ESLint on the changed files, and tsc -b: clean (ESLint keeps one existing warning in PlayerConfigContext.tsx on main).
  • Manual: local Silo with a seven-episode test series, driven in Chrome through Playwright, with the database 2 ms away. At desktop width I did five runs on main and six with the fix; at phone width, four on main and six with the fix. Every main run left episode 6 unwatched; every run with the fix showed it watched within about 0.7 s of leaving the player. With the fix I also left through the Up Next screen's Close button, which goes to the episode's own page; that page showed episode 6 watched as well (2 runs).
  • Full CI gate: left to CI on this pull request.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-4423/

Surface and build: web app series page, at desktop (1280 px) and phone (390 px) width, straight after leaving the player with the Exit button. Before is upstream main at 217ff25ab; after is this branch at 3dc97cb0d. Both ran against the same local backend built from 217ff25ab, with Postgres reached through a proxy that adds 1 ms each way. The test server has no online metadata, so I added episode 6's row the way a metadata provider's season listing would.

Risks

Each exit from the player triggers one more round of reads for the queries the current page has open (four small catalog reads on a series page). When the player unmounts to switch items, the callback marks the same queries stale that the existing unmount invalidation already marks at that moment. Nothing else changes.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (Claude desktop app)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
  • Adversarial review: n/a

Note

Refresh playback-surface queries after the player's stop request settles

  • Adds onSessionStopped to PlayerConfig so the host gets notified when a non-unloading session stop settles (success or failure); unloading stops do not notify (PlayerConfigContext.tsx)
  • WatchPlaybackHostContent wires the callback to a new refreshPlaybackSurfaceQueries helper, which cancels in-flight first fetches across the playback-surface query filters before invalidating those queries (playbackSurfaceRefresh.ts)
  • Cancelling first fetches matters because a pending first fetch would otherwise be reused instead of refetched after invalidation
  • Behavioral Change: a playback-surface refresh now cancels matching in-flight first fetches, so a request started before the refresh is replaced by a new one

Macroscope summarized 7eb1981.

Leaving the player marked the catalog queries stale in the same commit
that unmounted it, so the page the viewer returned to read its episodes
and Next Up while the session stop was still on its way. The stop writes
more than the last progress report: it marks the later episodes of a
multi-episode file watched. When the stop took longer than the page's
reads, those episodes stayed unwatched on the series page until a reload.

The player config gains an optional onSessionStopped callback, called
once the unmount stop settles. The watch chrome uses it to mark the
playback surfaces stale again, so the page reads them once more after
the stop. Leaving the player still does not wait on the network.

Closes Silo-Server#4374
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

When a playback session stop settles without page unloading, the player invokes a host callback. WatchPlaybackChrome uses the callback to cancel matching first-fetch queries and invalidate playback-surface queries.

Changes: Playback surface refresh

Layer / File(s) Summary
Notify the host after a session stop
web/src/player/context/PlayerConfigContext.tsx, web/src/player/hooks/usePlaybackSession.ts, web/src/player/hooks/usePlaybackSession.test.ts
PlayerConfig adds an optional onSessionStopped callback. The player invokes it after a non-unloading stop settles, including after a caught failure. The test verifies that it waits for the stop response.
Refresh playback-surface queries after stop
web/src/hooks/queries/playbackSurfaceRefresh.ts, web/src/hooks/queries/playbackSurfaceRefresh.test.ts, web/src/playback/WatchPlaybackChrome.tsx
A shared set of filters defines the playback surfaces. The refresh helper cancels matching first-fetch queries before invalidating those surfaces. WatchPlaybackChrome calls the helper through onSessionStopped. The test verifies that the later fetch supplies the cached value.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant usePlaybackSession
  participant PlaybackAPI
  participant WatchPlaybackChrome
  participant refreshPlaybackSurfaceQueries
  participant QueryClient
  usePlaybackSession->>PlaybackAPI: Send session stop request
  PlaybackAPI-->>usePlaybackSession: Stop request settles
  usePlaybackSession->>WatchPlaybackChrome: Invoke onSessionStopped when not unloading
  WatchPlaybackChrome->>refreshPlaybackSurfaceQueries: Refresh playback surfaces
  refreshPlaybackSurfaceQueries->>QueryClient: Cancel matching first-fetch queries
  refreshPlaybackSurfaceQueries->>QueryClient: Invalidate playback-surface filters
Loading

Suggested reviewers: quick104, rhainland

Merge Risk: Minimal · up to 7eb19

After leaving the player, the series page now rereads progress and watched data once the stop lands. The change is small, reversible and covered by targeted tests, so merge risk is minimal.

Security architecture risk: Minimal · up to 7eb19

The change improves watch-state refresh timing without introducing a demonstrated expansion of permissions or data access. Failed stops remain best-effort, and page-unload behavior is preserved.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The refresh scope is broader than the stopped episode: it matches catalog, progress, history, recommendation, person, home-item and non-layout library queries in the supplied QueryClient. Its operations cancel reads and invalidate cached results; they do not directly modify server-side records.

Trust Boundaries and Controls

  • inferred — The added notification does not transfer the stopped session's identity, credentials or response payload into the cache. A late notification can trigger matching reads, but this path does not itself install old-session data or grant additional authority.

Resilience and Maintainability Implications

  • observed — Pagehide uses the unloading path, which skips host notification; back-forward-cache pagehide preserves the session. Ordinary unmount initiates the notifying stop. Stop failure still leads to refresh, so the change remains best-effort reconciliation rather than a guaranteed persistence barrier.
Pre-merge checks: Passed 2

Check name Status Explanation
Title check Passed The title "fix(web): re-read the series page after the player's stop lands" matches the main change. The PR adds an onSessionStopped callback that runs after the player's session stop settles, and the…
Description check Passed The description states the problem (the series page shows stale watch state after leaving the web player), the cause (reads run before the session stop reaches the server), the approach (onSessionStop…
Full details: Title check

Explanation

The title "fix(web): re-read the series page after the player's stop lands" matches the main change. The PR adds an onSessionStopped callback that runs after the player's session stop settles, and the host re-invalidates playback-surface queries so the series page reads fresh watch state. The title is specific and names the affected page and trigger.

Full details: Description check

Explanation

The description states the problem (the series page shows stale watch state after leaving the web player), the cause (reads run before the session stop reaches the server), the approach (onSessionStopped callback and second invalidation pass), validation steps, and risks. It matches the changeset, which adds onSessionStopped, the usePlaybackSession change, and the refresh helper.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 17, 2026
@silo-kody

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

@silo-triage silo-triage Bot added bug Something isn't working impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish labels Nov 17, 2026
Invalidating a query that has no data yet reuses its in-flight fetch, so a
series page whose cache expired during playback could keep a read that
started before the stop was written. The post-stop refresh now cancels
those first fetches before invalidating, so they read again.

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.

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

I found one defect in the post-stop refresh. It's inline below, and I'm fixing it in a commit on this branch, so there's no need to change it yourself.

@silo-kody

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

@Quick104

Quick104 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Review summary

Reviewed head: 7eb198194 (your 3dc97cb0d plus one fix commit from this review).

The approach holds up. The player reports when its unmount stop settles, and the watch host reads the playback surfaces again, the same way Silo-Server/silo-android#954 handles it on Android TV. An episode switch inside the player stops the old session in place (usePlaybackSession.ts:1137, :1264), not through stopOnPageExit, so the new callback runs only when the viewer actually leaves the player. queryClient is the app-wide singleton, so adding it to the playerConfig memo doesn't change the config's identity or re-run the effects that stop a session.

Addressed

  • Post-stop refresh could keep a pre-stop read (Medium). Fixed in 7eb198194. When the series page's cache expired during playback, invalidating it joined a first fetch already in flight instead of starting a new one. The refresh now cancels those first fetches before invalidating. The regression test fails without the cancel step.

Follow-ups

Validation

  • usePlaybackSession.test.ts "tells the host once the unmount stop lands": fails on 217ff25ab, passes on the head.
  • playbackSurfaceRefresh.test.ts "reads again a first fetch that started before the write landed": fails on 3dc97cb0d's refresh, passes on the head.
  • Your live reproduction with a delayed database covers a page that still had its cache. The fix in this review doesn't change that path, so the published evidence still matches.
  • Validated features: no passed case on the v1.0 board is affected. Series — Web #1252 C4 and C9 (Series — Web) are the cases this fix reaches. Both are Not run, so the body's changes would read better as unblocks.

Other checks

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

Fit: this fixes stale watch state in the main browse-and-watch flow with one optional callback and no new setting or API surface. Readiness: the fix is shown live and by tests that fail without it. The narrower retireActiveSession gap is tracked in #4428.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: polish Annoyance, cosmetic, or nice-to-have 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.

Parity: series page re-reads episodes after the player's stop lands (from Silo-Server/silo-android#954)

2 participants