Skip to content

fix: prompt-cache max for xAI and Codex (git-root + HUD) - #661

Closed
justrach wants to merge 3 commits into
mainfrom
cursor/cache-max-codex-4ffc
Closed

fix: prompt-cache max for xAI and Codex (git-root + HUD)#661
justrach wants to merge 3 commits into
mainfrom
cursor/cache-max-codex-4ffc

Conversation

@justrach

@justrach justrach commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Prompt-cache max for both wires, not just xAI. Verified OOTB against Codex (DeepWiki / ModelClient), Claude’s current cache_control docs, and Kimi’s context-cache + chat OpenAPI.

What was already true

Codex HTTP/WS session_id already equals the Responses prompt_cache_key (ADR 0028). Both wires call projectRootId. We do not send prompt_cache_options / prompt_cache_breakpoint on Codex — the ChatGPT backend 400s them (openai/codex#35300).

What was wrong

  1. That id hashed the leaf cwd. Sibling sandboxes with the same system+tools prefix were different partitions (rematch: graff first-call cache 0–512, grok 11k–43k already warm).
  2. /cache only named xAI headers. A Codex session looked like it had no affinity.
  3. Native Claude marked system + last message, but not the last tool (writeAnthropicTools(..., is_kimi)). A long tool loop can walk Anthropic’s 20-block lookback off the system write.

This PR

  • Root affinity is the git root (or graff-scratch with no repo). Worktrees and eval sandboxes share. Includes fix: key prompt-cache affinity on git root, not cwd #659.
  • /cache prints Codex as session_id = prompt_cache_key on the same id. OpenAI Platform still gets the ADR 0009 breakpoint. Claude and Kimi are named on their own contracts (no fake Claude key).
  • Native Anthropic now marks tools + system + last message. MiniMax stays unmarked. No top-level automatic cache_control (that would be a 4th slot / no-op).
  • Kimi chat already sent prompt_cache_key (Code Plan / coding-agent). Unchanged.
  • ADR 0028: same git-root id as xAI; no Platform breakpoint on this wire.

You can just use it: pick the provider, /cache names the live contract. Merge this one if you want both wires in one shot (stacks on #659).

Open in Web Open in Cursor 

xAI partitions cache by prompt_cache_key. Hashing the leaf cwd made every
graff-evals sandbox a cold ~8k write (rematch first-call cache 0–512 vs
grok 11k–43k already warm). Seed is the git root so worktrees and sibling
sandboxes share; scratch -p uses graff-scratch. Prefix bytes still have to
match. ADR 0011.
xAI and Codex already share cache_affinity.rootId (git-root / graff-scratch)
for prompt_cache_key. /cache only named the xAI headers, so a Codex session
looked like it had no affinity. Record the wire, print session_id =
prompt_cache_key, and pin ADR 0028: same id as xAI, no Platform breakpoint
(the ChatGPT backend 400s it).
@justrach
justrach marked this pull request as ready for review August 28, 2026 07:49
Native Anthropic only marked system + last message; the last-tool
breakpoint was gated on is_kimi, so a long tool loop could walk the
20-block lookback off the system write. /cache now names Claude and
Kimi instead of showing a unused key as Claude affinity.
@justrach

Copy link
Copy Markdown
Owner Author

Already on main (prompt-cache max HUD + Claude last-tool cache_control). Closing as superseded.

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.

2 participants