mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Preserve content kinds during image preparation (#40281)
## Why Image preparation can rewrite message content, including replacing images that cannot be processed with model-visible error text. The positional content-kind metadata must stay aligned with those rewrites. ## What changed - Process message images together with their content-kind annotations. - Preserve existing kinds for unchanged and resized content. - Classify failed-image placeholders as `images.preparation_error`. ## Testing - Cover metadata preservation across successful, resized, and failed images. - Verify Responses Lite sends `user.image` and `images.preparation_error` kinds. GitOrigin-RevId: 1be7bcbe47014251019bfff0d826c9dfe3239dec
This commit is contained in:
@@ -19,6 +19,7 @@ use codex_protocol::protocol::SessionMeta;
|
||||
use codex_protocol::protocol::SessionMetaLine;
|
||||
use codex_protocol::protocol::WorldStateItem;
|
||||
use codex_protocol::security_risk::SecurityRiskScore;
|
||||
use core_test_support::responses::strip_metadata_from_items;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -171,7 +172,9 @@ async fn record_initial_history_ignores_security_risk_scores() {
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
raw_history_items(&session.state.lock().await.clone_history()),
|
||||
strip_metadata_from_items(&raw_history_items(
|
||||
&session.state.lock().await.clone_history()
|
||||
)),
|
||||
vec![user_item]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,10 @@ fn user_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
internal_chat_message_metadata_passthrough: Some(InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![ContentItemKind("unknown".to_string())]),
|
||||
..Default::default()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +325,10 @@ fn assistant_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
internal_chat_message_metadata_passthrough: Some(InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![ContentItemKind("unknown".to_string())]),
|
||||
..Default::default()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2504,7 +2510,16 @@ async fn prepares_resumed_history_before_installing_it() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
internal_chat_message_metadata_passthrough: Some(
|
||||
InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![
|
||||
ContentItemKind("images.preparation_error".to_string()),
|
||||
ContentItemKind("images.preparation_error".to_string()),
|
||||
ContentItemKind("unknown".to_string()),
|
||||
]),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
}]
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -11184,30 +11199,14 @@ async fn sample_rollout(
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
);
|
||||
|
||||
let user1 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "first user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let user1 = user_message("first user");
|
||||
live_history.record_items(
|
||||
std::iter::once(&user1),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user1.clone().into()));
|
||||
|
||||
let assistant1 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
content: vec![ContentItem::OutputText {
|
||||
text: "assistant reply one".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let assistant1 = assistant_message("assistant reply one");
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant1),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
@@ -11230,30 +11229,14 @@ async fn sample_rollout(
|
||||
window_id: Some(window_ids.window_id.to_string()),
|
||||
}));
|
||||
|
||||
let user2 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "second user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let user2 = user_message("second user");
|
||||
live_history.record_items(
|
||||
std::iter::once(&user2),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user2.clone().into()));
|
||||
|
||||
let assistant2 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
content: vec![ContentItem::OutputText {
|
||||
text: "assistant reply two".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let assistant2 = assistant_message("assistant reply two");
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant2),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
@@ -11276,30 +11259,14 @@ async fn sample_rollout(
|
||||
window_id: Some(window_ids.window_id.to_string()),
|
||||
}));
|
||||
|
||||
let user3 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "third user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let user3 = user_message("third user");
|
||||
live_history.record_items(
|
||||
std::iter::once(&user3),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user3.into()));
|
||||
|
||||
let assistant3 = ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
content: vec![ContentItem::OutputText {
|
||||
text: "assistant reply three".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
};
|
||||
let assistant3 = assistant_message("assistant reply three");
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant3),
|
||||
reconstruction_turn.model_info.truncation_policy.into(),
|
||||
|
||||
Reference in New Issue
Block a user