mirror of
https://github.com/openai/codex.git
synced 2026-11-25 15:24:26 +00:00
Track built-in control tool calls in analytics (#39510)
## What changed - Emit `codex_control_tool_call_event` for built-in control tools such as `request_user_input`, `update_plan`, `view_image`, and goal tools. - Record correlation and timing metadata plus completed, failed, rejected, or interrupted outcomes, and include these calls in turn-level tool counts. - Keep tool arguments out of control-tool analytics events. ## Testing - Extend the app-server turn profile test to cover successful and failed control tools, event correlation, turn counts, and argument exclusion. GitOrigin-RevId: c20f73dfb79654e31b4b5040eddb0e0d91cae10d
This commit is contained in:
1 parent
6972c57c78
commit
992f5c681f
13 files changed
+343
-9
No files matched your search
@@ -11,6 +11,8 @@ use crate::events::CodexCollabAgentToolCallEventRequest;
|
||||
use crate::events::CodexCommandExecutionEventParams;
|
||||
use crate::events::CodexCommandExecutionEventRequest;
|
||||
use crate::events::CodexCompactionEventRequest;
|
||||
use crate::events::CodexControlToolCallEventParams;
|
||||
use crate::events::CodexControlToolCallEventRequest;
|
||||
use crate::events::CodexDynamicToolCallEventParams;
|
||||
use crate::events::CodexDynamicToolCallEventRequest;
|
||||
use crate::events::CodexFileChangeEventParams;
|
||||
@@ -82,6 +84,8 @@ use crate::facts::CodeModeToolCallFact;
|
||||
use crate::facts::CodeModeToolCallStatus;
|
||||
use crate::facts::CodexCompactionEvent;
|
||||
use crate::facts::CodexGoalEvent;
|
||||
use crate::facts::ControlToolCallFact;
|
||||
use crate::facts::ControlToolCallStatus;
|
||||
use crate::facts::CustomAnalyticsFact;
|
||||
use crate::facts::ExternalAgentConfigImportCompletedInput;
|
||||
use crate::facts::ExternalAgentConfigImportFailureInput;
|
||||
@@ -589,6 +593,9 @@ impl AnalyticsReducer {
|
||||
CustomAnalyticsFact::CodeModeToolCall(input) => {
|
||||
self.ingest_code_mode_tool_call(input, out);
|
||||
}
|
||||
CustomAnalyticsFact::ControlToolCall(input) => {
|
||||
self.ingest_control_tool_call(input, out);
|
||||
}
|
||||
CustomAnalyticsFact::SubAgentThreadStarted(input) => {
|
||||
self.ingest_subagent_thread_started(input, out);
|
||||
}
|
||||
@@ -833,6 +840,83 @@ impl AnalyticsReducer {
|
||||
}
|
||||
}
|
||||
|
||||
fn ingest_control_tool_call(
|
||||
&mut self,
|
||||
input: ControlToolCallFact,
|
||||
out: &mut Vec<TrackEventRequest>,
|
||||
) {
|
||||
let ControlToolCallFact {
|
||||
thread_id,
|
||||
turn_id,
|
||||
call_id,
|
||||
cell_id,
|
||||
tool_name,
|
||||
started_at_ms,
|
||||
completed_at_ms,
|
||||
status,
|
||||
} = input;
|
||||
let drop_site = AnalyticsDropSite {
|
||||
event_name: "control tool",
|
||||
thread_id: &thread_id,
|
||||
turn_id: Some(&turn_id),
|
||||
review_id: None,
|
||||
item_id: Some(&call_id),
|
||||
};
|
||||
let Some((connection_state, thread_state, thread_metadata)) =
|
||||
self.thread_context_or_warn(drop_site)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let mut base = tool_item_base(
|
||||
&thread_id,
|
||||
&turn_id,
|
||||
call_id,
|
||||
tool_name,
|
||||
ToolItemOutcome {
|
||||
terminal_status: match status {
|
||||
ControlToolCallStatus::Completed => ToolItemTerminalStatus::Completed,
|
||||
ControlToolCallStatus::Failed => ToolItemTerminalStatus::Failed,
|
||||
ControlToolCallStatus::Rejected => ToolItemTerminalStatus::Rejected,
|
||||
ControlToolCallStatus::Interrupted => ToolItemTerminalStatus::Interrupted,
|
||||
},
|
||||
failure_kind: match status {
|
||||
ControlToolCallStatus::Failed => Some(ToolItemFailureKind::ToolError),
|
||||
ControlToolCallStatus::Rejected => Some(ToolItemFailureKind::PolicyForbidden),
|
||||
ControlToolCallStatus::Completed | ControlToolCallStatus::Interrupted => None,
|
||||
},
|
||||
execution_duration_ms: observed_duration_ms(started_at_ms, completed_at_ms),
|
||||
},
|
||||
ToolItemContext {
|
||||
started_at_ms,
|
||||
completed_at_ms,
|
||||
connection_state,
|
||||
thread_state,
|
||||
thread_metadata,
|
||||
review_summary: None,
|
||||
},
|
||||
);
|
||||
base.cell_id = cell_id;
|
||||
let event = TrackEventRequest::ControlToolCall(CodexControlToolCallEventRequest {
|
||||
event_type: "codex_control_tool_call_event",
|
||||
event_params: CodexControlToolCallEventParams {
|
||||
base,
|
||||
success: status == ControlToolCallStatus::Completed,
|
||||
},
|
||||
});
|
||||
self.turns
|
||||
.entry(turn_id.clone())
|
||||
.or_default()
|
||||
.tool_counts
|
||||
.total += 1;
|
||||
self.record_tool_event(
|
||||
&thread_id,
|
||||
&turn_id,
|
||||
event,
|
||||
ToolEventEmission::AwaitResponse,
|
||||
out,
|
||||
);
|
||||
}
|
||||
|
||||
fn ingest_sampling_response_completed(
|
||||
&mut self,
|
||||
thread_id: String,
|
||||
@@ -2307,6 +2391,7 @@ fn tool_event_base_mut(event: &mut TrackEventRequest) -> Option<&mut CodexToolIt
|
||||
TrackEventRequest::FileChange(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::McpToolCall(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::DynamicToolCall(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::ControlToolCall(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::CollabAgentToolCall(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::WebSearch(event) => Some(&mut event.event_params.base),
|
||||
TrackEventRequest::ImageGeneration(event) => Some(&mut event.event_params.base),
|
||||
|
||||
Reference in new issue
Block a user