Repository navigation
fix(history): clear a show's history card when an episode has no file - #2167
Conversation
The history page shows a watch of any episode on its series card, but removing the show, a season, or an episode with show scope only hid episodes that have a library file. A history import can record a watch for an episode the catalog knows only from metadata, and a deleted file leaves the same state, so the series card could never be cleared. Series and season removal now also hide the file-less episodes the profile has visible history or progress for. Unwatched file-less episodes stay out of the removal, so a long-running show with few files does not write thousands of hidden rows or events. The filter reads run in batches of 1,000 to stay under SQLite's bound-variable limit. Closes #2164 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughHistory removal now includes file-less episodes when resolving show and season targets. It hides those episodes only when the profile has history or progress for them. The change adds repository queries and tests for target removal and batched lookups. ChangesShow and season history removal
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: 🔵 Low · up to A concurrently imported watch may leave a show card visible until removal is repeated. This bounded, known race warrants owner awareness but does not otherwise block merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| watchedFileless, err := watchedHistoryItemIDs(ctx, store, profileID, filelessIDs) | ||
| if err != nil { | ||
| return apiError(http.StatusInternalServerError, "internal_error", "Failed to remove history") | ||
| } | ||
| addMediaItems(watchedFileless) |
There was a problem hiding this comment.
Race condition in file-less candidate filtering omits an episode when its imported watch commits after watchedHistoryItemIDs reads it but before RemoveHistoryItems runs, causing removal to return success without hiding the watch or creating its suppression watermark. Because RemoveHistoryItems alone acquires the profile lock, select watched candidates and remove them under the same profile-scoped transaction lock used by AddHistoryIfMissing.
Prompt for LLM
File internal/api/handlers/favorites.go:
Line 750 to 754:
Race condition in file-less candidate filtering omits an episode when its imported watch commits after watchedHistoryItemIDs reads it but before RemoveHistoryItems runs, causing removal to return success without hiding the watch or creating its suppression watermark. Because RemoveHistoryItems alone acquires the profile lock, select watched candidates and remove them under the same profile-scoped transaction lock used by AddHistoryIfMissing.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
The gap is real. It's already listed under Risks as accepted, and I'm leaving it open for a maintainer to decide.
What it takes: an import has to commit a watch for an episode that has no file and had no watch until then, in the few milliseconds between the reads in watchedHistoryItemIDs and the transaction in RemoveHistoryItems. The removal still succeeds for everything else. The new watch is visible, so the series card stays until the user removes the show again, and that second removal hides it. No data is lost.
The fix suggested here moves the candidate check inside the removal transaction under lockImportedHistory. That needs a new UserStore method implemented in both the Postgres and SQLite stores, plus the notifications wrapper, which is more than this bug fix should carry. If a maintainer wants it, I'll do it as a follow-up.
There was a problem hiding this comment.
That’s a reasonable scope boundary. The race is a real correctness issue, but you’ve documented the concurrent-import scenario, its impact, and the retry workaround. It doesn’t invalidate the fix for existing file-less watches.
I’d treat this suggestion as non-blocking if the maintainer accepts the documented risk, rather than require the cross-store transaction change in this PR. The suggested locking approach remains appropriate for a follow-up: candidate selection and removal need to share the profile-scoped lock so an import cannot commit between them.
One caveat: the gap is narrow, but not guaranteed to last only milliseconds under load. That doesn’t change the scope argument; it just means timing alone shouldn’t justify acceptance.
I haven’t changed the suggestion or its status.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bed3ffe978
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _, history := withHistory[id] | ||
| _, progress := withProgress[id] | ||
| if history || progress { | ||
| watched = append(watched, id) | ||
| } |
There was a problem hiding this comment.
Preserve tombstones for unwatched file-less episodes
When a file-less episode has no visible history or progress at lookup time, this condition omits its ID from RemoveHistoryItems, so no hidden-history marker is written. If a partial or later history import subsequently supplies an older watch for that catalog episode, AddHistoryIfMissing finds no marker, imports the watch, and the removed show's card reappears; library-backed episodes do not have this problem because removal tombstones all of them regardless of current state. Show/season removal therefore needs a durable way to suppress pre-removal imports for every known file-less episode rather than filtering solely on currently visible state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is deliberate. Writing a hidden-history marker for every file-less episode is what the earlier version of this PR did. A long-running show can have thousands of metadata-only episodes and only a few files, so that version wrote a permanent marker row and published a user-state event per episode on every removal.
Removal hides what the History page showed when the user removed it. A watch for a file-less episode that arrives in a later import was not on that card, so showing it is defensible. The difference from episodes with a file is real, and it is a maintainer's call. I've added it to the PR's Risks section and am leaving this thread open.
| } | ||
| addMediaItems(watchedFileless) | ||
|
|
||
| if err := store.RemoveHistoryItems(ctx, profileID, mediaItemIDs, time.Now().UTC()); err != nil { |
There was a problem hiding this comment.
Batch the final SQLite removal write
On the supported SQLite user-store backend, the new lookup is batched but the resulting combined ID list is passed to RemoveHistoryItems in one call. That implementation expands every ID into a SQL placeholder and adds five more parameters, so a request resolving more than roughly 32,761 IDs—such as a multi-target removal or a metadata-heavy show with many imported file-less watches—fails with SQLite's 32,766-variable limit and returns 500. This commit can introduce that failure even when the library-backed episode list was previously small; the SQLite store should execute bounded chunks within one transaction.
AGENTS.md reference: AGENTS.md:L13-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The SQLite RemoveHistoryItems takes the whole list in one call, and it did before this PR. A selection with more than about 32k episodes with a file already hits the limit on main. This PR adds only the file-less episodes the profile actually watched, which is bounded by watch history, not by catalog size; the candidate lookup over all file-less episodes is the part that got batched.
Chunking the SQLite store's writes inside its transaction would fix both cases. That is a store change, so I'd keep it out of this PR. Leaving the thread open for a maintainer.
Removal listed the episodes with a library file and the file-less ones in two statements. An episode whose first file was linked between them fell into neither list, so a watch on it survived the removal. One query now splits the episodes by availability. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
The file-less episode removal also changes which entries appear on the History screen at phone width, but the PR describes before-and-after web History captures without identifying phone-width captures. Please include before-and-after phone-width captures of the same seeded history state on the evidence page; API excerpts do not show the mobile screen. Suggested fix: No diff — add the phone-width before-and-after captures to the evidence page. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Added phone-width before-and-after captures of the History page to the evidence page, from the same seed on |
Problem
Closes #2164
Related issue: N/A
Validation tasks: none
After a watch-history import, removing a show from a profile's watch history can leave its card on the History page for good. "Remove Show Watch Data" returns success, but the card comes back after every refresh.
The History page shows a watch of any episode on its series card. Removal only reached episodes that have a file in a library. A history import can record a watch for an episode Silo knows only from metadata, and deleting an episode's file leaves the same state. A watch on such an episode was never hidden, so it kept the card. This affects every client that removes history, since removal runs on the server.
Approach
Removing a show or a season now also hides the episodes without a file that the profile has visible history or resume progress for. Episodes without a file that the profile never watched stay out of the removal. A long-running show can have thousands of metadata-only episodes, and hiding all of them would write a permanent hidden-history row and publish a user-state event for each one. Episodes with a file are handled as before.
The catalog gains
EpisodeRepository.PartitionIDsBySeries/PartitionIDsBySeason, which split a show's or season's episodes into those with a file and those without in one query. The handler filters them through the user store's existing history and progress reads, in batches of 1,000 to stay under SQLite's bound-variable limit. The change is in the removal seam shared by v1POST /history/removeand v2POST /api/v2/history/remove. The request and response shapes are unchanged.Validation
main(the watch of the episode without a file survives) and passes here. It covers show and season removal, season removal at item scope, and episode removal at show scope. It also checks that an unwatched episode without a file gets no hidden row. The test is added toscripts/ci/db-contracts.txtso the database job runs it.internal/api/handlers,internal/apiv2, andinternal/catalog: pass.internal/api/handlers,internal/apiv2, andinternal/jellycompat: four tests fail locally, and the same four fail on unmodifiedmain.make lint-changed: 0 issues.main, the removal returned 204 and the show stayed inGET /api/v2/historyand on the web History page. On this branch it is gone, and the other show remains.Evidence
Before-and-after captures of the web History page at desktop and phone width, and the API transcripts, are on the evidence page.
Evidence: https://evidence.siloserver.org/r/silo-server/issue-2164/
Risks
/api/v1through the shared seam. It is a correctness fix with no wire change.main. This PR adds only watched file-less episodes to that list.Follow-ups, not in this PR:
Checklist
AI Disclosure
sonnetmodel alias (two review subagents), gpt-6.1-sol (adversarial review)🤖 Generated with Claude Code
Note
Fix history removal to include watched file-less episodes
resolveHistoryRemovalMediaItemIDsreturns file-less episode candidates separately from directly removable IDs;seriesEpisodeIDsandseasonEpisodeIDsuse newPartitionIDsBySeries/PartitionIDsBySeasonrepository methods to split episode IDs in one querycompactHistoryItemIDsand batched at 1,000 IDs inwatchedHistoryItemIDsMacroscope summarized c562f0d.