Skip to content

The agent that grows with you

fix(agent): name an exhausted primary pool in the init refusal warning

kshitijk4poor2f9a14460c6e
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 4f090588ec3..40d03a6e072 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -884,13 +884,22 @@ def _routed_client_kwargs(agent, fallback_model, _provider_timeout) -> Optional[
agent.provider = _fb["provider"]
agent.model = _fb_model or _fb["model"]
return _client_kwargs_from_routed(_fb_client, _provider_timeout)
- if _refused_entries:
+ # A burned credential pool (#119533) is otherwise indistinguishable from missing config,
+ # so name it even when no fallback entries are configured.
+ _pool_exhausted = False
+ if _explicit and _explicit != "auto":
+ with suppress(Exception):
+ from agent.credential_pool import load_pool
+ _pool = load_pool(_explicit)
+ _pool_exhausted = _pool.has_credentials() and not _pool.has_available(model=agent.model)
+ if _refused_entries or _pool_exhausted:
# Neutral wording: the explicit-provider branch below raises the provider-specific
# missing-credentials message, not the generic "No LLM provider configured" one.
logger.warning(
- "Init-time provider resolution failed: primary %r unresolvable; fallback entries refused: %s",
+ "Init-time provider resolution failed: primary %r unresolvable (%s); fallback entries refused: %s",
agent.provider,
- "; ".join(f"{_p} ({_r})" for _p, _r in _refused_entries),
+ "credential pool exhausted" if _pool_exhausted else "no usable credentials",
+ "; ".join(f"{_p} ({_r})" for _p, _r in _refused_entries) or "none configured",
)
if _explicit and _explicit not in {"auto", "openrouter", "custom"}:
# Explicit non-OpenRouter provider with no creds and no usable fallback: fail fast.
diff --git a/tests/agent/test_init_fallback_refusal_warning.py b/tests/agent/test_init_fallback_refusal_warning.py
index 47cbbfd1af5..e5db73961fc 100644
--- a/tests/agent/test_init_fallback_refusal_warning.py
+++ b/tests/agent/test_init_fallback_refusal_warning.py
@@ -28,16 +28,37 @@ _LADDER = [
]
+_LADDER_REASONS = (
+ "deepseek",
+ "no usable credentials",
+ "kimi",
+ "kimi auth handshake refused",
+)
+
+
+class _Pool:
+ def __init__(self, available):
+ self._available = available
+
+ def has_credentials(self):
+ return True
+
+ def has_available(self, model=None):
+ return self._available
+
+
@pytest.mark.parametrize(
- "primary, raise_match",
+ "primary, ladder, pool_available, raise_match, expected",
[
- ("openrouter", "No LLM provider configured"),
+ ("openrouter", _LADDER, True, "No LLM provider configured", _LADDER_REASONS),
# Explicit non-OpenRouter primary: provider-specific missing-credentials error.
- ("anthropic", "no API key was found"),
+ ("anthropic", _LADDER, True, "no API key was found", _LADDER_REASONS),
+ # #119533: a burned primary pool with no ladder at all must still be named.
+ ("openrouter", [], False, "No LLM provider configured", ("credential pool exhausted",)),
],
)
def test_fully_refusing_ladder_warns_with_each_reason(
- monkeypatch, caplog, primary, raise_match
+ monkeypatch, caplog, primary, ladder, pool_available, raise_match, expected
):
"""Primary resolves no client; deepseek resolves none (missing key), kimi raises."""
from agent import agent_init
@@ -51,17 +72,20 @@ def test_fully_refusing_ladder_warns_with_each_reason(
monkeypatch.setattr(
"hermes_cli.fallback_config.resolve_entry_api_key", lambda entry: None
)
+ monkeypatch.setattr(
+ "agent.credential_pool.load_pool", lambda provider: _Pool(pool_available)
+ )
with caplog.at_level(logging.WARNING, logger="run_agent"):
with pytest.raises(RuntimeError, match=raise_match):
- agent_init._routed_client_kwargs(_agent(primary), _LADDER, 60)
+ agent_init._routed_client_kwargs(_agent(primary), ladder, 60)
warnings = [r for r in caplog.records if r.levelno >= logging.WARNING]
assert len(warnings) == 1
text = warnings[0].getMessage()
assert primary in text
- assert "deepseek" in text and "no usable credentials" in text
- assert "kimi" in text and "kimi auth handshake refused" in text
+ for fragment in expected:
+ assert fragment in text
def test_recovered_ladder_does_not_warn(monkeypatch, caplog):