{"record":{"id":"2d401453d2c781b0","repo":"langchain-ai/deepagents","slug":"device-flow-timed-out-try-logging-in-again","errorCode":null,"errorMessage":"Device flow timed out. Try logging in again.","messagePattern":"Device flow timed out\\. Try logging in again\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":1982,"sourceCode":"            try:\n                token_response.raise_for_status()\n            except httpx.HTTPStatusError as exc:\n                msg = (\n                    f\"Token request failed: HTTP {token_response.status_code} \"\n                    f\"from {token_url}.\"\n                )\n                raise RuntimeError(msg) from exc\n            try:\n                return OAuthToken.model_validate(body)\n            except ValidationError as exc:\n                msg = (\n                    f\"Token response from {token_url} is not a valid \"\n                    f\"OAuth token payload: {exc}\"\n                )\n                raise RuntimeError(msg) from exc\n\n    msg = \"Device flow timed out. Try logging in again.\"\n    raise RuntimeError(msg)\n\n\ndef format_login_failure(exc: BaseException) -> str:\n    \"\"\"Return a token-safe single-line summary of an OAuth-login exception.\n\n    OAuth handshakes commonly surface as `ExceptionGroup` (anyio task\n    groups) or as MCP-SDK errors whose `args`/`repr` may include an\n    `OAuthToken`. Never call `str()`/`repr()` on the raw exception for\n    display or logging — instead, prefer a known-safe nested\n    `MCPReauthRequiredError` message, fall back to the messages of our\n    own loopback-related exception types, and degrade to a class-name\n    chain for anything else.\n\n    Args:\n        exc: Root exception caught from the login worker.\n\n    Returns:\n        A user-displayable string that is safe to log and to render.","sourceCodeStart":1964,"sourceCodeEnd":2000,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L1964-L2000","documentation":"`_run_device_flow` gives up and raises this RuntimeError when the polling loop exhausts its time budget without ever receiving a terminal success or error response — the token poll kept returning `authorization_pending` (or `slow_down`) until the deadline. It is the normal failure mode when the user never completes the browser authorization in time.","triggerScenarios":"The device-flow poll loop runs past its timeout while the user has not yet opened the verification URL and entered the code; the loop exits its `while` and hits the unconditional raise at the end of the function.","commonSituations":"User ignored the browser prompt; verification URL blocked by browser policy; user entered the code after it expired without noticing; headless/CI environment where no one can complete the interactive step.","solutions":["Re-run the login and complete the browser authorization promptly within the timeout window","Ensure the verification URL is openable in your default browser (check BROWSER env var or open the printed URL manually)","In headless/SSH environments, copy the code and URL to a machine with a browser","Retry the login to get a fresh device code if the previous one expired"],"exampleFix":"// before: never opening the printed verification URL\n$ dcode mcp login\nDevice code: ABCD-1234  # ignore, flow times out\n// after\n$ dcode mcp login\n# open https://github.com/login/device immediately and enter ABCD-1234","handlingStrategy":"retry","validationCode":"# Verify a browser can open the verification URL before starting login\nimport webbrowser\nif not webbrowser.get():\n    print(\"No browser available; copy the device-code URL to another machine\")","typeGuard":null,"tryCatchPattern":"try:\n    login(server_name)\nexcept RuntimeError as exc:\n    if \"Device flow timed out\" in str(exc):\n        print(\"Authorization not completed in time. Re-run login and approve promptly.\")\n        login(server_name)  # fresh device code\n    raise","preventionTips":["Start the login only when ready to confirm in the browser immediately","Open the verification URL manually if the default browser does not launch","In headless environments, forward the code/URL to an interactive machine first"],"tags":["oauth","device-flow","timeout","github"],"backgroundTag":"oauth-device-flow-timeout","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}