Skip to content

Web player: every realtime catalog/user_state event refetches all active metadata queries, causing buffering #796

Closed

Description

@Quick104

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)

  1. Scope per-item catalog events (catalog.item.changed, metadata.updated, library.item_added) with a content_id to that item's query keys instead of invalidating all item/catalog queries.
  2. Coalesce the remaining broad media-surface invalidations from realtime events behind a debounce so scan event streams collapse to periodic refreshes.
  3. Narrow user_state progress events 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

  1. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  2. added theissue type on Sep 20, 2026
  3. removed
    bug
    on Sep 20, 2026
  4. added a commit that references this issue on Oct 13, 2026
    e21aaed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions