Skip to content

fix(importer): improve ARR import stability and queue handling#591

Merged
javi11 merged 2 commits into
javi11:mainfrom
drondeseries:main
May 18, 2026
Merged

fix(importer): improve ARR import stability and queue handling#591
javi11 merged 2 commits into
javi11:mainfrom
drondeseries:main

Conversation

@drondeseries
Copy link
Copy Markdown
Contributor

This pull request resolves several issues causing Sonarr/Radarr queue instability:

  1. Path Trimming: Fixed ghost detection logic to correctly trim path prefixes for both MountPath and ImportDir configurations.
  2. History Persistence: Refactored the import processor pipeline to pass and persist the 'DownloadID' into ImportHistory, ensuring SABnzbd History API returns consistent identifiers.
  3. Propagation Delay: Increased the VFS propagation delay from 1s to 3s to provide a larger buffer for FUSE mount synchronization, reducing 'FileNotFoundException' errors.
  4. API Compatibility: Treats limit=0 as 'unlimited' (defaulting to 10000) in the SABnzbd queue API to prevent ARR clients from receiving empty queues.

These changes ensure ARR instances can accurately track and clear processed items from their queues, improving overall stability of the import lifecycle.

@drondeseries
Copy link
Copy Markdown
Contributor Author

Updates to PR #591: Replaced the arbitrary 3-second sleep with a robust poll-until-exists check for the VFS mount in internal/importer/postprocessor/coordinator.go. This ensures ARR applications only receive import notifications once the file is fully visible, eliminating 'FileNotFoundException' race conditions while maximizing responsiveness.

@drondeseries drondeseries force-pushed the main branch 3 times, most recently from 56901c0 to 0405dc2 Compare May 18, 2026 13:15
…ion fixes

This comprehensive set of fixes resolves long-standing issues with Sonarr/Radarr queue synchronization and accidental file deletion:

### 1. ARR Queue Stability and Visibility
- State Synchronization: Refactored History API to proactively surface completed items from the active import queue. This prevents a race condition where successfully imported files vanish from Sonarr's sight because they haven't yet been persisted to the ImportHistory database.
- Improved Deduplication: Added deduplication logic in handleSABnzbdHistory to handle the overlap between active queue items and historical records.
- Queue Limit Logic: Fixed SABnzbd Queue API limit handling.
- ARR Queue Cleanup: Added a proactive removal trigger for successfully imported items via webhook, and implemented a more robust polling mechanism in the post-processor to ensure ARR applications only get notifications when files are fully visible on the VFS mount.

### 2. Health-Aware Deletion Guard
- Race Condition Resolution: Resolved a bug in the Redundant Deletion Guard where it blindly honored ARR EpisodeFileDelete webhooks even for files that had just been successfully verified as healthy.
- Health-Aware Logic: Updated the guard in arrs_handlers.go to query the healthRepo before proceeding. Deletion is now skipped if the file is confirmed Healthy and was recently imported (within 5 minutes).
- Grace Period: This prevents stale webhook events from previous failed import attempts (common during high-frequency retries) from deleting successfully imported media.

### 3. Stability & API Refinements
- Improved ID Persistence: Ensured DownloadID is correctly captured and persisted into ImportHistory.
- API Compatibility: Cleaned up the SABnzbd History API, decoupling it from the active queue while ensuring consistency with Sonarr's expectations.
@javi11 javi11 merged commit 123bbc9 into javi11:main May 18, 2026
2 checks passed
iPromKnight added a commit to iPromKnight/altmount that referenced this pull request May 18, 2026
…am conflict

Upstream main extended the if/else chain to add whisparr, lidarr, and
readarr cases in javi11#591. The drive-by tagged-switch cleanup from the
previous commit conflicts with that change. The lint finding (QF1003)
predates this PR and persists on main — appropriate venue is a
separate PR that resolves the conflict cleanly by extending the
switch with the new cases.

Keeps this PR scoped to the slot-semaphore refactor.
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.

2 participants