Include transparent background in image generation analytics (#40544)

## What changed

Add the optional `transparent_background` value to image generation event
parameters and populate it from the corresponding image generation item.

## Testing

Add reducer coverage for completed events with true, false, and unset values,
as well as failed events where the value is unset.

GitOrigin-RevId: a9ee13696acb34feb998b345f54889cac7a401d9
This commit is contained in:
alicec-oai authored and copyberry committed 2026-08-25 04:35:51 +00:00
1 parent 2e4675919e
commit 348f49b292
3 files changed
+74

No files matched your search

@@ -5092,6 +5092,78 @@ async fn turn_lifecycle_emits_turn_event() {
assert_eq!(payload["event_params"]["total_tokens"], json!(321));
}
#[tokio::test]
async fn image_generation_events_preserve_transparent_background_metadata() {
for (status, transparent_background) in [
("completed", Some(true)),
("completed", Some(false)),
("completed", None),
("failed", None),
] {
let mut reducer = AnalyticsReducer::default();
let mut out = Vec::new();
ingest_turn_prerequisites(
&mut reducer,
&mut out,
/*include_initialize*/ true,
/*include_resolved_config*/ true,
/*include_started*/ true,
/*include_token_usage*/ false,
)
.await;
let item = ThreadItem::ImageGeneration(ImageGenerationItem {
id: "image-1".to_string(),
status: status.to_string(),
revised_prompt: None,
result: "ok".to_string(),
transparent_background,
failure: None,
saved_path: None,
});
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemStarted(
ItemStartedNotification {
thread_id: "thread-2".to_string(),
turn_id: "turn-2".to_string(),
started_at_ms: 998,
item: item.clone(),
},
))),
&mut out,
)
.await;
reducer
.ingest(
AnalyticsFact::Notification(Box::new(ServerNotification::ItemCompleted(
ItemCompletedNotification {
thread_id: "thread-2".to_string(),
turn_id: "turn-2".to_string(),
completed_at_ms: 1_000,
item,
},
))),
&mut out,
)
.await;
let event = out
.iter()
.find(|event| matches!(event, TrackEventRequest::ImageGeneration(_)))
.expect("image generation event should be emitted");
let payload = serde_json::to_value(event).expect("serialize image generation event");
assert_eq!(
payload["event_params"].get("transparent_background"),
Some(&json!(transparent_background))
);
assert_eq!(payload["event_params"]["terminal_status"], json!(status));
}
}
#[tokio::test]
async fn turn_event_counts_completed_tool_items() {
let mut reducer = AnalyticsReducer::default();