diff --git a/codex-rs/core/src/tools/approvals.rs b/codex-rs/core/src/tools/approvals.rs index 4d9dfd9e02..693f37707a 100644 --- a/codex-rs/core/src/tools/approvals.rs +++ b/codex-rs/core/src/tools/approvals.rs @@ -9,7 +9,6 @@ use crate::sandboxing::SandboxPermissions; use crate::session::turn_context::TurnContext; use crate::tools::flat_tool_name; use crate::tools::sandboxing::ApprovalCtx; -use crate::tools::sandboxing::ToolCtx; use crate::tools::sandboxing::ToolError; use crate::tools::sandboxing::ToolRuntime; use codex_config::types::ApprovalsReviewer; @@ -193,9 +192,7 @@ pub(super) async fn resolve_tool_approval( req: &Rq, permission_request_run_id: &str, ctx: ApprovalCtx<'_>, - tool_ctx: &ToolCtx, reviewer: ApprovalReviewer, - otel: &codex_otel::SessionTelemetry, ) -> Result where T: ToolRuntime, @@ -214,7 +211,7 @@ where decision: ReviewDecision::Approved, source: ApprovalResolutionSource::Hook, }; - record_resolution(otel, tool_ctx, &resolution); + record_resolution(&ctx, &resolution); return resolution.into_tool_result(); } Some(PermissionRequestDecision::Deny { message }) => { @@ -222,7 +219,7 @@ where decision: ReviewDecision::denied(message), source: ApprovalResolutionSource::Hook, }; - record_resolution(otel, tool_ctx, &resolution); + record_resolution(&ctx, &resolution); return resolution.into_tool_result(); } None => {} @@ -245,7 +242,7 @@ where ), source: ApprovalResolutionSource::Guardian, }; - record_resolution(otel, tool_ctx, &resolution); + record_resolution(&ctx, &resolution); return resolution.into_tool_result(); } }; @@ -268,24 +265,20 @@ where decision: resolution, source, }; - record_resolution(otel, tool_ctx, &resolution); + record_resolution(&ctx, &resolution); resolution.into_tool_result() } -fn record_resolution( - otel: &codex_otel::SessionTelemetry, - tool_ctx: &ToolCtx, - resolution: &ApprovalResolution, -) { +fn record_resolution(ctx: &ApprovalCtx<'_>, resolution: &ApprovalResolution) { let source = match resolution.source { ApprovalResolutionSource::Hook => ToolDecisionSource::Config, ApprovalResolutionSource::Guardian => ToolDecisionSource::AutomatedReviewer, ApprovalResolutionSource::User => ToolDecisionSource::User, }; - let tool_name = flat_tool_name(&tool_ctx.tool_name); - otel.tool_decision( + let tool_name = flat_tool_name(ctx.tool_name); + ctx.turn.session_telemetry.tool_decision( tool_name.as_ref(), - &tool_ctx.call_id, + ctx.call_id, &resolution.decision, source, ); diff --git a/codex-rs/core/src/tools/orchestrator.rs b/codex-rs/core/src/tools/orchestrator.rs index b994c658f6..fbcbc596b5 100644 --- a/codex-rs/core/src/tools/orchestrator.rs +++ b/codex-rs/core/src/tools/orchestrator.rs @@ -171,6 +171,7 @@ impl ToolOrchestrator { session: &tool_ctx.session, turn: &tool_ctx.turn, call_id: &tool_ctx.call_id, + tool_name: &tool_ctx.tool_name, retry_reason: None, network_approval_context: None, }; @@ -179,9 +180,7 @@ impl ToolOrchestrator { req, tool_ctx.call_id.as_str(), approval_ctx, - tool_ctx, ApprovalReviewer::Guardian, - &otel, ) .await?; already_approved = true; @@ -202,6 +201,7 @@ impl ToolOrchestrator { session: &tool_ctx.session, turn: &tool_ctx.turn, call_id: &tool_ctx.call_id, + tool_name: &tool_ctx.tool_name, retry_reason: reason.clone(), network_approval_context: None, }; @@ -210,13 +210,11 @@ impl ToolOrchestrator { req, tool_ctx.call_id.as_str(), approval_ctx, - tool_ctx, if strict_auto_review { ApprovalReviewer::Guardian } else { ApprovalReviewer::for_turn(turn_ctx) }, - &otel, ) .await?; already_approved = true; @@ -397,6 +395,7 @@ impl ToolOrchestrator { session: &tool_ctx.session, turn: &tool_ctx.turn, call_id: &tool_ctx.call_id, + tool_name: &tool_ctx.tool_name, retry_reason: Some(retry_reason), network_approval_context: network_approval_context.clone(), }; @@ -407,13 +406,11 @@ impl ToolOrchestrator { req, &permission_request_run_id, approval_ctx, - tool_ctx, if strict_auto_review { ApprovalReviewer::Guardian } else { ApprovalReviewer::for_turn(turn_ctx) }, - &otel, ) .await?; } diff --git a/codex-rs/core/src/tools/sandboxing.rs b/codex-rs/core/src/tools/sandboxing.rs index 98332fd228..07bfeca90f 100644 --- a/codex-rs/core/src/tools/sandboxing.rs +++ b/codex-rs/core/src/tools/sandboxing.rs @@ -121,6 +121,7 @@ pub(crate) struct ApprovalCtx<'a> { pub session: &'a Arc, pub turn: &'a Arc, pub call_id: &'a str, + pub tool_name: &'a ToolName, pub retry_reason: Option, pub network_approval_context: Option, }