diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index bac87686a6..937d06047c 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -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 { diff --git a/codex-rs/core/src/context_manager/history_tests.rs b/codex-rs/core/src/context_manager/history_tests.rs index 87defcd1d6..2a39a5bfed 100644 --- a/codex-rs/core/src/context_manager/history_tests.rs +++ b/codex-rs/core/src/context_manager/history_tests.rs @@ -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); } diff --git a/codex-rs/core/tests/suite/view_image.rs b/codex-rs/core/tests/suite/view_image.rs index b72f66fce8..0c3121c1cc 100644 --- a/codex-rs/core/tests/suite/view_image.rs +++ b/codex-rs/core/tests/suite/view_image.rs @@ -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(()) }