feat: session affinity + prompt cache for multi-turn conversations#242
Merged
icebear0828 merged 2 commits intomasterfrom Mar 27, 2026
Merged
feat: session affinity + prompt cache for multi-turn conversations#242icebear0828 merged 2 commits intomasterfrom
icebear0828 merged 2 commits intomasterfrom
Conversation
Route subsequent turns of a conversation to the same account that created the initial response. This fixes two issues caused by account rotation breaking conversation chains: 1. previous_response_id becoming invalid across accounts — the backend stores conversation state per-account, so switching accounts meant losing server-side history 2. Prompt cache misses — cache is per-account on the backend, rotating accounts forced full context reprocessing every turn Implementation: - SessionAffinityMap: responseId → entryId mapping with 4h TTL - acquire() accepts preferredEntryId hint, falls back to normal rotation - proxy-handler captures responseId from both streaming and non-streaming paths (onResponseId callback was previously discarded) - Request logs now show affinity=hit/miss, payload size, and usage stats
Send prompt_cache_key (per-conversation UUID) in every request to enable backend prompt caching. The conversation ID is inherited across the previous_response_id chain via SessionAffinityMap. Also: - Forward service_tier on both WebSocket and HTTP paths (was dropped) - Send include: ["reasoning.encrypted_content"] when reasoning is active - Extend SessionAffinityMap with conversationId tracking
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
responseId → entryIdmapping, fixingprevious_response_idbreaking across account rotationprompt_cache_key: send per-conversation UUID to enable backend prompt caching — Turn 4+ sees 93% cache hit rate (was 0% before)service_tier,includeon WebSocket path (were silently dropped)Verified
Changes
session-affinity.tsresponseId → (entryId, conversationId)map with 4h TTLproxy-handler.tsresponse-processor.tsonResponseIdcallback (was discarded)account-lifecycle.tsacquire()supportspreferredEntryIdhintcodex-types.tsprompt_cache_key,includeto request typews-transport.tsservice_tier,prompt_cache_key,includeto WS messagecodex-api.tsservice_tieron HTTPTest plan