{"record":{"id":"7649881b0433c2e3","repo":"affaan-m/ECC","slug":"minimum-win-rate-must-be-between-0-and-1","errorCode":null,"errorMessage":"minimum win rate must be between 0 and 1","messagePattern":"minimum win rate must be between 0 and 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/harness_eval.rs","lineNumber":514,"sourceCode":"    pub passed: bool,\n    pub sample_count: usize,\n    pub candidate_mean: f64,\n    pub baseline_mean: f64,\n    pub mean_delta: f64,\n    pub win_rate: f64,\n    pub failures: Vec<String>,\n}\n\nimpl PromotionPolicy {\n    pub fn validate(self) -> Result<()> {\n        if self.min_samples == 0 {\n            bail!(\"minimum samples must be positive\");\n        }\n        if !self.min_mean_delta.is_finite() {\n            bail!(\"minimum mean delta must be finite\");\n        }\n        if !self.min_win_rate.is_finite() || !(0.0..=1.0).contains(&self.min_win_rate) {\n            bail!(\"minimum win rate must be between 0 and 1\");\n        }\n        Ok(())\n    }\n\n    pub fn compare(self, samples: &[PairedSample]) -> Result<Comparison> {\n        self.validate()?;\n        if samples.is_empty() {\n            bail!(\"samples cannot be empty\");\n        }\n        if samples\n            .iter()\n            .map(|sample| sample.seed)\n            .collect::<BTreeSet<_>>()\n            .len()\n            != samples.len()\n        {\n            bail!(\"sample seeds must be unique\");\n        }","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/harness_eval.rs#L496-L532","documentation":"`PromotionPolicy::validate` requires `min_win_rate` to be finite and within the inclusive range 0.0..=1.0, since it represents a fraction of wins. Values like 1.5, -0.1, or NaN are statistically meaningless and are rejected.","triggerScenarios":"Constructing a `PromotionPolicy` with `min_win_rate` outside [0.0, 1.0] (e.g. 1.5 meaning '150%', a negative rate, or NaN) and calling `compare` or `validate`.","commonSituations":"Users expressing the threshold as a percentage (85 for 85%) instead of a fraction (0.85); copy-pasting thresholds from percent-based tooling; unset/NaN sentinels from config.","solutions":["Express the win rate as a fraction between 0.0 and 1.0 (0.85, not 85) before calling `compare`","If your config uses percentages, divide by 100.0 at load time and validate the range","Use `0.0..=1.0` `contains` checks in your own config loader to fail early with a clear message"],"exampleFix":"// before\nlet policy = PromotionPolicy { min_win_rate: 85.0, .. };\nlet comparison = policy.compare(&samples)?;\n// after\nlet policy = PromotionPolicy { min_win_rate: 0.85, .. };\nlet comparison = policy.compare(&samples)?;","handlingStrategy":"validation","validationCode":"fn win_rate_is_valid(min_win_rate: f64) -> bool {\n    min_win_rate.is_finite() && (0.0..=1.0).contains(&min_win_rate)\n}","typeGuard":"fn fraction_f64(v: f64) -> Option<f64> {\n    if v.is_finite() && (0.0..=1.0).contains(&v) { Some(v) } else { None }\n}","tryCatchPattern":"match policy.compare(&samples) {\n    Ok(comparison) => comparison,\n    Err(e) if e.to_string().contains(\"win rate must be between 0 and 1\") => {\n        eprintln!(\"min_win_rate out of range (did you pass a percentage?): {e}\");\n        // retry assuming percentage input\n        PromotionPolicy { min_win_rate: policy.min_win_rate / 100.0, ..policy }.compare(&samples)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Store win-rate thresholds strictly as fractions 0.0..=1.0 in config","Convert percentages to fractions at the config boundary with a named helper","Clamp or reject percent-style values (>1.0) in your config loader with a clear message"],"tags":["validation","promotion-policy","range"],"backgroundTag":"value-out-of-range","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}