The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): gate the newest-only reasoning replay on its own Azure predicate
Erosika267a6b79c8e0
diff --git a/agent/transports/codex.py b/agent/transports/codex.pyindex b472d1c6708..121d348edfc 100644--- a/agent/transports/codex.py+++ b/agent/transports/codex.py@@ -405,6 +405,17 @@ def _is_post_tool_replay(messages: Optional[list[dict[str, Any]]]) -> bool:return False+def _is_azure_responses(params: dict[str, Any]) -> bool:+ """True for any Azure-hosted Responses endpoint: the ``azure-foundry`` provider, a resource-level+ ``*.openai.azure.com`` host, or the project-scoped ``*.services.ai.azure.com`` gateway."""+ from utils import base_url_host_matches++ if str(params.get("provider") or "").strip().lower() == "azure-foundry":+ return True+ base_url = str(params.get("base_url") or "")+ return base_url_host_matches(base_url, "openai.azure.com") or base_url_host_matches(base_url, "services.ai.azure.com")++def _newest_reasoning_only(messages: list[dict[str, Any]]) -> list[dict[str, Any]]:"""Copy of ``messages`` keeping ``codex_reasoning_items`` only on the newest assistant row that has any.Foundry rejects a request that replays encrypted reasoning from more than one prior response (HTTP 400@@ -554,12 +565,13 @@ class ResponsesApiTransport(ProviderTransport):is_github_responses = params.get("is_github_responses") is Trueis_codex_backend = params.get("is_codex_backend") is Trueis_xai_responses = params.get("is_xai_responses") is True- is_azure_foundry = _is_azure_foundry_responses(params)# Foundry 400s on encrypted-reasoning replay only in the post-tool follow-up turn.replay_encrypted_reasoning = bool(params.get("replay_encrypted_reasoning", True)) and not (- is_azure_foundry and _is_post_tool_replay(payload_messages)+ _is_azure_foundry_responses(params) and _is_post_tool_replay(payload_messages))- if is_azure_foundry and replay_encrypted_reasoning:+ # Own predicate: #101243 may narrow _is_azure_foundry_responses to the project gateway, and the+ # multi-item rejection happens on resource-level hosts too.+ if replay_encrypted_reasoning and _is_azure_responses(params):payload_messages = _newest_reasoning_only(payload_messages)# One predicate decides whether context_management goes out AND whether the converter may replay a checkpoint.context_management = params.get("context_management")diff --git a/tests/agent/transports/test_codex_transport.py b/tests/agent/transports/test_codex_transport.pyindex 4517132ef90..7b7153a4c2f 100644--- a/tests/agent/transports/test_codex_transport.py+++ b/tests/agent/transports/test_codex_transport.py@@ -419,6 +419,19 @@ class TestCodexBuildKwargs:assistant_text = [item for item in kw["input"] if item.get("role") == "assistant"]assert len(assistant_text) == 2+ @pytest.mark.parametrize("base_url", [+ "https://placeholder.openai.azure.com/openai/v1",+ "https://placeholder.services.ai.azure.com/api/projects/placeholder/openai/v1",+ ])+ def test_azure_host_without_provider_replays_only_newest_reasoning(self, transport, base_url):+ """Both Azure hosts are detected without ``provider``; the rejection is not gateway-specific."""+ kw = transport.build_kwargs(+ model="gpt-6-astra", messages=self._two_turn_messages(), tools=[], base_url=base_url,+ replay_encrypted_reasoning=True,+ )+ reasoning = [item for item in kw["input"] if item.get("type") == "reasoning"]+ assert [item["encrypted_content"] for item in reasoning] == ["sealed-2"]+def test_default_responses_new_turn_replays_all_reasoning(self, transport):"""Non-Azure Responses endpoints keep cross-turn reasoning replay."""kw = transport.build_kwargs(