Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hermes_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,28 @@ def _resolve_api_key_provider_secret(
key = str(key).strip()
if has_usable_secret(key):
return key, f"credential_pool:{provider_id}"
# fix(#40960): when all entries are in exhaustion cooldown,
# return any usable (even exhausted) key so the upstream API
# returns its real 429 with the quota-reset timestamp instead
# of a misleading 401 from sending an empty Authorization header.
try:
for exhausted_entry in pool._entries:
ex_key = (
getattr(exhausted_entry, "access_token", "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raw iteration includes STATUS_DEAD entries as well as cooldown entries. CredentialPool._available_entries() intentionally excludes dead credentials (agent/credential_pool.py:1483-1516); returning one here can send a permanently invalid key and retain the same 401 failure.

or getattr(exhausted_entry, "runtime_api_key", "")
or ""
)
ex_key = str(ex_key).strip()
if has_usable_secret(ex_key):
logger.warning(
"credential_pool: all entries for %s are exhausted; "
"returning an exhausted key to surface the real upstream error",
provider_id,
)
return ex_key, f"credential_pool:{provider_id}:exhausted"
except Exception:
# best-effort: if introspection fails, fall through to the empty return
pass
except Exception:
pass

Expand Down