mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Request omission of preliminary reasoning ciphertext (#63461)
## Why Reasoning replay only needs the ciphertext from the completed item, so sending it when the item is first added is unnecessary. ## What changed Default `x-codex-exclude-stream-fields` to `reasoning.added.encrypted_content` on Responses HTTP streams and WebSocket handshakes. Provider-configured values take precedence, and an empty value opts out. Use a separate header to preserve compatibility with servers that recognize `x-codex-exclude`. ## Testing Extend integration tests to cover the default on both transports, provider overrides, and replay with or without preliminary ciphertext. GitOrigin-RevId: 83b72e5dd896f96e2793e67f0f05828218b98af7
This commit is contained in:
@@ -4573,7 +4573,10 @@ async fn env_var_overrides_loaded_auth() {
|
||||
"Custom-Header".to_string(),
|
||||
"Value".into(),
|
||||
)])),
|
||||
env_http_headers: None,
|
||||
env_http_headers: Some(std::collections::HashMap::from([(
|
||||
"X-Codex-Exclude-Stream-Fields".to_string(),
|
||||
EXISTING_ENV_VAR_WITH_NON_EMPTY_VALUE.to_string(),
|
||||
)])),
|
||||
request_max_retries: None,
|
||||
stream_max_retries: None,
|
||||
stream_idle_timeout_ms: None,
|
||||
@@ -4618,6 +4621,10 @@ async fn env_var_overrides_loaded_auth() {
|
||||
.find(|request| request.url.path() == "/openai/responses")
|
||||
.expect("missing provider request");
|
||||
assert_eq!(request.headers.get(X_CODEX_ROUTING_HINT_HEADER), None);
|
||||
assert_eq!(
|
||||
request.headers["x-codex-exclude-stream-fields"],
|
||||
std::env::var(EXISTING_ENV_VAR_WITH_NON_EMPTY_VALUE).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
fn create_dummy_codex_auth() -> CodexAuth {
|
||||
|
||||
@@ -306,6 +306,10 @@ async fn responses_websocket_streams_request() {
|
||||
handshake.header(X_CLIENT_REQUEST_ID_HEADER),
|
||||
Some(harness.thread_id.to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
handshake.header("x-codex-exclude-stream-fields").as_deref(),
|
||||
Some("reasoning.added.encrypted_content")
|
||||
);
|
||||
assert_eq!(
|
||||
handshake.header("session-id"),
|
||||
Some(harness.session_id.to_string())
|
||||
@@ -346,6 +350,11 @@ async fn responses_websocket_omits_routing_hint_for_provider_with_own_credential
|
||||
let mut provider = websocket_provider(&server);
|
||||
provider.name = ModelProviderInfo::create_openai_provider(/*base_url*/ None).name;
|
||||
provider.experimental_bearer_token = Some("provider-specific-token".into());
|
||||
// An empty value opts out of the default stream exclusions.
|
||||
provider
|
||||
.http_headers
|
||||
.get_or_insert_default()
|
||||
.insert("X-Codex-Exclude-Stream-Fields".to_string(), "".into());
|
||||
let harness = websocket_harness_with_provider_options_and_auth(
|
||||
provider,
|
||||
/*runtime_metrics_enabled*/ false,
|
||||
@@ -365,6 +374,10 @@ async fn responses_websocket_omits_routing_hint_for_provider_with_own_credential
|
||||
Some("Bearer provider-specific-token".to_string())
|
||||
);
|
||||
assert_eq!(handshake.header(X_CODEX_ROUTING_HINT_HEADER), None);
|
||||
assert_eq!(
|
||||
handshake.header("x-codex-exclude-stream-fields").as_deref(),
|
||||
Some("")
|
||||
);
|
||||
|
||||
server.shutdown().await;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::ev_function_call;
|
||||
use core_test_support::responses::ev_reasoning_item;
|
||||
use core_test_support::responses::ev_reasoning_item_added;
|
||||
use core_test_support::responses::mount_sse_sequence;
|
||||
use core_test_support::responses::sse;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
@@ -28,6 +29,11 @@ async fn output_token_replay_respects_provider_and_preserves_history(
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let mut started = ev_reasoning_item_added("reasoning", &[]);
|
||||
if !openai_provider {
|
||||
// A provider that ignores the opt-in may still send a preliminary ciphertext.
|
||||
started["item"]["encrypted_content"] = json!("preliminary");
|
||||
}
|
||||
let mut reasoning = ev_reasoning_item("reasoning", &["I will check the result."], &[]);
|
||||
reasoning["item"]["content"] = json!(null);
|
||||
let mut commentary = ev_assistant_message("commentary", "I will record the completed step.");
|
||||
@@ -67,6 +73,7 @@ async fn output_token_replay_respects_provider_and_preserves_history(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
started,
|
||||
reasoning,
|
||||
commentary,
|
||||
call,
|
||||
@@ -111,6 +118,12 @@ async fn output_token_replay_respects_provider_and_preserves_history(
|
||||
|
||||
let requests = mock.requests();
|
||||
assert_eq!(requests.len(), 3);
|
||||
assert_eq!(
|
||||
requests[0]
|
||||
.header("x-codex-exclude-stream-fields")
|
||||
.as_deref(),
|
||||
Some("reasoning.added.encrypted_content")
|
||||
);
|
||||
let expected_include = if enabled && openai_provider {
|
||||
json!(["reasoning.encrypted_content", "output.encrypted_content"])
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user