Skip to content

Commit 5625ed7

Browse files
authored
Preserve IDs for more item types in azure (openai#3542)
openai#3509
1 parent 73e215d commit 5625ed7

2 files changed

Lines changed: 58 additions & 5 deletions

File tree

codex-rs/core/src/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,13 @@ fn attach_item_ids(payload_json: &mut Value, original_items: &[ResponseItem]) {
455455
};
456456

457457
for (value, item) in items.iter_mut().zip(original_items.iter()) {
458-
if let ResponseItem::Reasoning { id, .. } = item {
458+
if let ResponseItem::Reasoning { id, .. }
459+
| ResponseItem::Message { id: Some(id), .. }
460+
| ResponseItem::WebSearchCall { id: Some(id), .. }
461+
| ResponseItem::FunctionCall { id: Some(id), .. }
462+
| ResponseItem::LocalShellCall { id: Some(id), .. }
463+
| ResponseItem::CustomToolCall { id: Some(id), .. } = item
464+
{
459465
if id.is_empty() {
460466
continue;
461467
}

codex-rs/core/tests/suite/client.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use codex_core::CodexAuth;
2+
use codex_core::ContentItem;
23
use codex_core::ConversationManager;
4+
use codex_core::LocalShellAction;
5+
use codex_core::LocalShellExecAction;
6+
use codex_core::LocalShellStatus;
37
use codex_core::ModelClient;
48
use codex_core::ModelProviderInfo;
59
use codex_core::NewConversation;
@@ -15,6 +19,7 @@ use codex_core::protocol::Op;
1519
use codex_core::spawn::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR;
1620
use codex_protocol::mcp_protocol::ConversationId;
1721
use codex_protocol::models::ReasoningItemReasoningSummary;
22+
use codex_protocol::models::WebSearchAction;
1823
use core_test_support::load_default_config_for_test;
1924
use core_test_support::load_sse_fixture_with_id;
2025
use core_test_support::wait_for_event;
@@ -699,6 +704,45 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
699704
}]),
700705
encrypted_content: None,
701706
});
707+
prompt.input.push(ResponseItem::Message {
708+
id: Some("message-id".into()),
709+
role: "assistant".into(),
710+
content: vec![ContentItem::OutputText {
711+
text: "message".into(),
712+
}],
713+
});
714+
prompt.input.push(ResponseItem::WebSearchCall {
715+
id: Some("web-search-id".into()),
716+
status: Some("completed".into()),
717+
action: WebSearchAction::Search {
718+
query: "weather".into(),
719+
},
720+
});
721+
prompt.input.push(ResponseItem::FunctionCall {
722+
id: Some("function-id".into()),
723+
name: "do_thing".into(),
724+
arguments: "{}".into(),
725+
call_id: "function-call-id".into(),
726+
});
727+
prompt.input.push(ResponseItem::LocalShellCall {
728+
id: Some("local-shell-id".into()),
729+
call_id: Some("local-shell-call-id".into()),
730+
status: LocalShellStatus::Completed,
731+
action: LocalShellAction::Exec(LocalShellExecAction {
732+
command: vec!["echo".into(), "hello".into()],
733+
timeout_ms: None,
734+
working_directory: None,
735+
env: None,
736+
user: None,
737+
}),
738+
});
739+
prompt.input.push(ResponseItem::CustomToolCall {
740+
id: Some("custom-tool-id".into()),
741+
status: Some("completed".into()),
742+
call_id: "custom-tool-call-id".into(),
743+
name: "custom_tool".into(),
744+
input: "{}".into(),
745+
});
702746

703747
let mut stream = client
704748
.stream(&prompt)
@@ -722,10 +766,13 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
722766

723767
assert_eq!(body["store"], serde_json::Value::Bool(true));
724768
assert_eq!(body["stream"], serde_json::Value::Bool(true));
725-
assert_eq!(
726-
body["input"][0]["id"],
727-
serde_json::Value::String("reasoning-id".into())
728-
);
769+
assert_eq!(body["input"].as_array().map(Vec::len), Some(6));
770+
assert_eq!(body["input"][0]["id"].as_str(), Some("reasoning-id"));
771+
assert_eq!(body["input"][1]["id"].as_str(), Some("message-id"));
772+
assert_eq!(body["input"][2]["id"].as_str(), Some("web-search-id"));
773+
assert_eq!(body["input"][3]["id"].as_str(), Some("function-id"));
774+
assert_eq!(body["input"][4]["id"].as_str(), Some("local-shell-id"));
775+
assert_eq!(body["input"][5]["id"].as_str(), Some("custom-tool-id"));
729776
}
730777

731778
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)