{"record":{"id":"36b5d9021d6bae26","repo":"HKUDS/Vibe-Trading","slug":"the-vibe-trading-codex-oauth-session-was-invalidat","errorCode":null,"errorMessage":"The Vibe-Trading Codex OAuth session was invalidated","messagePattern":"The Vibe-Trading Codex OAuth session was invalidated","errorType":"exception","errorClass":"CodexAuthenticationError","httpStatus":null,"severity":"critical","filePath":"agent/src/providers/openai_codex.py","lineNumber":370,"sourceCode":"\n    with _codex_refresh_lock(storage):\n        latest = storage.load()\n        if not (latest and latest.access and latest.refresh and latest.account_id):\n            raise _missing_codex_login_error()\n        token = latest\n        now_ms = int(time.time() * 1000)\n\n        if rejected_access and token.access != rejected_access and _token_expiry_ms(token) > now_ms:\n            return token\n        if not force_refresh and _token_expiry_ms(token) - now_ms > _CODEX_REFRESH_MARGIN_SECONDS * 1000:\n            return token\n\n        try:\n            refreshed = _refresh_codex_token(token, storage)\n        except _CodexRefreshError as exc:\n            if exc.permanent:\n                _clear_codex_token(storage)\n                raise CodexAuthenticationError(\"The Vibe-Trading Codex OAuth session was invalidated\") from exc\n            if not force_refresh and _token_expiry_ms(token) > now_ms:\n                return token\n            raise CodexStreamError(\n                exc.status_code or 503,\n                f\"Codex OAuth recovery temporarily failed: {exc}\",\n            ) from exc\n        if refreshed.access == token.access:\n            if not force_refresh and _token_expiry_ms(token) > now_ms:\n                return token\n            _clear_codex_token(storage)\n            raise CodexAuthenticationError(\"The Codex backend rejected the access token and refresh did not replace it\")\n        return refreshed\n\n\ndef validate_codex_base_url(url: str) -> str:\n    \"\"\"Validate the only supported ChatGPT Codex OAuth endpoint.\n\n    ChatGPT OAuth tokens must not be sent to arbitrary OpenAI-compatible base","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/providers/openai_codex.py#L352-L388","documentation":"During token retrieval, the refresh attempt failed with a _CodexRefreshError marked permanent (e.g. refresh token invalidated/reused). The library clears the stored token and raises CodexAuthenticationError because the session cannot be recovered automatically.","triggerScenarios":"The stored Codex refresh token was revoked, reused by another process, or invalidated server-side (the token_invalidated/refresh_token_reused failure), then any request needing auth calls _get_codex_token.","commonSituations":"Logging in from two machines/processes sharing one token file (issue #975 style refresh-token reuse); revoking sessions in the ChatGPT UI; long-stale tokens after password/security changes.","solutions":["Re-authenticate interactively: run the Codex provider login command to write a fresh token to Vibe-owned storage","Ensure only one process owns the OAuth session (don't copy auth files between machines)","After re-login, retry the request; no code change needed"],"exampleFix":"# before\nCodexAuthenticationError: The Vibe-Trading Codex OAuth session was invalidated\n\n# after\n# terminal 1\nvibe-trading provider login openai-codex\n# then retry the original request","handlingStrategy":"try-catch","validationCode":"from src.providers.openai_codex import get_openai_codex_login_status\nif not get_openai_codex_login_status().logged_in:\n    raise SystemExit('Run Codex login first')","typeGuard":null,"tryCatchPattern":"try:\n    token = _get_codex_token(storage)\nexcept CodexAuthenticationError:\n    logging.warning('session invalidated; launching interactive login')\n    login_openai_codex()\n    token = _get_codex_token(storage)","preventionTips":["Never copy/share the auth token file between machines or processes","Catch CodexAuthenticationError separately from transient stream errors and prompt re-login"],"tags":["oauth","codex","token-invalidated","re-authentication"],"backgroundTag":"refresh-token-invalidated","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}