The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(transports): warn once about a dropped prompt_cache_options
kshitijk4poorc0cb1d7a34e9
diff --git a/agent/transports/codex.py b/agent/transports/codex.pyindex 4b71acb3741..bc1b99dffd8 100644--- a/agent/transports/codex.py+++ b/agent/transports/codex.py@@ -274,6 +274,8 @@ def _alias_wire_tools(# Models already warned that an explicit disable has no wire form on their route (one warning per process)._UNPROJECTABLE_DISABLE_WARNED: set[str] = set()+# request_overrides is static config: warn about a dropped prompt_cache_options once, not every turn.+_PROMPT_CACHE_OPTIONS_DROP_WARNED = Falsedef _resolve_reasoning(model: str, params: dict[str, Any]) -> tuple[Any, bool]:@@ -395,9 +397,9 @@ def _codex_efforts_for_route(model: Any, base_url: Any, *, is_codex_backend: boodef _sanitize_astra_request_kwargs(kwargs: dict[str, Any], model: Any, base_url: Any) -> None:"""Astra's official-API contract, applied AFTER ``request_overrides`` so an override can't put arejected field back on the wire: ``reasoning.effort`` is ``low..max`` only (``none``/``minimal``- 400), sampling and logprob knobs are rejected, and cache lifetime is fixed server-side- (``prompt_cache_options.ttl`` accepts only its ``30m`` default, so nothing is sent for it and the- pre-5.6 ``prompt_cache_retention`` knob is dropped)."""+ 400), sampling and logprob knobs are rejected, and cache lifetime is fixed server-side (the+ pre-5.6 ``prompt_cache_retention`` knob is dropped here; ``prompt_cache_options`` is already+ stripped on every route by ``build_kwargs``)."""if not _is_official_openai_responses_route(model, base_url):returnreasoning = kwargs.get("reasoning")@@ -754,15 +756,18 @@ class ResponsesApiTransport(ProviderTransport):kwargs["model"] = wire_model# ``prompt_cache_options`` is not a Responses.create() kwarg in the OpenAI SDK, so a- # top-level copy (the only place request_overrides can put it) fails the call before- # any request is sent, on every route. Endpoints that manage cache lifetime own it+ # top-level copy (e.g. from request_overrides) fails the call with TypeError before any+ # request is sent, on every route. Endpoints that manage cache lifetime own it# server-side; a proxy that accepts the field gets it via request_overrides# ``extra_body``, which the SDK merges into the body post-transform.if kwargs.pop("prompt_cache_options", None) is not None:- logger.warning(- "Dropped prompt_cache_options: not a Responses.create() kwarg "- "(use request_overrides={'extra_body': ...} for wire-only fields)."- )+ global _PROMPT_CACHE_OPTIONS_DROP_WARNED+ if not _PROMPT_CACHE_OPTIONS_DROP_WARNED:+ _PROMPT_CACHE_OPTIONS_DROP_WARNED = True+ logger.warning(+ "Dropped prompt_cache_options: not a Responses.create() kwarg "+ "(use request_overrides={'extra_body': ...} for wire-only fields)."+ )_sanitize_astra_request_kwargs(kwargs, model, params.get("base_url"))diff --git a/tests/agent/transports/test_codex_transport.py b/tests/agent/transports/test_codex_transport.pyindex 5c4639adf30..1f0bc0366bf 100644--- a/tests/agent/transports/test_codex_transport.py+++ b/tests/agent/transports/test_codex_transport.py@@ -97,15 +97,27 @@ class TestCodexBuildKwargs:assert kw["reasoning"]["effort"] == "none"assert kw["temperature"] == 0.4- def test_prompt_cache_options_dropped_from_overrides(self, transport):- """``prompt_cache_options`` has no Responses.create() kwarg, so a top-level copy- from request_overrides raises TypeError before any request is sent — on the- official API, the Codex backend, and custom Responses endpoints alike."""- for base_url, is_codex in (+ @pytest.mark.parametrize(+ "base_url,is_codex",+ [("https://api.openai.com/v1", False),("https://chatgpt.com/backend-api/codex", True),("https://responses.example.com/v1", False),- ):+ ],+ )+ def test_prompt_cache_options_dropped_from_overrides(+ self, transport, monkeypatch, caplog, base_url, is_codex+ ):+ """``prompt_cache_options`` has no Responses.create() kwarg, so a top-level copy+ from request_overrides raises TypeError before any request is sent — on the+ official API, the Codex backend, and custom Responses endpoints alike. The+ ``extra_body`` escape hatch the warning points to still reaches the wire, and+ the warning fires once per process rather than every turn."""+ import agent.transports.codex as codex_mod++ monkeypatch.setattr(codex_mod, "_PROMPT_CACHE_OPTIONS_DROP_WARNED", False)+ caplog.set_level("WARNING", logger=codex_mod.logger.name)+ for _ in range(2):kw = transport.build_kwargs(model="gpt-6-astra",messages=[{"role": "user", "content": "Hi"}],@@ -115,10 +127,14 @@ class TestCodexBuildKwargs:request_overrides={"prompt_cache_options": {"ttl": "30m"},"store": True,+ "extra_body": {"prompt_cache_options": {"ttl": "30m"}},},)- assert "prompt_cache_options" not in kw, base_url+ assert "prompt_cache_options" not in kwassert kw["store"] is True+ assert kw["extra_body"]["prompt_cache_options"] == {"ttl": "30m"}+ assert caplog.text.count("Dropped prompt_cache_options") == 1+ assert "extra_body" in caplog.textdef test_900k_context_variant_suffix_stripped_on_wire(self, transport):"""``-900k`` large-context picker variants are Hermes-side aliases —