mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve parent cache affinity for ephemeral forks (#44862)
## Why ChatGPT derives Responses cache affinity from the `session-id` header. Ephemeral forks need to reuse their parent's cache routing while retaining their own session and thread identities. ## What changed - Inherit the parent session ID as the `prompt_cache_key` for ephemeral root forks. - Use the prompt cache key for root-agent Responses `session-id` headers, including WebSocket handshakes. Preserve the actual session identity in turn metadata and leave non-root-agent routing unchanged. - Keep enabled goal tool definitions visible on ephemeral threads, but reject execution with `Goal tools require a persistent thread.` and disable automatic goal continuation without persistent state. ## Testing Add regression coverage for inherited cache routing with distinct fork identities, matching parent and fork tool definitions, WebSocket session headers, and rejection of ephemeral goal tool execution. GitOrigin-RevId: d235e97630068b27f7ebd562dd23ac6266ebc1b9
This commit is contained in:
1 parent
0818b6550b
commit
bc5957eac9
8 files changed
+167
-22
No files matched your search
@@ -508,6 +508,16 @@ impl ModelClient {
|
||||
responses_metadata.session_id.clone()
|
||||
}
|
||||
|
||||
// ChatGPT derives cache affinity from the Responses session-id header. Keep the
|
||||
// actual session identity in turn metadata, hooks, and history/notes requests.
|
||||
fn responses_session_id(&self, metadata: &CodexResponsesMetadata) -> String {
|
||||
if self.state.session_source.is_non_root_agent() {
|
||||
metadata.session_id.clone()
|
||||
} else {
|
||||
self.prompt_cache_key(metadata)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a fresh turn-scoped streaming session.
|
||||
///
|
||||
/// This constructor does not perform network I/O itself; the session opens a websocket lazily
|
||||
@@ -1162,7 +1172,7 @@ impl ModelClient {
|
||||
headers.insert("x-client-request-id", header_value);
|
||||
}
|
||||
headers.extend(build_session_headers(
|
||||
Some(responses_metadata.session_id.to_string()),
|
||||
Some(self.responses_session_id(responses_metadata)),
|
||||
Some(responses_metadata.thread_id.to_string()),
|
||||
));
|
||||
headers.extend(self.build_responses_compatibility_headers(responses_metadata));
|
||||
@@ -1217,7 +1227,7 @@ impl ModelClientSession {
|
||||
use_responses_lite: bool,
|
||||
) -> ApiResponsesOptions {
|
||||
ApiResponsesOptions {
|
||||
session_id: Some(responses_metadata.session_id.to_string()),
|
||||
session_id: Some(self.client.responses_session_id(responses_metadata)),
|
||||
thread_id: Some(responses_metadata.thread_id.to_string()),
|
||||
session_source: Some(self.client.state.session_source.clone()),
|
||||
extra_headers: {
|
||||
|
||||
Reference in new issue
Block a user