[rollout-trace] Add a trace ID to MCP calls. (#22326)

This allows us to connect individual tool calls to the logs of the
invocations.
This commit is contained in:
cassirer-openai authored and GitHub committed 2026-05-13 16:03:33 +00:00
1 parent 382404db99
commit 702e6a3c64
10 files changed
+265

No files matched your search

@@ -261,6 +261,12 @@ impl TraceReducer {
},
)?;
}
RawTraceEventPayload::McpToolCallCorrelationAssigned {
tool_call_id,
mcp_call_id,
} => {
self.assign_mcp_tool_call_correlation(tool_call_id, mcp_call_id)?;
}
RawTraceEventPayload::ToolCallRuntimeStarted {
tool_call_id,
runtime_payload,
@@ -7,6 +7,7 @@ use crate::model::CodeModeRuntimeToolId;
use crate::model::ConversationItemKind;
use crate::model::ExecutionStatus;
use crate::model::ExecutionWindow;
use crate::model::McpCallId;
use crate::model::ModelVisibleCallId;
use crate::model::ProducerRef;
use crate::model::ToolCall;
@@ -128,6 +129,7 @@ impl TraceReducer {
tool_call_id.clone(),
ToolCall {
tool_call_id: tool_call_id.clone(),
mcp_call_id: None,
model_visible_call_id,
code_mode_runtime_tool_id: started.code_mode_runtime_tool_id,
thread_id,
@@ -166,6 +168,21 @@ impl TraceReducer {
Ok(())
}
/// Attaches the bridge-visible MCP UUID after the generic tool call exists.
pub(super) fn assign_mcp_tool_call_correlation(
&mut self,
tool_call_id: ToolCallId,
mcp_call_id: McpCallId,
) -> Result<()> {
let Some(tool_call) = self.rollout.tool_calls.get_mut(&tool_call_id) else {
bail!("MCP correlation referenced unknown tool call {tool_call_id}");
};
if tool_call.mcp_call_id.replace(mcp_call_id).is_some() {
bail!("duplicate MCP correlation for tool call {tool_call_id}");
}
Ok(())
}
/// Completes the canonical tool call and any terminal operation driven by dispatch output.
///
/// Protocol-backed terminal tools end from runtime events; direct tools