The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: build the dashboard Codex poll client through the shared capped builder
teknium1e5258804df7a
diff --git a/hermes_cli/auth_codex.py b/hermes_cli/auth_codex.pyindex 083b1a93f2d..cf43cd7e9a9 100644--- a/hermes_cli/auth_codex.py+++ b/hermes_cli/auth_codex.py@@ -346,9 +346,7 @@ def _codex_http_client(**kwargs: Any) -> "httpx.Client":token refresh / device login / usage probes time out where the official Codex CLI (which races familiesper RFC 8305) works."""- hooks = dict(kwargs.pop("event_hooks", None) or {})- hooks["response"] = [_cap_codex_response_body, *hooks.get("response", [])]- client = httpx.Client(event_hooks=hooks, **kwargs)+ client = httpx.Client(event_hooks={"response": [_cap_codex_response_body]}, **kwargs)with suppress(Exception):from agent.process_bootstrap import enable_happy_eyeballs_on_clientenable_happy_eyeballs_on_client(client)diff --git a/hermes_cli/web_routers/oauth.py b/hermes_cli/web_routers/oauth.pyindex 49db119e6a0..ad7e8da787e 100644--- a/hermes_cli/web_routers/oauth.py+++ b/hermes_cli/web_routers/oauth.py@@ -150,15 +150,15 @@ def _codex_cancelled(sess: Dict[str, Any], session_id: str, stage: str = "") ->return True-def _codex_body_cap() -> Dict[str, list]:- """``event_hooks`` applying the CLI flow's 1 MiB auth-body cap to the dashboard's own client (#55253).+def _codex_client(httpx) -> Any:+ """15s ``httpx.Client`` for the device-login flow with the CLI flow's 1 MiB auth-body cap (#55253).The helpers take the ``httpx`` module as a parameter (tests inject a scripted one), so the- dashboard keeps building its client here and only shares the hook, not the client factory.+ dashboard builds its own client here and only shares the response hook, not the client factory."""from hermes_cli.auth_codex import _cap_codex_response_body- return {"response": [_cap_codex_response_body]}+ return httpx.Client(timeout=httpx.Timeout(15.0), event_hooks={"response": [_cap_codex_response_body]})def _codex_post(httpx, url: str, **kwargs: Any) -> Any:@@ -173,7 +173,7 @@ def _codex_post(httpx, url: str, **kwargs: Any) -> Any:attempt, attempts = 1, 3while True:try:- with httpx.Client(timeout=httpx.Timeout(15.0), event_hooks=_codex_body_cap()) as client:+ with _codex_client(httpx) as client:return client.post(url, **kwargs)except Exception as exc:if attempt == attempts or not _is_transient_transport_error(exc):@@ -207,7 +207,7 @@ def _codex_poll_authorization(httpx, sess: Dict[str, Any], session_id: str) -> Apayload = {"device_auth_id": sess["device_auth_id"], "user_code": sess["user_code"]}max_consecutive_blips = 6 # same cap as the CLI poll loop: survives drops, fails fast on a dead networkconsecutive_blips = 0- with httpx.Client(timeout=httpx.Timeout(15.0), event_hooks=_codex_body_cap()) as client:+ with _codex_client(httpx) as client:while time.monotonic() < deadline:if _codex_cancelled(sess, session_id):return _CANCELLEDdiff --git a/tests/hermes_cli/test_auth_codex_bounded_body.py b/tests/hermes_cli/test_auth_codex_bounded_body.pyindex 9179545e117..2c35d481b58 100644--- a/tests/hermes_cli/test_auth_codex_bounded_body.py+++ b/tests/hermes_cli/test_auth_codex_bounded_body.py@@ -2,8 +2,9 @@A hostile or broken auth endpoint/proxy answering 200 with megabytes of "JSON" used to befully buffered and parsed by every ``client.post(...).json()`` in the CLI device-code flow,-the dashboard login worker and ``refresh_codex_oauth_pure``. All of them build their client via-``auth_codex._codex_http_client``, whose response hook cuts the read off at the cap.+the dashboard login worker and ``refresh_codex_oauth_pure``. The CLI builds its client via+``auth_codex._codex_http_client`` and the dashboard via ``web_routers.oauth._codex_client``; both+install the response hook that cuts the read off at the cap."""from __future__ import annotations@@ -57,6 +58,12 @@ def test_oversized_200_auth_body_is_rejected_before_being_buffered(monkeypatch):with pytest.raises(AuthError, match="exceeded 1024 KiB"):web_oauth._codex_exchange_tokens(httpx, {"authorization_code": "c", "code_verifier": "v"})+ # The dashboard poll loop holds its own long-lived client; it must be built with the same cap.+ monkeypatch.setattr(web_oauth.time, "sleep", lambda *_: None)+ sess = {"expires_in": 900, "device_auth_id": "dev", "user_code": "ABCD-EFGH", "interval": 3}+ with pytest.raises(AuthError, match="exceeded 1024 KiB"):+ web_oauth._codex_poll_authorization(httpx, sess, "sid")+def test_normal_auth_body_still_parses(monkeypatch):_serve(monkeypatch, {"access_token": "at-new", "refresh_token": "rt-new"})