Feat/restore image generation history (#15223)

Restore image generation items in resumed thread history
This commit is contained in:
Won Park
2026-03-19 22:57:16 -07:00
committed by GitHub
Unverified
parent b3a4da84da
commit 461ba012fc
26 changed files with 213 additions and 10 deletions
+6 -1
View File
@@ -3751,7 +3751,12 @@ async fn handle_output_item_done_records_image_save_history_message() {
image_output_path.display(),
))
.into();
assert_eq!(history.raw_items(), &[save_message, item]);
let copy_message: ResponseItem = DeveloperInstructions::new(
"If you need to use a generated image at another path, copy it and leave the original in place unless the user explicitly asks you to delete it."
.to_string(),
)
.into();
assert_eq!(history.raw_items(), &[save_message, copy_message, item]);
assert_eq!(
std::fs::read(&expected_saved_path).expect("saved file"),
b"foo"
+26 -2
View File
@@ -105,7 +105,8 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
| EventMsg::UndoCompleted(_)
| EventMsg::TurnAborted(_)
| EventMsg::TurnStarted(_)
| EventMsg::TurnComplete(_) => Some(EventPersistenceMode::Limited),
| EventMsg::TurnComplete(_)
| EventMsg::ImageGenerationEnd(_) => Some(EventPersistenceMode::Limited),
EventMsg::ItemCompleted(event) => {
// Plan items are derived from streaming tags and are not part of the
// raw ResponseItem history, so we persist their completion to replay
@@ -123,7 +124,6 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
| EventMsg::PatchApplyEnd(_)
| EventMsg::McpToolCallEnd(_)
| EventMsg::ViewImageToolCall(_)
| EventMsg::ImageGenerationEnd(_)
| EventMsg::CollabAgentSpawnEnd(_)
| EventMsg::CollabAgentInteractionEnd(_)
| EventMsg::CollabWaitingEnd(_)
@@ -183,3 +183,27 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
| EventMsg::ImageGenerationBegin(_) => None,
}
}
#[cfg(test)]
mod tests {
use super::EventPersistenceMode;
use super::should_persist_event_msg;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::ImageGenerationEndEvent;
#[test]
fn persists_image_generation_end_events_in_limited_mode() {
let event = EventMsg::ImageGenerationEnd(ImageGenerationEndEvent {
call_id: "ig_123".into(),
status: "completed".into(),
revised_prompt: Some("final prompt".into()),
result: "Zm9v".into(),
saved_path: None,
});
assert!(should_persist_event_msg(
&event,
EventPersistenceMode::Limited
));
}
}
+6 -4
View File
@@ -372,11 +372,13 @@ pub(crate) async fn handle_non_tool_response_item(
image_output_path.display(),
))
.into();
sess.record_conversation_items(
turn_context,
std::slice::from_ref(&message),
let copy_message: ResponseItem = DeveloperInstructions::new(
"If you need to use a generated image at another path, copy it and leave the original in place unless the user explicitly asks you to delete it."
.to_string(),
)
.await;
.into();
sess.record_conversation_items(turn_context, &[message, copy_message])
.await;
}
Err(err) => {
let output_path = image_generation_artifact_path(