{"record":{"id":"f89c199aff5d0344","repo":"zeroclaw-labs/zeroclaw","slug":"xai-oauth-discovery-failed-status-body","errorCode":null,"errorMessage":"xAI OAuth discovery failed ({status}): {body}","messagePattern":"xAI OAuth discovery failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-providers/src/auth/xai_oauth.rs","lineNumber":141,"sourceCode":"        \"token endpoint\",\n    )?;\n    Ok(DeviceCodeDiscovery {\n        device_authorization_endpoint,\n        token_endpoint,\n    })\n}\n\nasync fn fetch_discovery(client: &Client) -> Result<DiscoveryResponse> {\n    let response = client\n        .get(XAI_OAUTH_DISCOVERY_URL)\n        .header(\"Accept\", \"application/json\")\n        .send()\n        .await\n        .context(\"Failed to fetch xAI OAuth discovery\")?;\n    if !response.status().is_success() {\n        let status = response.status();\n        let body = response.text().await.unwrap_or_default();\n        anyhow::bail!(\"xAI OAuth discovery failed ({status}): {body}\");\n    }\n    response\n        .json()\n        .await\n        .context(\"Failed to parse xAI OAuth discovery\")\n}\n\npub fn build_authorize_url(authorization_endpoint: &str, pkce: &PkceState) -> String {\n    let mut params = BTreeMap::new();\n    params.insert(\"response_type\", \"code\");\n    params.insert(\"client_id\", XAI_OAUTH_CLIENT_ID);\n    params.insert(\"redirect_uri\", XAI_OAUTH_REDIRECT_URI);\n    params.insert(\"scope\", XAI_OAUTH_SCOPE);\n    params.insert(\"state\", pkce.state.as_str());\n    params.insert(\"code_challenge\", pkce.code_challenge.as_str());\n    params.insert(\"code_challenge_method\", \"S256\");\n    params.insert(\"plan\", \"generic\");\n    params.insert(\"referrer\", \"zeroclaw\");","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-providers/src/auth/xai_oauth.rs#L123-L159","documentation":"`fetch_discovery` GETs `https://auth.x.ai/.well-known/openid-configuration` and any non-2xx aborts xAI OAuth setup; both `fetch_oauth_discovery` and `fetch_device_code_discovery` route through it. All endpoints xai_oauth.rs uses (authorize, token, device authorization) are discovered from this document, so a discovery failure blocks every xAI flow. The HTTP status and body are embedded in the error.","triggerScenarios":"xAI auth outage or maintenance returning 5xx; 429 rate limiting; a firewall, proxy, or captive portal blocking or rewriting auth.x.ai; DNS misresolution.","commonSituations":"CI runners without x.ai reachability; corporate TLS-inspecting proxies; transient provider incidents.","solutions":["Verify reachability directly: `curl -i https://auth.x.ai/.well-known/openid-configuration`","Retry with backoff for 5xx/429; check xAI status channels for incidents","Fix proxy/firewall exemptions so auth.x.ai answers with the JSON document","If discovery stays broken, authenticate another way (e.g. `import_grok_auth_profile` from an existing Grok auth file)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"let resp = reqwest::get(\"https://auth.x.ai/.well-known/openid-configuration\").await?;\nif !resp.status().is_success() {\n    // defer the OAuth flow and surface a connectivity hint instead of a raw error\n}","typeGuard":null,"tryCatchPattern":"match fetch_oauth_discovery(&client).await {\n    Ok(d) => d,\n    Err(e) if e.to_string().contains(\"discovery failed\") && is_transient(&e) => {\n        retry_with_backoff(fetch_oauth_discovery(&client)).await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure egress to auth.x.ai on 443 from CI and prod hosts","Fetch discovery once per run and reuse the result","Watch xAI status for auth incidents before debugging your code"],"tags":["oauth","xai","discovery","network","http","rust"],"backgroundTag":"oauth-discovery-failed","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}