Code-health ratchet: the pre-compression credential refresh grew agent/conversation_compression.py to 4591 lines, over its 4579 cap on main. Pure move (body byte-identical), late-imported at its one call site; no test or doc references the old path.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""Codex app-server compaction cooldown lookup.
|
|
|
|
Sibling of ``agent/conversation_compression.py`` (the facade), which late-imports it at its call site;
|
|
this module must never import the facade (import cycle). It logs under the facade's logger name so log
|
|
consumers keep one source.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger("agent.conversation_compression")
|
|
|
|
|
|
def _codex_compaction_cooldown_remaining(agent: Any) -> float:
|
|
"""Seconds left on this session's compaction-failure cooldown (0 = clear)."""
|
|
compressor = getattr(agent, "context_compressor", None)
|
|
getter = getattr(compressor, "get_active_compression_failure_cooldown", None)
|
|
if not callable(getter):
|
|
return 0.0
|
|
try:
|
|
state = getter(refresh=True)
|
|
except Exception:
|
|
logger.debug("codex compaction cooldown lookup failed", exc_info=True)
|
|
return 0.0
|
|
try:
|
|
return max(0.0, float(state.get("remaining_seconds") or 0.0)) if state else 0.0
|
|
except (TypeError, ValueError):
|
|
return 0.0
|