fix(daemon): regrab a failed grab once unblacklisted
ci / web (pull_request) Successful in 29s
e2e / e2e (pull_request) Successful in 2m12s
ci / rust (pull_request) Successful in 2m35s
ci / image (pull_request) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-15 15:42:59 +00:00
co-authored by Claude Opus 5.5
parent 3faa6ea8aa
commit d55c983620
2 changed files with 38 additions and 4 deletions
+36 -2
View File
@@ -700,7 +700,9 @@ impl Grabber {
// `infohash` is unique, so re-grabbing the same release conflicts
// with its own earlier row. A `sent`/`downloaded` row is the restart
// case and is left alone; a `vanished` one (§86) is reclaimed, since
// nothing blacklisted the release.
// nothing blacklisted the release. So is a `failed` one: a hard fail
// blacklists its torrent, so reaching here means the operator lifted
// that blacklisting (§6.3) and wants the release again.
//
// A row whose target no longer exists is reclaimed too, whatever its
// state. Deleting a title used to leave its grabs behind, and one of
@@ -721,7 +723,7 @@ impl Grabber {
state = 'sent',
grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
imported_at = NULL
WHERE grabs.state = 'vanished'
WHERE grabs.state IN ('vanished', 'failed')
OR (grabs.target_kind = 'movie'
AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))
OR (grabs.target_kind = 'season'
@@ -2076,6 +2078,38 @@ mod tests {
assert_eq!(state, "downloading");
}
/// A hard-failed grab whose blacklisting the operator lifted (§6.3) is
/// reclaimed by the next grab of the same torrent, instead of the
/// `failed` row silently swallowing it.
#[tokio::test]
async fn an_unblacklisted_failed_grab_can_regrab_the_same_infohash() {
let (_dir, database) = wanted_movie().await;
let indexer = prowlarr().await;
let (downloader, fake) = qbit().await;
let action = action(&indexer, &downloader);
action.tick(&database).await.unwrap();
sqlx::query("UPDATE grabs SET state = 'failed'")
.execute(database.pool())
.await
.unwrap();
sqlx::query("UPDATE movies SET state = 'missing' WHERE id = 1")
.execute(database.pool())
.await
.unwrap();
fake.torrents.lock().unwrap().clear();
let outcomes = action.tick(&database).await.unwrap();
assert_eq!(outcomes.len(), 1, "a fresh grab");
let grabs = grabs(&database).await;
assert_eq!(
grabs.len(),
1,
"the failed row is reclaimed, not duplicated"
);
assert_eq!(grabs[0].2, "sent");
}
/// A grab row left behind by a deleted title holds the release's unique
/// infohash. Re-adding the title and grabbing the same release used to
/// record nothing at all: the conflict hit a row in `sent`, which is only