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.
This commit is contained in:
kshitijk4poor
2026-08-20 02:43:18 +05:30
committed by kshitij
parent 26530e7df5
commit f6d1d774a1
2 changed files with 9 additions and 17 deletions
+6 -5
View File
@@ -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
@@ -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):