Track image generation request IDs in analytics (#40714)

## What changed

- Read `x-codex-imagegen-request-id` from image generation and edit responses.
- Propagate the ID to `codex_image_generation_event` analytics.
- Keep the ID in process only, excluding it from extension item serialization, generated types, app-server wire data, and rollout history.

## Testing

- Cover response-header extraction and missing-header behavior in the images client.
- Verify end-to-end analytics emission and the unchanged image-generation item wire shape.

GitOrigin-RevId: 9b8e09b7d655c0c2faa84f0eee99aabae583668d
This commit is contained in:
Chris Dong authored and copyberry committed 2026-08-25 21:38:10 +00:00
1 parent 1bc02aea50
commit 346c4db7c2
16 files changed
+124 -24

No files matched your search

@@ -34,6 +34,9 @@ use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
use super::analytics::mount_analytics_capture;
use super::analytics::wait_for_analytics_event;
const RESULT: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==";
const TINY_PNG_BYTES: &[u8] = &[
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 6, 0,
@@ -87,11 +90,7 @@ async fn standalone_image_generation_returns_saved_path_hint_to_model() -> Resul
let codex_home = TempDir::new()?;
create_config_toml(codex_home.path(), &server.uri(), ImagegenTestMode::Direct)?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("access-chatgpt"),
AuthCredentialsStoreMode::File,
)?;
mount_analytics_capture(&server, codex_home.path()).await?;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -183,6 +182,17 @@ async fn standalone_image_generation_returns_saved_path_hint_to_model() -> Resul
"standalone image generation should not emit the legacy developer-message hint"
);
let event = wait_for_analytics_event(
&server,
DEFAULT_READ_TIMEOUT,
"codex_image_generation_event",
)
.await?;
assert_eq!(
event["event_params"]["imagegen_request_id"],
json!("req-imagegen-123")
);
Ok(())
}
@@ -419,6 +429,7 @@ async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()>
transparent_background: None,
failure: None,
saved_path: None,
imagegen_request_id: None,
})
);
@@ -922,11 +933,15 @@ async fn mount_image_response(server: &MockServer) {
async fn mount_image_response_with_background(server: &MockServer, background: &str) {
Mock::given(method("POST"))
.and(path("/api/codex/images/generations"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"created": 1,
"background": background,
"data": [{"b64_json": RESULT}],
})))
.respond_with(
ResponseTemplate::new(200)
.insert_header("x-codex-imagegen-request-id", "req-imagegen-123")
.set_body_json(json!({
"created": 1,
"background": background,
"data": [{"b64_json": RESULT}],
})),
)
.expect(1)
.mount(server)
.await;