Skip to content

fix(scanner): confirm orphan candidates against the servers before declining - #3399

Open
fallenbagel wants to merge 1 commit into
developfrom
fix/scanner-orphan-decline-race
Open

fix(scanner): confirm orphan candidates against the servers before declining#3399
fallenbagel wants to merge 1 commit into
developfrom
fix/scanner-orphan-decline-race

Conversation

@fallenbagel

@fallenbagel fallenbagel commented Aug 15, 2026

Copy link
Copy Markdown
Member

Description

The Radarr and Sonarr scanners take a snapshot of the library at the start of a run and, at the end, decline any in-progress request that isn't in it. Anything requested while the scan is still running was never in that snapshot, so it gets declined a few minutes after Radarr or Sonarr already accepted it. On the default schedule, since both scan jobs fall on a watchlist sync tick and nothing stops the two running at the same time either thus this happening.

Before declining anything, the scanners now check the candidate against the servers directly instead of trusting the snapshot. If that check can't be completed the request is left alone, so a server being briefly unreachable can't decline someone's request.

How Has This Been Tested?

  • Tested via unit tests
  • Tested by reporter (available to test via preview-scanner-decline-race-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
    • Improved Radarr and Sonarr library synchronization during scans.
    • Prevents media added after a scan begins from being incorrectly marked as missing.
    • Preserves processing status when servers are unreachable or verification fails.
    • Correctly resets status only when a confirmed library lookup finds no matching movie or series.

…clining

The arr scanners snapshot the library once per run and then decline any PROCESSING request missing
from the snapshot, so a request created mid-scan gets declined minutes after the *arr accepted it.
The stock schedule makes it routine, as both scan jobs land on a plex-wtachlist-sync tick as well.
Now they are re-checked against the live servers before anything is declined, using the
library-filtered endpoints.
Copilot AI lite review requested due to automatic review settings August 15, 2026 10:22
@fallenbagel
fallenbagel requested a review from a team as a code owner August 15, 2026 10:22
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4eff68c1-616d-4077-98f4-169b9831a8b5

📥 Commits

Reviewing files that changed from the base of the PR and between 39ff48c and c058380.

📒 Files selected for processing (6)
  • server/api/servarr/radarr.ts
  • server/api/servarr/sonarr.ts
  • server/lib/scanners/radarr/index.ts
  • server/lib/scanners/radarr/radarr.test.ts
  • server/lib/scanners/sonarr/index.ts
  • server/lib/scanners/sonarr/sonarr.test.ts

📝 Walkthrough

Walkthrough

This change adds Radarr and Sonarr library lookups by external ID. Scanner cleanup now checks matching servers before resetting processing media. Lookup failures preserve processing status. Tests cover found, failed, and missing library results.

Changes

Servarr orphan cleanup

Layer / File(s) Summary
Library lookup APIs
server/api/servarr/radarr.ts, server/api/servarr/sonarr.ts
Adds Radarr TMDB and Sonarr TVDB library queries. Request failures include contextual errors and preserve the original cause.
Radarr cleanup verification
server/lib/scanners/radarr/index.ts, server/lib/scanners/radarr/radarr.test.ts
Checks matching enabled Radarr servers before cleanup. Tests cover existing movies, lookup failures, and missing TMDB matches.
Sonarr cleanup verification
server/lib/scanners/sonarr/index.ts, server/lib/scanners/sonarr/sonarr.test.ts
Checks matching enabled Sonarr servers before cleanup. Tests cover existing shows, lookup failures, and missing TVDB matches.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to c0583

The change adds server confirmation before declining orphan candidates and leaves requests untouched when confirmation is unavailable; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

Suggested reviewers: gauthier-th, 0xsysr3ll

Poem

I’m a rabbit checking libraries wide,
Across every Radarr and Sonarr side.
Found media stays in its processing lane,
Failed checks leave its status the same.
Missing IDs reset with care—
Clean orphan checks hop everywhere.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: scanners verify orphan candidates against live servers before declining them.

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.

Comment thread server/api/servarr/radarr.ts Dismissed
Comment thread server/api/servarr/sonarr.ts Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 prevents Radarr/Sonarr scanners from incorrectly declining in-progress requests that were added after a scan started by confirming “orphan” candidates directly against the Servarr servers before resetting status/declining requests.

Changes:

  • Add per-item existence checks against Radarr/Sonarr servers before orphan cleanup proceeds (and skip cleanup if confirmation fails).
  • Introduce new Radarr/Sonarr API helper methods to query library entries by TMDB/TVDB ID.
  • Add unit tests covering the new cleanup behavior (recently-added items, unreachable server, true orphan).

Reviewed changes

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

Show a summary per file
File Description
server/lib/scanners/sonarr/sonarr.test.ts Adds unit tests covering orphan cleanup confirmation behavior for Sonarr.
server/lib/scanners/sonarr/index.ts Adds server-confirmation step before resetting orphaned show statuses/declining requests.
server/lib/scanners/radarr/radarr.test.ts Adds unit tests covering orphan cleanup confirmation behavior for Radarr.
server/lib/scanners/radarr/index.ts Adds server-confirmation step before resetting orphaned movie statuses/declining requests.
server/api/servarr/sonarr.ts Adds API method to query library series by TVDB ID.
server/api/servarr/radarr.ts Adds API method to query library movies by TMDB ID.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/lib/scanners/radarr/index.ts
Comment thread server/lib/scanners/sonarr/index.ts

@0xSysR3ll 0xSysR3ll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Success

@seerr-automation-bot seerr-automation-bot added this to the v3.5.0 milestone Aug 15, 2026
@fallenbagel
fallenbagel enabled auto-merge (squash) August 15, 2026 12:19
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