From d55c98362045fa4d009437c8490a57728685b3a1 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Sun, 15 Nov 2026 15:42:59 +0000 Subject: [PATCH] fix(daemon): regrab a failed grab once unblacklisted Co-Authored-By: Claude Opus 5.5 --- ...360df98cfdaf1d4a33c9f163528f42e8d997.json} | 4 +- crates/arr-daemon/src/grab.rs | 38 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) rename .sqlx/{query-2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383.json => query-d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997.json} (59%) diff --git a/.sqlx/query-2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383.json b/.sqlx/query-d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997.json similarity index 59% rename from .sqlx/query-2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383.json rename to .sqlx/query-d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997.json index f003d88..6da5b66 100644 --- a/.sqlx/query-2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383.json +++ b/.sqlx/query-d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "INSERT INTO grabs (release_id, target_kind, target_id, infohash, state)\n VALUES (?, ?, ?, ?, 'sent')\n ON CONFLICT (infohash) DO UPDATE SET\n release_id = excluded.release_id,\n target_kind = excluded.target_kind,\n target_id = excluded.target_id,\n state = 'sent',\n grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),\n imported_at = NULL\n WHERE grabs.state = 'vanished'\n OR (grabs.target_kind = 'movie'\n AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'season'\n AND NOT EXISTS (SELECT 1 FROM seasons WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'episode'\n AND NOT EXISTS (SELECT 1 FROM episodes WHERE id = grabs.target_id))\n RETURNING id AS \"id!: i64\"", + "query": "INSERT INTO grabs (release_id, target_kind, target_id, infohash, state)\n VALUES (?, ?, ?, ?, 'sent')\n ON CONFLICT (infohash) DO UPDATE SET\n release_id = excluded.release_id,\n target_kind = excluded.target_kind,\n target_id = excluded.target_id,\n state = 'sent',\n grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),\n imported_at = NULL\n WHERE grabs.state IN ('vanished', 'failed')\n OR (grabs.target_kind = 'movie'\n AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'season'\n AND NOT EXISTS (SELECT 1 FROM seasons WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'episode'\n AND NOT EXISTS (SELECT 1 FROM episodes WHERE id = grabs.target_id))\n RETURNING id AS \"id!: i64\"", "describe": { "columns": [ { @@ -22,5 +22,5 @@ null ] }, - "hash": "2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383" + "hash": "d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997" } diff --git a/crates/arr-daemon/src/grab.rs b/crates/arr-daemon/src/grab.rs index e47fe2a..eb538cc 100644 --- a/crates/arr-daemon/src/grab.rs +++ b/crates/arr-daemon/src/grab.rs @@ -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 -- 2.47.3