{"record":{"id":"18211a4979d06eb4","repo":"affaan-m/ECC","slug":"minimum-mean-delta-must-be-finite","errorCode":null,"errorMessage":"minimum mean delta must be finite","messagePattern":"minimum mean delta must be finite","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/harness_eval.rs","lineNumber":511,"sourceCode":"\n#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]\npub struct Comparison {\n    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()","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/harness_eval.rs#L493-L529","documentation":"`PromotionPolicy::validate` requires `min_mean_delta` to be a finite number (not NaN or infinity). A non-finite threshold would make every comparison degenerate (always pass or always fail), so the policy is rejected.","triggerScenarios":"Building a `PromotionPolicy` with `min_mean_delta` set to `f64::NAN`, `f64::INFINITY`, or a value computed from a division by zero, then calling `compare` or `validate`.","commonSituations":"Thresholds read from config where a sentinel 'unset' value of NaN/inf is used; computing the delta threshold as `a / b` with `b == 0.0`; JSON deserialization of a float that overflowed.","solutions":["Set `min_mean_delta` to a finite threshold (e.g. 0.05) before calling `compare`","Replace NaN/inf sentinels with `Option<f64>` in your config layer and validate before constructing the policy","Check the computation producing the threshold for division by zero or overflow"],"exampleFix":"// before\nlet policy = PromotionPolicy { min_mean_delta: f64::NAN, .. };\nlet comparison = policy.compare(&samples)?;\n// after\nlet policy = PromotionPolicy { min_mean_delta: 0.05, .. };\nlet comparison = policy.compare(&samples)?;","handlingStrategy":"validation","validationCode":"fn delta_threshold_is_valid(min_mean_delta: f64) -> bool {\n    min_mean_delta.is_finite()\n}","typeGuard":"fn finite_f64(v: f64) -> Option<f64> {\n    if v.is_finite() { Some(v) } else { None }\n}","tryCatchPattern":"match policy.compare(&samples) {\n    Ok(comparison) => comparison,\n    Err(e) if e.to_string().contains(\"mean delta must be finite\") => {\n        eprintln!(\"non-finite min_mean_delta in policy config: {e}\");\n        Err(anyhow::anyhow!(\"fix min_mean_delta in promotion config\"))\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Model optional thresholds as Option<f64>, never NaN sentinels","Check divisions producing the threshold for zero denominators","Validate all f64 config fields with is_finite() at load time"],"tags":["validation","promotion-policy","float"],"backgroundTag":"invalid-config-value","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"}