Skip to content

fix: SABnzbd duplicates no longer fail the request, and a retried upload is not added twice - #480

Merged
kikootwo merged 3 commits into
mainfrom
fix/329-sab-duplicate-nzb
Oct 27, 2026
Merged

kikootwo merged 3 commits into
mainfrom
fix/329-sab-duplicate-nzb

Conversation

@kikootwo

@kikootwo kikootwo commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #329

What changed

  • New src/lib/integrations/sabnzbd-duplicates.ts: finds the job SABnzbd already holds for an NZB and decides what to do with it. A job matches when its name equals the release title the processor passes (releaseTitle) or the upload name, letters and digits compared ignoring case, in the same category, with failed jobs skipped. It looks in the queue first, then history, then the history archive. The upload name only counts when it is specific: never a generic name (download, the fallback for a Prowlarr /download URL without Content-Disposition, or api, nzb, get, file, index, a bare number), and only when it shares a word with the release title. With no usable name, the response is handled as on main. A queued, downloading or post-processing job is tracked as the request's download. A finished job is tracked only when its storage path exists after remote path mapping, so the monitor's normal completion path imports it. A finished job whose files are gone raises UnusableDownloadSourceError with a blocklistReason.
  • SABnzbdService.addNZBJob() (addNZB() and addDownload() go through it):
    • Discard mode: a refused add with no error text ({status: false, nzo_ids: []}) runs the lookup. With nothing found, the error is the same as before.
    • Pause and Fail modes: after an accepted add, one queue call checks the new job. If it is paused, or already in history and not completed, and an existing job is found, RMAB removes its own new copy (deletes the paused job, archives the Duplicate NZB row) and uses the existing job.
    • Retried add: with retry: true, the lookup runs after the NZB is fetched and before the upload, and a usable job is reused instead of uploading a second copy.
    • addDownload() returns alreadyInClient: true for a reused job, so the row is recorded addedByRmab: false.
  • getNZB(): when the job is not in the queue or the newest 100 history rows, it looks the job up by nzo_ids, then in the archive. A taken-over job can be older or archived.
  • download-torrent.processor.ts: an UnusableDownloadSourceError with a blocklistReason blocklists the release (addAutoBlock, download_fail) before the next ranked release is tried, the same loop a failed grab uses. On a Bull retry (job.attemptsMade > 0, passed in by job-queue.service.ts) it adds retry: true to the add options, and usenet adds get releaseTitle. A held job SABnzbd reports as paused (paused: true) is resumed only when a download row for that nzo_id says RMAB added it (addedByRmab: true). Any other paused job is tracked as it is, with a warning to resume it in SABnzbd.
  • Taken-over jobs are never removed. Request delete already skipped a row recorded addedByRmab: false before any client call, and that is now covered by a test. RMAB's own usenet job is now also kept while another active request tracks the same nzo_id (otherActiveRequestsUsingNzb() in src/lib/utils/shared-torrent.ts, counted as kept-shared, like the torrent guard). Remove-after-processing (planDownloadCleanup() in organize-cleanup-guard.ts) makes no plan for a row recorded addedByRmab: false, so the job's files stay. The stale "always RMAB's" comment is gone.
  • Docs: documentation/phase3/sabnzbd.md (new "Duplicate NZBs and Retried Adds" section with the response table, lookup names, ownership, history params, Fixed Issue 9), documentation/phase3/download-clients.md, documentation/admin-features/request-deletion.md, documentation/phase3/file-organization.md, documentation/TABLEOFCONTENTS.md.

Why

SABnzbd's "Detect duplicate downloads" treats a job as a duplicate when a non-failed history row (archived rows included) or a queued job has the same name or the same NZB md5. RMAB archives every job it imports, so asking again for a release RMAB downloaded before is a duplicate. What happened next depended on the mode:

Mode addfile answer Before
Off {status: true, nzo_ids: [new]} second copy downloads (fine)
Discard {status: false, nzo_ids: []}, nothing added request failed: "Failed to add NZB to SABnzbd"
Pause {status: true, nzo_ids: [new]}, new job paused request stuck on a paused job
Fail {status: true, nzo_ids: [new]}, history row Failed, "Duplicate NZB" request failed by the monitor, release blocklisted
Tag {status: true, nzo_ids: [new]}, downloading second copy downloads (fine)

On SABnzbd 4.2 and later, a copy already in the queue makes the new job paused in every mode except Off and Tag. The nzo_ids in the answer always name the new job, never the existing one, so the existing job has to be found by name and category.

Separately, an addfile upload that times out is a transient error, so Bull re-runs the whole download job (3 attempts). The retry uploaded the NZB again even when SABnzbd had accepted the first upload. The result was a second copy, or a duplicate refusal for a job the request never tracked.

Evidence

  • New tests/fixtures/sabnzbd-duplicates.ts pins the addfile answer and what each mode leaves behind, read from SABnzbd 4.0 to 5.x source (api._api_addfile, nzbparser.process_single_nzb, NzbObject.handle_duplicate_action).
  • New tests/integrations/sabnzbd-duplicates.test.ts runs the real SABnzbdService against a stateful fake SABnzbd API (queue, history, archive, its search wildcards) and real directories for the files check:
    • Discard: a downloading job is tracked; a finished job with files is taken over, also from the archive; a finished job without files is rejected with the blocklist reason; no match, a failed row, or another category keeps the old error.
    • Fail: the finished job is taken over and the Duplicate NZB row is archived; without files the release is rejected.
    • Pause: the paused copy is deleted and the finished or downloading job is used; without files the release is rejected.
    • Tag, Off, and a normal add: the new job is tracked, unchanged. A post-add check that cannot reach SABnzbd keeps the new job.
    • Retry: a queued or finished first try is reused with no second upload; a finished job without files, or no job at all, uploads.
    • Monitor: a finished job past the newest 100 history rows, or archived, is found by its nzo_id.
    • Generic names: a Prowlarr /download URL with no Content-Disposition (upload name download.nzb) does not match another book's queued or archived download job, on a retry or in Discard mode. An upload name that shares no word with the release title does not match either. A job named as the release title is still found.
    • A paused existing job is reported as paused: true.
  • New tests/processors/download-torrent-duplicate.test.ts: a rejected duplicate is blocklisted (release name, indexer, reason, job) and the next release is grabbed; a taken-over job is recorded addedByRmab: false and monitored; an unusable source without a reason is skipped without blocklisting, unchanged; a Bull retry passes retry: true and a first attempt does not.
  • The processor test also checks that usenet adds get the release title, and that a paused held job is resumed when RMAB added it earlier but left paused when it did not.
  • New tests/services/request-delete.usenet-ownership.test.ts: a taken-over SABnzbd job and its files survive request delete. RMAB's own job is kept while another active request tracks it, and is deleted with its files when none does.
  • New tests/processors/organize-cleanup-guard.takeover.test.ts: no remove-after-processing plan for a taken-over job; RMAB's own job (true, or a legacy null) still gets one.
  • With main's src (f182a0d) and the first round's tests: 15 failed, 12 passed, all on an assertion. With the first round's src merged with main (599d48b) and this branch's tests: 9 failed, 32 passed, all on an assertion (the generic-name, release-title, paused-job, shared-job and cleanup cases). On this branch: 41/41 pass.

Checks

  • Unit tests for the changed code (vitest related on the 8 changed source files, plus the 4 test files): PASS, 141 files, 2061/2061
  • Type check and lint: PASS (tsc --noEmit clean; ESLint finds nothing new in the touched files compared with main, and the 6 new files are clean)
  • No image build or E2E run: the change is in src/lib only
  • Full unit suite: PR Tests (CI)

Risk and rollback

  • Every SABnzbd add now makes one extra queue call after the upload. If that call fails, the new job is tracked as before.
  • With no duplicate, nothing changes: the lookup only runs on a refused add, on a new job that is paused or failed on add, or on a Bull retry.
  • On the add path, RMAB deletes or archives only the job its own add just created, and only after it has found the existing job. A reused job is recorded as not added by RMAB. Request delete and remove-after-processing then leave that job and its files in SABnzbd.
  • A retried add that reuses RMAB's own first upload is also recorded as not added by RMAB. That job is kept after import and on request delete, which errs on the safe side.
  • A taken-over finished job goes through the normal import; its download folder is not removed afterwards.
  • A paused job someone else holds stays paused. The request waits on it, and the log says to resume it in SABnzbd.
  • Not covered: a duplicate SABnzbd matched only by md5 or by its NZB backup folder, one under a different or generic name, or one in another category. Those keep the old failure. Off and Tag still download a second copy, as the user's setting asks.
  • Rollback: revert this PR. No schema or data changes.

Release note

  • SABnzbd: an NZB SABnzbd reports as a duplicate no longer fails the request. RMAB uses the job SABnzbd already has, imports its files if they are on disk, or skips that release and tries the next one. A retried add after an upload timeout no longer adds the NZB a second time (SABnzbd: handle a duplicate NZB without failing the request #329).

🤖 Generated with Claude Code

kikootwo and others added 3 commits October 27, 2026 04:23
… add reuses the first upload

When SABnzbd discards, pauses or fails an NZB as a duplicate, RMAB finds the job it
already holds by name and category: a queued or post-processing job is tracked, a
finished job whose files are on disk after path mapping is imported through the normal
completion path, and otherwise the release is blocklisted and the next one is tried.
A Bull retry after a timed-out upload looks for the earlier job before uploading again.

Closes #329.

Co-authored-by: thehaven <420380+thehaven@users.noreply.github.com>
Co-authored-by: connor2k <connormiddleton@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… resume only RMAB's paused job (#329)

- Request delete leaves a taken-over usenet job alone (already, via the ownership check) and
  now keeps RMAB's own job while another active request tracks the same nzo_id;
  remove-after-processing keeps the files of a job recorded addedByRmab false.
- The existing-job lookup matches the release title, or the upload name only when it is
  specific: never download/api or a name that shares no word with the release title.
- A held job that waits paused is resumed only when RMAB added it for an earlier download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo marked this pull request as ready for review October 27, 2026 11:25
@kikootwo
kikootwo merged commit b49a0ff into main Oct 27, 2026
1 check passed
@kikootwo
kikootwo deleted the fix/329-sab-duplicate-nzb branch October 27, 2026 11:25
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.

SABnzbd: handle a duplicate NZB without failing the request

1 participant