mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Add trusted request-country metadata to Responses requests (#61535)
## What changed - Add `RequestCountry` for host-supplied country codes. Normalize two-letter ASCII codes to uppercase, omit the field by default, and serialize explicit unknown (`XX`) as `null` to prevent fallback to request provenance. - Carry `request_country` through thread defaults and captured step settings into Codex backend HTTP and WebSocket requests. Allow live country updates without enabling `step_model_switching`, and preserve WebSocket continuation reuse when the country changes. - Propagate the captured country to subagents, reviews, and compaction requests. ## Testing Add coverage for country validation and serialization, thread and live-turn update lifetimes, prewarm settings capture, agent inheritance and reloads, compaction and reviews, WebSocket country changes, and HTTP fallback. GitOrigin-RevId: 787cd1fa7ba5d465a4eb64a92f13c79e93d9bca7
This commit is contained in:
@@ -1171,7 +1171,22 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn direct_serialization_preserves_websocket_request_payload() {
|
||||
for (country_code, expected_country) in [
|
||||
(None, None),
|
||||
(Some(" de "), Some(json!("DE"))),
|
||||
(Some("xX"), Some(Value::Null)),
|
||||
] {
|
||||
assert_serialized_request(country_code, expected_country);
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_serialized_request(country_code: Option<&str>, expected_country: Option<Value>) {
|
||||
let api_request = ResponsesApiRequest {
|
||||
request_country: country_code
|
||||
.map(codex_protocol::RequestCountry::from_iso_code)
|
||||
.transpose()
|
||||
.expect("country is valid")
|
||||
.unwrap_or_default(),
|
||||
model: "gpt-test".to_string(),
|
||||
input: vec![ResponseItem::Message {
|
||||
status: None,
|
||||
@@ -1224,6 +1239,10 @@ mod tests {
|
||||
|
||||
let mut expected_payload =
|
||||
serde_json::to_value(&api_request).expect("serialize responses API request");
|
||||
assert_eq!(
|
||||
expected_payload.get("request_country"),
|
||||
expected_country.as_ref()
|
||||
);
|
||||
expected_payload["type"] = json!("response.create");
|
||||
expected_payload["previous_response_id"] = json!("resp-1");
|
||||
expected_payload["generate"] = json!(false);
|
||||
@@ -1235,6 +1254,10 @@ mod tests {
|
||||
let wire_payload =
|
||||
serde_json::from_str::<Value>(&request_text).expect("parse websocket request");
|
||||
|
||||
assert_eq!(
|
||||
wire_payload.get("request_country"),
|
||||
expected_country.as_ref()
|
||||
);
|
||||
assert_eq!(wire_payload, expected_payload);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user