{"record":{"id":"317b014577007254","repo":"langchain-ai/deepagents","slug":"chatgpt-session-expired-run-auth-and-select-op","errorCode":null,"errorMessage":"ChatGPT session expired. Run `/auth` and select openai_codex to sign in again.","messagePattern":"ChatGPT session expired\\. Run `/auth` and select openai_codex to sign in again\\.","errorType":"exception","errorClass":"MissingCredentialsError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5911,"sourceCode":"        kwargs.pop(\"api_key\", None)\n        try:\n            model = _codex.build_chat_model(model_name, **kwargs)\n        except FileNotFoundError as exc:\n            msg = (\n                \"Not signed in to ChatGPT. Run `/auth` and select \"\n                \"openai_codex to sign in with your ChatGPT account.\"\n            )\n            raise MissingCredentialsError(msg, provider=provider, env_var=None) from exc\n        except _codex.CodexAuthExpiredError as exc:\n            # A token exists but its refresh token is dead. Route through the\n            # same `MissingCredentialsError` recovery path as a missing token\n            # (which the retry flow re-attempts after `/auth`) instead of the\n            # generic `ModelConfigError` below, which would not offer sign-in.\n            msg = (\n                \"ChatGPT session expired. Run `/auth` and select openai_codex \"\n                \"to sign in again.\"\n            )\n            raise MissingCredentialsError(msg, provider=provider, env_var=None) from exc\n        except Exception as exc:\n            spec = f\"{provider}:{model_name}\"\n            msg = f\"Failed to initialize Codex model '{spec}': {exc}\"\n            raise ModelConfigError(msg) from exc\n    elif class_path:\n        model = _create_model_from_class(class_path, model_name, provider, kwargs)\n    else:\n        model = _create_model_via_init(model_name, provider, kwargs)\n\n    resolved_provider = provider or getattr(model, \"_model_provider\", provider)\n    from deepagents_code.cost_tracking import _set_configured_model_metadata\n\n    _set_configured_model_metadata(model, model_name, resolved_provider)\n\n    # Apply profile overrides from config.toml (e.g., max_input_tokens)\n    if provider:\n        config_profile_overrides = config.get_profile_overrides(\n            provider, model_name=model_name","sourceCodeStart":5893,"sourceCodeEnd":5929,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5893-L5929","documentation":"Raised as MissingCredentialsError when the Codex integration reports CodexAuthExpiredError: an auth token file exists but its refresh token is no longer accepted (refresh flow failed), i.e. the ChatGPT session has lapsed. It deliberately routes through the MissingCredentialsError recovery path instead of generic ModelConfigError so the retry flow re-attempts after the user signs in via `/auth`.","triggerScenarios":"Building/refreshing an `openai_codex` model when `_codex.CodexAuthExpiredError` is raised by `_codex.build_chat_model` — the stored refresh token was revoked or expired (long idle period, password change, token rotated elsewhere, signing out of ChatGPT on another device).","commonSituations":"Returning to dcode after weeks of inactivity; ChatGPT account password reset or session revocation; copying an old auth file from a backup; multiple machines sharing one account where a newer sign-in invalidated older refresh tokens.","solutions":["Run `/auth`, select `openai_codex`, and sign in again to obtain a fresh token; the retry flow then re-attempts the request.","Remove the stale auth file if `/auth` behaves oddly, then re-authenticate.","Keep sessions alive by using dcode regularly, or re-auth proactively after account-level security changes."],"exampleFix":"// inside dcode\n/auth            # select openai_codex, complete browser sign-in\n// previous request is then retried with the fresh token","handlingStrategy":"retry","validationCode":"from deepagents_code import codex as _codex\n\ndef codex_auth_still_valid() -> bool:\n    try:\n        _codex.refresh_auth_if_needed()  # surfaces CodexAuthExpiredError early\n        return True\n    except _codex.CodexAuthExpiredError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    model = build_model(\"openai_codex\", model_name)\nexcept MissingCredentialsError as exc:\n    if \"expired\" in str(exc).lower():\n        run_auth_flow(\"openai_codex\")  # re-sign in to get a fresh refresh token\n        model = build_model(\"openai_codex\", model_name)","preventionTips":["Re-run `/auth` after account security changes (password reset, session revocation, signing out elsewhere).","Don't restore stale auth files from backups; always re-authenticate.","Expect re-auth after long idle periods; surface a clear prompt in automated wrappers instead of failing silently."],"tags":["authentication","token-expired","oauth","codex","chatgpt"],"backgroundTag":"jwt-token-expired","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}