Don't let `openai_prompt_cache_retention` widen the cache-health window on GPT-5.6+

Merged
DO
2mo ago
+54-8

On GPT-5.6 and later, OpenAIChatModel/OpenAIResponsesModel.resolve_cache_retention() no longer turns openai_prompt_cache_retention='24h' into a 24-hour window. Cache-health classification and prompt_cache_outlook fall back to the profile's 30-minute default_cache_retention instead.

Per OpenAI's prompt caching guide, on GPT-5.6+ prompt_cache_retention is deprecated in favour of prompt_cache_options.ttl (a 30-minute minimum). 24h is still accepted, but only as an independent maximum, so it doesn't guarantee a longer-lived prefix. Before this change, setting it moved our expected window from 30m to 24h, and a collapse after 45 idle minutes was labelled unexpected (emitting pydantic_ai.cache.collapse) instead of ttl_expired.

Behaviour on earlier models is unchanged: '24h' still resolves to 24 hours there. The flag that gates this is openai_supports_prompt_cache_breakpoints, the same one that sets the 30-minute default. On OpenAI-compatible endpoints that share the flag but have no default_cache_retention, the window becomes unknown rather than 24h, which is the conservative direction.

Tests: the existing parametrized resolver test now uses gpt-5.5 (pre-5.6 behaviour). A new test drives CacheHealthDetector with a real gpt-5.6 Chat/Responses model and '24h' settings, and checks that a 45-minute idle collapse is ttl_expired with a 30-minute retention and no alert. The docs in logfire.md and message-history.md that describe the window now say this applies "before GPT-5.6".

  • No issue: fixes a bug in #6534's cache-health classification

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code