The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): handle completed auxiliary responses
Kyle48ded07155ef
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 264e4c80d33..21649aa5bc4 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -1226,11 +1226,19 @@ class _CodexCompletionsAdapter:event_stream = self._client.responses.create(**stream_kwargs)try:- final = _consume_codex_event_stream(- event_stream,- model=resp_kwargs.get("model"),- on_event=_on_each_event,- )+ # Some Codex-compatible hosts accept ``stream=True`` but return+ # a completed Responses object instead of an SSE iterator. Do+ # not hand that object to the event consumer: typed Responses+ # (and compatibility shims such as SimpleNamespace) are not+ # event streams and may not be iterable at all.+ if hasattr(event_stream, "output"):+ final = event_stream+ else:+ final = _consume_codex_event_stream(+ event_stream,+ model=str(resp_kwargs.get("model") or model),+ on_event=_on_each_event,+ )finally:close_fn = getattr(event_stream, "close", None)if callable(close_fn):diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.pyindex 42afde0eea9..eb930eba788 100644--- a/tests/agent/test_auxiliary_client.py+++ b/tests/agent/test_auxiliary_client.py@@ -3302,6 +3302,43 @@ class TestCodexAuxiliaryAdapterNullOutputRecovery:codex_runtime._consume_codex_event_stream = original_consume+class TestCodexAuxiliaryAdapterCompletedResponse:+ def test_accepts_completed_response_when_stream_was_requested(self):+ completed = SimpleNamespace(+ status="completed",+ id="resp_completed",+ output=[SimpleNamespace(+ type="message",+ content=[SimpleNamespace(+ type="output_text",+ text="completed response",+ )],+ )],+ usage=SimpleNamespace(+ input_tokens=11,+ output_tokens=3,+ total_tokens=14,+ ),+ )++ class FakeResponses:+ def create(self, **kwargs):+ assert kwargs["stream"] is True+ return completed++ fake_client = SimpleNamespace(responses=FakeResponses())+ adapter = _CodexCompletionsAdapter(fake_client, "gpt-5.6-terra")++ response = adapter.create(+ messages=[{"role": "user", "content": "review this"}],+ )++ assert response.choices[0].message.content == "completed response"+ assert response.usage.prompt_tokens == 11+ assert response.usage.completion_tokens == 3+ assert response.usage.total_tokens == 14++# ---------------------------------------------------------------------------# Issue #23432 — auxiliary timeout poisons cached client; later aux calls fail# ---------------------------------------------------------------------------