Repository navigation
Description
Observed
During playback in the web app, the network log fills with repeated identical batches of metadata requests — episode-tvdb-… watch detail, seasons, and two episodes fetches — even though nothing on screen changed. Video buffering coincides with the bursts, and request latency climbs as they stack (177 ms → 520 ms):
episodes 200 fetch 2.5 kB 186 ms
episode-tvdb-366924-1-2 200 fetch 5.3 kB 177 ms
seasons 200 fetch 1.5 kB 514 ms
episodes 200 fetch 2.3 kB 522 ms
episodes 200 fetch 2.5 kB 515 ms
episode-tvdb-366924-1-2 200 fetch 5.3 kB 178 ms
... (batch repeats many times)
Root cause
While the player is open, four queries stay active: the watch detail (web/src/player/components/WatchPage.tsx) plus seasons and two episodes queries from useSeriesEpisodes (web/src/playback/WatchPlaybackChrome.tsx). All have a 5-minute staleTime.
That staleTime is defeated by the realtime websocket handler. RealtimeEventsProvider responds to every catalog event and every user_state event on the profile by calling invalidateMediaSurfaceQueries (web/src/hooks/queries/mediaSurfaceRefresh.ts), which invalidates itemKeys.all, catalogKeys.all, sections, progress, history, favorites, watchlist, recommendations, and persons — unscoped. The event's content_id is only used to add invalidations, never to narrow them. React Query then immediately refetches every invalidated active query, which on the watch page is exactly the repeated 4-request batch.
The events themselves are routine background churn: the metadata worker publishes catalog.item.changed per enriched item (internal/metadata/worker.go), scans publish per-item/per-library events (internal/libraryingest/executor.go), and progress/favorite changes on the profile (e.g. another device syncing) publish user_state.changed (internal/api/handlers/progress.go). So any scan or metadata refresh makes the invalidation near-continuous, and the refetch bursts compete with HLS segment fetches on the same origin.
Proposed fix (web frontend only; no API change)
- Scope per-item catalog events (
catalog.item.changed,metadata.updated,library.item_added) with acontent_idto that item's query keys instead of invalidating all item/catalog queries. - Coalesce the remaining broad media-surface invalidations from realtime events behind a debounce so scan event streams collapse to periodic refreshes.
- Narrow
user_stateprogressevents to progress/history/section surfaces and the affected item, instead of the full media-surface blast.
Direct user mutations (favorite/watchlist toggles, etc.) keep their current immediate invalidation behavior.
AI Disclosure
- Tool(s): Claude Code
- Model(s): claude-fable-5[1m]
- Involvement: Fully AI-generated, human verified
- Adversarial review: root cause traced through web query layer and server event publishers; fix PR to follow with its own review summary
Activity
fix(web): scope realtime query invalidation by item (Silo-Server#857)
test(web): move the series-refresh tests to their own file
fix(realtime): name the series on watched and progress events (#2504)