Skip to content

fix(cache): align Codex session_id/x-client-request-id headers with body key - #12

Closed
JoaoMarcos44 wants to merge 1 commit into
fix/78941-prompt-cache-key-session-scopefrom
fix/79013-codex-header-body-parity
Closed

JoaoMarcos44 wants to merge 1 commit into
fix/78941-prompt-cache-key-session-scopefrom
fix/79013-codex-header-body-parity

Conversation

@JoaoMarcos44

Copy link
Copy Markdown
Owner

Summary

Fixes NousResearch#79013. Split out of NousResearch#78959's continuation for standalone review.

ResponsesApiTransport.build_kwargs() sent both Codex-backend headers (session_id, x-client-request-id) as the same normalized scope string (e.g. cron_job42), while the body's prompt_cache_key is a content hash (pck_<hash>). Two problems:

  1. session_id header lost the raw physical id, contradicting the Align Codex cache affinity header NousResearch/hermes-agent#57012 contract (session_id = transcript identity, x-client-request-id = cache-routing key).
  2. x-client-request-id never actually matched the key the body was cached under.

Fix

session_id header = raw physical session_id, untouched. x-client-request-id = the same effective (already-bounded) prompt_cache_key sent in the body. Also fixed the fallback cache_key (used when instructions/tools are empty) to fall back to the normalized scope instead of the raw session_id -- same class of bug.

Test plan

  • test_codex_cache_scope_boundary — session_id header stays raw; x-client-request-id mirrors body key
  • test_codex_cache_scope_headers_normalize_cron_session_id — x-client-request-id stable across cron re-fires of the same job; session_id stays per-fire physical
  • Full test_codex_transport.py suite green (68 tests)
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#00f0ff', 'mainBkg': '#0a0a16', 'primaryTextColor': '#ffffff', 'primaryBorderColor': '#ff007f', 'lineColor': '#00f0ff'}}}%%
graph TD
    A[Codex Request] --> B[body.prompt_cache_key<br/>pck_content_hash]
    A --> C[header.session_id<br/>Before: normalized scope]
    A --> D[header.x-client-request-id<br/>Before: normalized scope]

    C -->|Mismatch| E[Broken #57012 Contract]
    D -->|Mismatch| F[Diverges From Body Key]

    A --> G[header.session_id<br/>After: raw physical id]
    A --> H[header.x-client-request-id<br/>After: mirrors body key]
    G --> I[Transcript Identity Preserved]
    H --> J[Header/Body Agreement]

    style E fill:#3a0030,stroke:#ff007f,color:#fff
    style F fill:#3a0030,stroke:#ff007f,color:#fff
    style I fill:#003a3a,stroke:#00f0ff,color:#fff
    style J fill:#003a3a,stroke:#00f0ff,color:#fff
Loading

…ody key

Fixes NousResearch#79013. session_id header now carries the raw physical session
id (NousResearch#57012 contract); x-client-request-id mirrors the body's effective
prompt_cache_key instead of both diverging to a bare, un-hashed scope
string. Fallback cache_key (when instructions/tools are empty) now
falls back to the normalized scope instead of the raw session_id,
same class of fix.
@JoaoMarcos44

Copy link
Copy Markdown
Owner Author

Folded back into the upstream PR (NousResearch#78959) so maintainers review everything in one visible upstream PR instead of fork-only ones. Closing.

@JoaoMarcos44
JoaoMarcos44 deleted the fix/79013-codex-header-body-parity branch August 5, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant