{"record":{"id":"767737ecedd53821","repo":"Hmbown/CodeWhale","slug":"codewhale-account-login-timed-out-run-codewhale","errorCode":null,"errorMessage":"Codewhale account login timed out; run `codewhale account login` to try again","messagePattern":"Codewhale account login timed out; run `codewhale account login` to try again","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/cli/src/cloud.rs","lineNumber":327,"sourceCode":"        expect_json(response, &[200])\n    }\n\n    fn poll_device(\n        &self,\n        device: &DeviceStart,\n        timeout: Duration,\n        sleep: &mut dyn FnMut(Duration),\n    ) -> Result<AuthBundle> {\n        validate_device_code(&device.device_code)?;\n        let server_lifetime =\n            Duration::from_secs(device.expires_in.clamp(1, MAX_LOGIN_TIMEOUT_SECONDS));\n        let timeout = timeout.min(server_lifetime);\n        let interval = Duration::from_secs(device.interval.clamp(1, 10));\n        let started = Instant::now();\n\n        loop {\n            if started.elapsed() >= timeout {\n                bail!(\n                    \"Codewhale account login timed out; run `codewhale account login` to try again\"\n                );\n            }\n            let response = self.transport.execute(CloudRequest {\n                method: HttpMethod::Post,\n                path: \"/api/cli/device/token\".to_string(),\n                bearer: None,\n                body: Some(json_body(&DeviceTokenRequest {\n                    device_code: &device.device_code,\n                })?),\n            })?;\n            match response.status {\n                200 => {\n                    let bundle: AuthBundle = parse_json_body(&response.body)?;\n                    validate_auth_bundle(&bundle)?;\n                    self.save_auth(bundle.clone())?;\n                    return Ok(bundle);\n                }","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/cli/src/cloud.rs#L309-L345","documentation":"During OAuth device-code login polling, this bail fires when the elapsed time reaches the timeout (the lesser of the CLI's --timeout and the server-declared device code lifetime, clamped to 1 hour). It is the outer deadline check at the top of the polling loop: the user never completed authorization in the browser before the code expired or the client gave up.","triggerScenarios":"User starts `codewhale account login`, never opens the verification URL (or doesn't approve it), and the min(--timeout, device.expires_in) deadline passes; headless terminal where nobody can open the browser; verification page unreachable.","commonSituations":"Unattended/CI shells where the device flow stalls, slow mail relay for the login link, user stepped away, or a --timeout value smaller than the time the user needed to authorize.","solutions":["Simply rerun `codewhale account login` and complete the browser authorization promptly using the printed user_code.","If you routinely need longer, pass a larger --timeout (bounded by the server's device code lifetime, max 3600s).","In headless environments, copy the verification_uri_complete URL to a machine with a browser and finish within the window.","Check network access to the verification host if the page never loads."],"exampleFix":"# before\ncodewhale account login --timeout 30\n# (user needs ~2 minutes to authorize)\n\n# after\ncodewhale account login --timeout 600","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// CLI-internal; the user-facing pattern is rerunning the command\n// Wrap automation: check for signed-in state before attempting account work\nif !account_logged_in(profile)? {\n    return run_login_with_timeout(profile, Duration::from_secs(600));\n}","preventionTips":["Open the verification URL immediately when login starts.","Use a generous --timeout in interactive sessions (up to 3600).","In scripts, check for an existing session before triggering device flow."],"tags":["oauth","device-flow","login-timeout","cloud","cli"],"backgroundTag":"device-flow-authorization-pending-timeout","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}