JuliusBrussee/caveman · error · Error
device login polling failed
Error message
device login polling failed: ${error instanceof Error ? error.message : String(error)} What it means
Thrown by runCavemanDeviceFlow when a token-polling request throws (network error, invalid JSON, etc.) and the polling deadline has already passed. The original error's message is wrapped in 'device login polling failed: ...'. If the signal aborted, the signal's reason is rethrown instead; if time remains, the loop retries after a backoff wait.
Solutions
- Restart the device flow (call runCavemanDeviceFlow again) to obtain a fresh device code with a new expiry window.
- Fix the underlying network issue named in the wrapped message (DNS, TLS, proxy).
- Complete approval in the browser before expires_in elapses; the wrapped message shows the last poll error after the deadline.
- If timeouts are frequent, check system clock skew — Date.now() vs server time affects the deadline.
Example fix
// before: user approves too late
await runCavemanDeviceFlow({ ..., onCode: c => console.log(c.user_code) }); // expired after 15 min
// after: detect and retry with a fresh code
try { await runCavemanDeviceFlow(opts); } catch (e) {
if (String(e.message).startsWith('device login polling failed')) await runCavemanDeviceFlow(opts);
} Defensive patterns
Strategy: retry
Try / catch
try {
await runCavemanDeviceFlow(opts);
} catch (e) {
if (e instanceof Error && e.message.startsWith('device login polling failed')) {
// deadline passed with a transport error: restart the flow with a fresh device code
await runCavemanDeviceFlow(opts);
} else throw e;
} Prevention
- Prompt users to approve promptly within expires_in
- Restart the whole flow on polling failure rather than resuming
- Ensure network stability (avoid sleeping/suspending mid-flow)
- Check AbortSignal wiring — pass a signal only when cancellation is intended
When it happens
Trigger: Inside the polling loop's catch block: a fetch or response.json() error occurs AND Date.now() >= deadline (the expires_in window from the device code has elapsed).
Common situations: User takes longer than expires_in to approve, network drops out mid-poll, server returns malformed JSON on the last poll after the window closed, or laptop sleeps past the deadline.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
Related errors
- device login timed out before approval
- AbortError
- awscreds: request failed
- cave_agent_tool_timeout | cave_network_error
- caveman trial proxy did not become ready on
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/fbd49cba268080d7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/device-auth/src/index.ts:134
let retryAfterMs = 0;
try {
const response = await fetcher(`${baseURL}/api/v1/auth/device/token`, {
method: "POST",
headers: { "content-type": "application/json", "x-cave-client": options.client },
body: JSON.stringify({ device_code: code.device_code }),
signal: requestSignal(options.signal, 5000),
});
status = response.status;
const retryAfter = response.headers.get("retry-after");
if (retryAfter !== null) {
const seconds = Number(retryAfter);
if (Number.isFinite(seconds) && seconds >= 0) retryAfterMs = seconds * 1000;
}
payload = await response.json() as Record<string, unknown>;
} catch (error) {
if (options.signal?.aborted) throw options.signal.reason;
if (Date.now() >= deadline) {
throw new Error(`device login polling failed: ${error instanceof Error ? error.message : String(error)}`);
}
await wait(Math.max(intervalMs, retryAfterMs, 200));
continue;
}
if (status === 429) {
await wait(Math.max(intervalMs, retryAfterMs, 200));
continue;
}
const accessToken = typeof payload.access_token === "string" ? payload.access_token : "";
if (accessToken !== "") {
const credentials = { ...payload, access_token: accessToken } as DeviceCredentials;
let acknowledged = false;
return {
code: structuredClone(code),
credentials: structuredClone(credentials),
async acknowledge() {
if (acknowledged) return;
await acknowledge({View on GitHub (pinned to 3ee70a1026)