fix(credential-pool): correct pool rotation when weekly usage limit is reached
After key #1 is marked exhausted the retry still called the API with key #1 due to env-var bias in _get_cached_client / resolve_api_key_provider_credentials. Fix: peek the pool and pass the active entry's key as explicit_api_key. Secondary: api_key_hint in mark_exhausted_and_rotate pins the correct entry under concurrent CLI+gateway calls; _is_payment_error matches GoUsageLimitError; extract_api_error_context parses "Resets in Xhr Ymin".
This commit is contained in:
@@ -4089,6 +4089,25 @@ class TestCredentialPoolRecovery:
|
||||
assert context["reason"] == "usage_limit_reached"
|
||||
assert context["message"] == "The usage limit has been reached"
|
||||
|
||||
def test_extract_api_error_context_parses_resets_in_hours_and_minutes(self, agent, monkeypatch):
|
||||
from agent import agent_runtime_helpers
|
||||
|
||||
monkeypatch.setattr(agent_runtime_helpers.time, "time", lambda: 1_000.0)
|
||||
error = SimpleNamespace(
|
||||
body={
|
||||
"error": {
|
||||
"type": "GoUsageLimitError",
|
||||
"message": "Weekly usage limit reached. Resets in 6hr 29min.",
|
||||
}
|
||||
},
|
||||
response=SimpleNamespace(headers={}),
|
||||
)
|
||||
|
||||
context = agent._extract_api_error_context(error)
|
||||
|
||||
assert context["reason"] == "GoUsageLimitError"
|
||||
assert context["reset_at"] == 1_000.0 + (6 * 60 * 60) + (29 * 60)
|
||||
|
||||
def test_recover_with_pool_passes_error_context_on_rotated_429(self, agent):
|
||||
next_entry = SimpleNamespace(label="secondary")
|
||||
captured = {}
|
||||
|
||||
Reference in New Issue
Block a user