Skip to content

The agent that grows with you

refactor(agent): move _parse_absolute_timestamp to credential_pool_timestamps

Teknium0d90fac99d9d
diff --git a/agent/credential_pool.py b/agent/credential_pool.py
index 096a10277ec..6dd967601d4 100644
--- a/agent/credential_pool.py
+++ b/agent/credential_pool.py
@@ -4,6 +4,7 @@ from __future__ import annotations
from agent.credential_pool_admin import CredentialPoolAdminMixin
from agent.credential_pool_model_cooldowns import CredentialPoolModelCooldownMixin, model_cooldown_until
+from agent.credential_pool_timestamps import _parse_absolute_timestamp
import logging
import os
@@ -400,31 +401,6 @@ def _exhausted_ttl(
return base
-def _parse_absolute_timestamp(value: Any) -> Optional[float]:
- """Best-effort parse of epoch seconds / epoch ms / ISO-8601 into epoch seconds."""
- if value is None or value == "":
- return None
- if isinstance(value, (int, float)):
- numeric = float(value)
- if numeric <= 0:
- return None
- return numeric / 1000.0 if numeric > 1_000_000_000_000 else numeric
- if isinstance(value, str):
- raw = value.strip()
- if not raw:
- return None
- try:
- numeric = float(raw)
- return numeric / 1000.0 if numeric > 1_000_000_000_000 else numeric
- except ValueError:
- pass
- try:
- return datetime.fromisoformat(raw.replace("Z", "+00:00")).timestamp()
- except ValueError:
- return None
- return None
-
-
def _singleton_predates_entry(state: Any, entry: "PooledCredential") -> bool:
"""True only when the auth.json singleton is PROVABLY older than *entry*.
diff --git a/agent/credential_pool_timestamps.py b/agent/credential_pool_timestamps.py
new file mode 100644
index 00000000000..6cb3cafdb34
--- /dev/null
+++ b/agent/credential_pool_timestamps.py
@@ -0,0 +1,31 @@
+"""Timestamp parsing shared by credential-pool status, refresh, and cooldown bookkeeping."""
+
+from __future__ import annotations
+
+from datetime import datetime
+from typing import Any, Optional
+
+
+def _parse_absolute_timestamp(value: Any) -> Optional[float]:
+ """Best-effort parse of epoch seconds / epoch ms / ISO-8601 into epoch seconds."""
+ if value is None or value == "":
+ return None
+ if isinstance(value, (int, float)):
+ numeric = float(value)
+ if numeric <= 0:
+ return None
+ return numeric / 1000.0 if numeric > 1_000_000_000_000 else numeric
+ if isinstance(value, str):
+ raw = value.strip()
+ if not raw:
+ return None
+ try:
+ numeric = float(raw)
+ return numeric / 1000.0 if numeric > 1_000_000_000_000 else numeric
+ except ValueError:
+ pass
+ try:
+ return datetime.fromisoformat(raw.replace("Z", "+00:00")).timestamp()
+ except ValueError:
+ return None
+ return None