{"record":{"id":"db1304ad246f9586","repo":"langchain-ai/deepagents","slug":"is-expired-is-only-meaningful-when-logged-in-i","errorCode":null,"errorMessage":"`is_expired` is only meaningful when `logged_in` is True.","messagePattern":"`is_expired` is only meaningful when `logged_in` is True\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/integrations/openai_codex.py","lineNumber":115,"sourceCode":"                logged-out snapshot carries an `expires_at`, `is_expired`,\n                `account_id`, or `plan_type`; or a logged-in snapshot is\n                missing its `expires_at`.\n        \"\"\"\n        if self.unreadable_reason is not None and self.logged_in:\n            msg = (\n                \"`unreadable_reason` implies the token is not usable; \"\n                \"`logged_in` must be False.\"\n            )\n            raise ValueError(msg)\n        if self.logged_in and self.expires_at is None:\n            msg = \"`expires_at` must be set when `logged_in` is True.\"\n            raise ValueError(msg)\n        if not self.logged_in and self.expires_at is not None:\n            msg = \"`expires_at` is only meaningful when `logged_in` is True.\"\n            raise ValueError(msg)\n        if not self.logged_in and self.is_expired:\n            msg = \"`is_expired` is only meaningful when `logged_in` is True.\"\n            raise ValueError(msg)\n        if not self.logged_in and (self.account_id or self.plan_type):\n            msg = (\n                \"`account_id`/`plan_type` are only meaningful when `logged_in` is True.\"\n            )\n            raise ValueError(msg)\n\n\ndef default_store_path() -> Path:\n    \"\"\"Return the ChatGPT OAuth token store path.\n\n    Stored under Deep Agents' own state dir\n    (`~/.deepagents/.state/chatgpt-auth.json`) so the credential lives\n    alongside the rest of the app's state rather than in `langchain_openai`'s\n    default `~/.langchain`.\n    \"\"\"\n    from deepagents_code.model_config import DEFAULT_STATE_DIR\n\n    return DEFAULT_STATE_DIR / \"chatgpt-auth.json\"","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/integrations/openai_codex.py#L97-L133","documentation":"`__post_init__` invariant: `is_expired` is a derived property meaningful only when `logged_in` is True; a state with `logged_in=False` and a truthy `is_expired` is contradictory and raises ValueError.","triggerScenarios":"Constructing with `logged_in=False` while the derived `is_expired` evaluates truthy (typically because `expires_at` leaked into the object or `is_expired` was set directly), e.g. `TokenState(logged_in=False, expires_at=past_time)` per its internal logic.","commonSituations":"Logged-out snapshots that retain an expired timestamp, test fixtures built with all fields populated, or custom subclasses overriding the expiry logic.","solutions":["Set `expires_at=None` (and thus a falsy `is_expired`) when `logged_in=False`.","Keep `logged_in=True` if expiry tracking is needed.","Ensure any state-transformation code resets expiry-derived fields on logout."],"exampleFix":"// before\nstate = CodexAuthState(logged_in=False, expires_at=past_timestamp)\n// after\nstate = CodexAuthState(logged_in=False, expires_at=None)","handlingStrategy":"validation","validationCode":"def valid_state(state) -> bool:\n    if state.logged_in:\n        return state.expires_at is not None\n    return state.expires_at is None and not state.is_expired and not (state.account_id or state.plan_type)","typeGuard":null,"tryCatchPattern":"try:\n    state = CodexAuthState(**fields)\nexcept ValueError as exc:\n    logger.warning('contradictory token state: %s', exc)\n    state = CodexAuthState(logged_in=False)","preventionTips":["Treat is_expired/expiry fields as meaningful only for logged-in states","Reset expiry-derived fields whenever logged_in flips to False","Add an invariant round-trip test when persisting/restoring state"],"tags":["python","validation","dataclass","state"],"backgroundTag":"invariant-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}