The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): count additional_rate_limits in the Codex quota-restored probe
teknium14c3d31eb4dbb
diff --git a/hermes_cli/auth_codex.py b/hermes_cli/auth_codex.pyindex 75593f3cca0..61a6c29630d 100644--- a/hermes_cli/auth_codex.py+++ b/hermes_cli/auth_codex.py@@ -667,12 +667,19 @@ def _probe_codex_quota_restored(with _codex_http_client(timeout=10.0) as client:response = client.get(_codex_usage_probe_url(base_url), headers=headers)if response.status_code == 200:- rate_limit = (response.json() or {}).get("rate_limit") or {}+ payload = response.json() or {}+ # A model-scoped allowance (``additional_rate_limits``) at 100% still 429s that+ # model, so it counts against "restored" like the account-wide windows (#97315).+ windows = [payload.get("rate_limit") or {}] + [+ extra.get("rate_limit") or {}+ for extra in (payload.get("additional_rate_limits") or [])+ if isinstance(extra, dict)]worst_used: Optional[float] = None- for key in ("primary_window", "secondary_window"):- used = (rate_limit.get(key) or {}).get("used_percent")- if isinstance(used, (int, float)):- worst_used = max(worst_used or 0.0, float(used))+ for rate_limit in windows:+ for key in ("primary_window", "secondary_window"):+ used = (rate_limit.get(key) or {}).get("used_percent")+ if isinstance(used, (int, float)):+ worst_used = max(worst_used or 0.0, float(used))if worst_used is not None:result = worst_used < 100.0elif response.status_code == 429:diff --git a/tests/hermes_cli/test_auth_codex_quota_probe.py b/tests/hermes_cli/test_auth_codex_quota_probe.pyindex 461f6d8ee43..5aa8decb600 100644--- a/tests/hermes_cli/test_auth_codex_quota_probe.py+++ b/tests/hermes_cli/test_auth_codex_quota_probe.py@@ -439,3 +439,14 @@ def test_pool_selection_throttles_failing_pre_probe_refresh(tmp_path, monkeypatcassert attempts == ["rf-old"]assert len(http_calls) <= 1++def test_probe_counts_additional_rate_limits(monkeypatch):+ """#97315: a model-scoped allowance at 100% still 429s that model; the account-wide+ windows being open must not report the quota as restored."""+ payload = _usage_payload(0.0, 0.0)+ payload["additional_rate_limits"] = [+ {"limit_name": "codex_model_scoped",+ "rate_limit": {"primary_window": {"used_percent": 100.0}}}]+ _patch_httpx(monkeypatch, _StubResponse(200, payload))++ assert _probe_codex_quota_restored(_jwt({"exp": time.time() + 3600})) is False