feat: rank 4K first, fall back to good 1080p
ci / web (push) Successful in 1m3s
e2e / e2e (push) Failing after 1m37s
ci / rust (push) Successful in 2m21s
ci / image (push) Successful in 2m33s

Resolution preference becomes strict tiers (step 10 000) and every
size band gains a ceiling that waives bloated releases, so a 60 GB
remux cannot win the top tier unattended. Movie grab, TV grab, RSS
and the search deck now share one ranking key from arr-core.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-07 18:02:12 +00:00
co-authored by Claude Opus 5.5
parent abb7e0a489
commit cd9e8a891c
13 changed files with 290 additions and 69 deletions
+26 -1
View File
@@ -39,6 +39,10 @@ pub struct SizeBandSpec {
pub floor_gib: u64,
pub target_gib: u64,
pub penalty_points_per_gib_over: i32,
/// Above this a release is waived, never picked automatically. Absent
/// is no ceiling.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ceiling_gib: Option<u64>,
}
/// The scoring weights (`DESIGN.md` §5.5). `resolution_step` defaults to the
@@ -117,10 +121,18 @@ impl PolicyInput {
));
}
}
for resolution in self.size_bands.keys() {
for (resolution, band) in &self.size_bands {
if arr_db::policy::resolution_value(resolution).is_none() {
return Err(format!("size_bands: unknown resolution '{resolution}'"));
}
if band
.ceiling_gib
.is_some_and(|ceiling| ceiling < band.target_gib)
{
return Err(format!(
"size_bands.{resolution}.ceiling_gib: must not be below target_gib"
));
}
}
let mut seen = std::collections::BTreeSet::new();
for resolution in &self.resolution_pref {
@@ -696,6 +708,19 @@ mod tests {
}),
"source_weights",
),
(
with(&|payload| {
payload["size_bands"] = serde_json::json!({
"1080p": {
"floor_gib": 3,
"target_gib": 8,
"penalty_points_per_gib_over": 60,
"ceiling_gib": 6
}
});
}),
"ceiling_gib",
),
];
for (payload, field) in cases {
+19 -2
View File
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::time::UNIX_EPOCH;
use arr_core::policy::{evaluate, Candidate};
use arr_core::score::{claimed_episode_count, score};
use arr_core::score::{claimed_episode_count, score, RankKey};
use arr_core::{Language, Policy, Rule, TitleOverrides, Verdict};
use arr_db::policy::language;
use arr_db::{blacklist, Blacklist};
@@ -482,7 +482,13 @@ pub async fn releases(
))
}
};
classified.sort_by_key(|release| (bucket(&release.verdict), -release.score));
// The daemon's own order inside each bucket, so the deck's top eligible
// row is the release an automatic grab would take.
classified.sort_by(|left, right| {
bucket(&left.verdict)
.cmp(&bucket(&right.verdict))
.then_with(|| rank_key(left).cmp(&rank_key(right)))
});
Ok(Json(classified))
}
@@ -949,6 +955,14 @@ fn rule_name(rule: &Rule) -> String {
}
}
fn rank_key(release: &ClassifiedRelease) -> RankKey<'_> {
RankKey {
score: release.score,
indexer_id: release.indexer_id,
guid: &release.guid,
}
}
fn bucket(verdict: &str) -> u8 {
match verdict {
"eligible" => 0,
@@ -1661,6 +1675,7 @@ mod tests {
floor_bytes: 8 << 30,
target_bytes: 22 << 30,
penalty_points_per_gib_over: 60,
ceiling_bytes: None,
},
),
(
@@ -1669,6 +1684,7 @@ mod tests {
floor_bytes: 3 << 30,
target_bytes: 8 << 30,
penalty_points_per_gib_over: 60,
ceiling_bytes: None,
},
),
]),
@@ -1694,6 +1710,7 @@ mod tests {
floor_bytes: 8 << 30,
target_bytes: 22 << 30,
penalty_points_per_gib_over: 60,
ceiling_bytes: None,
},
)]),
resolution_preference: vec![Resolution::R2160p],