{"record":{"id":"381d4dc7b6dbc9b6","repo":"langchain-ai/deepagents","slug":"coldcachewarning-age-seconds-self-age-seconds-r","errorCode":null,"errorMessage":"ColdCacheWarning age_seconds={self.age_seconds!r} does not pair with reason={self.reason!r}: an age is required except for 'age_unknown', which must have none","messagePattern":"ColdCacheWarning age_seconds=(.+?) does not pair with reason=(.+?): an age is required except for 'age_unknown', which must have none","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/cold_cache.py","lineNumber":260,"sourceCode":"    \"\"\"\n\n    reason: ColdCacheReason\n    \"\"\"Why the cache is treated as cold; selects the modal's copy.\"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Enforce the documented `age_seconds`/`reason` pairing.\n\n        Raises:\n            ValueError: When an age is present for `age_unknown`, or absent for\n                any other reason.\n        \"\"\"\n        if (self.age_seconds is None) != (self.reason == \"age_unknown\"):\n            msg = (\n                f\"ColdCacheWarning age_seconds={self.age_seconds!r} does not \"\n                f\"pair with reason={self.reason!r}: an age is required except \"\n                f\"for 'age_unknown', which must have none\"\n            )\n            raise ValueError(msg)\n\n\ndef debug_stand_in_policy() -> PromptCachePolicy:\n    \"\"\"Build the placeholder policy used by `DEEPAGENTS_CODE_DEBUG_COLD_CACHE`.\n\n    Keeps the modal reachable on providers with no documented cache policy.\n    Lives here rather than in the caller so the Anthropic window and minimum\n    stay tied to `_ANTHROPIC_MIDDLEWARE_TTL_SECONDS` and\n    `_ANTHROPIC_DEFAULT_MINIMUM_TOKENS` instead of being re-hardcoded, which\n    would silently drift the moment either constant is revised.\n\n    The provider name is deliberately Anthropic's: under the debug flag the\n    modal may therefore cite Anthropic retention while a different provider is\n    active. The figures are illustrative in that mode, not real estimates.\n\n    Returns:\n        Stand-in policy shaped like Anthropic's.\n    \"\"\"","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/cold_cache.py#L242-L278","documentation":"ColdCacheWarning pairs a reason with an optional age_seconds; __post_init__ enforces the XOR invariant that age_seconds is present exactly when reason != 'age_unknown' (and absent for 'age_unknown'). This keeps rendering honest: a warning never claims an age it cannot know, and never hides a known age.","triggerScenarios":"Constructing ColdCacheWarning(reason='age_unknown', age_seconds=120) or ColdCacheWarning(reason='stale_cache', age_seconds=None) — either mismatch of the pairing raises.","commonSituations":"Plumbing an age through code paths where it is unknown but leaving the reason as a concrete one, or defaulting age_seconds=None for a reason that does have a measured age.","solutions":["Use reason='age_unknown' when the cache age is genuinely unknown and pass age_seconds=None.","Provide the measured age_seconds for any concrete reason (e.g. 'stale_cache') instead of None.","Derive the reason from the presence of the age ((age_seconds is None) -> 'age_unknown') instead of hardcoding them independently."],"exampleFix":"// before\nwarn = ColdCacheWarning(reason=\"stale_cache\", age_seconds=None)\n// after\nwarn = ColdCacheWarning(reason=\"stale_cache\", age_seconds=measured_age) if measured_age is not None else ColdCacheWarning(reason=\"age_unknown\", age_seconds=None)","handlingStrategy":"type-guard","validationCode":"reason = \"age_unknown\" if age is None else concrete_reason\nwarn = ColdCacheWarning(reason=reason, age_seconds=age)","typeGuard":"def is_valid_warning_args(reason: str, age: float | None) -> bool:\n    return (age is None) == (reason == \"age_unknown\")","tryCatchPattern":"try:\n    warn = ColdCacheWarning(reason=reason, age_seconds=age)\nexcept ValueError as e:\n    logger.warning(\"dropping malformed cold-cache warning: %s\", e)\n    warn = None","preventionTips":["Derive reason from age availability instead of hardcoding both independently","Reserve 'age_unknown' strictly for genuinely unknown ages","Centralize ColdCacheWarning construction in one helper that enforces the pairing"],"tags":["validation","dataclass","invariant"],"backgroundTag":"inconsistent-field-pairing","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}