Use session IDs for prompt cache keys (#33035)

## What changed

- Default `prompt_cache_key` to the session ID from response metadata instead of the thread ID.
- Preserve explicit prompt cache key overrides.
- Verify that API-key-authenticated root and subagent requests use the same session-based cache key even though they have different thread IDs.

GitOrigin-RevId: cb1bf21a3cb8fa2c5083c5c6afd4829ff2adcf1f
This commit is contained in:
jif
2026-07-14 10:37:23 +00:00
committed by copyberry
parent 7790524d6b
commit 4aa950d456
4 changed files with 165 additions and 4 deletions
+3 -3
View File
@@ -466,10 +466,10 @@ impl ModelClient {
self
}
fn prompt_cache_key(&self) -> String {
fn prompt_cache_key(&self, responses_metadata: &CodexResponsesMetadata) -> String {
self.prompt_cache_key_override
.clone()
.unwrap_or_else(|| self.state.thread_id.to_string())
.unwrap_or_else(|| responses_metadata.session_id.clone())
}
/// Creates a fresh turn-scoped streaming session.
@@ -885,7 +885,7 @@ impl ModelClient {
&prompt.output_schema,
prompt.output_schema_strict,
);
let prompt_cache_key = Some(self.prompt_cache_key());
let prompt_cache_key = Some(self.prompt_cache_key(responses_metadata));
let service_tier = model_info.service_tier_for_request(service_tier);
let request = ResponsesApiRequest {
model: model_info.slug.clone(),