{"record":{"id":"795316bb50df2182","repo":"langchain-ai/deepagents","slug":"device-flow-failed-err-body-get-error-descri","errorCode":null,"errorMessage":"Device flow failed: {err}: {body.get('error_description', '')}","messagePattern":"Device flow failed: (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":1963,"sourceCode":"            except ValueError as exc:\n                # Malformed JSON would otherwise cascade into a confusing\n                # OAuthToken.model_validate({}) error below; log the cause\n                # explicitly so debugging is possible.\n                logger.warning(\n                    \"Token endpoint %s returned non-JSON body: %s\",\n                    token_url,\n                    exc,\n                )\n                body = {}\n            err = body.get(\"error\")\n            if err == \"authorization_pending\":\n                continue\n            if err == \"slow_down\":\n                interval += 5\n                continue\n            if err:\n                msg = f\"Device flow failed: {err}: {body.get('error_description', '')}\"\n                raise RuntimeError(msg)\n            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.\"","sourceCodeStart":1945,"sourceCodeEnd":1981,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L1945-L1981","documentation":"This RuntimeError is raised by `_run_device_flow` in mcp_auth.py when the GitHub OAuth device-flow token poll returns a terminal `error` value in its response body. Only transient errors (`authorization_pending`, `slow_down`) are retried; any other error (e.g. `access_denied`, `expired_token`) aborts the flow with the error code and GitHub's `error_description` embedded in the message.","triggerScenarios":"Calling `login` (via `_preseed_github_auth`) for an http/sse MCP server while the device-flow poll endpoint returns a non-retryable error field: the user denied the authorization request, the device code expired before confirmation, or the poll request was otherwise rejected.","commonSituations":"User clicks 'Cancel' on the GitHub activation page; user takes too long to enter the code so it expires; corporate proxy or SSO policy blocks the token endpoint; clock/network issues cause the polling loop to outlive the code's lifetime.","solutions":["Re-run the login command and complete the authorization in the browser promptly before the device code expires","Check the `error_description` in the message — if `access_denied`, the user declined; approve the request on the github.com/activate page","Verify network/proxy settings allow HTTPS POSTs to github.com's OAuth token endpoint","If `expired_token` recurs, retry login immediately after starting the flow rather than delaying confirmation"],"exampleFix":"// before: delaying too long before confirming\ncode = start_login()\ntime.sleep(900)  # device code expires\nrun_cli_login()\n// after\nrun_cli_login()  # confirm the code in the browser immediately","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible; errors come from the interactive poll.\n// Ensure network access to github.com and complete browser auth promptly.","typeGuard":null,"tryCatchPattern":"try:\n    login(server_name)\nexcept RuntimeError as exc:\n    if \"Device flow failed\" in str(exc):\n        print(f\"GitHub denied the device flow: {exc}. Re-run login and approve the request.\")\n    raise","preventionTips":["Complete the browser authorization as soon as the verification URL appears","Do not delay between starting login and entering the code (device codes expire quickly)","Verify proxy/VPN settings allow access to github.com OAuth endpoints"],"tags":["oauth","device-flow","github","authentication"],"backgroundTag":"oauth-device-flow-denied","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}