The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor: extract shared _coerce_positive_timeout helper (#95433)
kshitijk4poorba7df6a4bfc8
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex a67264fe1fd..e371b0f6769 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -5100,6 +5100,18 @@ def _fallback_chain_entry(task: Optional[str], fb_label: str) -> Optional[Dict[sreturn entry if isinstance(entry, dict) else None+def _coerce_positive_timeout(raw: Any) -> Optional[float]:+ """Coerce a config ``timeout`` value to a positive float, or None.++ Rejects bools (``True``/``False`` are ``int`` subclasses in Python) and+ non-positive values. Shared by the aux client's fallback timeout resolver+ and the compression stall-fallback route resolver (#78981).+ """+ if isinstance(raw, (int, float)) and not isinstance(raw, bool) and raw > 0:+ return float(raw)+ return None++def _fallback_entry_timeout(task: Optional[str], fb_label: str) -> Optional[float]:"""Resolve a per-entry ``timeout`` for a configured fallback candidate.@@ -5118,9 +5130,7 @@ def _fallback_entry_timeout(task: Optional[str], fb_label: str) -> Optional[floa"""entry = _fallback_chain_entry(task, fb_label)raw = entry.get("timeout") if entry else None- if isinstance(raw, (int, float)) and not isinstance(raw, bool) and raw > 0:- return float(raw)- return None+ return _coerce_positive_timeout(raw)def _fallback_provider_from_label(label: str) -> str:diff --git a/agent/conversation_compression.py b/agent/conversation_compression.pyindex 05fed80da87..6c25c05dd02 100644--- a/agent/conversation_compression.py+++ b/agent/conversation_compression.py@@ -890,12 +890,9 @@ def resolve_compression_fallback_route() -> Optional[dict]:exc_info=True,)api_key = None- raw_timeout = entry.get("timeout")- timeout = None- if isinstance(raw_timeout, (int, float)) and not isinstance(- raw_timeout, bool- ) and raw_timeout > 0:- timeout = float(raw_timeout)+ from agent.auxiliary_client import _coerce_positive_timeout++ timeout = _coerce_positive_timeout(entry.get("timeout"))return {"label": f"fallback_chain[{index}]({provider})","provider": provider,