[codex] Add optional IDs to response items (#28812)

## Why

`ResponseItem` variants do not have a consistent internal ID shape: some
variants carry required IDs, some carry optional IDs, and some cannot
represent an ID at all. The existing fields also use inconsistent serde,
TypeScript, and JSON-schema annotations. A single enum-level access path
is needed before history recording can assign and retain IDs.

This PR establishes that internal model only. It intentionally does not
generate or serialize IDs; allocation and wire persistence are isolated
in the stacked follow-up.

## What changed

- Give every concrete `ResponseItem` variant an `Option<String>` ID
field.
- Apply the same internal-only annotations to every ID field:
`#[serde(default, skip_serializing)]`, `#[ts(skip)]`, and
`#[schemars(skip)]`.
- Add `ResponseItem::id()` and `ResponseItem::set_id()` as the shared
accessors.
- Preserve IDs when history items are rewritten for truncation.
- Adapt consumers that previously assumed reasoning and image-generation
IDs were required.
- Regenerate app-server schemas so the hidden fields are represented
consistently.

The serde catch-all `ResponseItem::Other` remains ID-less because it
must remain a unit variant.

## Test plan

- `cargo check --tests -p codex-core -p codex-api -p codex-rollout-trace
-p codex-image-generation-extension`
- `just test -p codex-protocol`
- `just test -p codex-app-server-protocol`
- `just test -p codex-api -p codex-rollout-trace -p
codex-image-generation-extension`
- `just test -p codex-core event_mapping`
This commit is contained in:
pakrym-oai
2026-06-17 18:27:43 -07:00
committed by GitHub
Unverified
parent c274a83f8b
commit dbd2857f4b
36 changed files with 278 additions and 258 deletions
+1 -1
View File
@@ -878,7 +878,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
assistant_message("parent final answer", Some(MessagePhase::FinalAnswer)),
assistant_message("parent unknown phase", /*phase*/ None),
ResponseItem::Reasoning {
id: "parent-reasoning".to_string(),
id: Some("parent-reasoning".to_string()),
summary: Vec::new(),
content: None,
encrypted_content: None,
+4
View File
@@ -23,6 +23,7 @@ fn prompt_with_image_outputs() -> Prompt {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "function-call".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -33,6 +34,7 @@ fn prompt_with_image_outputs() -> Prompt {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "custom-call".to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
@@ -69,6 +71,7 @@ fn responses_lite_request_copies_strip_image_details() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "function-call".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -79,6 +82,7 @@ fn responses_lite_request_copies_strip_image_details() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "custom-call".to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
+5
View File
@@ -403,20 +403,24 @@ pub(crate) fn trim_function_call_history_to_fit_context_window(
fn rewritten_output_for_context_window(item: &ResponseItem) -> Option<ResponseItem> {
Some(match item {
ResponseItem::FunctionCallOutput {
id,
call_id,
output,
metadata,
} => ResponseItem::FunctionCallOutput {
id: id.clone(),
call_id: call_id.clone(),
output: truncated_output_payload(output),
metadata: metadata.clone(),
},
ResponseItem::CustomToolCallOutput {
id,
call_id,
name,
output,
metadata,
} => ResponseItem::CustomToolCallOutput {
id: id.clone(),
call_id: call_id.clone(),
name: name.clone(),
output: truncated_output_payload(output),
@@ -429,6 +433,7 @@ fn rewritten_output_for_context_window(item: &ResponseItem) -> Option<ResponseIt
metadata,
..
} => ResponseItem::ToolSearchOutput {
id: item.id().map(str::to_string),
call_id: call_id.clone(),
status: status.clone(),
execution: execution.clone(),
+9 -1
View File
@@ -231,7 +231,10 @@ async fn run_remote_compact_task_inner_impl(
)
.await?;
let mut input = prompt_input.clone();
input.push(ResponseItem::CompactionTrigger { metadata: None });
input.push(ResponseItem::CompactionTrigger {
id: None,
metadata: None,
});
let prompt = Prompt {
input,
tools: tool_router.model_visible_specs(),
@@ -609,11 +612,13 @@ mod tests {
metadata: None,
},
ResponseItem::Compaction {
id: None,
encrypted_content: "old".to_string(),
metadata: None,
},
];
let output = ResponseItem::Compaction {
id: None,
encrypted_content: "new".to_string(),
metadata: None,
};
@@ -642,6 +647,7 @@ mod tests {
new.clone(),
];
let output = ResponseItem::Compaction {
id: None,
encrypted_content: "new".to_string(),
metadata: None,
};
@@ -673,6 +679,7 @@ mod tests {
metadata: None,
}];
let output = ResponseItem::Compaction {
id: None,
encrypted_content: "new".to_string(),
metadata: None,
};
@@ -800,6 +807,7 @@ mod tests {
#[tokio::test]
async fn collect_compaction_output_accepts_additional_output_items() {
let compaction = ResponseItem::Compaction {
id: None,
encrypted_content: "encrypted".to_string(),
metadata: None,
};
+2
View File
@@ -654,6 +654,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
#[test]
fn insert_initial_context_before_last_real_user_or_summary_keeps_compaction_last() {
let compacted_history = vec![ResponseItem::Compaction {
id: None,
encrypted_content: "encrypted".to_string(),
metadata: None,
}];
@@ -680,6 +681,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_compaction_last
metadata: None,
},
ResponseItem::Compaction {
id: None,
encrypted_content: "encrypted".to_string(),
metadata: None,
},
@@ -339,20 +339,24 @@ impl ContextManager {
let policy_with_serialization_budget = policy * 1.2;
match item {
ResponseItem::FunctionCallOutput {
id,
call_id,
output,
metadata,
} => ResponseItem::FunctionCallOutput {
id: id.clone(),
call_id: call_id.clone(),
output: truncate_function_output_payload(output, policy_with_serialization_budget),
metadata: metadata.clone(),
},
ResponseItem::CustomToolCallOutput {
id,
call_id,
name,
output,
metadata,
} => ResponseItem::CustomToolCallOutput {
id: id.clone(),
call_id: call_id.clone(),
name: name.clone(),
output: truncate_function_output_payload(output, policy_with_serialization_budget),
@@ -154,6 +154,7 @@ fn reference_context_item() -> TurnContextItem {
fn custom_tool_call_output(call_id: &str, output: &str) -> ResponseItem {
ResponseItem::CustomToolCallOutput {
id: None,
call_id: call_id.to_string(),
name: None,
output: FunctionCallOutputPayload::from_text(output.to_string()),
@@ -163,7 +164,7 @@ fn custom_tool_call_output(call_id: &str, output: &str) -> ResponseItem {
fn reasoning_msg(text: &str) -> ResponseItem {
ResponseItem::Reasoning {
id: String::new(),
id: None,
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "summary".to_string(),
}],
@@ -177,7 +178,7 @@ fn reasoning_msg(text: &str) -> ResponseItem {
fn reasoning_with_encrypted_content(len: usize) -> ResponseItem {
ResponseItem::Reasoning {
id: String::new(),
id: None,
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "summary".to_string(),
}],
@@ -222,7 +223,7 @@ fn filters_non_api_messages() {
items,
vec![
ResponseItem::Reasoning {
id: String::new(),
id: None,
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "summary".to_string(),
}],
@@ -409,6 +410,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputText {
@@ -430,6 +432,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "tool-1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
@@ -476,6 +479,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputText {
@@ -497,6 +501,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "tool-1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
@@ -544,7 +549,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
let history = create_history_with_items(vec![
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
id: Some("ig_123".to_string()),
status: "generating".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
@@ -565,7 +570,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
history.for_prompt(&default_input_modalities()),
vec![
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
id: Some("ig_123".to_string()),
status: "generating".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
@@ -597,7 +602,7 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
metadata: None,
},
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
id: Some("ig_123".to_string()),
status: "completed".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
@@ -618,7 +623,7 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
metadata: None,
},
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
id: Some("ig_123".to_string()),
status: "completed".to_string(),
revised_prompt: Some("lobster".to_string()),
result: String::new(),
@@ -662,6 +667,7 @@ fn remove_first_item_removes_matching_output_for_function_call() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -676,6 +682,7 @@ fn remove_first_item_removes_matching_output_for_function_call() {
fn remove_first_item_removes_matching_call_for_output() {
let items = vec![
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -699,6 +706,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
let items = vec![
user_input_text_msg("hi"),
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::ContentItems(vec![
@@ -721,6 +729,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
vec![
user_input_text_msg("hi"),
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::ContentItems(vec![
@@ -771,6 +780,7 @@ fn remove_first_item_handles_local_shell_pair() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-3".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -998,6 +1008,7 @@ fn remove_first_item_handles_custom_tool_pair() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "tool-1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
@@ -1026,6 +1037,7 @@ fn normalization_retains_local_shell_outputs() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "shell-1".to_string(),
output: FunctionCallOutputPayload::from_text("Total output lines: 1\n\nok".to_string()),
metadata: None,
@@ -1047,6 +1059,7 @@ fn record_items_truncates_function_call_output_content() {
let long_line = "a very long line to trigger truncation\n";
let long_output = long_line.repeat(2_500);
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-100".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::Text(long_output.clone()),
@@ -1086,6 +1099,7 @@ fn record_items_truncates_custom_tool_call_output_content() {
let line = "custom output that is very long\n";
let long_output = line.repeat(2_500);
let item = ResponseItem::CustomToolCallOutput {
id: None,
call_id: "tool-200".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text(long_output.clone()),
@@ -1118,6 +1132,7 @@ fn record_items_respects_custom_token_limit() {
let policy = TruncationPolicy::Tokens(10);
let long_output = "tokenized content repeated many times ".repeat(200);
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-custom-limit".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::Text(long_output),
@@ -1261,6 +1276,7 @@ fn normalize_adds_missing_output_for_function_call() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-x".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -1296,6 +1312,7 @@ fn normalize_adds_missing_output_for_custom_tool_call() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "tool-x".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
@@ -1342,6 +1359,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "shell-1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -1354,6 +1372,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
#[test]
fn normalize_removes_orphan_function_call_output() {
let items = vec![ResponseItem::FunctionCallOutput {
id: None,
call_id: "orphan-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -1369,6 +1388,7 @@ fn normalize_removes_orphan_function_call_output() {
#[test]
fn normalize_removes_orphan_custom_tool_call_output() {
let items = vec![ResponseItem::CustomToolCallOutput {
id: None,
call_id: "orphan-2".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
@@ -1396,6 +1416,7 @@ fn normalize_mixed_inserts_and_removals() {
},
// Orphan output that should be removed
ResponseItem::FunctionCallOutput {
id: None,
call_id: "c2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -1440,6 +1461,7 @@ fn normalize_mixed_inserts_and_removals() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "c1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -1453,6 +1475,7 @@ fn normalize_mixed_inserts_and_removals() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "t1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
@@ -1472,6 +1495,7 @@ fn normalize_mixed_inserts_and_removals() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "s1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -1504,6 +1528,7 @@ fn normalize_adds_missing_output_for_function_call_inserts_output() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-x".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -1538,6 +1563,7 @@ fn normalize_adds_missing_output_for_tool_search_call() {
metadata: None,
},
ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("search-call-x".to_string()),
status: "completed".to_string(),
execution: "client".to_string(),
@@ -1590,6 +1616,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id_panics_in_debug()
#[should_panic]
fn normalize_removes_orphan_function_call_output_panics_in_debug() {
let items = vec![ResponseItem::FunctionCallOutput {
id: None,
call_id: "orphan-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -1603,6 +1630,7 @@ fn normalize_removes_orphan_function_call_output_panics_in_debug() {
#[should_panic]
fn normalize_removes_orphan_custom_tool_call_output_panics_in_debug() {
let items = vec![ResponseItem::CustomToolCallOutput {
id: None,
call_id: "orphan-2".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
@@ -1616,6 +1644,7 @@ fn normalize_removes_orphan_custom_tool_call_output_panics_in_debug() {
#[test]
fn normalize_removes_orphan_client_tool_search_output() {
let items = vec![ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("orphan-search".to_string()),
status: "completed".to_string(),
execution: "client".to_string(),
@@ -1634,6 +1663,7 @@ fn normalize_removes_orphan_client_tool_search_output() {
#[should_panic]
fn normalize_removes_orphan_client_tool_search_output_panics_in_debug() {
let items = vec![ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("orphan-search".to_string()),
status: "completed".to_string(),
execution: "client".to_string(),
@@ -1647,6 +1677,7 @@ fn normalize_removes_orphan_client_tool_search_output_panics_in_debug() {
#[test]
fn normalize_keeps_server_tool_search_output_without_matching_call() {
let items = vec![ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("server-search".to_string()),
status: "completed".to_string(),
execution: "server".to_string(),
@@ -1660,6 +1691,7 @@ fn normalize_keeps_server_tool_search_output_without_matching_call() {
assert_eq!(
h.raw_items(),
vec![ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("server-search".to_string()),
status: "completed".to_string(),
execution: "server".to_string(),
@@ -1683,6 +1715,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "c2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -1757,6 +1790,7 @@ fn image_data_url_payload_does_not_dominate_function_call_output_estimate() {
let payload = "B".repeat(50_000);
let image_url = format!("data:image/png;base64,{payload}");
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-abc".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputText {
@@ -1783,6 +1817,7 @@ fn image_data_url_payload_does_not_dominate_custom_tool_call_output_estimate() {
let payload = "C".repeat(50_000);
let image_url = format!("data:image/png;base64,{payload}");
let item = ResponseItem::CustomToolCallOutput {
id: None,
call_id: "call-js-repl".to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
@@ -1818,6 +1853,7 @@ fn non_base64_image_urls_are_unchanged() {
metadata: None,
};
let function_output_item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -1842,6 +1878,7 @@ fn non_base64_image_urls_are_unchanged() {
fn encrypted_function_output_uses_plaintext_byte_estimate() {
let encrypted_content = "A".repeat(1_868);
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-encrypted".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::EncryptedContent {
@@ -1883,6 +1920,7 @@ fn non_image_base64_data_url_is_unchanged() {
let payload = "C".repeat(4_096);
let image_url = format!("data:application/octet-stream;base64,{payload}");
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-octet".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -1971,6 +2009,7 @@ fn original_detail_images_scale_with_dimensions() {
let payload = BASE64_STANDARD.encode(bytes.get_ref());
let image_url = format!("data:image/png;base64,{payload}");
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-original".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -2002,6 +2041,7 @@ fn original_detail_images_are_capped_at_max_patch_count() {
let payload = BASE64_STANDARD.encode(bytes.get_ref());
let image_url = format!("data:image/png;base64,{payload}");
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-original-capped".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -2036,6 +2076,7 @@ fn original_detail_webp_images_scale_with_dimensions() {
let payload = BASE64_STANDARD.encode(bytes.get_ref());
let image_url = format!("data:image/webp;base64,{payload}");
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-original-webp".to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -47,6 +47,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
missing_outputs_to_insert.push((
idx,
ResponseItem::FunctionCallOutput {
id: None,
call_id: call_id.clone(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
@@ -61,6 +62,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
missing_outputs_to_insert.push((
idx,
ResponseItem::ToolSearchOutput {
id: None,
call_id: Some(call_id.clone()),
status: "completed".to_string(),
execution: "client".to_string(),
@@ -78,6 +80,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
missing_outputs_to_insert.push((
idx,
ResponseItem::CustomToolCallOutput {
id: None,
call_id: call_id.clone(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
@@ -96,6 +99,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
missing_outputs_to_insert.push((
idx,
ResponseItem::FunctionCallOutput {
id: None,
call_id: call_id.clone(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
+2 -2
View File
@@ -178,7 +178,7 @@ pub fn parse_turn_item(item: &ResponseItem) -> Option<TurnItem> {
})
.collect();
Some(TurnItem::Reasoning(ReasoningItem {
id: id.clone(),
id: id.clone().unwrap_or_default(),
summary_text,
raw_content,
}))
@@ -202,7 +202,7 @@ pub fn parse_turn_item(item: &ResponseItem) -> Option<TurnItem> {
..
} => Some(TurnItem::ImageGeneration(
codex_protocol::items::ImageGenerationItem {
id: id.clone(),
id: id.clone()?,
status: status.clone(),
revised_prompt: revised_prompt.clone(),
result: result.clone(),
+2 -2
View File
@@ -391,7 +391,7 @@ fn parses_agent_message() {
#[test]
fn parses_reasoning_summary_and_raw_content() {
let item = ResponseItem::Reasoning {
id: "reasoning_1".to_string(),
id: Some("reasoning_1".to_string()),
summary: vec![
ReasoningItemReasoningSummary::SummaryText {
text: "Step 1".to_string(),
@@ -424,7 +424,7 @@ fn parses_reasoning_summary_and_raw_content() {
#[test]
fn parses_reasoning_including_raw_content() {
let item = ResponseItem::Reasoning {
id: "reasoning_2".to_string(),
id: Some("reasoning_2".to_string()),
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "Summarized step".to_string(),
}],
+2
View File
@@ -309,6 +309,7 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
"repo visibility: public".to_string(),
@@ -827,6 +828,7 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
"repo is public".to_string(),
@@ -106,6 +106,7 @@ fn preparation_replaces_only_failed_tool_images_and_preserves_metadata() {
let (valid_image_url, _) = png_data_url(/*width*/ 64, /*height*/ 32);
let expected_valid_image_url = valid_image_url.clone();
let mut items = vec![ResponseItem::CustomToolCallOutput {
id: None,
call_id: "call-1".to_string(),
name: None,
output: FunctionCallOutputPayload {
@@ -140,6 +141,7 @@ fn preparation_replaces_only_failed_tool_images_and_preserves_metadata() {
assert_eq!(
items,
vec![ResponseItem::CustomToolCallOutput {
id: None,
call_id: "call-1".to_string(),
name: None,
output: FunctionCallOutputPayload {
+5 -3
View File
@@ -1664,6 +1664,7 @@ async fn resize_all_images_prepares_failures_before_history_insertion() {
)
.await;
let item = ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::ContentItems(vec![
@@ -1689,6 +1690,7 @@ async fn resize_all_images_prepares_failures_before_history_insertion() {
.await;
let expected = vec![ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload {
body: FunctionCallOutputBody::ContentItems(vec![
@@ -7720,7 +7722,7 @@ async fn build_initial_context_omits_default_image_save_location_with_image_hist
session
.replace_history(
vec![ResponseItem::ImageGenerationCall {
id: "ig-test".to_string(),
id: Some("ig-test".to_string()),
status: "completed".to_string(),
revised_prompt: Some("a tiny blue square".to_string()),
result: "Zm9v".to_string(),
@@ -7973,7 +7975,7 @@ async fn handle_output_item_done_records_image_save_history_message() {
);
let _ = std::fs::remove_file(&expected_saved_path);
let item = ResponseItem::ImageGenerationCall {
id: call_id.to_string(),
id: Some(call_id.to_string()),
status: "completed".to_string(),
revised_prompt: Some("a tiny blue square".to_string()),
result: "Zm9v".to_string(),
@@ -8030,7 +8032,7 @@ async fn handle_output_item_done_skips_image_save_message_when_save_fails() {
);
let _ = std::fs::remove_file(&expected_saved_path);
let item = ResponseItem::ImageGenerationCall {
id: call_id.to_string(),
id: Some(call_id.to_string()),
status: "completed".to_string(),
revised_prompt: Some("broken payload".to_string()),
result: "_-8".to_string(),
+4
View File
@@ -624,6 +624,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
match input {
ResponseInputItem::FunctionCallOutput { call_id, output } => {
Some(ResponseItem::FunctionCallOutput {
id: None,
call_id: call_id.clone(),
output: output.clone(),
metadata: None,
@@ -634,6 +635,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
name,
output,
} => Some(ResponseItem::CustomToolCallOutput {
id: None,
call_id: call_id.clone(),
name: name.clone(),
output: output.clone(),
@@ -642,6 +644,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
ResponseInputItem::McpToolCallOutput { call_id, output } => {
let output = output.as_function_call_output_payload();
Some(ResponseItem::FunctionCallOutput {
id: None,
call_id: call_id.clone(),
output,
metadata: None,
@@ -653,6 +656,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
execution,
tools,
} => Some(ResponseItem::ToolSearchOutput {
id: None,
call_id: Some(call_id.clone()),
status: status.clone(),
execution: execution.clone(),
@@ -64,6 +64,7 @@ fn external_context_pollution_items_include_web_search_and_tool_search() {
metadata: None,
},
ResponseItem::ToolSearchOutput {
id: None,
call_id: Some("search-1".to_string()),
status: "completed".to_string(),
execution: "client".to_string(),
@@ -104,6 +105,7 @@ fn external_context_pollution_items_exclude_local_tool_calls() {
metadata: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
@@ -117,6 +119,7 @@ fn external_context_pollution_items_exclude_local_tool_calls() {
metadata: None,
},
ResponseItem::CustomToolCallOutput {
id: None,
call_id: "custom-1".to_string(),
name: Some("apply_patch".to_string()),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
@@ -418,7 +421,7 @@ fn completed_item_keeps_mailbox_delivery_open_for_commentary_messages() {
#[test]
fn completed_item_defers_mailbox_delivery_for_image_generation_calls() {
let item = ResponseItem::ImageGenerationCall {
id: "ig-1".to_string(),
id: Some("ig-1".to_string()),
status: "completed".to_string(),
revised_prompt: None,
result: "Zm9v".to_string(),
+1 -1
View File
@@ -76,7 +76,7 @@ fn truncates_before_requested_user_message() {
user_msg("u2"),
assistant_msg("a3"),
ResponseItem::Reasoning {
id: "r1".to_string(),
id: Some("r1".to_string()),
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "s".to_string(),
}],
@@ -73,7 +73,7 @@ fn truncates_rollout_from_start_before_nth_user_only() {
user_msg("u2"),
assistant_msg("a3"),
ResponseItem::Reasoning {
id: "r1".to_string(),
id: Some("r1".to_string()),
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "s".to_string(),
}],
@@ -299,6 +299,7 @@ impl CoreTurnHost {
self.exec
.session
.inject_if_running(vec![ResponseItem::CustomToolCallOutput {
id: None,
call_id,
name: Some(PUBLIC_TOOL_NAME.to_string()),
output: FunctionCallOutputPayload::from_text(text),
+1
View File
@@ -149,6 +149,7 @@ fn response_item_records_turn_ttft_ignores_empty_non_output_items() {
}));
assert!(!response_item_records_turn_ttft(
&ResponseItem::FunctionCallOutput {
id: None,
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
+6 -1
View File
@@ -611,6 +611,7 @@ async fn resume_replays_legacy_js_repl_image_rollout_shapes() {
RolloutLine {
timestamp: "2024-01-01T00:00:02.000Z".to_string(),
item: RolloutItem::ResponseItem(ResponseItem::CustomToolCallOutput {
id: None,
call_id: "legacy-js-call".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("legacy js_repl stdout".to_string()),
@@ -751,6 +752,7 @@ async fn resume_replays_image_tool_outputs_with_detail() {
RolloutLine {
timestamp: "2024-01-01T00:00:01.500Z".to_string(),
item: RolloutItem::ResponseItem(ResponseItem::FunctionCallOutput {
id: None,
call_id: function_call_id.to_string(),
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
@@ -775,6 +777,7 @@ async fn resume_replays_image_tool_outputs_with_detail() {
RolloutLine {
timestamp: "2024-01-01T00:00:02.500Z".to_string(),
item: RolloutItem::ResponseItem(ResponseItem::CustomToolCallOutput {
id: None,
call_id: custom_call_id.to_string(),
name: None,
output: FunctionCallOutputPayload::from_content_items(vec![
@@ -2518,7 +2521,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
let mut prompt = Prompt::default();
prompt.input.push(ResponseItem::Reasoning {
id: "reasoning-id".into(),
id: Some("reasoning-id".into()),
summary: vec![ReasoningItemReasoningSummary::SummaryText {
text: "summary".into(),
}],
@@ -2555,6 +2558,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
metadata: None,
});
prompt.input.push(ResponseItem::FunctionCallOutput {
id: None,
call_id: "function-call-id".into(),
output: FunctionCallOutputPayload::from_text("ok".into()),
metadata: None,
@@ -2581,6 +2585,7 @@ async fn azure_responses_request_includes_store_and_reasoning_ids() {
metadata: None,
});
prompt.input.push(ResponseItem::CustomToolCallOutput {
id: None,
call_id: "custom-tool-call-id".into(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".into()),
+3
View File
@@ -1995,6 +1995,7 @@ async fn auto_compact_runs_after_resume_when_token_usage_is_over_limit() {
metadata: None,
},
codex_protocol::models::ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -3994,6 +3995,7 @@ async fn auto_compact_counts_encrypted_reasoning_before_last_user() {
metadata: None,
},
codex_protocol::models::ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -4121,6 +4123,7 @@ async fn auto_compact_runs_when_reasoning_header_clears_between_turns() {
metadata: None,
},
codex_protocol::models::ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -157,6 +157,7 @@ fn format_labeled_requests_snapshot(
fn compacted_summary_only_output(summary: &str) -> Vec<ResponseItem> {
vec![ResponseItem::Compaction {
id: None,
encrypted_content: summary_with_prefix(summary),
metadata: None,
}]
@@ -329,6 +330,7 @@ async fn remote_compact_replaces_history_for_followups() -> Result<()> {
.await;
let compacted_history = vec![ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
}];
@@ -2356,6 +2358,7 @@ async fn remote_compact_persists_replacement_history_in_rollout() -> Result<()>
let compacted_history = vec![
ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -2511,6 +2514,7 @@ async fn remote_compact_and_resume_refresh_stale_developer_instructions() -> Res
metadata: None,
},
ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -2653,6 +2657,7 @@ async fn remote_compact_refreshes_stale_developer_instructions_without_resume()
metadata: None,
},
ResponseItem::Compaction {
id: None,
encrypted_content: "ENCRYPTED_COMPACTION_SUMMARY".to_string(),
metadata: None,
},
@@ -4059,6 +4064,7 @@ async fn snapshot_request_shape_remote_mid_turn_compaction_summary_only_reinject
.await;
let compacted_history = vec![ResponseItem::Compaction {
id: None,
encrypted_content: summary_with_prefix("REMOTE_SUMMARY_ONLY"),
metadata: None,
}];