Skip to content

Fixed prompt caching for ChatGPT Subscription and model aliases for subagents - #187

Merged
oleg68 merged 1 commit into
nbplugins:mainfrom
oleg68:bugfix/codex-prompt-cache
Oct 7, 2026
Merged

oleg68 merged 1 commit into
nbplugins:mainfrom
oleg68:bugfix/codex-prompt-cache

Conversation

@oleg68

@oleg68 oleg68 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Codex prompt-cache routing needs the session_id header besides prompt_cache_key: it is now sent (main sessions went from ~0% to 90–99% cache hits).
  • Every subagent gets its own cache key (<session>/<x-claude-code-agent-id>).
  • Explicit caching fields rejected by Codex with HTTP 400 (prompt_cache_options, prompt_cache_retention) are no longer sent to ChatGPT Subscription.
  • role:"system" messages sent by Claude Code 2.1.288 are no longer lost (Codex: developer item; Chat Completions: kept in place).
  • Model Aliases now apply to ChatGPT Subscription sessions (fixes subagent/background 400 "model is not supported").
  • Model combo lists aliased models by their own id, in Model Aliases order.
  • cache_write_tokens nested in usage details is parsed; cached_tokens is logged for aggregated Codex responses.
  • Diagnostics: PromptPrefixTracker logs how much of the prompt prefix is unchanged between requests (per cache key and model).
  • Experiments in claude-launch-tests/ (results in docstrings): Codex needs session_id; the OpenAI-compatible router's cache is random for glm-5.3 / gpt-6-luna and ignores sticky hints and explicit fields.

Test plan

  • mvn package (all unit tests)
  • Manual: ChatGPT Subscription main session and subagents cache; no 400 for subagents
  • Manual: OpenAI Compatible (deepseek-v4.1-flash) subagents cache ~91%
  • Manual: profiles load, model combo order follows Model Aliases

🤖 Generated with Claude Code

…ubagents

Codex backend cache routing needs the session_id header besides
prompt_cache_key; the proxy now sends it, gives every subagent its own
cache key (session id + x-claude-code-agent-id) and no longer sends the
explicit caching fields that Codex rejects with HTTP 400
(prompt_cache_options, prompt_cache_retention).

- Kept role:"system" messages sent by Claude Code 2.1.288 inside
  messages[] (Codex: developer item, Chat Completions: in place).
- Parsed cache_write_tokens nested in input/prompt_tokens_details and
  logged cached_tokens for aggregated Codex responses.
- Applied Model Aliases to ChatGPT Subscription sessions so subagents
  and background requests use a supported model.
- Listed models mapped to sonnet/opus/haiku by their own id in the
  model combo, in the order of the Model Aliases dialog (modelOrder;
  derived getComboModelIds is @JsonIgnore'd).
- Added PromptPrefixTracker (per cache key and model) to log how much of
  the prompt prefix is unchanged between requests.
- Added claude-launch-tests for prefix stability, Codex cache routing
  and router sticky/explicit cache experiments (results in docstrings).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oleg68
oleg68 merged commit f511e49 into nbplugins:main Oct 7, 2026
3 checks passed
@oleg68
oleg68 deleted the bugfix/codex-prompt-cache branch October 7, 2026 05:40
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