{"record":{"id":"c307da235922a25e","repo":"xai-org/grok-build","slug":"failed-to-clear-auth-e","errorCode":null,"errorMessage":"Failed to clear auth: {e}","messagePattern":"Failed to clear auth: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/auth/flow.rs","lineNumber":987,"sourceCode":"            auth_manager.remove_scope(scope)?;\n        } else {\n            auth_manager.clear()?;\n        }\n        crate::managed_config::clear_orphan();\n    }\n    Ok(LogoutResult {\n        was_logged_in,\n        email,\n        api_key_still_set: crate::agent::auth_method::has_xai_api_key_env(),\n    })\n}\n/// `grok logout` CLI handler. Calls [`perform_logout`] and formats\n/// the result to stderr.\npub fn run_cli_logout(config: &crate::agent::config::Config) -> anyhow::Result<()> {\n    let grok_home = grok_home::grok_home();\n    let auth_manager = AuthManager::new(&grok_home, config.grok_com_config.clone());\n    let result = perform_logout(&auth_manager, None)\n        .map_err(|e| anyhow::anyhow!(\"Failed to clear auth: {e}\"))?;\n    if !result.was_logged_in {\n        eprintln!(\"No cached session to log out of.\");\n        if result.api_key_still_set {\n            eprintln!(\"You are authenticated via XAI_API_KEY (environment variable).\");\n        }\n        return Ok(());\n    }\n    if let Some(email) = result.email {\n        eprintln!(\"Logged out (was signed in as {email})\");\n    } else {\n        eprintln!(\"Logged out\");\n    }\n    if result.api_key_still_set {\n        eprintln!(\"XAI_API_KEY is still set and will be used for authentication.\");\n    }\n    Ok(())\n}\n#[cfg(test)]","sourceCodeStart":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/auth/flow.rs#L969-L1005","documentation":"run_cli_logout (the `grok logout` CLI handler) calls perform_logout to clear cached credentials. If perform_logout returns an error (e.g. the auth store cannot be read/written or the backend rejects the revocation), it is wrapped as 'Failed to clear auth: {e}'. The local session may still be present.","triggerScenarios":"Running `grok logout` when the auth store is unreadable/corrupted, the grok home directory is not writable, the keyring is locked/unavailable, or the remote token revocation request fails.","commonSituations":"Corrupted ~/.grok auth file; read-only home in containers; keyring locked after reboot on headless Linux; network failure during server-side revocation.","solutions":["Read the wrapped cause after the colon; fix that underlying issue (permissions, disk, keyring, network).","If the store is corrupted, back it up and delete the auth file, then log in again.","Ensure grok home is writable (`chmod 700 ~/.grok`) and a keyring/secret service is available and unlocked.","If revocation failed due to network, fix connectivity and retry; the local credentials are the security concern, so clear them manually if needed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const home = process.env.GROK_HOME || '~/.grok';\ntry { fs.accessSync(home, fs.constants.W_OK | fs.constants.R_OK); }\ncatch { console.error('grok home unreadable/unwritable; logout will fail'); }","typeGuard":null,"tryCatchPattern":"match run_cli_logout(config) {\n    Err(e) if e.to_string().starts_with(\"Failed to clear auth\") => {\n        eprintln!(\"{e:#} — fix the root cause (permissions/keyring/corrupt store) and retry\");\n    }\n    other => other?,\n}","preventionTips":["Keep grok home readable/writable by the running user","Unlock the keyring before scripted logouts on headless hosts","Replace corrupted auth store files instead of forcing logout","Check network before assuming revocation failure is local"],"tags":["auth","logout","cli","persistence"],"backgroundTag":"logout-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}