{"record":{"id":"9a1847f62773731b","repo":"Hmbown/CodeWhale","slug":"xai-device-code-authorization-timed-out-re-run-de","errorCode":null,"errorMessage":"xAI device-code authorization timed out. Re-run device login and approve the code before it expires.","messagePattern":"xAI device-code authorization timed out\\. Re-run device login and approve the code before it expires\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/xai_oauth.rs","lineNumber":556,"sourceCode":"        .or(device.verification_uri.clone())\n        .unwrap_or_else(|| format!(\"{issuer}/device\"));\n\n    eprintln!(\"xAI device-code login\");\n    eprintln!(\"  Open:  {verify}\");\n    eprintln!(\"  Code:  {}\", device.user_code);\n    eprintln!(\"Waiting for approval in the browser… (Ctrl+C to abort)\");\n    if open_browser && let Err(err) = webbrowser::open(&verify) {\n        eprintln!(\"Could not open the browser automatically: {err}\");\n    }\n\n    let mut interval = device.interval.unwrap_or(DEVICE_POLL_DEFAULT_SECS).max(1);\n    let deadline = std::time::Instant::now()\n        + Duration::from_secs(device.expires_in.unwrap_or(DEVICE_POLL_MAX_SECS).max(30));\n\n    loop {\n        let now = std::time::Instant::now();\n        if now >= deadline {\n            bail!(\n                \"xAI device-code authorization timed out. Re-run device login \\\n                 and approve the code before it expires.\"\n            );\n        }\n        // Never sleep past the code's expiry, even after slow_down backoff.\n        thread::sleep(Duration::from_secs(interval).min(deadline - now));\n        match poll_device_token(&endpoints.token_endpoint, client_id, &device.device_code) {\n            Ok(token) => {\n                return Ok(PendingXaiDeviceLogin {\n                    issuer: issuer.to_string(),\n                    client_id: client_id.to_string(),\n                    token,\n                });\n            }\n            Err(err) => {\n                let msg = err.to_string();\n                match device_poll_backoff(interval, &msg) {\n                    Some(next_interval) => {","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/xai_oauth.rs#L538-L574","documentation":"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.","triggerScenarios":"Thrown at crates/tui/src/xai_oauth.rs:556 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-run the device login command to get a fresh verification code","Approve the code in the browser before it expires on the next attempt","Use `codewhale auth xai-device` again and complete approval promptly"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}