Hmbown/CodeWhale · error

xAI device-code authorization timed out. Re-run device login

Error message

xAI device-code authorization timed out. Re-run device login and approve the code before it expires.

What it means

Raised in the xAI device-code login flow when the polling loop exceeds the device grant's expiry deadline (device.expires_in) without the user approving the verification code. The device code is no longer valid at the issuer, so the flow aborts instead of polling forever; the printed code has expired and a new login must be started.

Source

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

        .or(device.verification_uri.clone())
        .unwrap_or_else(|| format!("{issuer}/device"));

    eprintln!("xAI device-code login");
    eprintln!("  Open:  {verify}");
    eprintln!("  Code:  {}", device.user_code);
    eprintln!("Waiting for approval in the browser… (Ctrl+C to abort)");
    if open_browser && let Err(err) = webbrowser::open(&verify) {
        eprintln!("Could not open the browser automatically: {err}");
    }

    let mut interval = device.interval.unwrap_or(DEVICE_POLL_DEFAULT_SECS).max(1);
    let deadline = std::time::Instant::now()
        + Duration::from_secs(device.expires_in.unwrap_or(DEVICE_POLL_MAX_SECS).max(30));

    loop {
        let now = std::time::Instant::now();
        if now >= deadline {
            bail!(
                "xAI device-code authorization timed out. Re-run device login \
                 and approve the code before it expires."
            );
        }
        // Never sleep past the code's expiry, even after slow_down backoff.
        thread::sleep(Duration::from_secs(interval).min(deadline - now));
        match poll_device_token(&endpoints.token_endpoint, client_id, &device.device_code) {
            Ok(token) => {
                return Ok(PendingXaiDeviceLogin {
                    issuer: issuer.to_string(),
                    client_id: client_id.to_string(),
                    token,
                });
            }
            Err(err) => {
                let msg = err.to_string();
                match device_poll_backoff(interval, &msg) {
                    Some(next_interval) => {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Re-run the device login command to get a fresh verification code
  2. Approve the code in the browser before it expires on the next attempt
  3. Use `codewhale auth xai-device` again and complete approval promptly
Defensive patterns

Strategy: retry

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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