Skip to content

Next Up rail wiped out after bulk mark-watched (row-capped anchor scan evicts all other series) #592

Closed

Description

@Quick104

Symptom

Reported by user vanbaster (web UI): marking one series watched from Continue Watching made the entire Next Up row disappear, and it stayed gone across logout/login.

Root cause

buildListNextUpQuery bounds the global anchor scan with nextUpAnchorMaxRows = 500 — a cap on raw completed rows, introduced in #350 to fix a real 44.7s regression. But the query only needs one anchor per series. A bulk mark-watched writes hundreds of completed rows with the newest timestamps; those rows flood the 500-row window and evict every other series.

Production evidence (2026-08-10 ~18:00 UTC, profile valfam of user 134):

  • Marking SpongeBob SquarePants watched wrote 572 completed rows in <2s (17:59:59.965 → 18:00:01.718).
  • The 500-row anchor window afterwards contained exactly 1 distinct series (the fully-watched one, which yields no next episode) → rail returned 0 rows.
  • Replaying the query unbounded returned the user's real 16-row rail — no data was lost, only unreachable.

The cap also degrades rails organically: on another prod profile (11k completed rows), the row-capped query returns 2 Next Up rows where a series-bounded scan returns the full 24.

Fix direction

Replace the row-capped anchor CTE with a recursive skip-scan (loose index scan) over idx_uwp_profile_completed that emits the newest row of each not-yet-seen series and stops after 96 distinct series. One series can then never evict others. Compound (updated_at, media_item_id) cursor so same-timestamp bulk writes across different series aren't skipped. Series-scoped branch (show-detail tile) unchanged.

Measured on prod (PG 18.4), full generated query: worst profile (23k rows/271 series) ~210ms vs ~84ms old (acceptable; the correctness bug is disqualifying); typical heavy profile 102ms new vs 181ms old, returning 24 rows vs 2.

AI Disclosure

  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-fable-5 (diagnosis, review), gpt-5.6-sol (implementation)
  • Involvement: fully AI-generated, human-operated
  • Adversarial review: see linked PR

Activity

  1. added
    bug
    on Aug 11, 2026
  2. added a commit that references this issue on Aug 11, 2026
    e77d9e9
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions