Hmbown/CodeWhale · error · anyhow::Error

Codewhale-owned xAI OAuth credentials are inactive until the

Error message

Codewhale-owned xAI OAuth credentials are inactive until the xAI route explicitly selects OAuth

What it means

State guard in get_credentials: Codewhale's own xAI OAuth credential storage exists but is considered inactive because the xAI route in config does not explicitly select OAuth as its auth mode. The credentials are not deleted — they are gated until the route opts in, preventing an unexpected auth-mode switch.

Source

Thrown at crates/tui/src/xai_oauth.rs:365

        codewhale_config::ExternalCredentialSource::GrokCli,
        &path,
    ) else {
        return false;
    };
    let Ok(mut file) = load_external_auth_file(&grant) else {
        return false;
    };
    select_entry(&mut file).is_some_and(|(_, entry)| entry_access_token_is_fresh(&entry))
}

/// Load xAI OAuth credentials. Codewhale-owned credentials may refresh and
/// rewrite Codewhale-owned storage. External credentials are read-only.
pub fn get_access_token(config: &Config) -> Result<String> {
    Ok(get_credentials(config)?.access_token)
}

pub fn get_credentials(config: &Config) -> Result<XaiOAuthCredentials> {
    anyhow::ensure!(
        config.api_provider() == ApiProvider::Xai
            && config
                .provider_config_for(ApiProvider::Xai)
                .and_then(|entry| entry.auth_mode.as_deref())
                .is_some_and(auth_mode_uses_xai_oauth),
        "Codewhale-owned xAI OAuth credentials are inactive until the xAI route explicitly selects OAuth"
    );
    if let Some(owned_path) = configured_owned_auth_file_path(config)? {
        return get_owned_credentials(&owned_path);
    }
    let owned_path = codewhale_auth_file_path()?;
    if load_owned_auth_file(&owned_path)?.is_some() {
        return get_owned_credentials(&owned_path);
    }

    let external_path = auth_file_path();
    let grant = config.external_credential_read_grant(
        ApiProvider::Xai,

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Set the xAI provider route's auth mode to explicitly select OAuth in the config.
  2. Run `codewhale auth xai-device` to re-provision and activate Codewhale-owned OAuth credentials.
  3. Continue with the currently selected auth mode if OAuth is not the intended path.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/xai_oauth.rs:365 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/70cf2d29c050d9d9. Report an issue: GitHub.