feat: return an error if the image sent by the user is a bad image (#9146)

## Before
When we detect an `InvalidImageRequest`, we replace the image by a
placeholder and keep going

## Now
In such `InvalidImageRequest`, we check if the image is due to a user
message or a tool call output. For tool call output we still replace it
with a placeholder to avoid breaking the agentic loop bu tif this is
because of a user message, we send an error to the user
This commit is contained in:
jif-oai
2026-01-14 09:07:45 +00:00
committed by GitHub
parent 6fbb89e858
commit dc3deaa3e7
3 changed files with 81 additions and 18 deletions

View File

@@ -2629,9 +2629,18 @@ pub(crate) async fn run_turn(
Err(CodexErr::InvalidImageRequest()) => {
let mut state = sess.state.lock().await;
error_or_panic(
"Invalid image detected, replacing it in the last turn to prevent poisoning",
"Invalid image detected; sanitizing tool output to prevent poisoning",
);
state.history.replace_last_turn_images("Invalid image");
if state.history.replace_last_turn_images("Invalid image") {
continue;
}
let event = EventMsg::Error(ErrorEvent {
message: "Invalid image in your last message. Please remove it and try again."
.to_string(),
codex_error_info: Some(CodexErrorInfo::BadRequest),
});
sess.send_event(&turn_context, event).await;
break;
}
Err(e) => {
info!("Turn error: {e:#}");