Skip to content

fix(codex): bound cache keys at provider boundaries - #66330

Merged
teknium1 merged 3 commits into
mainfrom
fix/codex-cache-key-boundaries
Jul 17, 2026
Merged

fix(codex): bound cache keys at provider boundaries#66330
teknium1 merged 3 commits into
mainfrom
fix/codex-cache-key-boundaries

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Provider-facing Codex/Responses cache-routing keys are now bounded at every mutable boundary, including after request middleware.

Changes

  • Hash over-length session_id / x-client-request-id cache-scope headers while preserving short IDs and unrelated caller headers.
  • Bound explicit top-level and xAI extra_body.prompt_cache_key overrides.
  • Reapply the guard in final preflight_kwargs() so execution middleware cannot reintroduce an oversized key immediately before the provider call.
  • Cover the 64/65-character boundary, deterministic hashing, collision resistance, caller headers, body/header parity, xAI overrides, and a full middleware-to-dispatch path.

This preserves @webtecnica's #66272 commit authorship, folds in the broader provider-boundary design from #62349 by @thegoodguysla, credits @Armib20's earliest #24273 submission, and follows @gracejudy's live diagnosis that isolated the production failure to the cache-scope headers.

Validation

  • tests/agent/transports/test_codex_transport.py
  • tests/run_agent/test_run_agent_codex_responses.py
  • 186 targeted tests passed
  • Ruff and git diff --check passed
  • Real-import probe verified Codex header, top-level, and xAI body keys remain ≤64 after late mutation

Fixes #66045.

Infographic

Safe cache routing

@teknium1
teknium1 force-pushed the fix/codex-cache-key-boundaries branch from 6bc5ba8 to 3603ee0 Compare July 17, 2026 13:53
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API codex P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) labels Jul 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #24273 and #62349: this PR also bounds override keys at final preflight, so it has broader provider-boundary scope than the existing open repairs. Please consolidate the cache-key contract.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Clean, well-scoped change with good test coverage. No security concerns.


Reviewed by Hermes Agent

webtecnica and others added 3 commits July 17, 2026 13:20
Exercise the real transport path for long session ids, including stable hashing and bounded body/header cache keys.
Fold #62349's broader provider-boundary handling into the header fix: bound top-level and xAI override keys again at preflight after middleware, preserve unrelated headers, and cover boundaries and collisions.

Co-authored-by: Nick Taylor <nicktaylor@TheWorldofNick-Lappy.local>
@teknium1
teknium1 force-pushed the fix/codex-cache-key-boundaries branch from 3603ee0 to b2d6d92 Compare July 17, 2026 20:22
@teknium1
teknium1 merged commit 61bbc39 into main Jul 17, 2026
33 checks passed
@teknium1
teknium1 deleted the fix/codex-cache-key-boundaries branch July 17, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex transport emits an over-length prompt_cache_key (>64) → every openai-codex request 400s and silently falls back

4 participants