Skip to content

The agent that grows with you

refactor(codex): name the dropped shape in the wire-guard warning

kshitijk4poorf6d1d774a126
diff --git a/agent/codex_runtime.py b/agent/codex_runtime.py
index dffb0340d6c..6c8a811dd46 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 671fd8424be..c1f815801c2 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):