{"record":{"id":"1dd5f359c3156fe0","repo":"xai-org/grok-build","slug":"no-user-grok-home-set-grok-home-or-home","errorCode":null,"errorMessage":"no user grok home (set $GROK_HOME or $HOME)","messagePattern":"no user grok home \\(set \\$GROK_HOME or \\$HOME\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/hub_auth/mod.rs","lineNumber":88,"sourceCode":"    #[serde(default)]\n    user_id: String,\n    #[serde(default)]\n    refresh_token: Option<String>,\n    #[serde(default)]\n    oidc_issuer: Option<String>,\n    #[serde(default)]\n    oidc_client_id: Option<String>,\n    #[serde(default)]\n    principal_type: Option<String>,\n    #[serde(default)]\n    principal_id: Option<String>,\n    #[serde(default)]\n    expires_at: Option<chrono::DateTime<chrono::Utc>>,\n}\n\npub fn default_auth_path() -> anyhow::Result<PathBuf> {\n    let grok = xai_grok_config::user_grok_home()\n        .ok_or_else(|| anyhow::anyhow!(\"no user grok home (set $GROK_HOME or $HOME)\"))?;\n    Ok(grok.join(\"auth.json\"))\n}\n\n/// Read the active OIDC entry and its scope key. The key is threaded to the\n/// refresh write so rotation updates exactly the entry that was read.\n///\n/// When several OIDC entries qualify, pick the **latest `expires_at`** — the\n/// entry the shell is actively refreshing. The previous first-key selection\n/// was alphabetical and could rotate a *different principal's* RT chain than\n/// the one the user's sessions use.\nfn read_auth_entry(path: &Path) -> anyhow::Result<(String, AuthEntry)> {\n    if !path.exists() {\n        anyhow::bail!(\n            \"No auth credentials found at {}. Run `grok login` first.\",\n            path.display()\n        );\n    }\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/hub_auth/mod.rs#L70-L106","documentation":"default_auth_path resolves the directory holding the user's grok credentials by calling xai_grok_config::user_grok_home(), which reads $GROK_HOME (falling back to $HOME). If neither environment variable is set/resolvable, this error is thrown instead of guessing a path.","triggerScenarios":"Calling default_auth_path (or `provider()`, which uses it) in an environment where both GROK_HOME and HOME are unset — e.g. systemd services with a scrubbed environment, Docker containers without HOME, or CI jobs running as a user without a home directory.","commonSituations":"Docker images running as non-root without ENV HOME set; systemd unit files lacking Environment=HOME=; CI runners with minimal env; running the tool via a wrapper that strips environment variables.","solutions":["Set the HOME environment variable for the process/user running the tool.","Set GROK_HOME explicitly to the directory containing auth.json.","In Docker, add `ENV HOME=/root` or run with `-e HOME=...`.","In systemd units, add `Environment=HOME=%h` to the [Service] section."],"exampleFix":"// before: no home in container\nCMD [\"grok\", \"serve\"]\n// after\nENV HOME=/root\nCMD [\"grok\", \"serve\"]\n# or: docker run -e GROK_HOME=/data/grok ...","handlingStrategy":"validation","validationCode":"fn ensure_grok_home_configured() -> Result<(), String> {\n    if std::env::var_os(\"GROK_HOME\").is_some() || std::env::var_os(\"HOME\").is_some() {\n        Ok(())\n    } else {\n        Err(\"set $GROK_HOME or $HOME before running\".into())\n    }\n}","typeGuard":null,"tryCatchPattern":"match default_auth_path() {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"no user grok home\") => {\n        eprintln!(\"set GROK_HOME or HOME and retry\");\n        std::process::exit(2);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always set HOME in Dockerfiles (ENV HOME=/root) and systemd units (Environment=HOME=%h)","Prefer explicit GROK_HOME in service/container deployments","Check env vars in startup/health scripts before first auth call"],"tags":["environment","config","auth","missing-env-var"],"backgroundTag":"missing-env-var","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}