fix(core): stop the size floor condemning a download
ci / web (push) Successful in 1m1s
ci / rust (push) Successful in 2m23s
e2e / e2e (push) Failing after 3m20s

The floor is a selection filter (§5.5): it keeps the ranking from picking
mud while better candidates are still on the table. Once a release is
grabbed there is nothing left to choose between, so a hard fail at import
condemns a file already on disk and blacklists the release under §5.7 —
over a number the indexer gave before the grab. Size is not post-download
evidence either; §5.6 gives ffprobe audio, HDR, codec and duration.

It bit packs hardest. Pre-grab measures a pack by its total over the
season length; import measures each file on its own, so one short episode
condemned the whole release and reopened the season. And §6.3 outlasts the
fix: a blacklisted release stays rejected however the operator later sets
allow_below_floor, with no delete path.

Post-download the floor now waives instead, whatever the overrides say.
The file imports and carries a waiver naming the floor it missed.
This commit is contained in:
Miguel Palhas
2026-08-26 18:34:57 +01:00
parent d3613c6081
commit 58ad90951c
2 changed files with 118 additions and 1 deletions
+58 -1
View File
@@ -237,6 +237,16 @@ impl PolicyRule for SourceRule {
/// automatically and its import is recorded as a §5.7 waiver. This mirrors
/// [`ResolutionRule`], where an override moves a failure between hard and
/// soft and never makes the rule stop applying.
///
/// **The floor only ever rejects pre-grab.** It exists to keep the ranking
/// from picking mud when something better is in the same search (§5.5), and
/// that job is finished once a release is grabbed: at import there is
/// nothing left to choose between, so a hard fail there condemns a file
/// already on disk and blacklists the release under §5.7. Size is also not
/// post-download evidence — §5.6 gives `ffprobe` real audio, HDR, codec and
/// duration, and the size was on the release before the grab. So after
/// download the floor is a soft fail whatever the overrides say: the file
/// imports and carries a waiver naming the floor it missed.
#[derive(Clone, Copy, Debug, Default)]
pub struct SizeRule;
@@ -254,7 +264,10 @@ impl PolicyRule for SizeRule {
context.runtime_minutes,
) {
None => RuleEvaluation::Unknown(RuleKind::Size),
Some(true) if context.overrides.allow_below_floor => {
Some(true)
if context.overrides.allow_below_floor
|| context.candidate.phase() == EvaluationPhase::PostDownload =>
{
RuleEvaluation::SoftFail(Rule::Size)
}
Some(true) => RuleEvaluation::HardFail(Rule::Size),
@@ -752,6 +765,50 @@ mod tests {
);
}
/// The floor is a selection filter (§5.5), so it only rejects while
/// there is still a selection to make. A pack accepted pre-grab on its
/// per-episode average carries episodes that individually fall short;
/// hard-failing them at import blacklists a release the operator chose
/// and reopens every episode, over a number that was known before the
/// grab. Post-download the floor waives instead, with no override.
#[test]
fn below_the_floor_after_download_waives_rather_than_condemning_the_release() {
let policy = banded_policy();
let overrides = TitleOverrides::default();
let claims = claims(Some(ClaimedResolution::P1080), Some(ClaimedSource::WebDl));
// Pre-grab the same size is still a rejection: nothing is on disk
// yet and a better candidate may be one row down.
assert_eq!(
evaluate(
&policy,
&overrides,
&en(),
Candidate::PreGrab(&claims),
Some(1 << 30),
1,
0,
)
.verdict,
Verdict::Rejected(Rule::Size)
);
let media = probed(Resolution::R1080p, Some(Source::WebDl));
assert_eq!(
evaluate(
&policy,
&overrides,
&en(),
Candidate::PostDownload(&media),
Some(1 << 30),
1,
0,
)
.verdict,
Verdict::Waived(Rule::Size)
);
}
#[test]
fn allow_below_floor_says_nothing_about_a_release_that_clears_the_floor() {
let overrides = TitleOverrides {
+60
View File
@@ -1980,6 +1980,18 @@ mod tests {
]
}"#;
/// The same file, one gigabyte instead of ten: under the 2160p floor.
/// A pack accepted pre-grab on its per-episode average carries episodes
/// like this whenever one runs short.
const TV_THIN_PROBE: &str = r#"{
"format": {"format_name": "matroska,webm", "duration": "3300.0", "size": "1073741824"},
"streams": [
{"codec_type": "video", "codec_name": "hevc", "width": 3840, "height": 1600,
"color_transfer": "smpte2084"},
{"codec_type": "audio", "codec_name": "eac3", "tags": {"language": "eng"}}
]
}"#;
const PACK_RELEASE_NAME: &str = "Fallout.S01.2160p.WEB-DL.DDP5.1.Atmos";
struct TvHarness {
@@ -2193,6 +2205,54 @@ mod tests {
assert_eq!(grab_state, "imported");
}
/// §5.5's floor is a selection filter, so it condemns nothing after the
/// download. A pack whose episodes come in under the band imports and
/// records the waiver: blacklisting it would throw away a file already
/// on disk over a number that was on the release before the grab, and
/// §6.3 would then outlast any override the operator later writes.
#[tokio::test]
async fn a_pack_under_the_floor_imports_with_a_waiver_rather_than_blacklisting() {
let h = tv_harness(TV_THIN_PROBE).await;
h.action.tick(&h.database).await.unwrap();
let blacklisted: i64 = sqlx::query_scalar("SELECT count(*) FROM blacklist")
.fetch_one(h.database.pool())
.await
.unwrap();
assert_eq!(blacklisted, 0, "the floor blacklists nothing post-download");
let waivers: Vec<Option<String>> =
sqlx::query_scalar("SELECT waiver FROM media_files ORDER BY path")
.fetch_all(h.database.pool())
.await
.unwrap();
assert_eq!(
waivers,
vec![
Some(r#"{"rule":"size"}"#.to_owned()),
Some(r#"{"rule":"size"}"#.to_owned())
],
"§5.7: import it, record the waiver, surface it"
);
let states: Vec<(String, bool)> =
sqlx::query_as("SELECT state, wanted FROM episodes ORDER BY number")
.fetch_all(h.database.pool())
.await
.unwrap();
assert_eq!(
states,
vec![
("available".to_owned(), true),
("available".to_owned(), true)
]
);
let grab_state: String = sqlx::query_scalar("SELECT state FROM grabs")
.fetch_one(h.database.pool())
.await
.unwrap();
assert_eq!(grab_state, "imported");
}
/// The third acceptance case, import side: a pack whose file hard-fails
/// blacklists that release and reopens the episodes — it does not
/// blacklist or block the season.