mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
fix(codex): rotate pool on usage limit 429
This commit is contained in:
parent
dffb602f37
commit
e51d74ab91
2 changed files with 57 additions and 2 deletions
|
|
@ -3746,6 +3746,37 @@ class TestCredentialPoolRecovery:
|
|||
assert retry_same is False
|
||||
agent._swap_credential.assert_called_once_with(next_entry)
|
||||
|
||||
def test_recover_with_pool_rotates_usage_limit_429_immediately(self, agent):
|
||||
next_entry = SimpleNamespace(label="secondary")
|
||||
captured = {}
|
||||
|
||||
class _Pool:
|
||||
def current(self):
|
||||
return SimpleNamespace(label="primary")
|
||||
|
||||
def mark_exhausted_and_rotate(self, *, status_code, error_context=None):
|
||||
captured["status_code"] = status_code
|
||||
captured["error_context"] = error_context
|
||||
return next_entry
|
||||
|
||||
agent._credential_pool = _Pool()
|
||||
agent._swap_credential = MagicMock()
|
||||
|
||||
recovered, retry_same = agent._recover_with_credential_pool(
|
||||
status_code=429,
|
||||
has_retried_429=False,
|
||||
error_context={
|
||||
"reason": "usage_limit_reached",
|
||||
"message": "The usage limit has been reached",
|
||||
},
|
||||
)
|
||||
|
||||
assert recovered is True
|
||||
assert retry_same is False
|
||||
assert captured["status_code"] == 429
|
||||
assert captured["error_context"]["reason"] == "usage_limit_reached"
|
||||
agent._swap_credential.assert_called_once_with(next_entry)
|
||||
|
||||
|
||||
def test_recover_with_pool_refreshes_on_401(self, agent):
|
||||
"""401 with successful refresh should swap to refreshed credential."""
|
||||
|
|
@ -3832,6 +3863,22 @@ class TestCredentialPoolRecovery:
|
|||
assert context["message"] == "Weekly credits exhausted."
|
||||
assert context["reset_at"] == "2026-04-12T10:30:00Z"
|
||||
|
||||
def test_extract_api_error_context_uses_type_as_reason(self, agent):
|
||||
error = SimpleNamespace(
|
||||
body={
|
||||
"error": {
|
||||
"type": "usage_limit_reached",
|
||||
"message": "The usage limit has been reached",
|
||||
}
|
||||
},
|
||||
response=SimpleNamespace(headers={}),
|
||||
)
|
||||
|
||||
context = agent._extract_api_error_context(error)
|
||||
|
||||
assert context["reason"] == "usage_limit_reached"
|
||||
assert context["message"] == "The usage limit has been reached"
|
||||
|
||||
def test_recover_with_pool_passes_error_context_on_rotated_429(self, agent):
|
||||
next_entry = SimpleNamespace(label="secondary")
|
||||
captured = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue