From f6d1d774a126e4a8197cdb2a668bdc34af6264e1 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 20 Aug 2026 02:43:18 +0530 Subject: [PATCH] refactor(codex): name the dropped shape in the wire-guard warning Review polish from the 3-angle pass on the final stack: - The warning now says WHICH shape leaked (top-level, extra_body, or both). Relay injects top-level while request_overrides typically inject via extra_body, so the shape identifies the offending middleware when debugging. - Fold the 'always returns a fresh mapping' assertion into the parametrized real-endpoint test (the caller mutates the result with stream=True, so the copy contract is load-bearing on no-drop paths too) and drop the SimpleNamespace stub test it strictly subsumes. The nested-preserve stub stays: the parametrized test only exercises top-level retention. --- agent/codex_runtime.py | 11 ++++++----- tests/run_agent/test_run_agent_codex_responses.py | 15 +++------------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/agent/codex_runtime.py b/agent/codex_runtime.py index dffb0340d6..6c8a811dd4 100644 --- a/agent/codex_runtime.py +++ b/agent/codex_runtime.py @@ -1334,10 +1334,10 @@ def _sanitize_consumer_codex_request( ) if not is_consumer_codex: return sanitized - dropped = False + dropped_from: list[str] = [] if "prompt_cache_retention" in sanitized: sanitized.pop("prompt_cache_retention") - dropped = True + dropped_from.append("top-level") # The OpenAI SDK merges ``extra_body`` into the outgoing JSON body, so a # nested ``extra_body.prompt_cache_retention`` reaches the endpoint just # like the top-level field would. Copy before editing — the caller's @@ -1350,12 +1350,13 @@ def _sanitize_consumer_codex_request( sanitized["extra_body"] = extra_body else: sanitized.pop("extra_body") - dropped = True - if dropped: + dropped_from.append("extra_body") + if dropped_from: logger.warning( "Dropped unsupported prompt_cache_retention at consumer Codex " - "wire boundary (model=%s).", + "wire boundary (model=%s, via %s).", sanitized.get("model", getattr(agent, "model", "unknown")), + ", ".join(dropped_from), ) return sanitized diff --git a/tests/run_agent/test_run_agent_codex_responses.py b/tests/run_agent/test_run_agent_codex_responses.py index 671fd8424b..c1f815801c 100644 --- a/tests/run_agent/test_run_agent_codex_responses.py +++ b/tests/run_agent/test_run_agent_codex_responses.py @@ -590,18 +590,6 @@ def test_run_codex_stream_strips_relay_added_retention_at_consumer_wire( ) -def test_consumer_codex_wire_guard_preserves_compatible_endpoint_retention(): - from agent.codex_runtime import _sanitize_consumer_codex_request - - agent = SimpleNamespace(_is_codex_backend=lambda: False) - request = {"model": "openai.gpt-5.5", "prompt_cache_retention": "24h"} - - sanitized = _sanitize_consumer_codex_request(agent, request) - - assert sanitized["prompt_cache_retention"] == "24h" - assert sanitized is not request - - def test_consumer_codex_wire_guard_strips_nested_extra_body_retention(caplog): """The SDK merges ``extra_body`` into the JSON body, so a nested ``extra_body.prompt_cache_retention`` reaches the endpoint exactly like the @@ -716,6 +704,9 @@ def test_wire_guard_scopes_retention_drop_by_real_endpoint( # disturb the prompt-cache key, on any endpoint. assert sanitized["prompt_cache_key"] == "cache-key-sentinel" assert request["prompt_cache_retention"] == "24h" + # The caller mutates the result (stream_kwargs["stream"] = True), so the + # guard must return a fresh mapping on EVERY path, including no-drop ones. + assert sanitized is not request def test_run_codex_stream_returns_collected_items_when_stream_ends_without_terminal(monkeypatch):