The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(auth): codex pool reads call read_credential_pool directly; cooldown clear decides ownership under the lock
kshitijk4poorfe6351000f04
diff --git a/hermes_cli/auth_codex.py b/hermes_cli/auth_codex.pyindex ad3b833dbab..a2b02611a08 100644--- a/hermes_cli/auth_codex.py+++ b/hermes_cli/auth_codex.py@@ -579,18 +579,17 @@ def clear_codex_pool_quota_cooldowns(access_token: Optional[str] = None) -> int:rate-limited entry does (a redeemed banked reset restores the whole account; a still-exhaustedentry just re-freezes with fresh metadata on its next 429)."""- from agent.credential_pool import _borrowed_single_use_pool_root, _profile_owns_pool_provider+ from agent.credential_pool import _borrowed_single_use_pool_rootfrom hermes_cli.auth import _auth_store_lock, _load_auth_store, _save_auth_store- cleared = 0- try:- # A profile borrowing the global-root pool must clear the cooldown where the rows live,- # or the restored quota stays frozen behind the root's stale ``last_error_reset_at``.- target = None if _profile_owns_pool_provider("openai-codex") else _borrowed_single_use_pool_root()++ def _clear_in(target: Optional[Path]) -> Optional[int]:+ """Clear inside *target* (None = active store); None when that store has no codex rows."""+ cleared = 0with _auth_store_lock(target_path=target):auth_store = _load_auth_store(target)entries = _pool_entries(auth_store, "openai-codex")- if entries is None:- return 0+ if not entries:+ return Nonefor entry in _codex_pool_dicts(entries):if access_token and str(entry.get("access_token") or "") != access_token:continue@@ -599,9 +598,19 @@ def clear_codex_pool_quota_cooldowns(access_token: Optional[str] = None) -> int:cleared += 1if cleared:_save_auth_store(auth_store, target_path=target)+ return cleared++ try:+ cleared = _clear_in(None)+ if cleared is None:+ # No rows of its own: this profile borrows the global-root pool (the same fallback+ # ``read_credential_pool`` reads through), so the cooldown must clear where the rows live.+ root = _borrowed_single_use_pool_root()+ cleared = _clear_in(root) if root is not None else 0+ return cleared or 0except Exception:logger.debug("Failed to clear Codex pool quota cooldowns", exc_info=True)- return cleared+ return 0def _codex_pool_dicts(entries: Optional[List[Any]]) -> Iterator[Dict[str, Any]]:@@ -610,23 +619,16 @@ def _codex_pool_dicts(entries: Optional[List[Any]]) -> Iterator[Dict[str, Any]]:yield entry-def _read_codex_pool_entries() -> Optional[List[Any]]:- """Locked read of ``credential_pool.openai-codex`` (None when absent).-- Goes through ``read_credential_pool`` so a named profile with an empty local Codex pool- inherits the global-root pool, the same per-provider fallback every other pool read uses."""- from hermes_cli.auth import _auth_store_lock, read_credential_pool- with _auth_store_lock():- return read_credential_pool("openai-codex") or None--def _codex_pool_rate_limit_status() -> Optional[Dict[str, Any]]:- """Return metadata for a pool-only Codex credential in quota cooldown."""- from hermes_cli.auth import _nonempty_str+ """Return metadata for a pool-only Codex credential in quota cooldown.++ Reads through ``read_credential_pool`` so a named profile with no Codex rows of its own sees+ the global-root pool (the per-provider fallback every other pool read uses)."""+ from hermes_cli.auth import _nonempty_str, read_credential_poolfrom agent.credential_pool import _parse_absolute_timestamptry:now = time.time()- for entry in _codex_pool_dicts(_read_codex_pool_entries()):+ for entry in _codex_pool_dicts(read_credential_pool("openai-codex")):token = entry.get("access_token")if not _nonempty_str(token) or not _entry_is_rate_limit_exhausted(entry):continue@@ -652,11 +654,12 @@ def _pool_entries(auth_store: Dict[str, Any], provider_id: str) -> Optional[Listdef _pool_codex_access_token() -> str:"""First non-empty pool access_token not in an exhaustion cooldown window, else "".- Fallback for ``resolve_codex_runtime_credentials`` when the singleton has no creds.+ Fallback for ``resolve_codex_runtime_credentials`` when the singleton has no creds; reads+ through ``read_credential_pool`` so a profile inherits the global-root pool (#34143)."""- from hermes_cli.auth import _nonempty_str+ from hermes_cli.auth import _nonempty_str, read_credential_pooltry:- for entry in _codex_pool_dicts(_read_codex_pool_entries()):+ for entry in _codex_pool_dicts(read_credential_pool("openai-codex")):token, reset_at = entry.get("access_token"), entry.get("last_error_reset_at")in_cooldown = isinstance(reset_at, (int, float)) and reset_at > time.time()if _nonempty_str(token) and not in_cooldown: