Skip to content

The agent that grows with you

fix(auxiliary): skip output_text in leak rescue when a commentary item is present

kshitijk4poor8f848ecda9f8
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 9d4d4512936..bf78dc34ce6 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -1164,11 +1164,13 @@ def _parse_codex_final_response(
_field(item, "type") not in _SERVER_SIDE_TOOL_CALL_TYPES
and _lower_or_none(_field(item, "status")) in _INCOMPLETE_STATUSES
for item in output):
+ # Same gate as the normalizer: commentary/analysis is never the answer, nor is output_text alongside it.
+ narration = {"commentary", "analysis"}
+ phases = {_lower_or_none(_field(item, "phase")) for item in output if _field(item, "type") == "message"}
answer = "\n".join(filter(None, (
_extract_responses_message_text(item) for item in output
- if _field(item, "type") == "message"
- and _lower_or_none(_field(item, "phase")) not in {"commentary", "analysis"}
- ))).strip() or (normalized_final.output_text or "").strip()
+ if _field(item, "type") == "message" and _lower_or_none(_field(item, "phase")) not in narration
+ ))).strip() or ("" if phases & narration else (normalized_final.output_text or "").strip())
if answer and _leaked_tool_call_text(answer):
message.content, finish_reason = answer, "stop"
# Aux consumers speak Chat Completions: "length" activates their existing
diff --git a/tests/agent/test_auxiliary_codex_completion_status.py b/tests/agent/test_auxiliary_codex_completion_status.py
index 804bc2064f7..bb910007f3e 100644
--- a/tests/agent/test_auxiliary_codex_completion_status.py
+++ b/tests/agent/test_auxiliary_codex_completion_status.py
@@ -94,6 +94,9 @@ _CODEX_REASONING_ONLY = SimpleNamespace(
"length", id="tool-call-like-partial-item"),
# A str ``output`` is delivered only via output_text (empty output list), as streamed Codex answers can be.
pytest.param("", "completed", _LEAK_LIKE_ANSWER, None, _LEAK_LIKE_ANSWER, "stop", id="tool-call-like-output-text"),
+ # (items, text): output_text beside a commentary item is narration, never the rescued answer.
+ pytest.param("", "completed", ([_message("", phase="commentary")], _LEAK_LIKE_ANSWER), None, None, "length",
+ id="tool-call-like-output-text-beside-commentary"),
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.
@@ -104,9 +107,9 @@ _CODEX_REASONING_ONLY = SimpleNamespace(
def test_actual_adapter_preserves_completion_contract(
streamed, base_url, status, output, reason, expected_content, expected_finish,
):
+ items, output_text = output if isinstance(output, tuple) else ([], output) if isinstance(output, str) else (output, "")
final = SimpleNamespace(
- status=status, output=[] if isinstance(output, str) else output,
- output_text=output if isinstance(output, str) else "",
+ status=status, output=items, output_text=output_text,
incomplete_details={"reason": reason} if reason else None, error=None,
usage={"input_tokens": 11, "output_tokens": 3, "total_tokens": 14},
)