Preserve response IDs for fast collaborator tool events (#42752)

## Why

Collaborator tools can finish before their sampling response arrives, causing
their analytics events to be emitted without response correlation.

## What changed

Hold completed collaborator tool events until the reducer can attach their
originating and subsequent response IDs.

## Testing

Add coverage for both orderings of collaborator completion and sampling
response arrival.

GitOrigin-RevId: 5933424dd90702685cdb4a9693fed96c7885989a
This commit is contained in:
jif authored and copyberry committed 2026-09-04 12:39:40 +00:00
1 parent a1294e57f1
commit 1cd78651e2
2 files changed
+96 -2

No files matched your search

+9 -1
View File
@@ -1966,12 +1966,20 @@ impl AnalyticsReducer {
.get(&notification.turn_id)
.and_then(|turn| turn.resolved_config.as_ref())
.and_then(|config| config.turn_metadata.root_turn_id());
// Fast collaborator tools can complete before their sampling response.
// Keep the event until that response can supply its originating ID.
let emission =
if matches!(&notification.item, ThreadItem::CollabAgentToolCall { .. }) {
ToolEventEmission::AwaitResponse
} else {
ToolEventEmission::ImmediateUnlessCorrelated
};
self.record_tool_event(
&notification.thread_id,
&notification.turn_id,
root_turn_id,
event,
ToolEventEmission::ImmediateUnlessCorrelated,
emission,
out,
);
}