From 6f795f22cc2db4cdf497f23e41b44d0e92a55bf7 Mon Sep 17 00:00:00 2001 From: webtecnica <75556242+webtecnica@users.noreply.github.com> Date: Fri, 17 Jul 2026 08:32:56 -0300 Subject: [PATCH] fix: cap cache-scope headers at 64 chars to avoid Codex 400 error (#66045) --- agent/transports/codex.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent/transports/codex.py b/agent/transports/codex.py index ef7ffbaffd2..484fd4ec7af 100644 --- a/agent/transports/codex.py +++ b/agent/transports/codex.py @@ -338,6 +338,14 @@ class ResponsesApiTransport(ProviderTransport): # headers while keeping ``prompt_cache_key`` in the body for # standard OpenAI routing as a belt-and-braces fallback. cache_scope_id = str(session_id or "").strip() + # OpenAI/Codex backend enforces 64-char limit on the session_id + # and x-client-request-id headers, mapping them internally to + # prompt_cache_key. Hash long IDs to stay within the limit; + # the hash is a cache-routing hint only, never a correctness bound. + if len(cache_scope_id) > 64: + cache_scope_id = "pck_" + hashlib.sha256( + cache_scope_id.encode("utf-8", "replace") + ).hexdigest()[:24] if cache_scope_id: existing_extra_headers = kwargs.get("extra_headers") merged_extra_headers: Dict[str, str] = {}