fix(scanners): decline orphaned requests when media is removed from servarr#3191
Conversation
…ervarr When an approved request's media was removed from Radarr/Sonarr before completion, the orphan cleanup reset the media to UNKNOWN but left the request APPROVED, leaving it stuck due to the duplicate guard block while UI showed it as un-requested. Decline the matching approved requests during cleanup so the guard clears and the user can request it again. Also skips orphan cleanup when the server returns an empty list, so a servarr related issues can't mass-orphan an entire library.
📝 WalkthroughWalkthroughAdds a ChangesOrphaned Request Decline Flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR addresses a stuck “duplicate request” state by ensuring that when Sonarr/Radarr orphan cleanup resets orphaned in-flight media back to UNKNOWN, any associated APPROVED requests are also transitioned to DECLINED so users can re-request the media. It also adds a safety guard to skip orphan cleanup for a profile type when a Servarr server returns an empty library list, preventing accidental mass-orphan/mass-decline during rebuilds.
Changes:
- Decline
APPROVEDrequests for media determined to be orphaned during Radarr/Sonarr orphan cleanup. - Add “empty scan” detection to skip orphan cleanup for that profile type when a server returns
200 []. - Update/add unit tests for Radarr and Sonarr scanners to reflect the new cleanup behavior and the empty-scan guard.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/lib/scanners/baseScanner.ts | Adds shared helper to decline orphaned approved requests during scanner cleanup. |
| server/lib/scanners/radarr/index.ts | Adds empty-scan guard and declines orphaned requests during Radarr orphan cleanup. |
| server/lib/scanners/sonarr/index.ts | Adds empty-scan guard and declines orphaned requests during Sonarr orphan cleanup. |
| server/lib/scanners/radarr/radarr.test.ts | Updates existing tests and adds coverage for orphaned request handling + empty-scan guard. |
| server/lib/scanners/sonarr/sonarr.test.ts | Updates existing tests and adds coverage for orphaned request handling + empty-scan guard. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This fixes a stuck state where a movie/show shows a Request button but blocks the request as a duplicate.
When an approved request is sent to Radarr/Sonarr and the entry later disappears before completion (manual removal, DB rebuild, list cleanup), the orphan cleanup from #2757 resets the media to UNKNOWN but doesn't touch the request. The request stays APPROVED, so the duplicate-request guard keeps blocking re-requests while the media page renders as un-requested and the user can neither see it as requested nor request it again.
Cleanup now declines the approved requests bound to the orphaned media. DECLINED is the correct terminal state here (the request's fulfilment was abandoned) and it's the one status that clears the duplicate guard, so the user can simply request again. The decline runs through the normal request path, so the standard
MEDIA_DECLINEDnotification fires, which is still appropriate here, since removing an in-flight item from the servarr is an implicit cancellation.This PR also adds an empty-scan guard. If a server returns an empty list, orphan cleanup for that profile type is skipped. A servarr mid-rebuild serving
200 []would otherwise look like "every movie was deleted" and mass-orphan (and now mass-decline) the whole library. Genuinely-deleted items are still cleaned up on the next scan once the servarr is populated again.Orphan cleanup no longer treats an empty servarr response as "everything deleted." Existing tests that encoded deletion as an empty list were updated to use a populated scan missing the target instead.
How Has This Been Tested?
(Only via unit tests)
Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extractSummary by CodeRabbit
New Features
Tests