mirror of
https://github.com/openai/codex.git
synced 2026-05-18 18:22:39 +00:00
## Why Some consumers expect conventional hyphenated HTTP headers. Codex already sends the session and thread IDs on outbound Responses requests, but it only uses the underscore spellings today, which makes those IDs harder to consume in systems that normalize or reject underscore header names. Full context here: https://openai.slack.com/archives/C08KCGLSPSQ/p1778248578422369 ## What changed - `build_session_headers` now emits both `session_id` and `session-id` when a session ID is present. - It does the same for `thread_id` and `thread-id`. - Added regression coverage in `codex-api/tests/clients.rs` and `core/tests/suite/client.rs` so both the lower-level client tests and the end-to-end request tests assert the two header spellings are present. ## Test plan - Added header assertions in `codex-api/tests/clients.rs`. - Added request-header assertions in `core/tests/suite/client.rs` for both the `/v1/responses` and `/api/codex/responses` request paths.
43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
use codex_protocol::protocol::SessionSource;
|
|
use http::HeaderMap;
|
|
use http::HeaderValue;
|
|
|
|
pub fn build_session_headers(session_id: Option<String>, thread_id: Option<String>) -> HeaderMap {
|
|
let mut headers = HeaderMap::new();
|
|
if let Some(id) = session_id {
|
|
insert_header(&mut headers, "session_id", &id);
|
|
insert_header(&mut headers, "session-id", &id);
|
|
}
|
|
if let Some(id) = thread_id {
|
|
insert_header(&mut headers, "thread_id", &id);
|
|
insert_header(&mut headers, "thread-id", &id);
|
|
}
|
|
headers
|
|
}
|
|
|
|
pub(crate) fn subagent_header(source: &Option<SessionSource>) -> Option<String> {
|
|
let SessionSource::SubAgent(sub) = source.as_ref()? else {
|
|
return None;
|
|
};
|
|
match sub {
|
|
codex_protocol::protocol::SubAgentSource::Review => Some("review".to_string()),
|
|
codex_protocol::protocol::SubAgentSource::Compact => Some("compact".to_string()),
|
|
codex_protocol::protocol::SubAgentSource::MemoryConsolidation => {
|
|
Some("memory_consolidation".to_string())
|
|
}
|
|
codex_protocol::protocol::SubAgentSource::ThreadSpawn { .. } => {
|
|
Some("collab_spawn".to_string())
|
|
}
|
|
codex_protocol::protocol::SubAgentSource::Other(label) => Some(label.clone()),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn insert_header(headers: &mut HeaderMap, name: &str, value: &str) {
|
|
if let (Ok(header_name), Ok(header_value)) = (
|
|
name.parse::<http::HeaderName>(),
|
|
HeaderValue::from_str(value),
|
|
) {
|
|
headers.insert(header_name, header_value);
|
|
}
|
|
}
|