{"record":{"id":"37b9505fe15d3b13","repo":"openai/codex","slug":"generated-image-destination-already-exists","errorCode":null,"errorMessage":"generated image destination already exists","messagePattern":"generated image destination already exists","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"warning","filePath":"codex-rs/ext/image-generation/src/tool.rs","lineNumber":361,"sourceCode":"                        .get_metadata(&parent_uri, Default::default(), sandbox)\n                        .await?;\n                    if metadata.is_symlink || !metadata.is_directory {\n                        return Err(io::Error::new(\n                            io::ErrorKind::PermissionDenied,\n                            \"generated image directory is not a real directory\",\n                        ));\n                    }\n                }\n\n                // Existing destination hardlinks could otherwise overwrite files outside the workspace.\n                let path_uri = PathUri::from_abs_path(&path);\n                match environment\n                    .file_system\n                    .get_metadata(&path_uri, Default::default(), sandbox)\n                    .await\n                {\n                    Ok(_) => {\n                        return Err(io::Error::new(\n                            io::ErrorKind::AlreadyExists,\n                            \"generated image destination already exists\",\n                        ));\n                    }\n                    Err(error) if error.kind() == io::ErrorKind::NotFound => {}\n                    Err(error) => return Err(error),\n                }\n\n                environment\n                    .file_system\n                    .write_file(&path_uri, bytes, Default::default(), sandbox)\n                    .await?;\n                Ok(path)\n            }\n            .await;\n            (output_dir, save_result)\n        }\n    };","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/ext/image-generation/src/tool.rs#L343-L379","documentation":"Immediately before writing, save_image_generation_result stats the destination (derived from session_id and call_id): any successful stat returns AlreadyExists. Only NotFound proceeds — an existing destination (e.g. a hardlink) could otherwise overwrite files outside the workspace, so overwriting is never attempted.","triggerScenarios":"The same image tool call is retried or replayed with the same session_id and call_id, or a file already exists at generated_images/<artifact-name>.","commonSituations":"Client retry of a timed-out tool call reusing the call id; two executions sharing a session id; leftover artifacts from a previous run.","solutions":["Generate a fresh call_id when retrying the image tool call.","Delete the stale artifact named in the warning if the run is genuinely new.","Treat as informational: the model still receives the generated image; only persistence is skipped."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before replaying a tool call, ensure the artifact name is free\nif artifact_path.exists() {\n    std::fs::remove_file(&artifact_path)?; // or mint a fresh call_id\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mint a new call_id on every retry so destination names never collide.","Clean generated_images between unrelated runs in shared workspaces.","Treat AlreadyExists on replay as benign — persistence is skipped, the result is unaffected."],"tags":["rust","image-generation","file-exists","executor","codex"],"backgroundTag":"file-already-exists","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}