From 7a7084857d1ef3444d4b088f410cfc7bb4b94d72 Mon Sep 17 00:00:00 2001 From: Kunyao Liu Date: Tue, 7 Jul 2026 15:16:48 -0700 Subject: [PATCH 1/2] fix(imagegen): avoid duplicate markdown image links --- .../core/src/context/image_generation_instructions.rs | 2 +- codex-rs/ext/image-generation/src/tests.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/context/image_generation_instructions.rs b/codex-rs/core/src/context/image_generation_instructions.rs index 6986a7c64f25..aa0872e0394a 100644 --- a/codex-rs/core/src/context/image_generation_instructions.rs +++ b/codex-rs/core/src/context/image_generation_instructions.rs @@ -18,7 +18,7 @@ fn image_generation_hint( image_output_path: impl Display, ) -> String { format!( - "Generated images are saved to {image_output_dir} as {image_output_path} by default.\nIf 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." + "Generated images are saved to {image_output_dir} as {image_output_path} by default.\nThe generated image is already displayed to the user. Do not embed or link it, or an unchanged copy of it, in Markdown.\nIf you need to use the generated image at another path for further work, copy it and leave the original in place unless the user explicitly asks you to delete it." ) } diff --git a/codex-rs/ext/image-generation/src/tests.rs b/codex-rs/ext/image-generation/src/tests.rs index 1ec9371214a4..a0e5df3c20ed 100644 --- a/codex-rs/ext/image-generation/src/tests.rs +++ b/codex-rs/ext/image-generation/src/tests.rs @@ -224,9 +224,12 @@ async fn recent_image_fallback_requires_requested_count() { fn generated_output_returns_image_input_and_output_hint() { let output_hint = extension_image_generation_output_hint("/tmp", "/tmp/call-1.png").expect("hint should fit"); + let expected_output_hint = "Generated images are saved to /tmp as /tmp/call-1.png by default. +The generated image is already displayed to the user. Do not embed or link it, or an unchanged copy of it, in Markdown. +If you need to use the generated image at another path for further work, copy it and leave the original in place unless the user explicitly asks you to delete it."; let output = GeneratedImageOutput { result: RESULT.to_string(), - output_hint: Some(output_hint.clone()), + output_hint: Some(output_hint), }; let ResponseInputItem::FunctionCallOutput { @@ -246,7 +249,9 @@ fn generated_output_returns_image_input_and_output_hint() { image_url: format!("data:image/png;base64,{RESULT}"), detail: Some(DEFAULT_IMAGE_DETAIL), }, - FunctionCallOutputContentItem::InputText { text: output_hint }, + FunctionCallOutputContentItem::InputText { + text: expected_output_hint.to_string(), + }, ] ); } From cebe14fa2f7feefc98417889e9a815255a447d41 Mon Sep 17 00:00:00 2001 From: Kunyao Liu Date: Tue, 7 Jul 2026 16:13:01 -0700 Subject: [PATCH 2/2] fix(imagegen): scope render-once hint --- .../src/context/image_generation_instructions.rs | 2 +- codex-rs/core/tests/suite/model_switching.rs | 14 ++++++++++---- codex-rs/ext/image-generation/src/tests.rs | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/context/image_generation_instructions.rs b/codex-rs/core/src/context/image_generation_instructions.rs index aa0872e0394a..b0c274f00f22 100644 --- a/codex-rs/core/src/context/image_generation_instructions.rs +++ b/codex-rs/core/src/context/image_generation_instructions.rs @@ -18,7 +18,7 @@ fn image_generation_hint( image_output_path: impl Display, ) -> String { format!( - "Generated images are saved to {image_output_dir} as {image_output_path} by default.\nThe generated image is already displayed to the user. Do not embed or link it, or an unchanged copy of it, in Markdown.\nIf you need to use the generated image at another path for further work, copy it and leave the original in place unless the user explicitly asks you to delete it." + "Generated images are saved to {image_output_dir} as {image_output_path} by default.\nAlready displayed; do not repeat it or an unchanged copy in final Markdown unless asked.\nFor another path, copy it and keep the original unless asked to delete it." ) } diff --git a/codex-rs/core/tests/suite/model_switching.rs b/codex-rs/core/tests/suite/model_switching.rs index 9ef3675b3ed2..b53ee1cba7ae 100644 --- a/codex-rs/core/tests/suite/model_switching.rs +++ b/codex-rs/core/tests/suite/model_switching.rs @@ -703,8 +703,11 @@ async fn generated_image_is_replayed_for_image_capable_models() -> Result<()> { second_request .message_input_texts("developer") .iter() - .any(|text| text.contains("Generated images are saved to")), - "second request should include the saved-path note in model-visible history" + .any(|text| { + text.contains("Generated images are saved to") + && text.contains("do not repeat it or an unchanged copy") + }), + "second request should include the saved-path and render-once note in model-visible history" ); let _ = std::fs::remove_file(&saved_path); @@ -827,8 +830,11 @@ async fn model_change_from_generated_image_to_text_preserves_prior_generated_ima second_request .message_input_texts("developer") .iter() - .any(|text| text.contains("Generated images are saved to")), - "second request should include the saved-path note in model-visible history" + .any(|text| { + text.contains("Generated images are saved to") + && text.contains("do not repeat it or an unchanged copy") + }), + "second request should include the saved-path and render-once note in model-visible history" ); let _ = std::fs::remove_file(&saved_path); diff --git a/codex-rs/ext/image-generation/src/tests.rs b/codex-rs/ext/image-generation/src/tests.rs index a0e5df3c20ed..a607ef6314f4 100644 --- a/codex-rs/ext/image-generation/src/tests.rs +++ b/codex-rs/ext/image-generation/src/tests.rs @@ -225,8 +225,8 @@ fn generated_output_returns_image_input_and_output_hint() { let output_hint = extension_image_generation_output_hint("/tmp", "/tmp/call-1.png").expect("hint should fit"); let expected_output_hint = "Generated images are saved to /tmp as /tmp/call-1.png by default. -The generated image is already displayed to the user. Do not embed or link it, or an unchanged copy of it, in Markdown. -If you need to use the generated image at another path for further work, copy it and leave the original in place unless the user explicitly asks you to delete it."; +Already displayed; do not repeat it or an unchanged copy in final Markdown unless asked. +For another path, copy it and keep the original unless asked to delete it."; let output = GeneratedImageOutput { result: RESULT.to_string(), output_hint: Some(output_hint),