Repository navigation
fix(core): send Codex session headers with ChatGPT token sharing - #53767
Merged
Merged
Conversation
ChatGPT token sharing only sent prompt_cache_key, while the legacy Codex route also sends a session-id header that ChatGPT uses for prompt-cache affinity. Send session-id, thread-id, and x-client-request-id on token-sharing requests the way the Codex client does.
2 of 6 tasks
3 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sign in with ChatGPT (token sharing) requests go to
api.openai.com/v1with only the sharedprompt_cache_key. The legacy Codex route also sends asession-idheader, which ChatGPT uses for prompt-cache affinity, and Codex itself sendssession-id,thread-id, andx-client-request-id. Testing showed token-sharing cache reuse near zero while the Codex route caches normally (#53765).This adds a
model.requesthook to the token-sharing plugin that sends:session-id: the session's cache-affinity ID (the parent for child sessions, matching the Codex route)thread-idandx-client-request-id: the current session IDAPI-key OpenAI connections and the Codex route are unchanged.
This is an experiment: whether the token-sharing backend actually routes its cache on these headers still needs a live check.
Tests
bun test test/plugin/provider-chatgpt.test.ts test/plugin/provider-openai.test.tsbun run typecheckinpackages/coreRefs #53765
Requested by: @rekram1-node (Aiden Cline via Slack)