mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Give Responses Lite prefix items stable IDs (#40962)
## Why Responses Lite rebuilds its tools and base-instruction prefix for each request. Stable item identities let follow-up WebSocket requests recognize that unchanged prefix and send only incremental input. ## What changed - Derive deterministic IDs for additional-tools and base-instruction items from the thread ID and each item's serialized payload. - Preserve IDs when rebuilding an unchanged request or resuming a session, while changing them when the thread or payload changes. ## Testing - Cover ID stability and payload/thread sensitivity in request construction. - Verify resumed Responses Lite sessions reuse prefix IDs and WebSocket follow-ups use `previous_response_id` with only new input items. GitOrigin-RevId: 3c8548b96979d7578865b0ccc51c147926823478
This commit is contained in:
1 parent
7f82397363
commit
e77773085c
4 files changed
+174
-12
No files matched your search
@@ -74,6 +74,7 @@ use codex_login::default_client::add_originator_header;
|
||||
use codex_login::default_client::create_client_for_route;
|
||||
use codex_otel::SessionTelemetry;
|
||||
use codex_otel::current_span_w3c_trace_context;
|
||||
use codex_protocol::ResponseItemId;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
|
||||
use codex_protocol::ThreadId;
|
||||
@@ -108,6 +109,7 @@ use tokio_util::sync::CancellationToken;
|
||||
use tracing::instrument;
|
||||
use tracing::trace;
|
||||
use tracing::warn;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::attestation::AttestationContext;
|
||||
use crate::attestation::AttestationProvider;
|
||||
@@ -898,20 +900,34 @@ impl ModelClient {
|
||||
let mut input = prompt.get_formatted_input_for_request(model_info.use_responses_lite);
|
||||
let is_openai = self.state.provider.info().is_openai();
|
||||
let (instructions, tools) = if model_info.use_responses_lite {
|
||||
// These prompt-only items are rebuilt on every request. Hash their visible payloads
|
||||
// within the thread so retries and resumed sessions preserve their identity.
|
||||
let prefix_namespace = Uuid::new_v5(
|
||||
&Uuid::NAMESPACE_OID,
|
||||
self.state.thread_id.to_string().as_bytes(),
|
||||
);
|
||||
let tools = if self.state.provider.capabilities().namespace_tools {
|
||||
create_tools_json_for_responses_lite(&prompt.tools)?
|
||||
} else {
|
||||
create_tools_json_for_responses_api(&prompt.tools)?
|
||||
};
|
||||
let mut prefix = vec![ResponseItem::AdditionalTools {
|
||||
id: None,
|
||||
id: Some(ResponseItemId::with_suffix(
|
||||
"at",
|
||||
Uuid::new_v5(&prefix_namespace, &serde_json::to_vec(&tools)?),
|
||||
)),
|
||||
role: "developer".to_string(),
|
||||
tools,
|
||||
}];
|
||||
if !prompt.base_instructions.text.is_empty() {
|
||||
prefix.push(ContextualUserFragment::into(BaseInstructionsFragment(
|
||||
let mut instructions = ContextualUserFragment::into(BaseInstructionsFragment(
|
||||
prompt.base_instructions.text.clone(),
|
||||
));
|
||||
instructions.set_id(Some(ResponseItemId::with_suffix(
|
||||
"msg",
|
||||
Uuid::new_v5(&prefix_namespace, prompt.base_instructions.text.as_bytes()),
|
||||
)));
|
||||
prefix.push(instructions);
|
||||
}
|
||||
input.splice(0..0, prefix);
|
||||
(String::new(), None)
|
||||
|
||||
Reference in new issue
Block a user