{"record":{"id":"7822090234b38cac","repo":"zeroclaw-labs/zeroclaw","slug":"gemini-cli-exited-with-non-zero-status-code-che","errorCode":null,"errorMessage":"Gemini CLI exited with non-zero status {code}. Check that Gemini CLI is authenticated and the CLI is supported.{stderr_note}","messagePattern":"Gemini CLI exited with non-zero status (.+?)\\. Check that Gemini CLI is authenticated and the CLI is supported\\.(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-providers/src/gemini_cli.rs","lineNumber":222,"sourceCode":"                        .with_outcome(::zeroclaw_log::EventOutcome::Failure)\n                        .with_attrs(::serde_json::json!({\n                            \"phase\": \"process_wait\",\n                            \"error\": format!(\"{}\", err),\n                        })),\n                    \"gemini_cli: process wait failed\"\n                );\n                anyhow::Error::msg(format!(\"Gemini CLI process failed: {err}\"))\n            })?;\n\n        if !output.status.success() {\n            let code = output.status.code().unwrap_or(-1);\n            let stderr_excerpt = Self::redact_stderr(&output.stderr);\n            let stderr_note = if stderr_excerpt.is_empty() {\n                String::new()\n            } else {\n                format!(\" Stderr: {stderr_excerpt}\")\n            };\n            anyhow::bail!(\n                \"Gemini CLI exited with non-zero status {code}. \\\n                 Check that Gemini CLI is authenticated and the CLI is supported.{stderr_note}\"\n            );\n        }\n\n        let text = String::from_utf8(output.stdout).map_err(|err| {\n            ::zeroclaw_log::record!(\n                ERROR,\n                ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Fail)\n                    .with_outcome(::zeroclaw_log::EventOutcome::Failure)\n                    .with_attrs(::serde_json::json!({\n                        \"phase\": \"utf8_decode\",\n                        \"error\": format!(\"{}\", err),\n                    })),\n                \"gemini_cli: non-UTF-8 stdout\"\n            );\n            anyhow::Error::msg(format!(\"Gemini CLI produced non-UTF-8 output: {err}\"))\n        })?;","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-providers/src/gemini_cli.rs#L204-L240","documentation":"The spawned gemini binary exited with a non-zero code. The message includes the exit code and a redacted, clipped stderr excerpt (redact_stderr caps length); the dominant causes the message itself names are missing CLI authentication and an unsupported/changed CLI version.","triggerScenarios":"invoke_cli runs after the binary spawned successfully but the CLI failed: never-authenticated gemini CLI, expired credentials, major-version flag changes, or a sandboxed CI environment without HOME/auth cache.","commonSituations":"Fresh machine or CI container where gemini was installed but never logged in; CLI auto-updated overnight and changed behavior; GEMINI_CLI_PATH pointing at a wrapper script that fails early.","solutions":["Run the same prompt manually with the CLI and complete its auth flow","Pin or reinstall a supported gemini CLI version","Set GEMINI_CLI_PATH to a known-good binary","Read the appended Stderr excerpt for the CLI's own complaint"],"exampleFix":"# before: CI never authenticates the CLI\n- run: zeroclaw chat --provider gemini_cli \"hi\"\n\n# after: authenticate once, cache HOME\n- run: gemini --version && gemini auth login  # or restore a cached auth dir\n- run: zeroclaw chat --provider gemini_cli \"hi\"","handlingStrategy":"try-catch","validationCode":"async fn gemini_cli_healthy(binary: &str) -> bool {\n    tokio::process::Command::new(binary)\n        .arg(\"--version\")\n        .output()\n        .await\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","typeGuard":"fn is_gemini_cli_exit_error(e: &anyhow::Error) -> bool {\n    e.to_string().starts_with(\"Gemini CLI exited with non-zero status\")\n}","tryCatchPattern":"match provider.chat_with_system(None, prompt, model, temp).await {\n    Ok(t) => Ok(t),\n    Err(e) if e.to_string().starts_with(\"Gemini CLI exited with non-zero status\") => {\n        // read the embedded Stderr excerpt; check auth, then retry once\n        run_gemini_auth_check().await?;\n        provider.chat_with_system(None, prompt, model, temp).await\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Run the CLI's auth login during provisioning, not at chat time","Pin the gemini CLI version and re-test after upgrades","Set GEMINI_CLI_PATH explicitly in CI to avoid PATH drift","Smoke-test the binary with --version at provider construction"],"tags":["rust","zeroclaw","gemini-cli","process-exit","authentication"],"backgroundTag":"cli-nonzero-exit","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}