Skip to content

The agent that grows with you

fix(auxiliary): keep completed aux text that resembles a leaked tool call

kshitijk4poor6968bedc7aa4
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index bc1d4461771..e3f2a92e9ff 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -1133,7 +1133,9 @@ def _parse_codex_final_response(
final: Any, *, issuer_kind: Optional[str] = None, issuer_model: Optional[str] = None,
) -> Tuple[List[str], List[Any], Any, str]:
"""Normalize Responses output without losing phase or completion state for aux callers."""
- from agent.codex_responses_adapter import _normalize_codex_response
+ from agent.codex_responses_adapter import (
+ _extract_responses_message_text, _leaked_tool_call_text, _normalize_codex_response,
+ )
# The shared normalizer reads SDK-style items. Keep support for compatible hosts
# returning dict items, and the aux adapter's legacy empty completed response.
@@ -1153,6 +1155,17 @@ def _parse_codex_final_response(
)
status = str(normalized_final.status or "").strip().lower()
reason = str(_field(normalized_final.incomplete_details, "reason", "") or "").strip().lower()
+ # The main loop's leaked-tool-call recovery clears the text so its continuation can re-elicit a
+ # real call; aux has no continuation, so a completed answer quoting such text keeps it.
+ if finish_reason == "incomplete" and status != "incomplete" and not message.tool_calls \
+ and message.codex_message_items is None:
+ answer = "\n".join(filter(None, (
+ _extract_responses_message_text(item) for item in output
+ if _field(item, "type") == "message"
+ and str(_field(item, "phase", "") or "").strip().lower() not in {"commentary", "analysis"}
+ ))).strip()
+ if answer and _leaked_tool_call_text(answer):
+ message.content, finish_reason = answer, "stop"
# Aux consumers speak Chat Completions: "length" activates their existing
# partial-summary rejection/fallback, whereas Codex's "incomplete" does not.
# A final_answer phase cannot override the provider's incomplete status, but completed
diff --git a/tests/agent/test_auxiliary_codex_completion_status.py b/tests/agent/test_auxiliary_codex_completion_status.py
index ab7b6974481..3975bce8e38 100644
--- a/tests/agent/test_auxiliary_codex_completion_status.py
+++ b/tests/agent/test_auxiliary_codex_completion_status.py
@@ -74,6 +74,7 @@ def test_compressor_rejects_actual_adapter_partial_summary(monkeypatch):
_TOOL_CALL = SimpleNamespace(
type="function_call", status="completed", call_id="call_1", name="inspect", arguments='{"path":"x"}',
)
+_LEAK_LIKE_ANSWER = 'Summary of work.\nRunning the tests next.\n{"cmd": "pytest -q"}'
_CODEX_REASONING_ONLY = SimpleNamespace(
type="reasoning", id="rs_test", encrypted_content=None, summary=[SimpleNamespace(text="still thinking")],
)
@@ -86,6 +87,8 @@ _CODEX_REASONING_ONLY = SimpleNamespace(
pytest.param("", "completed", [_message("FINAL")], None, "FINAL", "stop", id="final-answer"),
pytest.param("", "completed", [_message("COMMENTARY", phase="commentary")], None, None, "length", id="commentary-only"),
pytest.param("", "completed", [_TOOL_CALL], None, None, "tool_calls", id="tool-call"),
+ pytest.param("", "completed", [_message(_LEAK_LIKE_ANSWER, phase=None)], None, _LEAK_LIKE_ANSWER, "stop",
+ id="tool-call-like-answer"),
pytest.param("", "incomplete", [_message("PARTIAL")], "max_output_tokens", "PARTIAL", "length", id="token-cap"),
pytest.param("", "incomplete", [_TOOL_CALL], "max_output_tokens", None, "tool_calls", id="token-cap-after-tool-call"),
# Route-sensitive normalization: the issuer comes from the request's route classification.