Skip to content

fix(watchlistsync): re-request deleted media from watchlist#3072

Merged
fallenbagel merged 1 commit into
developfrom
fix/watchlist-sync-deleted-media-rerequests
May 25, 2026
Merged

fix(watchlistsync): re-request deleted media from watchlist#3072
fallenbagel merged 1 commit into
developfrom
fix/watchlist-sync-deleted-media-rerequests

Conversation

@fallenbagel
Copy link
Copy Markdown
Collaborator

@fallenbagel fallenbagel commented May 24, 2026

Description

When a movie or show was deleted from the media server, its status was set to DELETED but the existing completed auto-request record remained in the database. This caused watchlist sync to skip re-requesting it entirely and the autoRequestedTmdbIds set included the stale auto-request, short-circuiting the filter before it even reached the status check. Even if that was fixed, the unavailableItems filter for movies excluded anything with a status other than UNKNOWN, so DELETED media was never eligible. On top of that, manually requesting the deleted media also failed because MediaRequest.request() found the stale auto-request and threw a DuplicateMediaRequestError.

This PR excludes DELETED media from autoRequestedTmdbIds, adds DELETED alongside UNKNOWN in the unavailableItems movie filter, updates the duplicate auto-request guard to ignore stale requests where the media is DELETED, and ensures the media status is correctly reset to PENDING when a new request is created for deleted media.

How Has This Been Tested?

  • Manually verified by deleting a movie from the media server, confirming it showed as DELETED, then waiting for watchlist sync to run and confirming it re-requested it automatically
  • Manually confirmed that requesting deleted media through the UI no longer returns a 409 error
  • Covered by the integration test in which fails on develop and passes with the fix

Screenshots / Logs (if applicable)

Checklist:

  • I have read and followed the contribution guidelines.
  • Disclosed any use of AI (see our policy)
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • Successful build pnpm build
  • Translation keys pnpm i18n:extract
  • Database migration (if required)

Summary by CodeRabbit

  • Bug Fixes

    • Media requests now mark deleted or unknown variants as pending so re-requests can proceed, and stale/deleted auto-requests no longer block new auto-requests.
  • Tests

    • Added watchlist sync tests verifying re-request behavior for DELETED, UNKNOWN, AVAILABLE, and BLOCKLISTED items, including cases with existing stale auto-request records to ensure correct re-request gating.

Review Change Stack

@fallenbagel fallenbagel requested a review from Copilot May 24, 2026 20:54
@fallenbagel fallenbagel requested a review from a team as a code owner May 24, 2026 20:54
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e081f22c-ecba-4eed-bf4a-b6f0edb906f0

📥 Commits

Reviewing files that changed from the base of the PR and between 4ca0462 and 3f02025.

📒 Files selected for processing (3)
  • server/entity/MediaRequest.ts
  • server/lib/watchlistsync.test.ts
  • server/lib/watchlistsync.ts

📝 Walkthrough

Walkthrough

MediaRequest now transitions existing media marked UNKNOWN or DELETED to PENDING (including 4K variant) and excludes auto-request records tied to DELETED media. WatchlistSync treats DELETED media as unavailable and ignores deleted auto-requests when deciding which watchlist items to re-request; tests validate these behaviors.

Changes

DELETED Media Re-request Handling

Layer / File(s) Summary
Media Request entity status transitions
server/entity/MediaRequest.ts
MediaRequest.request sets status or status4k to PENDING when existing media is UNKNOWN or DELETED (respecting requestBody.is4k). The existing-request lookup uses leftJoinAndSelect for request.media. The duplicate auto-request predicate now excludes cases where the associated media is DELETED.
Watchlist Sync filtering and availability checks
server/lib/watchlistsync.ts
When computing already-auto-requested TMDB IDs, exclude auto-request records whose joined media is DELETED. Movie availability logic now treats DELETED as ineligible alongside UNKNOWN.
Watchlist Sync re-request gating test suite
server/lib/watchlistsync.test.ts
New tests mock Plex and MediaRequest, seed media rows across DELETED/UNKNOWN/AVAILABLE/BLOCKLISTED, run syncWatchlist(), and assert re-requests occur only for DELETED and UNKNOWN. Includes a test verifying re-request when a stale completed auto-request exists for a DELETED media.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • seerr-team/seerr#2478: Refines watchlistsync.ts filtering to avoid creating new requests for ineligible media.

Suggested labels

bug

Suggested reviewers

  • 0xSysR3ll
  • gauthier-th

Poem

🐰 I nibble through deleted chains,
Finding seeds where status wanes.
Old requests sleep, then wake to send,
Pending sprouts begin again.
A hop, a sync — re-request and mend.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: enabling re-requests of deleted media during watchlist sync, which directly addresses the core problem described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@seerr-automation-bot seerr-automation-bot added this to the v3.3.0 milestone May 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Plex watchlist sync and manual request behavior for media that was deleted from the backing media server by ensuring deleted media can be re-requested and stale auto-requests don’t incorrectly block new requests.

Changes:

  • Exclude DELETED media from the autoRequestedTmdbIds short-circuit so watchlist sync can re-request deleted items.
  • Treat DELETED movies similarly to UNKNOWN in the watchlist “unavailable” filter so they become eligible for auto-request.
  • Adjust MediaRequest.request() to avoid duplicate auto-request conflicts for DELETED media and to reset status back to PENDING when re-requesting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
server/lib/watchlistsync.ts Updates watchlist gating logic to allow re-requesting DELETED media and avoid stale auto-request short-circuits.
server/lib/watchlistsync.test.ts Adds an integration-style test verifying watchlist sync re-requests DELETED items while skipping non-requestable statuses.
server/entity/MediaRequest.ts Updates request creation and duplicate auto-request guards to treat DELETED media as re-requestable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/entity/MediaRequest.ts Outdated
Comment thread server/lib/watchlistsync.test.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/entity/MediaRequest.ts`:
- Around line 162-165: The current conditional mutates media.status4k (when it
is MediaStatus.UNKNOWN or MediaStatus.DELETED) regardless of the request mode;
restrict that transition to only run for 4K requests by requiring
requestBody.is4k to be true before changing media.status4k to
MediaStatus.PENDING. Update the conditional that checks media.status4k (the
block that assigns media.status4k = MediaStatus.PENDING) to first verify
requestBody.is4k, and keep the existing checks for MediaStatus.UNKNOWN and
MediaStatus.DELETED (and the special-case for DELETED) so non-4K requests do not
alter the 4K lifecycle state.
- Around line 204-207: The duplicate auto-request guard currently checks
r.media?.status only; update it to be tier-aware by checking the appropriate
media status for 4K requests. Replace the r.media?.status !==
MediaStatus.DELETED check with a conditional that uses the 4K status when the
incoming request is 4K (e.g., (request.is4k ? r.media?.status4k :
r.media?.status) !== MediaStatus.DELETED), keeping the rest of the predicate
(r.requestedBy.id, r.isAutoRequest) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7de26685-2257-4c06-92bd-aaeff4cbdb86

📥 Commits

Reviewing files that changed from the base of the PR and between 4ed29cf and 699a49d.

📒 Files selected for processing (3)
  • server/entity/MediaRequest.ts
  • server/lib/watchlistsync.test.ts
  • server/lib/watchlistsync.ts

Comment thread server/entity/MediaRequest.ts
Comment thread server/entity/MediaRequest.ts Outdated
@fallenbagel fallenbagel force-pushed the fix/watchlist-sync-deleted-media-rerequests branch 2 times, most recently from fe34dc1 to 4ca0462 Compare May 24, 2026 21:04
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as duplicate.

Allow watchlist sync to re-request movies and shows whose media status is DELETED, and fix the
duplicate auto-request guard blocking both sync and manual requests
@fallenbagel fallenbagel force-pushed the fix/watchlist-sync-deleted-media-rerequests branch from 4ca0462 to 3f02025 Compare May 24, 2026 21:10
@fallenbagel fallenbagel enabled auto-merge (squash) May 25, 2026 08:27
Copy link
Copy Markdown
Member

@gauthier-th gauthier-th left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fallenbagel fallenbagel merged commit 2588e49 into develop May 25, 2026
17 checks passed
@fallenbagel fallenbagel deleted the fix/watchlist-sync-deleted-media-rerequests branch May 25, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants