Skip to content

The agent that grows with you

fix: log the provider in the vision-gate skip and prove capacity 429s do not rotate the pool

teknium1a1238adfae4e
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 2b7e3c70ef9..ba9f945c6b8 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -4122,7 +4122,7 @@ def _try_main_agent_model_fallback(
main_provider in _PROVIDERS_WITHOUT_VISION or not _main_model_supports_vision(main_provider, main_model)):
# Same capability gate as the auto-route (_vision_main_provider_client): handing an image to a
# text-only main model turns a transient 429 into a guaranteed 400 (#108349).
- logger.info("Auxiliary vision: %s on %s — main agent model %s accepts no image input, not falling back",
+ logger.info("Auxiliary vision: %s on %s — main agent provider %s accepts no image input, not falling back",
reason, failed_provider, main_provider)
return None, None, ""
main_base_url = _custom_health_base_url(main_provider)
diff --git a/tests/agent/test_auxiliary_error_classification.py b/tests/agent/test_auxiliary_error_classification.py
index 145ba0be30c..d6e686c8bd2 100644
--- a/tests/agent/test_auxiliary_error_classification.py
+++ b/tests/agent/test_auxiliary_error_classification.py
@@ -53,8 +53,40 @@ def test_vision_fallback_skips_text_only_main_model(monkeypatch):
assert ac._try_main_agent_model_fallback("nous", "vision", reason="rate limit") == (None, None, "")
-def test_upstream_capacity_429_is_not_a_credential_to_bench():
- exc = _Err("Error code: 429 - {'status': 429, 'message': \"The requested model is temporarily at capacity upstream. "
- "This is not your API key's rate limit — please retry shortly.\"}", 429)
- assert ac._is_overloaded_error(exc)
- assert classify_api_error(exc).reason is FailoverReason.overloaded
[email protected]("body, benches_pool", [
+ ("Error code: 429 - {'status': 429, 'message': \"The requested model is temporarily at capacity upstream. "
+ "This is not your API key's rate limit — please retry shortly.\"}", False),
+ ("Error code: 429 - {'error': {'message': 'Rate limit exceeded for this API key', 'code': 429}}", True),
+])
+def test_upstream_capacity_429_is_not_a_credential_to_bench(monkeypatch, body, benches_pool):
+ exc = _Err(body, 429)
+ assert ac._is_rate_limit_error(exc)
+ assert ac._is_overloaded_error(exc) is (not benches_pool)
+ assert classify_api_error(exc).reason is (
+ FailoverReason.rate_limit if benches_pool else FailoverReason.overloaded)
+
+ # The predicate is only half the contract: _recover_provider_pool must not bench a credential
+ # for an upstream-capacity 429, while a real per-key rate limit still rotates the pool.
+ class _StubPool:
+ def __init__(self):
+ self.rotate_calls = []
+
+ def has_credentials(self):
+ return True
+
+ def try_refresh_current(self):
+ return None
+
+ def mark_exhausted_and_rotate(self, **kwargs):
+ self.rotate_calls.append(kwargs)
+ return object() # a next entry exists
+
+ pool = _StubPool()
+ monkeypatch.setattr(ac, "load_pool", lambda provider: pool)
+ monkeypatch.setattr(ac, "_evict_cached_clients", lambda provider: None)
+ recovered = ac._recover_provider_pool("openrouter", exc, failed_api_key="sk-failed")
+ assert recovered is benches_pool
+ assert len(pool.rotate_calls) == (1 if benches_pool else 0)
+ if benches_pool:
+ assert pool.rotate_calls[0]["status_code"] == 429
+ assert pool.rotate_calls[0]["api_key_hint"] == "sk-failed"