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
@@ -284,6 +284,71 @@ fn test_model_info() -> ModelInfo {
|
||||
.expect("deserialize test model info")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn responses_lite_prefix_ids_track_thread_and_payload() -> anyhow::Result<()> {
|
||||
let thread_id = ThreadId::new();
|
||||
let client = test_model_client_with_thread_id(thread_id, SessionSource::Cli);
|
||||
let mut model = test_model_info();
|
||||
model.use_responses_lite = true;
|
||||
let mut prompt = Prompt {
|
||||
base_instructions: BaseInstructions {
|
||||
text: "base instructions".to_string(),
|
||||
provenance: None,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let build = |client: &ModelClient, prompt: &Prompt| {
|
||||
client.build_responses_request(
|
||||
prompt,
|
||||
&model,
|
||||
/*effort*/ None,
|
||||
codex_protocol::config_types::ReasoningSummary::None,
|
||||
/*service_tier*/ None,
|
||||
&test_responses_metadata_for_client(
|
||||
client,
|
||||
/*turn_id*/ None,
|
||||
format!("{}:0", client.state.thread_id),
|
||||
/*parent_thread_id*/ None,
|
||||
TestCodexResponsesRequestKind::Turn,
|
||||
),
|
||||
)
|
||||
};
|
||||
|
||||
let original = build(&client, &prompt)?;
|
||||
assert_eq!(build(&client, &prompt)?, original);
|
||||
|
||||
prompt.base_instructions.text.push_str(" with an update");
|
||||
let changed_instructions = build(&client, &prompt)?;
|
||||
assert_eq!(changed_instructions.input[0], original.input[0]);
|
||||
assert_ne!(changed_instructions.input[1].id(), original.input[1].id());
|
||||
|
||||
prompt.tools = vec![codex_tools::ToolSpec::Freeform(codex_tools::FreeformTool {
|
||||
name: "exec".to_string(),
|
||||
description: "Execute JavaScript.".to_string(),
|
||||
defer_loading: None,
|
||||
format: codex_tools::FreeformToolFormat {
|
||||
r#type: "grammar".to_string(),
|
||||
syntax: "lark".to_string(),
|
||||
definition: "start: /.+/".to_string(),
|
||||
},
|
||||
})]
|
||||
.into();
|
||||
let changed_tools = build(&client, &prompt)?;
|
||||
assert_ne!(
|
||||
changed_tools.input[0].id(),
|
||||
changed_instructions.input[0].id()
|
||||
);
|
||||
assert_eq!(changed_tools.input[1], changed_instructions.input[1]);
|
||||
|
||||
let independent = build(
|
||||
&test_model_client_with_thread_id(ThreadId::new(), SessionSource::Cli),
|
||||
&prompt,
|
||||
)?;
|
||||
assert_ne!(independent.input[0].id(), changed_tools.input[0].id());
|
||||
assert_ne!(independent.input[1].id(), changed_tools.input[1].id());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn test_session_telemetry() -> SessionTelemetry {
|
||||
SessionTelemetry::new(
|
||||
ThreadId::new(),
|
||||
|
||||
Reference in new issue
Block a user