{"record":{"id":"c16dcc243febe090","repo":"zeroclaw-labs/zeroclaw","slug":"gemini-cli-model-provider-received-non-finite-temp","errorCode":null,"errorMessage":"Gemini CLI model_provider received non-finite temperature value","messagePattern":"Gemini CLI model_provider received non-finite temperature value","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-providers/src/gemini_cli.rs","lineNumber":89,"sourceCode":"            binary_path: None,\n        }\n    }\n\n    /// Returns true if the model argument should be forwarded to the CLI.\n    fn should_forward_model(model: &str) -> bool {\n        let trimmed = model.trim();\n        !trimmed.is_empty() && trimmed != DEFAULT_MODEL_MARKER\n    }\n\n    fn supports_temperature(temperature: f64) -> bool {\n        GEMINI_CLI_SUPPORTED_TEMPERATURES\n            .iter()\n            .any(|v| (temperature - v).abs() < TEMP_EPSILON)\n    }\n\n    fn validate_temperature(temperature: f64) -> anyhow::Result<()> {\n        if !temperature.is_finite() {\n            anyhow::bail!(\"Gemini CLI model_provider received non-finite temperature value\");\n        }\n        if !Self::supports_temperature(temperature) {\n            anyhow::bail!(\n                \"temperature unsupported by Gemini CLI: {temperature}. \\\n                 Supported values: 0.7 or 1.0\"\n            );\n        }\n        Ok(())\n    }\n\n    fn redact_stderr(stderr: &[u8]) -> String {\n        let text = String::from_utf8_lossy(stderr);\n        let trimmed = text.trim();\n        if trimmed.is_empty() {\n            return String::new();\n        }\n        if trimmed.chars().count() <= MAX_GEMINI_CLI_STDERR_CHARS {\n            return trimmed.to_string();","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-providers/src/gemini_cli.rs#L71-L107","documentation":"GeminiCliModelProvider::validate_temperature rejects NaN and +/-inf temperatures before spawning the CLI. Only finite f64 values can be compared against the supported set, so non-finite input is a caller bug - usually arithmetic or deserialized config producing NaN upstream.","triggerScenarios":"Passing Some(f64::NAN) or Some(f64::INFINITY) as temperature to chat_with_system/chat_with_history; computing temperature via a division that can yield 0/0; a TOML/JSON config containing nan or inf.","commonSituations":"temperature = nan in config files; dynamic formulas like base * factor where factor is NaN; temperatures forwarded from another provider's response without sanitization.","solutions":["Sanitize at the source: reject or clamp non-finite values before they reach the provider","Fix the arithmetic producing NaN (guard divisions, validate deserialized floats)","Pass None to use the CLI default instead of a bogus value"],"exampleFix":"// before\nlet temperature = base * scale; // may be NaN\nlet text = provider.chat_with_system(None, prompt, model, Some(temperature)).await?;\n\n// after\nlet temperature = (base * scale).is_finite().then_some(base * scale);\nlet text = provider.chat_with_system(None, prompt, model, temperature).await?;","handlingStrategy":"validation","validationCode":"fn safe_temperature(t: Option<f64>) -> anyhow::Result<Option<f64>> {\n    match t {\n        Some(v) if v.is_finite() => Ok(Some(v)),\n        Some(_) => anyhow::bail!(\"temperature must be finite (got NaN/inf)\"),\n        None => Ok(None),\n    }\n}","typeGuard":"fn temperature_is_finite(t: f64) -> bool { t.is_finite() }","tryCatchPattern":"if let Err(e) = provider.chat_with_system(None, prompt, model, Some(t)).await {\n    if e.to_string().contains(\"non-finite temperature\") {\n        // programmer error: fix the value source, do not retry\n    }\n    return Err(e);\n}","preventionTips":["Validate deserialized floats with is_finite() at the config boundary","Guard any division feeding temperature math","Fail fast at startup on non-finite config instead of at first chat call"],"tags":["rust","zeroclaw","gemini-cli","temperature","nan","validation"],"backgroundTag":"invalid-numeric-config","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}