mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Replace invalid MCP image blocks with text fallback for non-multimodal models
This commit is contained in:
@@ -3921,7 +3921,9 @@ pub(crate) async fn run_turn(
|
||||
error_or_panic(
|
||||
"Invalid image detected; sanitizing tool output to prevent poisoning",
|
||||
);
|
||||
if state.history.replace_last_turn_images("Invalid image") {
|
||||
if state.history.replace_last_turn_images(
|
||||
"[there was an image here but it was removed for non-multimodal models]",
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let event = EventMsg::Error(ErrorEvent {
|
||||
|
||||
@@ -354,7 +354,9 @@ fn replace_last_turn_images_replaces_tool_output_images() {
|
||||
];
|
||||
let mut history = create_history_with_items(items);
|
||||
|
||||
assert!(history.replace_last_turn_images("Invalid image"));
|
||||
assert!(history.replace_last_turn_images(
|
||||
"[there was an image here but it was removed for non-multimodal models]"
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
history.raw_items(),
|
||||
@@ -365,7 +367,9 @@ fn replace_last_turn_images_replaces_tool_output_images() {
|
||||
output: FunctionCallOutputPayload {
|
||||
body: FunctionCallOutputBody::ContentItems(vec![
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "Invalid image".to_string(),
|
||||
text:
|
||||
"[there was an image here but it was removed for non-multimodal models]"
|
||||
.to_string(),
|
||||
},
|
||||
]),
|
||||
success: Some(true),
|
||||
@@ -388,7 +392,9 @@ fn replace_last_turn_images_does_not_touch_user_images() {
|
||||
}];
|
||||
let mut history = create_history_with_items(items.clone());
|
||||
|
||||
assert!(!history.replace_last_turn_images("Invalid image"));
|
||||
assert!(!history.replace_last_turn_images(
|
||||
"[there was an image here but it was removed for non-multimodal models]"
|
||||
));
|
||||
assert_eq!(history.raw_items(), items);
|
||||
}
|
||||
|
||||
|
||||
@@ -597,7 +597,9 @@ async fn replaces_invalid_local_image_after_bad_request() -> anyhow::Result<()>
|
||||
"second request should replace the invalid image"
|
||||
);
|
||||
let user_texts = second_request.message_input_texts("user");
|
||||
assert!(user_texts.iter().any(|text| text == "Invalid image"));
|
||||
assert!(user_texts.iter().any(|text| {
|
||||
text == "[there was an image here but it was removed for non-multimodal models]"
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user