fix(agent): notify gateway users when all provider credentials are auth-exhausted

When all credentials for a provider are exhausted due to 401/403 failures,
emit a plain-language _emit_status() notification so gateway users (Telegram,
Discord, etc.) know their primary AI has become unavailable and what to do.

Same-provider key rotation remains silent — the message only fires when
rotation itself fails and Hermes is forced to fall back.

This is distinct from the cooldown duration change in PR #10058 (which was
closed). The notification half of that fix stands on its own: the configured
fallback_model path already calls _emit_status() on provider switch, so this
makes the credential pool exhaustion path consistent with that behavior.

Closes #10476
This commit is contained in:
André Angelantoni 2026-04-15 12:30:35 -07:00
parent d1d425e9d0
commit 9eccb11edf
No known key found for this signature in database
GPG key ID: EFA639A844761253

View file

@ -4799,6 +4799,18 @@ class AIAgent:
)
self._swap_credential(next_entry)
return True, False
# All credentials for this provider are exhausted due to an auth
# failure. Emit a plain-language notification so gateway users
# (Telegram, Discord, etc.) know their primary AI is unavailable
# and what to do about it. Same-provider key rotation (above)
# remains silent — the message only fires when rotation fails.
_provider_label = getattr(self, "provider", "unknown")
self._emit_status(
f"⚠️ Primary AI ({_provider_label}) is unavailable — the API key "
f"may be invalid or expired (HTTP {rotate_status}). Switched to "
f"fallback if one is configured. To restore: check your API key "
f"and run `hermes auth reset {_provider_label}`."
)
return False, has_retried_429