mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +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
@@ -19,6 +19,7 @@ use crate::tools::context::FunctionToolOutput;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::context::ToolOutput;
|
||||
use crate::tools::context::ToolPayload;
|
||||
use crate::tools::control_tool_analytics::ControlToolCallGuard;
|
||||
use crate::tools::flat_tool_name;
|
||||
use crate::tools::handlers::multi_agents_spec::MULTI_AGENT_V1_NAMESPACE;
|
||||
use crate::tools::hook_names::HookToolName;
|
||||
@@ -27,6 +28,7 @@ use crate::tools::lifecycle::notify_tool_start;
|
||||
use crate::tools::router::tool_log_payload;
|
||||
use crate::tools::tool_dispatch_trace::ToolDispatchTrace;
|
||||
use crate::util::error_or_panic;
|
||||
use codex_analytics::ControlToolCallStatus;
|
||||
use codex_extension_api::ToolCallOutcome;
|
||||
use codex_protocol::models::FunctionCallOutputPayload;
|
||||
use codex_protocol::models::ResponseInputItem;
|
||||
@@ -51,6 +53,11 @@ pub use codex_tools::ToolExposure;
|
||||
/// Implementers provide the shared `ToolExecutor` behavior plus optional
|
||||
/// core-owned metadata for hooks, telemetry, tool search, and argument diffs.
|
||||
pub(crate) trait CoreToolRuntime: ToolExecutor<ToolInvocation> {
|
||||
/// Whether this built-in control tool needs a structured tool-call event.
|
||||
fn is_builtin_control_tool(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns a shared spec when both the spec and search metadata are immutable.
|
||||
fn immutable_spec(&self) -> Option<&Arc<ToolSpec>> {
|
||||
None
|
||||
@@ -577,6 +584,10 @@ impl ToolRegistry {
|
||||
.await
|
||||
{
|
||||
PreToolUseHookResult::Blocked(message) => {
|
||||
if tool.is_builtin_control_tool() {
|
||||
let mut analytics = ControlToolCallGuard::new(&invocation);
|
||||
analytics.finish(ControlToolCallStatus::Rejected);
|
||||
}
|
||||
let err = FunctionCallError::RespondToModel(message);
|
||||
dispatch_trace.record_failed(&err);
|
||||
notify_tool_finish_if_unclaimed(
|
||||
@@ -594,6 +605,10 @@ impl ToolRegistry {
|
||||
invocation = updated_invocation;
|
||||
}
|
||||
Err(err) => {
|
||||
if tool.is_builtin_control_tool() {
|
||||
let mut analytics = ControlToolCallGuard::new(&invocation);
|
||||
analytics.finish(ControlToolCallStatus::Failed);
|
||||
}
|
||||
dispatch_trace.record_failed(&err);
|
||||
notify_tool_finish_if_unclaimed(
|
||||
&invocation,
|
||||
@@ -613,6 +628,9 @@ impl ToolRegistry {
|
||||
}
|
||||
|
||||
notify_tool_start(&invocation).await;
|
||||
let mut control_tool_analytics = tool
|
||||
.is_builtin_control_tool()
|
||||
.then(|| ControlToolCallGuard::new(&invocation));
|
||||
|
||||
if let Some(command) = shell_script_for_invocation(&invocation) {
|
||||
let parsed = parse_shell_script(&command);
|
||||
@@ -663,6 +681,13 @@ impl ToolRegistry {
|
||||
Ok((_, success)) => *success,
|
||||
Err(_) => false,
|
||||
};
|
||||
if let Some(analytics) = control_tool_analytics.as_mut() {
|
||||
analytics.finish(if success {
|
||||
ControlToolCallStatus::Completed
|
||||
} else {
|
||||
ControlToolCallStatus::Failed
|
||||
});
|
||||
}
|
||||
emit_metric_for_tool_read(&invocation, success);
|
||||
let post_tool_use_payload = if success {
|
||||
let guard = response_cell.lock().await;
|
||||
|
||||
Reference in new issue
Block a user