Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Record local image inputs on completed image-generation items (#54420)

Matt Kaufer592964c0cb4d
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock
index 23e5f20b74..e31c88515d 100644
--- a/codex-rs/Cargo.lock
+++ b/codex-rs/Cargo.lock
@@ -3775,10 +3775,13 @@ dependencies = [
"codex-utils-image",
"codex-utils-path-uri",
"http 1.4.0",
+ "image",
"pretty_assertions",
"schemars 0.8.22",
"serde",
"serde_json",
+ "sha2 0.10.9",
+ "tempfile",
"tokio",
"tracing",
]
diff --git a/codex-rs/analytics/src/tests/suite/tools_tests.rs b/codex-rs/analytics/src/tests/suite/tools_tests.rs
index f43d0c88ba..6272b8458f 100644
--- a/codex-rs/analytics/src/tests/suite/tools_tests.rs
+++ b/codex-rs/analytics/src/tests/suite/tools_tests.rs
@@ -882,6 +882,7 @@ async fn image_generation_events_preserve_transparent_background_metadata() {
transparent_background,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
});
diff --git a/codex-rs/analytics/src/tests/suite/turns/events_tests.rs b/codex-rs/analytics/src/tests/suite/turns/events_tests.rs
index bfcf6c7b32..959dfe72c4 100644
--- a/codex-rs/analytics/src/tests/suite/turns/events_tests.rs
+++ b/codex-rs/analytics/src/tests/suite/turns/events_tests.rs
@@ -557,6 +557,7 @@ async fn turn_event_counts_completed_tool_items() {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: Some("req-imagegen-123".to_string()),
generation_id: Some("gen-image-123".to_string()),
}),
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json
index 1bda7da8a6..122d6dc781 100644
--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json
@@ -2591,6 +2591,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"ItemCompletedNotification": {
"properties": {
"completedAtMs": {
@@ -5406,6 +5423,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
index 37dfc25506..16358792de 100644
--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json
@@ -13807,6 +13807,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/v2/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"InAppBrowserRequirements": {
"properties": {
"allowExternalBrowserSettingsImport": {
@@ -22882,6 +22899,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/v2/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
index be25aa9d0a..b2cadebfd1 100644
--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json
@@ -9734,6 +9734,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"InAppBrowserRequirements": {
"properties": {
"allowExternalBrowserSettingsImport": {
@@ -20596,6 +20613,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json
index 0daf5a7733..f822591d7d 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json
@@ -507,6 +507,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1565,6 +1582,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json
index b9dda6f5f5..d766bf8d55 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json
@@ -507,6 +507,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1565,6 +1582,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json
index 6675cce9d1..eac1c0ab70 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json
@@ -655,6 +655,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1768,6 +1785,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
index a754510467..2b728204ba 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json
@@ -759,6 +759,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2382,6 +2399,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadItemsListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadItemsListResponse.json
index c6c0b0987e..41a14aa338 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadItemsListResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadItemsListResponse.json
@@ -507,6 +507,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1565,6 +1582,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json
index e297f3a3cf..8f1b2483c7 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json
index 19e039653c..e01baa846e 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json
index cb116237c8..a81e27a536 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
index 6886c4dee2..4f4d578780 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json
@@ -775,6 +775,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2434,6 +2451,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadRevertResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadRevertResponse.json
index e2b4e9b859..56cf784b34 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadRevertResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadRevertResponse.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
index 26c772ce40..9597b7a900 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json
@@ -759,6 +759,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2382,6 +2399,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json
index d1453d23f9..d1f288b3e4 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadTurnsListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadTurnsListResponse.json
index 03167f2455..fdf532baf3 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadTurnsListResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadTurnsListResponse.json
@@ -655,6 +655,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1768,6 +1785,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json
index 3f287eea16..c4ba9a866d 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json
@@ -681,6 +681,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -2173,6 +2190,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json
index ac2f9e2a8e..e718e1fa97 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json
@@ -655,6 +655,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1768,6 +1785,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json
index 3919455d5a..3c47c0d872 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json
@@ -655,6 +655,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1768,6 +1785,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json
index c85c9ff41b..e395230a4b 100644
--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json
+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json
@@ -655,6 +655,23 @@
}
]
},
+ "ImageGenerationInputImage": {
+ "description": "A local image file successfully read for this exact image-generation request.",
+ "properties": {
+ "path": {
+ "$ref": "#/definitions/AbsolutePathBuf"
+ },
+ "sha256": {
+ "description": "Lowercase SHA-256 of the file bytes read before image normalization.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "path",
+ "sha256"
+ ],
+ "type": "object"
+ },
"LegacyAppPathString": {
"type": "string"
},
@@ -1768,6 +1785,13 @@
"id": {
"type": "string"
},
+ "inputImages": {
+ "description": "Observed local inputs for a completed generation, absent on older items.",
+ "items": {
+ "$ref": "#/definitions/ImageGenerationInputImage"
+ },
+ "type": "array"
+ },
"revisedPrompt": {
"type": [
"string",
diff --git a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst
index a966e2d0b0..38af43dca9 100644
Binary files a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst and b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst differ
diff --git a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst
index cee1aa5eb7..50a4721a56 100644
Binary files a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst and b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst differ
diff --git a/codex-rs/app-server-protocol/schema/typescript/ImageGenerationInputImage.ts b/codex-rs/app-server-protocol/schema/typescript/ImageGenerationInputImage.ts
new file mode 100644
index 0000000000..fe604dfc27
--- /dev/null
+++ b/codex-rs/app-server-protocol/schema/typescript/ImageGenerationInputImage.ts
@@ -0,0 +1,13 @@
+// GENERATED CODE! DO NOT MODIFY BY HAND!
+
+// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+import type { AbsolutePathBuf } from "./AbsolutePathBuf";
+
+/**
+ * A local image file successfully read for this exact image-generation request.
+ */
+export type ImageGenerationInputImage = { path: AbsolutePathBuf,
+/**
+ * Lowercase SHA-256 of the file bytes read before image normalization.
+ */
+sha256: string, };
diff --git a/codex-rs/app-server-protocol/schema/typescript/ImageGenerationItem.ts b/codex-rs/app-server-protocol/schema/typescript/ImageGenerationItem.ts
index 29783fa9fa..1dfe3aa120 100644
--- a/codex-rs/app-server-protocol/schema/typescript/ImageGenerationItem.ts
+++ b/codex-rs/app-server-protocol/schema/typescript/ImageGenerationItem.ts
@@ -3,5 +3,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AbsolutePathBuf } from "./AbsolutePathBuf";
import type { ImageGenerationFailure } from "./ImageGenerationFailure";
+import type { ImageGenerationInputImage } from "./ImageGenerationInputImage";
-export type ImageGenerationItem = { id: string, status: string, revisedPrompt: string | null, transparentBackground?: boolean, failure: ImageGenerationFailure | null, savedPath?: AbsolutePathBuf, } & ({ fileId: string, } | { result: string, });
+export type ImageGenerationItem = { id: string, status: string, revisedPrompt: string | null, transparentBackground?: boolean, failure: ImageGenerationFailure | null, savedPath?: AbsolutePathBuf,
+/**
+ * Observed local inputs for a completed generation, absent on older items.
+ */
+inputImages?: Array<ImageGenerationInputImage>, } & ({ fileId: string, } | { result: string, });
diff --git a/codex-rs/app-server-protocol/schema/typescript/index.ts b/codex-rs/app-server-protocol/schema/typescript/index.ts
index 79f9f52ffc..3135f430e9 100644
--- a/codex-rs/app-server-protocol/schema/typescript/index.ts
+++ b/codex-rs/app-server-protocol/schema/typescript/index.ts
@@ -39,6 +39,7 @@ export type { GitDiffToRemoteResponse } from "./GitDiffToRemoteResponse";
export type { GitSha } from "./GitSha";
export type { ImageDetail } from "./ImageDetail";
export type { ImageGenerationFailure } from "./ImageGenerationFailure";
+export type { ImageGenerationInputImage } from "./ImageGenerationInputImage";
export type { ImageGenerationItem } from "./ImageGenerationItem";
export type { InitializeCapabilities } from "./InitializeCapabilities";
export type { InitializeParams } from "./InitializeParams";
diff --git a/codex-rs/app-server-protocol/src/protocol/thread_history.rs b/codex-rs/app-server-protocol/src/protocol/thread_history.rs
index 2a685e7335..8fb3a38f5d 100644
--- a/codex-rs/app-server-protocol/src/protocol/thread_history.rs
+++ b/codex-rs/app-server-protocol/src/protocol/thread_history.rs
@@ -28,6 +28,8 @@ use crate::protocol::v2::WebSearchAction;
use crate::protocol::v2::WebSearchItem;
use crate::protocol::v2::web_search_action_from_core;
use codex_extension_items::image_generation::GeneratedImageRef;
+#[cfg(test)]
+use codex_extension_items::image_generation::ImageGenerationInputImage;
use codex_extension_items::image_generation::ImageGenerationItem;
use codex_protocol::items::parse_hook_prompt_message;
use codex_protocol::protocol::AgentMessageEvent;
@@ -906,6 +908,7 @@ impl ThreadHistoryBuilder {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
});
@@ -921,6 +924,7 @@ impl ThreadHistoryBuilder {
transparent_background: payload.transparent_background,
failure: payload.failure.clone(),
saved_path: payload.saved_path.clone(),
+ input_images: payload.input_images.clone(),
imagegen_request_id: None,
generation_id: None,
});
@@ -2333,6 +2337,10 @@ mod tests {
let turn_id = "turn-1";
let thread_id = ThreadId::new();
let saved_path = test_path_buf("/tmp/image-1.png").abs();
+ let input_images = vec![ImageGenerationInputImage {
+ path: test_path_buf("/tmp/reference.png").abs(),
+ sha256: "ab".repeat(32),
+ }];
let events = vec![
EventMsg::TurnStarted(TurnStartedEvent {
turn_attribution: None,
@@ -2357,6 +2365,7 @@ mod tests {
transparent_background: Some(true),
failure: None,
saved_path: Some(saved_path.clone()),
+ input_images: input_images.clone(),
imagegen_request_id: None,
generation_id: None,
},
@@ -2378,6 +2387,10 @@ mod tests {
let items = events
.into_iter()
.map(RolloutItem::EventMsg)
+ .map(|item| {
+ serde_json::from_value(serde_json::to_value(item).expect("serialize rollout"))
+ .expect("deserialize rollout")
+ })
.collect::<Vec<_>>();
let turns = build_turns_from_rollout_items(&items);
@@ -2394,6 +2407,7 @@ mod tests {
transparent_background: Some(true),
failure: None,
saved_path: Some(saved_path),
+ input_images,
imagegen_request_id: None,
generation_id: None,
})]
@@ -2689,6 +2703,10 @@ mod tests {
},
),
saved_path: Some(test_path_buf("/tmp/ig_123.png").abs()),
+ input_images: vec![ImageGenerationInputImage {
+ path: test_path_buf("/tmp/reference.png").abs(),
+ sha256: "ab".repeat(32),
+ }],
})),
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
root_turn_id: None,
@@ -2739,6 +2757,10 @@ mod tests {
},
),
saved_path: Some(test_path_buf("/tmp/ig_123.png").abs()),
+ input_images: vec![ImageGenerationInputImage {
+ path: test_path_buf("/tmp/reference.png").abs(),
+ sha256: "ab".repeat(32),
+ }],
imagegen_request_id: None,
generation_id: None,
}),
diff --git a/codex-rs/app-server-protocol/src/protocol/v2/item.rs b/codex-rs/app-server-protocol/src/protocol/v2/item.rs
index 0fbc99088b..bde4c2aa87 100644
--- a/codex-rs/app-server-protocol/src/protocol/v2/item.rs
+++ b/codex-rs/app-server-protocol/src/protocol/v2/item.rs
@@ -17,6 +17,7 @@ use codex_experimental_api_macros::ExperimentalApi;
use codex_extension_items::ExtensionItem;
pub use codex_extension_items::image_generation::GeneratedImageRef;
pub use codex_extension_items::image_generation::ImageGenerationFailure;
+pub use codex_extension_items::image_generation::ImageGenerationInputImage;
pub use codex_extension_items::image_generation::ImageGenerationItem;
pub use codex_extension_items::sleep::SleepItem;
pub use codex_extension_items::web_search::WebSearchAction;
@@ -1016,6 +1017,7 @@ impl From<CoreTurnItem> for ThreadItem {
transparent_background: None,
failure: None,
saved_path: image.saved_path,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
})
diff --git a/codex-rs/app-server/src/request_processors/thread_resume_redaction.rs b/codex-rs/app-server/src/request_processors/thread_resume_redaction.rs
index 92027dc4ff..9238d91f67 100644
--- a/codex-rs/app-server/src/request_processors/thread_resume_redaction.rs
+++ b/codex-rs/app-server/src/request_processors/thread_resume_redaction.rs
@@ -116,6 +116,7 @@ mod tests {
transparent_background: None,
failure: None,
saved_path: Some(test_path_buf("/tmp/ig-1.png").abs()),
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
}),
diff --git a/codex-rs/app-server/tests/suite/v2/imagegen_extension.rs b/codex-rs/app-server/tests/suite/v2/imagegen_extension.rs
index 67c6c75304..4d531a7776 100644
--- a/codex-rs/app-server/tests/suite/v2/imagegen_extension.rs
+++ b/codex-rs/app-server/tests/suite/v2/imagegen_extension.rs
@@ -9,6 +9,7 @@ use app_test_support::TestAppServer;
use app_test_support::write_chatgpt_auth;
use codex_app_server_protocol::GeneratedImageRef;
use codex_app_server_protocol::ImageGenerationFailure;
+use codex_app_server_protocol::ImageGenerationInputImage;
use codex_app_server_protocol::ImageGenerationItem;
use codex_app_server_protocol::ImageReference as V2ImageReference;
use codex_app_server_protocol::ItemCompletedNotification;
@@ -24,10 +25,13 @@ use codex_app_server_protocol::TurnStartResponse;
use codex_app_server_protocol::UserInput as V2UserInput;
use codex_config::types::AuthCredentialsStoreMode;
use codex_features::Feature;
+use codex_utils_absolute_path::AbsolutePathBuf;
use core_test_support::responses;
use core_test_support::skip_if_remote;
use pretty_assertions::assert_eq;
use serde_json::json;
+use sha2::Digest;
+use sha2::Sha256;
use tempfile::TempDir;
use test_case::test_case;
use tokio::time::timeout;
@@ -264,11 +268,46 @@ async fn standalone_image_generation_returns_saved_path_hint_to_model(
Ok(())
}
+#[derive(Clone, Copy)]
+enum ImagegenInput {
+ PromptOnly,
+ ReferencedFile,
+}
+
+#[test_case(ImagegenInput::PromptOnly; "prompt_only")]
+#[test_case(ImagegenInput::ReferencedFile; "referenced_file")]
#[tokio::test]
-async fn transparent_image_preserves_output_metadata_and_persisted_history() -> Result<()> {
+async fn transparent_image_preserves_output_metadata_and_persisted_history(
+ input: ImagegenInput,
+) -> Result<()> {
let call_id = "transparent-image-run-1";
let server = responses::start_mock_server().await;
- mount_image_response_with_background(&server, "transparent").await;
+ let codex_home = TempDir::new()?;
+ let mut arguments = json!({
+ "prompt": "a blue whale on a transparent background",
+ "transparent_background": true,
+ });
+ let expected_inputs = match input {
+ ImagegenInput::PromptOnly => {
+ mount_image_response_with_background(&server, "transparent").await;
+ Vec::new()
+ }
+ ImagegenInput::ReferencedFile => {
+ skip_if_remote!(
+ Ok(()),
+ "remote executors use different imagegen storage approaches, so host-local image paths are unavailable"
+ );
+ let path =
+ AbsolutePathBuf::from_absolute_path(codex_home.path().join("reference.png"))?;
+ std::fs::write(path.as_path(), TINY_PNG_BYTES)?;
+ arguments["referenced_image_paths"] = json!([path]);
+ mount_image_edit_response(&server).await;
+ vec![ImageGenerationInputImage {
+ path,
+ sha256: format!("{:x}", Sha256::digest(TINY_PNG_BYTES)),
+ }]
+ }
+ };
responses::mount_sse_sequence(
&server,
vec![
@@ -278,11 +317,7 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
call_id,
"image_gen",
"imagegen",
- &json!({
- "prompt": "a blue whale on a transparent background",
- "transparent_background": true,
- })
- .to_string(),
+ &arguments.to_string(),
),
responses::ev_completed("resp-1"),
]),
@@ -294,7 +329,6 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
)
.await;
- let codex_home = TempDir::new()?;
create_config_toml(codex_home.path(), &server.uri(), ImagegenTestMode::Direct)?;
write_chatgpt_auth(
codex_home.path(),
@@ -323,6 +357,7 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
status,
image,
transparent_background,
+ input_images,
..
}) = completed.item
else {
@@ -336,6 +371,7 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
}
);
assert_eq!(transparent_background, Some(true));
+ assert_eq!(input_images, expected_inputs);
drop(mcp);
let mut resumed = TestAppServer::builder()
@@ -361,6 +397,7 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
})
.context("persisted legacy history should contain the generated image")?;
assert_eq!(persisted_image.transparent_background, Some(true));
+ assert_eq!(persisted_image.input_images, expected_inputs);
let resume_id = resumed
.send_thread_resume_request(ThreadResumeParams {
@@ -380,6 +417,7 @@ async fn transparent_image_preserves_output_metadata_and_persisted_history() ->
})
.context("resumed legacy history should contain the generated image")?;
assert_eq!(resumed_image.transparent_background, Some(true));
+ assert_eq!(resumed_image.input_images, expected_inputs);
Ok(())
}
@@ -519,12 +557,31 @@ async fn invalid_transparent_background_does_not_dispatch(
Ok(())
}
+#[test_case(ImagegenInput::PromptOnly; "prompt_only")]
+#[test_case(ImagegenInput::ReferencedFile; "referenced_file")]
#[tokio::test]
-async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()> {
+async fn standalone_image_generation_failure_emits_terminal_item(
+ input: ImagegenInput,
+) -> Result<()> {
let call_id = "image-run-failed";
let server = responses::start_mock_server().await;
+ let codex_home = TempDir::new()?;
+ let mut arguments = json!({"prompt": "paint a blue whale"});
+ let image_endpoint = match input {
+ ImagegenInput::PromptOnly => "/api/codex/images/generations",
+ ImagegenInput::ReferencedFile => {
+ skip_if_remote!(
+ Ok(()),
+ "remote executors use different imagegen storage approaches, so host-local image paths are unavailable"
+ );
+ let input_path = codex_home.path().join("reference.png");
+ std::fs::write(&input_path, TINY_PNG_BYTES)?;
+ arguments["referenced_image_paths"] = json!([input_path]);
+ "/api/codex/images/edits"
+ }
+ };
Mock::given(method("POST"))
- .and(path("/api/codex/images/generations"))
+ .and(path(image_endpoint))
.respond_with(
ResponseTemplate::new(500)
.insert_header("x-codex-imagegen-request-id", "req-imagegen-failed-123")
@@ -542,7 +599,7 @@ async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()>
call_id,
"image_gen",
"imagegen",
- &json!({"prompt": "paint a blue whale"}).to_string(),
+ &arguments.to_string(),
),
responses::ev_completed("resp-1"),
]),
@@ -554,7 +611,6 @@ async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()>
)
.await;
- let codex_home = TempDir::new()?;
create_config_toml(codex_home.path(), &server.uri(), ImagegenTestMode::Direct)?;
write_chatgpt_auth(
codex_home.path(),
@@ -585,6 +641,7 @@ async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()>
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
})
@@ -768,9 +825,11 @@ async fn standalone_image_edit_uses_attached_model_visible_image(
"remote executors use different imagegen storage approaches, so host-local image paths are unavailable"
);
- let (edit_request, _) = run_image_edit_test(|codex_home| {
+ let mut expected_input_path = None;
+ let (edit_request, completed_image) = run_image_edit_test(|codex_home| {
let image_path = codex_home.join("attached.png");
std::fs::write(&image_path, TINY_PNG_BYTES)?;
+ expected_input_path = Some(AbsolutePathBuf::from_absolute_path(&image_path)?);
let mut arguments = imagegen_arguments("add a red hat", requested_transparent_background);
arguments["referenced_image_paths"] = json!([image_path.display().to_string()]);
Ok((
@@ -800,6 +859,14 @@ async fn standalone_image_edit_uses_attached_model_visible_image(
})
);
+ assert_eq!(
+ completed_image.input_images,
+ vec![ImageGenerationInputImage {
+ path: expected_input_path.expect("input path"),
+ sha256: format!("{:x}", Sha256::digest(TINY_PNG_BYTES)),
+ }]
+ );
+
Ok(())
}
diff --git a/codex-rs/app-server/tests/suite/v2/thread_resume.rs b/codex-rs/app-server/tests/suite/v2/thread_resume.rs
index a3870ea7ac..20649549fd 100644
--- a/codex-rs/app-server/tests/suite/v2/thread_resume.rs
+++ b/codex-rs/app-server/tests/suite/v2/thread_resume.rs
@@ -2900,6 +2900,7 @@ fn append_resume_redaction_history(
transparent_background: None,
failure: None,
saved_path: Some(test_absolute_path("/tmp/ig-1.png")),
+ input_images: Vec::new(),
}),
]
.into_iter()
diff --git a/codex-rs/core/src/tools/handlers/extension_tools.rs b/codex-rs/core/src/tools/handlers/extension_tools.rs
index 784f7abfdf..793bc97925 100644
--- a/codex-rs/core/src/tools/handlers/extension_tools.rs
+++ b/codex-rs/core/src/tools/handlers/extension_tools.rs
@@ -576,6 +576,7 @@ mod tests {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
});
@@ -589,6 +590,7 @@ mod tests {
transparent_background: Some(true),
failure: None,
saved_path: Some(expected_path.clone()),
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
});
@@ -616,6 +618,7 @@ mod tests {
transparent_background: Some(true),
failure: None,
saved_path: Some(expected_path.clone()),
+ input_images: Vec::new(),
})],
},
)
diff --git a/codex-rs/ext/image-generation/Cargo.toml b/codex-rs/ext/image-generation/Cargo.toml
index 0c74fddf12..7bb334e22d 100644
--- a/codex-rs/ext/image-generation/Cargo.toml
+++ b/codex-rs/ext/image-generation/Cargo.toml
@@ -33,8 +33,11 @@ http = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
+sha2 = { workspace = true }
tracing = { workspace = true }
[dev-dependencies]
+image = { workspace = true, features = ["png"] }
pretty_assertions = { workspace = true }
-tokio = { workspace = true, features = ["macros", "rt"] }
+tempfile = { workspace = true }
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
diff --git a/codex-rs/ext/image-generation/src/tests.rs b/codex-rs/ext/image-generation/src/tests.rs
index 97a3adc452..8adc858b5d 100644
--- a/codex-rs/ext/image-generation/src/tests.rs
+++ b/codex-rs/ext/image-generation/src/tests.rs
@@ -1,10 +1,14 @@
+use base64::Engine;
use codex_api::ImageBackground;
use codex_api::ImageEditRequest;
use codex_api::ImageGenerationRequest;
use codex_api::ImageQuality;
+use codex_exec_server::FileSystemEnvironmentAccessor;
+use codex_exec_server::LOCAL_FS;
use codex_extension_api::ToolOutput;
use codex_extension_api::ToolPayload;
use codex_extension_api::ToolSpec;
+use codex_extension_items::image_generation::ImageGenerationInputImage;
use codex_protocol::ResponseItemId;
use codex_protocol::models::ContentItem;
use codex_protocol::models::DEFAULT_IMAGE_DETAIL;
@@ -15,12 +19,17 @@ use codex_protocol::models::ImageReference;
use codex_protocol::models::ResponseInputItem;
use codex_protocol::models::ResponseItem;
use codex_tools::ResponsesApiNamespaceTool;
+use codex_tools::ToolEnvironment;
use codex_utils_absolute_path::AbsolutePathBuf;
+use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
+use sha2::Digest;
+use sha2::Sha256;
use super::GeneratedImageOutput;
use super::ImageRequest;
use super::ImagegenArgs;
+use super::PreparedImageRequest;
use super::imagegen_tool_spec;
use super::request_for_call_args;
use crate::IMAGE_GEN_NAMESPACE;
@@ -30,6 +39,97 @@ use crate::artifact::image_generation_output_hint;
const RESULT: &str = "cG5n";
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn referenced_files_record_the_exact_bytes_read_for_each_request() {
+ let directory = tempfile::tempdir().expect("temporary directory");
+ let root = AbsolutePathBuf::from_absolute_path(directory.path()).expect("absolute root");
+ let first = root.join("first.png");
+ let second = root.join("second.png");
+ let access = FileSystemEnvironmentAccessor::unrestricted(&LOCAL_FS);
+ let environment =
+ ToolEnvironment::new("test".to_string(), PathUri::from_abs_path(&root), &access);
+ let args = ImagegenArgs {
+ prompt: "combine the references".to_string(),
+ transparent_background: false,
+ referenced_image_paths: Some(vec![second.clone(), first.clone()]),
+ num_last_images_to_include: None,
+ };
+ let png = |color| {
+ let image = image::RgbaImage::from_pixel(1, 1, image::Rgba(color));
+ let mut bytes = std::io::Cursor::new(Vec::new());
+ image
+ .write_to(&mut bytes, image::ImageFormat::Png)
+ .expect("encode PNG");
+ bytes.into_inner()
+ };
+ let second_bytes = png([0, 255, 0, 255]);
+ std::fs::write(second.as_path(), &second_bytes).expect("write second image");
+ std::fs::write(root.join("unused.png").as_path(), png([0, 0, 255, 255]))
+ .expect("write unused image");
+
+ // Reusing a path after replacing its contents must produce a new observation.
+ for first_bytes in [png([255, 0, 0, 255]), png([255, 255, 0, 255])] {
+ std::fs::write(first.as_path(), &first_bytes).expect("write first image");
+ let inputs = [(&second, &second_bytes), (&first, &first_bytes)];
+ let expected = PreparedImageRequest {
+ request: ImageRequest::Edit(ImageEditRequest {
+ images: inputs
+ .iter()
+ .map(|(_, bytes)| ImageReference::Inline {
+ image_url: format!(
+ "data:image/png;base64,{}",
+ base64::engine::general_purpose::STANDARD.encode(bytes)
+ ),
+ })
+ .collect(),
+ prompt: args.prompt.clone(),
+ background: Some(ImageBackground::Opaque),
+ model: "gpt-image-2".to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images: inputs
+ .iter()
+ .map(|(path, bytes)| ImageGenerationInputImage {
+ path: (*path).clone(),
+ sha256: format!("{:x}", Sha256::digest(bytes)),
+ })
+ .collect(),
+ };
+ assert_eq!(
+ request_for_call_args(&args, &[], std::slice::from_ref(&environment))
+ .await
+ .expect("edit request"),
+ expected
+ );
+ }
+}
+
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn unreadable_or_invalid_reference_does_not_build_an_edit_request() {
+ let directory = tempfile::tempdir().expect("temporary directory");
+ let root = AbsolutePathBuf::from_absolute_path(directory.path()).expect("absolute root");
+ let invalid = root.join("invalid.png");
+ std::fs::write(invalid.as_path(), b"not an image").expect("write invalid image");
+ let access = FileSystemEnvironmentAccessor::unrestricted(&LOCAL_FS);
+ let environment =
+ ToolEnvironment::new("test".to_string(), PathUri::from_abs_path(&root), &access);
+ for path in [root.join("missing.png"), invalid] {
+ let args = ImagegenArgs {
+ prompt: "edit the reference".to_string(),
+ transparent_background: false,
+ referenced_image_paths: Some(vec![path]),
+ num_last_images_to_include: None,
+ };
+ assert!(
+ request_for_call_args(&args, &[], std::slice::from_ref(&environment))
+ .await
+ .is_err()
+ );
+ }
+}
+
#[test]
fn artifact_path_sanitizes_session_and_call_ids() {
let save_root = AbsolutePathBuf::current_dir().expect("current directory should be absolute");
@@ -70,14 +170,17 @@ async fn omitted_references_generate_with_fixed_defaults() {
)
.await
.expect("generation request should build"),
- ImageRequest::Generate(ImageGenerationRequest {
- prompt: "paint a moonlit lake".to_string(),
- background: Some(ImageBackground::Opaque),
- model: "gpt-image-2".to_string(),
- n: None,
- quality: Some(ImageQuality::Auto),
- size: Some("auto".to_string()),
- })
+ PreparedImageRequest {
+ request: ImageRequest::Generate(ImageGenerationRequest {
+ prompt: "paint a moonlit lake".to_string(),
+ background: Some(ImageBackground::Opaque),
+ model: "gpt-image-2".to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images: Vec::new(),
+ }
);
}
@@ -166,10 +269,13 @@ async fn recent_image_fallback_selects_newest_images_in_chronological_order() {
)
.await
.expect("history-backed edit request should build"),
- ImageRequest::Edit(expected_edit_request(
- "change the lighting",
- &["user-2", "mcp", "code-mode", "generated", "standalone"],
- ))
+ PreparedImageRequest {
+ request: ImageRequest::Edit(expected_edit_request(
+ "change the lighting",
+ &["user-2", "mcp", "code-mode", "generated", "standalone"],
+ )),
+ input_images: Vec::new(),
+ }
);
}
@@ -206,17 +312,20 @@ async fn recent_image_fallback_passes_file_backed_image_to_edit_request() {
assert_eq!(
request,
- ImageRequest::Edit(ImageEditRequest {
- images: vec![ImageReference::File {
- file_id: "newer-file-backed-image".to_string(),
- }],
- prompt: "change the lighting".to_string(),
- background: Some(ImageBackground::Opaque),
- model: "gpt-image-2".to_string(),
- n: None,
- quality: Some(ImageQuality::Auto),
- size: Some("auto".to_string()),
- })
+ PreparedImageRequest {
+ request: ImageRequest::Edit(ImageEditRequest {
+ images: vec![ImageReference::File {
+ file_id: "newer-file-backed-image".to_string(),
+ }],
+ prompt: "change the lighting".to_string(),
+ background: Some(ImageBackground::Opaque),
+ model: "gpt-image-2".to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images: Vec::new(),
+ }
);
}
@@ -261,17 +370,20 @@ async fn recent_image_fallback_passes_file_backed_tool_output_to_edit_request()
assert_eq!(
request,
- ImageRequest::Edit(ImageEditRequest {
- images: vec![ImageReference::File {
- file_id: "newer-file-backed-image".to_string(),
- }],
- prompt: "change the lighting".to_string(),
- background: Some(ImageBackground::Opaque),
- model: "gpt-image-2".to_string(),
- n: None,
- quality: Some(ImageQuality::Auto),
- size: Some("auto".to_string()),
- })
+ PreparedImageRequest {
+ request: ImageRequest::Edit(ImageEditRequest {
+ images: vec![ImageReference::File {
+ file_id: "newer-file-backed-image".to_string(),
+ }],
+ prompt: "change the lighting".to_string(),
+ background: Some(ImageBackground::Opaque),
+ model: "gpt-image-2".to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images: Vec::new(),
+ }
);
}
diff --git a/codex-rs/ext/image-generation/src/tool.rs b/codex-rs/ext/image-generation/src/tool.rs
index 5623bb9a13..fb154371f7 100644
--- a/codex-rs/ext/image-generation/src/tool.rs
+++ b/codex-rs/ext/image-generation/src/tool.rs
@@ -24,6 +24,7 @@ use codex_extension_api::parse_tool_input_schema;
use codex_extension_items::ExtensionItem;
use codex_extension_items::image_generation::GeneratedImageRef;
use codex_extension_items::image_generation::ImageGenerationFailure;
+use codex_extension_items::image_generation::ImageGenerationInputImage;
use codex_extension_items::image_generation::ImageGenerationItem;
use codex_protocol::error::CodexErr;
use codex_protocol::error::CodexErrorDetails;
@@ -52,6 +53,8 @@ use schemars::r#gen::SchemaSettings;
use serde::Deserialize;
use serde_json::Map;
use serde_json::Value;
+use sha2::Digest;
+use sha2::Sha256;
use crate::IMAGE_GEN_NAMESPACE;
use crate::IMAGEGEN_TOOL_NAME;
@@ -110,6 +113,7 @@ fn legacy_end_event(item: &ImageGenerationItem) -> EventMsg {
transparent_background: item.transparent_background,
failure: item.failure.clone(),
saved_path: item.saved_path.clone(),
+ input_images: item.input_images.clone(),
})
}
@@ -151,9 +155,11 @@ impl ImageGenerationTool {
call: ToolCall<'_>,
) -> Result<Box<dyn ToolOutput>, FunctionCallError> {
let args = parse_args(&call)?;
- let request =
- request_for_call_args(&args, call.conversation_history.items(), &call.environments)
- .await?;
+ let PreparedImageRequest {
+ request,
+ input_images,
+ } = request_for_call_args(&args, call.conversation_history.items(), &call.environments)
+ .await?;
call.turn_item_emitter
.emit_started(extension_turn_item(
ImageGenerationItem {
@@ -166,6 +172,7 @@ impl ImageGenerationTool {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
},
@@ -226,6 +233,7 @@ impl ImageGenerationTool {
transparent_background: None,
failure,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id,
generation_id: None,
};
@@ -290,6 +298,7 @@ impl ImageGenerationTool {
transparent_background,
failure: None,
saved_path: saved_path.clone(),
+ input_images,
imagegen_request_id,
generation_id,
};
@@ -461,11 +470,22 @@ enum ImageRequest {
Edit(ImageEditRequest),
}
+#[derive(Debug, PartialEq)]
+struct PreparedImageRequest {
+ request: ImageRequest,
+ input_images: Vec<ImageGenerationInputImage>,
+}
+
+struct LoadedInputImage {
+ image: ImageReference,
+ identity: ImageGenerationInputImage,
+}
+
async fn request_for_call_args(
args: &ImagegenArgs,
history: &[ResponseItem],
environments: &[ToolEnvironment<'_>],
-) -> Result<ImageRequest, FunctionCallError> {
+) -> Result<PreparedImageRequest, FunctionCallError> {
let background = if args.transparent_background {
ImageBackground::Transparent
} else {
@@ -477,16 +497,20 @@ async fn request_for_call_args(
"`referenced_image_paths` must contain at most {MAX_EDIT_IMAGES} paths"
)));
}
+ let mut input_images = Vec::with_capacity(paths.len());
let images = match (paths.is_empty(), args.num_last_images_to_include) {
(true, None) => {
- return Ok(ImageRequest::Generate(ImageGenerationRequest {
- prompt: args.prompt.clone(),
- background: Some(background),
- model: IMAGE_MODEL.to_string(),
- n: None,
- quality: Some(ImageQuality::Auto),
- size: Some("auto".to_string()),
- }));
+ return Ok(PreparedImageRequest {
+ request: ImageRequest::Generate(ImageGenerationRequest {
+ prompt: args.prompt.clone(),
+ background: Some(background),
+ model: IMAGE_MODEL.to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images,
+ });
}
(false, None) => {
let Some(environment) = environments
@@ -499,7 +523,9 @@ async fn request_for_call_args(
};
let mut images = Vec::with_capacity(paths.len());
for path in paths {
- images.push(image_url(path, environment).await?);
+ let input = load_input_image(path, environment).await?;
+ images.push(input.image);
+ input_images.push(input.identity);
}
images
}
@@ -522,15 +548,18 @@ async fn request_for_call_args(
}
};
- Ok(ImageRequest::Edit(ImageEditRequest {
- images,
- prompt: args.prompt.clone(),
- background: Some(background),
- model: IMAGE_MODEL.to_string(),
- n: None,
- quality: Some(ImageQuality::Auto),
- size: Some("auto".to_string()),
- }))
+ Ok(PreparedImageRequest {
+ request: ImageRequest::Edit(ImageEditRequest {
+ images,
+ prompt: args.prompt.clone(),
+ background: Some(background),
+ model: IMAGE_MODEL.to_string(),
+ n: None,
+ quality: Some(ImageQuality::Auto),
+ size: Some("auto".to_string()),
+ }),
+ input_images,
+ })
}
fn recent_images(
@@ -606,10 +635,10 @@ fn output_images(output: &FunctionCallOutputPayload) -> impl Iterator<Item = &Im
})
}
-async fn image_url(
+async fn load_input_image(
path: &AbsolutePathBuf,
environment: &ToolEnvironment<'_>,
-) -> Result<ImageReference, FunctionCallError> {
+) -> Result<LoadedInputImage, FunctionCallError> {
let path_uri = PathUri::from_abs_path(path);
let bytes = environment
.fs()
@@ -621,6 +650,7 @@ async fn image_url(
path.display()
))
})?;
+ let sha256 = format!("{:x}", Sha256::digest(&bytes));
let image = load_for_prompt_bytes(path.as_path(), bytes, PromptImageMode::Original).map_err(
|error| {
FunctionCallError::RespondToModel(format!(
@@ -629,8 +659,14 @@ async fn image_url(
))
},
)?;
- Ok(ImageReference::Inline {
- image_url: image.into_data_url(),
+ Ok(LoadedInputImage {
+ image: ImageReference::Inline {
+ image_url: image.into_data_url(),
+ },
+ identity: ImageGenerationInputImage {
+ path: path.clone(),
+ sha256,
+ },
})
}
diff --git a/codex-rs/ext/items/src/image_generation.rs b/codex-rs/ext/items/src/image_generation.rs
index 8c10d17d50..59d4ece0b7 100644
--- a/codex-rs/ext/items/src/image_generation.rs
+++ b/codex-rs/ext/items/src/image_generation.rs
@@ -19,6 +19,16 @@ pub enum ImageGenerationFailure {
},
}
+/// A local image file successfully read for this exact image-generation request.
+#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+#[ts(rename_all = "camelCase")]
+pub struct ImageGenerationInputImage {
+ pub path: AbsolutePathBuf,
+ /// Lowercase SHA-256 of the file bytes read before image normalization.
+ pub sha256: String,
+}
+
// Standalone image-generation item owned by the image extension. This is also
// the field-level representation exposed by app-server; core and rollout
// persistence only carry it inside an ExtensionItem envelope.
@@ -39,6 +49,10 @@ pub struct ImageGenerationItem {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub saved_path: Option<AbsolutePathBuf>,
+ /// Observed local inputs for a completed generation, absent on older items.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ #[ts(as = "Option<_>", optional)]
+ pub input_images: Vec<ImageGenerationInputImage>,
/// Exact nested ImageGen request ID retained only for in-process analytics.
///
/// This is deliberately excluded from the extension/app-server wire shape
diff --git a/codex-rs/ext/items/src/tests.rs b/codex-rs/ext/items/src/tests.rs
index e0d8b07f72..ca26d9a581 100644
--- a/codex-rs/ext/items/src/tests.rs
+++ b/codex-rs/ext/items/src/tests.rs
@@ -4,10 +4,12 @@ use ts_rs::TS;
use super::ExtensionItem;
use super::image_generation::GeneratedImageRef;
+use super::image_generation::ImageGenerationInputImage;
use super::image_generation::ImageGenerationItem;
use super::sleep::SleepItem;
use super::web_search::WebSearchAction;
use super::web_search::WebSearchItem;
+use codex_utils_absolute_path::AbsolutePathBuf;
fn completed_image_generation_item() -> ExtensionItem {
ExtensionItem::ImageGeneration(ImageGenerationItem {
@@ -20,6 +22,7 @@ fn completed_image_generation_item() -> ExtensionItem {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
})
@@ -84,6 +87,7 @@ fn image_generation_item_reads_transitional_file_wire_shape() {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
});
@@ -126,6 +130,30 @@ fn image_generation_item_reads_transitional_file_wire_shape() {
);
}
+#[test]
+fn image_generation_input_images_survive_serialization() {
+ let ExtensionItem::ImageGeneration(mut image) = completed_image_generation_item() else {
+ panic!("expected image-generation item");
+ };
+ let path = AbsolutePathBuf::current_dir()
+ .expect("absolute cwd")
+ .join("reference.png");
+ image.input_images = vec![ImageGenerationInputImage {
+ path: path.clone(),
+ sha256: "ab".repeat(32),
+ }];
+ let item = ExtensionItem::ImageGeneration(image);
+ let value = serde_json::to_value(&item).expect("serialize image generation");
+ assert_eq!(
+ value["inputImages"],
+ json!([{"path": path, "sha256": "ab".repeat(32)}])
+ );
+ assert_eq!(
+ serde_json::from_value::<ExtensionItem>(value).expect("deserialize image generation"),
+ item
+ );
+}
+
#[test]
fn image_generation_item_preserves_authoritative_transparency() {
let ExtensionItem::ImageGeneration(mut image) = completed_image_generation_item() else {
diff --git a/codex-rs/protocol/src/legacy_events.rs b/codex-rs/protocol/src/legacy_events.rs
index 228d9e893c..3a04fdaec7 100644
--- a/codex-rs/protocol/src/legacy_events.rs
+++ b/codex-rs/protocol/src/legacy_events.rs
@@ -470,6 +470,7 @@ impl ImageGenerationItem {
transparent_background: None,
failure: None,
saved_path: self.saved_path.clone(),
+ input_images: Vec::new(),
})
}
}
diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs
index d2db6663a1..e2457f8104 100644
--- a/codex-rs/protocol/src/protocol.rs
+++ b/codex-rs/protocol/src/protocol.rs
@@ -67,6 +67,7 @@ use crate::turn_input::TurnInputSubmission;
use crate::turn_input::TurnStartOptions;
use codex_extension_items::image_generation::GeneratedImageRef;
use codex_extension_items::image_generation::ImageGenerationFailure;
+use codex_extension_items::image_generation::ImageGenerationInputImage;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use schemars::JsonSchema;
@@ -2936,6 +2937,9 @@ pub struct ImageGenerationEndEvent {
#[serde(skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub saved_path: Option<AbsolutePathBuf>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ #[ts(as = "Option<_>", optional)]
+ pub input_images: Vec<ImageGenerationInputImage>,
}
// Conversation kept for backward compatibility.
diff --git a/codex-rs/rollout/src/policy_tests.rs b/codex-rs/rollout/src/policy_tests.rs
index c8303f1a58..63f87b1d09 100644
--- a/codex-rs/rollout/src/policy_tests.rs
+++ b/codex-rs/rollout/src/policy_tests.rs
@@ -19,6 +19,7 @@ fn image_item(image: GeneratedImageRef) -> ImageGenerationItem {
transparent_background: Some(false),
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
}
@@ -67,6 +68,7 @@ fn legacy_image_generation_preserves_file_reference() {
transparent_background: Some(false),
failure: None,
saved_path: None,
+ input_images: Vec::new(),
});
let persisted = persisted_event_msg(&event, ThreadHistoryMode::Legacy)
diff --git a/codex-rs/thread-store/src/local/rollout_migration/legacy_event.rs b/codex-rs/thread-store/src/local/rollout_migration/legacy_event.rs
index 80176ddf6c..a90417c6c2 100644
--- a/codex-rs/thread-store/src/local/rollout_migration/legacy_event.rs
+++ b/codex-rs/thread-store/src/local/rollout_migration/legacy_event.rs
@@ -221,6 +221,7 @@ pub(super) fn completed_item(
transparent_background: event.transparent_background,
failure: event.failure.clone(),
saved_path: event.saved_path.clone(),
+ input_images: event.input_images.clone(),
imagegen_request_id: None,
generation_id: None,
})),
diff --git a/codex-rs/thread-store/src/local/rollout_migration_tests.rs b/codex-rs/thread-store/src/local/rollout_migration_tests.rs
index d67ad997a1..f3ef5849f0 100644
--- a/codex-rs/thread-store/src/local/rollout_migration_tests.rs
+++ b/codex-rs/thread-store/src/local/rollout_migration_tests.rs
@@ -11,6 +11,7 @@ use codex_app_server_protocol::build_turns_from_rollout_items;
use codex_extension_items::ExtensionItem;
use codex_extension_items::image_generation::GeneratedImageRef;
use codex_extension_items::image_generation::ImageGenerationFailure;
+use codex_extension_items::image_generation::ImageGenerationInputImage;
use codex_extension_items::image_generation::ImageGenerationItem;
use codex_protocol::AgentPath;
use codex_protocol::ResponseItemId;
@@ -50,6 +51,7 @@ use codex_rollout::RetainedContextEvent;
use codex_rollout::RolloutConfig;
use codex_rollout::RolloutItem;
use codex_rollout::RolloutLine;
+use codex_utils_absolute_path::AbsolutePathBuf;
use pretty_assertions::assert_eq;
use serde_json::json;
use tempfile::TempDir;
@@ -542,6 +544,7 @@ async fn migration_preserves_image_generation_failure_metadata() {
resets_at: Some(1_786_150_800),
}),
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
};
@@ -554,6 +557,70 @@ async fn migration_preserves_image_generation_failure_metadata() {
transparent_background: expected_item.transparent_background,
failure: expected_item.failure.clone(),
saved_path: expected_item.saved_path.clone(),
+ input_images: Vec::new(),
+ }));
+ let path = write_rollout(
+ home.path(),
+ thread_id,
+ SessionSource::Cli,
+ vec![
+ started("image-turn"),
+ image_completion,
+ completed("image-turn"),
+ ],
+ );
+ let store = indexed_store(home.path()).await;
+
+ store
+ .migrate_rollouts(apply_options())
+ .await
+ .expect("migrate legacy image completion");
+
+ let migrated_item = read_rollout(&path)
+ .into_iter()
+ .find_map(|line| match line.item {
+ RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => Some(event.item),
+ _ => None,
+ })
+ .expect("migrated image completion");
+ let TurnItem::Extension(ExtensionItem::ImageGeneration(migrated_item)) = migrated_item else {
+ panic!("expected migrated extension image-generation item");
+ };
+ assert_eq!(migrated_item, expected_item);
+}
+
+#[tokio::test]
+async fn migration_preserves_image_generation_input_observations() {
+ let home = TempDir::new().expect("create Codex home");
+ let thread_id = ThreadId::new();
+ let expected_item = ImageGenerationItem {
+ id: "image-call".to_string(),
+ status: "completed".to_string(),
+ revised_prompt: Some("paint a blue whale".to_string()),
+ image: GeneratedImageRef::Inline {
+ result: "cG5n".to_string(),
+ },
+ transparent_background: None,
+ failure: None,
+ saved_path: None,
+ input_images: vec![ImageGenerationInputImage {
+ path: AbsolutePathBuf::from_absolute_path(home.path().join("reference.png"))
+ .expect("absolute input path"),
+ sha256: "ab".repeat(32),
+ }],
+ imagegen_request_id: None,
+ generation_id: None,
+ };
+ let image_completion =
+ RolloutItem::EventMsg(EventMsg::ImageGenerationEnd(ImageGenerationEndEvent {
+ call_id: expected_item.id.clone(),
+ status: expected_item.status.clone(),
+ revised_prompt: expected_item.revised_prompt.clone(),
+ image: expected_item.image.clone(),
+ transparent_background: expected_item.transparent_background,
+ failure: expected_item.failure.clone(),
+ saved_path: expected_item.saved_path.clone(),
+ input_images: expected_item.input_images.clone(),
}));
let path = write_rollout(
home.path(),
diff --git a/codex-rs/tui/src/chatwidget/tests/helpers.rs b/codex-rs/tui/src/chatwidget/tests/helpers.rs
index 897d9f4d26..1b5451de87 100644
--- a/codex-rs/tui/src/chatwidget/tests/helpers.rs
+++ b/codex-rs/tui/src/chatwidget/tests/helpers.rs
@@ -863,6 +863,7 @@ pub(super) fn handle_image_generation_end(
transparent_background: None,
failure: None,
saved_path,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
}),
diff --git a/codex-rs/tui/src/thread_transcript/other_items_tests.rs b/codex-rs/tui/src/thread_transcript/other_items_tests.rs
index 2d27bd7137..de095cffce 100644
--- a/codex-rs/tui/src/thread_transcript/other_items_tests.rs
+++ b/codex-rs/tui/src/thread_transcript/other_items_tests.rs
@@ -131,6 +131,7 @@ fn tool_and_notice_projection_uses_normal_transcript_presentation() {
transparent_background: None,
failure: None,
saved_path: None,
+ input_images: Vec::new(),
imagegen_request_id: None,
generation_id: None,
};
diff --git a/sdk/python/src/openai_codex/generated/v2_all.py b/sdk/python/src/openai_codex/generated/v2_all.py
index 102cae18fd..b36a01b4b9 100644
--- a/sdk/python/src/openai_codex/generated/v2_all.py
+++ b/sdk/python/src/openai_codex/generated/v2_all.py
@@ -2102,6 +2102,17 @@ class ImageGenerationFailure(RootModel[UsageLimitExceededImageGenerationFailure]
root: UsageLimitExceededImageGenerationFailure
+class ImageGenerationInputImage(BaseModel):
+ model_config = ConfigDict(
+ populate_by_name=True,
+ )
+ path: AbsolutePathBuf
+ sha256: Annotated[
+ str,
+ Field(description="Lowercase SHA-256 of the file bytes read before image normalization."),
+ ]
+
+
class InAppBrowserRequirements(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -5530,6 +5541,13 @@ class FileIdThreadItem(BaseModel):
)
failure: ImageGenerationFailure | None = None
id: str
+ input_images: Annotated[
+ list[ImageGenerationInputImage] | None,
+ Field(
+ alias="inputImages",
+ description="Observed local inputs for a completed generation, absent on older items.",
+ ),
+ ] = None
revised_prompt: Annotated[str | None, Field(alias="revisedPrompt")] = None
saved_path: Annotated[AbsolutePathBuf | None, Field(alias="savedPath")] = None
status: str
@@ -5544,6 +5562,13 @@ class ResultThreadItem(BaseModel):
)
failure: ImageGenerationFailure | None = None
id: str
+ input_images: Annotated[
+ list[ImageGenerationInputImage] | None,
+ Field(
+ alias="inputImages",
+ description="Observed local inputs for a completed generation, absent on older items.",
+ ),
+ ] = None
revised_prompt: Annotated[str | None, Field(alias="revisedPrompt")] = None
saved_path: Annotated[AbsolutePathBuf | None, Field(alias="savedPath")] = None
status: str