Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions agent/auxiliary_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,23 @@ def create(self, **kwargs) -> Any:
# build_kwargs, so they need the same guard applied independently.
_host_for_input = str(getattr(self._client, "base_url", "") or "")
_is_github_for_input = base_url_host_matches(_host_for_input, "githubcopilot.com")
_is_xai_for_input = (
base_url_host_matches(_host_for_input, "x.ai")
or base_url_host_matches(_host_for_input, "api.x.ai")
)
# Match main Codex transport issuer stamps so encrypted reasoning
# from a foreign Responses endpoint is not replayed here.
if _is_xai_for_input:
_issuer_kind = "xai_responses"
elif _is_github_for_input:
_issuer_kind = "github_responses"
else:
_issuer_kind = "codex_backend"
input_items = _chat_messages_to_responses_input(
replay_messages, is_github_responses=_is_github_for_input,
replay_messages,
is_github_responses=_is_github_for_input,
is_xai_responses=_is_xai_for_input,
current_issuer_kind=_issuer_kind,
)

resp_kwargs: Dict[str, Any] = {
Expand Down Expand Up @@ -1371,8 +1386,17 @@ def create(self, **kwargs) -> Any:
# Codex backend, which rejects e.g. {"effort": null}
# with a 400.
effort = reasoning_cfg.get("effort") or "medium"
# Codex backend rejects "minimal"; clamp to "low" to
# match the main-agent Codex transport behavior.
# Match agent/transports/codex.py effort clamps.
_effort_clamp = {"minimal": "low"}
if "gpt-5.6" in (model or "").lower():
# Ultra is Hermes' GPT-5.6 product label; wire is max.
_effort_clamp["ultra"] = "max"
if _is_xai_for_input:
# xAI Responses tops out at high.
_effort_clamp.update(
{"xhigh": "high", "max": "high", "ultra": "high"}
)
effort = _effort_clamp.get(str(effort).strip().lower(), effort)
if effort == "minimal":
effort = "low"
resp_kwargs["reasoning"] = {
Expand Down
96 changes: 95 additions & 1 deletion tests/agent/test_auxiliary_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,7 +2790,7 @@ class TestCodexAdapterReasoningTranslation:
"""

@staticmethod
def _build_adapter():
def _build_adapter(base_url="https://chatgpt.com/backend-api/codex"):
"""Build a _CodexCompletionsAdapter with a mocked responses.create()."""
from agent.auxiliary_client import _CodexCompletionsAdapter
from types import SimpleNamespace
Expand Down Expand Up @@ -2829,12 +2829,106 @@ def _create(**kwargs):
return _FakeCreateStream()

real_client = MagicMock()
real_client.base_url = base_url
real_client.responses.create = _create
adapter = _CodexCompletionsAdapter(real_client, "gpt-5.3-codex")
return adapter, captured_kwargs



def test_gpt_56_reasoning_effort_ultra_clamped_to_max(self):
"""GPT-5.6 Codex rejects Hermes' Ultra label; emit its wire maximum."""
adapter, captured = self._build_adapter()
adapter.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "hi"}],
extra_body={"reasoning": {"effort": "ultra"}},
)
assert captured.get("reasoning") == {"effort": "max", "summary": "auto"}
assert captured.get("include") == ["reasoning.encrypted_content"]

def test_xai_reasoning_effort_ultra_clamped_to_high(self):
"""xAI Responses rejects generic Ultra; emit the endpoint ceiling."""
adapter, captured = self._build_adapter(base_url="https://api.x.ai/v1")
adapter.create(
model="grok-4.5",
messages=[{"role": "user", "content": "hi"}],
extra_body={"reasoning": {"effort": "ultra"}},
)
assert captured.get("reasoning") == {"effort": "high", "summary": "auto"}
assert captured.get("include") == ["reasoning.encrypted_content"]

def test_xai_reasoning_effort_xhigh_and_max_clamped_to_high(self):
"""xAI Responses also clamps sibling above-high labels to high."""
for label in ("xhigh", "max"):
adapter, captured = self._build_adapter(base_url="https://api.x.ai/v1")
adapter.create(
model="grok-4.5",
messages=[{"role": "user", "content": "hi"}],
extra_body={"reasoning": {"effort": label}},
)
assert captured.get("reasoning") == {
"effort": "high",
"summary": "auto",
}, label

def test_xai_auxiliary_drops_codex_issued_encrypted_reasoning(self):
"""A GPT fallback must not poison the next MoA/xAI aggregator turn."""
adapter, captured = self._build_adapter(base_url="https://api.x.ai/v1")
adapter.create(
model="grok-4.5",
messages=[
{"role": "user", "content": "first"},
{
"role": "assistant",
"content": "fallback answer",
"codex_reasoning_items": [
{
"type": "reasoning",
"encrypted_content": "codex-sealed-blob",
"summary": [],
"_issuer_kind": "codex_backend",
}
],
},
{"role": "user", "content": "next"},
],
)
assert not [
item for item in captured["input"]
if item.get("type") == "reasoning"
]

def test_xai_auxiliary_keeps_xai_issued_encrypted_reasoning(self):
"""The foreign-issuer guard must preserve normal xAI continuity."""
adapter, captured = self._build_adapter(base_url="https://api.x.ai/v1")
adapter.create(
model="grok-4.5",
messages=[
{"role": "user", "content": "first"},
{
"role": "assistant",
"content": "grok answer",
"codex_reasoning_items": [
{
"type": "reasoning",
"encrypted_content": "xai-sealed-blob",
"summary": [],
"_issuer_kind": "xai_responses",
}
],
},
{"role": "user", "content": "next"},
],
)
reasoning = [
item for item in captured["input"]
if item.get("type") == "reasoning"
]
assert len(reasoning) == 1
assert reasoning[0]["encrypted_content"] == "xai-sealed-blob"
assert "_issuer_kind" not in reasoning[0]

def test_reasoning_effort_low_passed_through(self):
adapter, captured = self._build_adapter()
adapter.create(
Expand Down